Documentation
¶
Overview ¶
Package profile loads and validates profiles (PROFILE_FORMAT.md): JSON files that map the elements of one XML schema to the shared model. A loaded profile is immutable and safe for concurrent use.
Index ¶
- Constants
- func HasToken(v, t string) bool
- func Tokens(v string) map[string]bool
- type As
- type AttrTest
- type Declarer
- type Display
- type Error
- type KV
- type Level
- type Match
- type Path
- type Profile
- func (p *Profile) Anchored() bool
- func (p *Profile) ElementNamespace(uri string) string
- func (p *Profile) KeptAttrs() []QName
- func (p *Profile) Lookup(path Path) *Rule
- func (p *Profile) MatchesRoot(path Path, doctypePublic string) bool
- func (p *Profile) MaxSteps() int
- func (p *Profile) OfReads(name QName) []QName
- func (p *Profile) ReadsChildAttrs() bool
- func (p *Profile) TestedAttrs() []QName
- type QName
- type RestTable
- type Rule
- type Selector
- type Step
- type Test
- type TokenPath
- type Value
Constants ¶
const ( MaxProfileBytes = 4 << 20 MaxRules = 10000 MaxCells = 64 MaxHeaderBytes = 256 )
MaxProfileBytes bounds the size of a profile file; MaxRules its rules. MaxCells bounds the entries of a row's "cells" and a table's "header"; MaxHeaderBytes the text of one header cell.
const ( MediaHTML = "text/html" MediaXHTML = "application/xhtml+xml" // MediaOctetStream is the media type of an attachment that says none. MediaOctetStream = "application/octet-stream" )
Media types a "document" rule may hand over.
const ( OpExists = iota // [@a] OpEquals // [@a='v'] OpToken // [@a~='t'] )
Test operators of an attribute test.
const ( MaxSelectorBytes = 4096 MaxSteps = 64 )
MaxSelectorBytes bounds a selector's text, MaxSteps its steps.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type As ¶
type As uint8
As is a rule kind.
type Declarer ¶ added in v0.2.0
Declarer is a root path that can tell which namespaces its element declares.
type Match ¶
type Match struct {
Root QName
DoctypePublic string
Attr []AttrTest
// Declares: the root element declares this namespace URI, with any
// prefix or as the default ("declares").
Declares string
}
Match is one entry of "match".
type Path ¶
Path is the element being matched and its ancestors: index 0 is the element, 1 its parent, and so on. Attr of an ancestor need answer only for the names KeptAttrs lists.
type Profile ¶
type Profile struct {
Name string
Title string
HeadingBase int
Matches []Match
Rules []*Rule
// contains filtered or unexported fields
}
Profile is a loaded profile.
func (*Profile) ElementNamespace ¶
ElementNamespace returns the namespace an element of namespace uri is matched in: the target of "namespace_aliases", or uri itself.
func (*Profile) KeptAttrs ¶
KeptAttrs lists the attributes whose values a reader keeps on open elements: those that selectors test and those read from ancestors.
func (*Profile) MatchesRoot ¶
MatchesRoot reports whether the profile applies to a document whose root is root with attributes attrs (index 0 of path) and DOCTYPE public identifier doctypePublic.
func (*Profile) ReadsChildAttrs ¶
ReadsChildAttrs reports whether a rule reads an attribute of a child element ({"attr": ..., "child": ...}).
func (*Profile) TestedAttrs ¶
TestedAttrs lists every attribute a selector tests.
type QName ¶
type QName struct {
URI, Local string
}
QName is a namespace URI and a local name.
func ResolveName ¶
ResolveName resolves a prefixed or unprefixed name.
type RestTable ¶ added in v0.3.0
type RestTable struct {
Names string `json:"names"`
ID int `json:"id"`
Header []string `json:"header"`
}
RestTable is a "rest_table": the rows of names and values a row holds beyond its column cells, written as a table after the table. Names: "path" (relative to the row's element) or "local". ID: a column of the row whose text is the first cell of each of its rows (the line's id), 0 for none. Header: the table's header row, the profile's text.
type Rule ¶
type Rule struct {
Index int
Selector *Selector
As As
Kind gofastcore.Kind // block
PartKind gofastcore.PartKind
StoredKind string
Language string
Notation string
NoteType string
Style gofastcore.Style
Model string // rows or cals
Field string
Key string
Join string
AlsoHeading int
DuplicateOf string
OutOfLine bool // a block or note met inside an open block is a block of its own
// Split: met inside an open paragraph-like block, the element ends
// that block, is read on its own, and text after it starts a new
// block ("split"), as a table or image does.
Split bool
// Space: the element's text is set off by white space ("space",
// inline): a space is held before and after it, where the source has
// none, as between the fields of a name or a citation.
Space bool
Level Level
Ordered *Test
Header *Test
Colspan *QName
Rowspan *QName
Display *Display
Marker, Link, Title, ID, Alt, Name, Value, Anchor *Value
Attrs, Mark, Extra []KV
// Cells are the cells of a row made from its element's attributes
// ("cells", row). HeaderText is a header row of fixed text ("header",
// table).
Cells []*Value
HeaderText []string
// Heading: a section's heading from its own attributes, the first
// present and not empty ("heading", section: XLIFF file@original).
Heading []*Value
// HeadingAnchor: the child the section's anchor is read from is also
// its heading, where the child stands ("heading": "anchor": a PubMed
// record's PMID).
HeadingAnchor bool
// SectionTable: the section is also a table whose header row is
// HeaderText ("table_header", section: an XLIFF 2 file, whose rows
// have no table element of their own); its table block comes where
// the section ends.
SectionTable bool
// Column: a cell placed in this column (1-based) of the row it stands
// in, at any depth inside the row element ("column", cell). Rest: the
// column that takes the row's content no column cell takes ("rest",
// row). With: attributes of the element's own written after its text,
// each set off by a space ("with": unitCode, currencyID, schemeID).
// OneRow: the table's element is also its one row, filled by column
// cells ("one_row", table: CII's monetary summation).
Column int
Rest int
// ColumnKey: the cell's column is chosen by this attribute's value
// ("column_key", cell with "column"): each value as written has a
// column of its own, from Column on, in order of first appearance in
// the table, and its header cell is the value (TMX tuv@xml:lang).
ColumnKey *Value
With []*Value
OneRow bool
// Pairs: the table's element is read as names and values, a row for
// each element with text inside it and each of their attributes
// ("pairs", table: "path", "parent" (the path with the name of the
// table's parent element before it) or "local"). RestTable: what a row (or a
// one_row table) holds that no column cell takes is a table of names
// and values after the table ("rest_table", row and table).
Pairs string
// PairsEmpty: in a "pairs" table an element with no content and no
// attributes is a row of its name and an empty value ("pairs_empty").
PairsEmpty bool
RestTable *RestTable
// A "document" rule: the media type handed over, a constant
// (MediaType) or chosen by an attribute (MediaAttr, MediaMap: a value
// not in the map, or no attribute, and the rule does not apply).
// WhenMarkup: the rule applies only when the element's text holds
// markup; otherwise its fallback paragraph is made.
MediaType string
MediaAttr *QName
MediaMap map[string]string
WhenMarkup bool
// Base64: "encoding": "base64", the element's text is base64, decoded
// before it is handed over (an attachment); with it, MediaAttr may
// have no map: the attribute's value is the media type as written.
// NameAttr: "name": {"attr": ...}, the attribute that names the
// child (a file name).
Base64 bool
NameAttr *QName
// Reads lists the attributes of the element the rule reads.
Reads []QName
// Claims lists the value sources read from children.
Claims []*Value
}
Rule is a compiled rule.
type Selector ¶
type Selector struct {
Source string
Anchored bool
Steps []Step
// contains filtered or unexported fields
}
Selector is a compiled selector. Steps go from the outermost element to the element matched.
func ParseSelector ¶
ParseSelector compiles a selector. Prefixes are resolved with ns; an unprefixed element name is in defaultNS, an unprefixed attribute name in no namespace.
type TokenPath ¶
TokenPath is a Path that answers token tests itself, splitting each value once per element rather than once per test.
type Value ¶
type Value struct {
Literal string
IsLiteral bool
Attr QName // {"attr": ...}
Of *QName // {"attr": ..., "of": ...}
Child *Selector
Structure *Selector
// AttrChild: {"attr": ..., "child": ...}, the attribute Attr of the
// first matching child, which is still read by its own rule.
AttrChild *Selector
// Codepoint: {"attr": ..., "codepoint": "hex"}, the character whose
// code point the attribute holds in hexadecimal (Formex QUOT.START).
Codepoint bool
// AnchorOf: {"anchor_of": ...}, in "anchor" only: the anchor of the
// nearest enclosing element of that name, as its rule's "anchor" gave
// it (PubMed: a record's heading takes the record's PMID).
AnchorOf *QName
}
Value is a value source (A4).