@miy2/xml-api 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CST = void 0;
4
+ /**
5
+ * Represents a node in the Concrete Syntax Tree (Parse Tree).
6
+ * Each node corresponds to a match of a grammatical structure or rule.
7
+ */
8
+ class CST {
9
+ constructor(
10
+ /**
11
+ * The type of the grammatical structure matched.
12
+ * Common values include "literal", "regex", "sequence", "repeat".
13
+ * This describes the structural nature of the match, not the grammar rule name.
14
+ */
15
+ type,
16
+ /**
17
+ * The name of the grammar rule corresponding to this node (e.g., "element", "attribute").
18
+ * Defined only if this node represents a named rule reference; otherwise undefined.
19
+ */
20
+ name,
21
+ /**
22
+ * The 0-based starting index of this node in the entire input string (inclusive).
23
+ */
24
+ start,
25
+ /**
26
+ * The 0-based ending index of this node in the entire input string (exclusive).
27
+ * The length of the match is (end - start).
28
+ */
29
+ end,
30
+ /**
31
+ * Child nodes contained within this structure.
32
+ * Empty for leaf nodes like literals or regex matches.
33
+ */
34
+ children = [],
35
+ /**
36
+ * Indicates whether the node satisfies additional validation logic beyond basic parsing.
37
+ * If false, the node was parsed successfully according to the grammar structure
38
+ * but failed a semantic or contextual validation check.
39
+ */
40
+ wellFormed = true) {
41
+ this.type = type;
42
+ this.name = name;
43
+ this.start = start;
44
+ this.end = end;
45
+ this.children = children;
46
+ this.wellFormed = wellFormed;
47
+ /**
48
+ * Reference to the parent node in the syntax tree.
49
+ * Null if this is the root node.
50
+ */
51
+ this.parent = null;
52
+ for (const child of children) {
53
+ child.parent = this;
54
+ }
55
+ }
56
+ /**
57
+ * Retrieves the substring matching this node from the entire original input string.
58
+ */
59
+ getText(input) {
60
+ return input.slice(this.start, this.end);
61
+ }
62
+ /**
63
+ * Shifts the start and end positions of this node and its children.
64
+ * @param pos The position where the change occurred.
65
+ * @param delta The change in length.
66
+ */
67
+ shift(pos, delta) {
68
+ if (delta > 0) {
69
+ if (this.start >= pos) {
70
+ this.start += delta;
71
+ }
72
+ if (this.end > pos) {
73
+ this.end += delta;
74
+ }
75
+ }
76
+ else {
77
+ // For deletion, delta is negative.
78
+ // The deletion range in original coordinates is [pos, pos - delta).
79
+ const deleteEnd = pos - delta;
80
+ if (this.start >= deleteEnd) {
81
+ // Node started after the deletion; shift it back.
82
+ this.start += delta;
83
+ }
84
+ else if (this.start > pos) {
85
+ // Node started inside the deletion region.
86
+ // It now starts at the deletion point.
87
+ this.start = pos;
88
+ }
89
+ if (this.end >= deleteEnd) {
90
+ // Node ended after the deletion; shift it back.
91
+ this.end += delta;
92
+ }
93
+ else if (this.end > pos) {
94
+ // Node ended inside the deletion region.
95
+ // It now ends at the deletion point.
96
+ this.end = pos;
97
+ }
98
+ }
99
+ for (const child of this.children) {
100
+ child.shift(pos, delta);
101
+ }
102
+ }
103
+ /**
104
+ * Unwraps single-child Reference nodes to find the underlying structural node.
105
+ */
106
+ unwrap() {
107
+ let current = this;
108
+ while (current.children.length === 1 &&
109
+ current.children[0].start === current.start &&
110
+ current.children[0].end === current.end) {
111
+ current = current.children[0];
112
+ }
113
+ return current;
114
+ }
115
+ }
116
+ exports.CST = CST;
@@ -0,0 +1,45 @@
1
+ import { GrammarBuilder } from "./grammar";
2
+ /**
3
+ * Unimplemented Well-formedness Constraints (WFC)
4
+ *
5
+ * The following constraints are currently not enforced by this parser.
6
+ * Implementation would require an Entity Manager, DTD Processor, and extended Context.
7
+ *
8
+ * - [WFC: PEs in Internal Subset]
9
+ * "In the internal DTD subset, parameter-entity references MUST NOT occur within markup declarations..."
10
+ * https://www.w3.org/TR/xml/#wfc-PEinInternalSubset
11
+ *
12
+ * - [WFC: External Subset]
13
+ * "The external subset, if any, MUST match the production for extSubset."
14
+ * https://www.w3.org/TR/xml/#ExtSubset
15
+ *
16
+ * - [WFC: PE Between Declarations]
17
+ * "The replacement text of a parameter entity reference in a DeclSep MUST match the production extSubsetDecl."
18
+ * https://www.w3.org/TR/xml/#PE-between-Decls
19
+ *
20
+ * - [WFC: No External Entity References]
21
+ * "Attribute values MUST NOT contain direct or indirect entity references to external entities."
22
+ * https://www.w3.org/TR/xml/#NoExternalRefs
23
+ *
24
+ * - [WFC: No < in Attribute Values]
25
+ * "The replacement text of any entity referred to directly or indirectly in an attribute value MUST NOT contain a <."
26
+ * https://www.w3.org/TR/xml/#CleanAttrVals
27
+ *
28
+ * - [WFC: Entity Declared]
29
+ * "In a document without any DTD, a document with only an internal DTD subset which contains no parameter entity references, or a document with standalone='yes', for an entity reference that does not occur within the external subset or a parameter entity, the Name given in the entity reference MUST match that in an entity declaration..."
30
+ * https://www.w3.org/TR/xml/#wf-entdeclared
31
+ *
32
+ * - [WFC: Parsed Entity]
33
+ * "An internal general parsed entity MUST match the production content."
34
+ * https://www.w3.org/TR/xml/#textent
35
+ *
36
+ * - [WFC: No Recursion]
37
+ * "A parsed entity MUST NOT contain a recursive reference to itself, either directly or indirectly."
38
+ * https://www.w3.org/TR/xml/#norecursion
39
+ *
40
+ * - [WFC: In DTD]
41
+ * "Parameter-entity references MUST NOT occur outside the DTD."
42
+ * https://www.w3.org/TR/xml/#indtd
43
+ */
44
+ export declare const grammar: import("./grammar").Grammar;
45
+ export declare const g_deprecated: GrammarBuilder;
@@ -0,0 +1,366 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.g_deprecated = exports.grammar = void 0;
4
+ const grammar_1 = require("./grammar");
5
+ const g = new grammar_1.GrammarBuilder();
6
+ const SQ = "\u0027"; // Single Quote '
7
+ const DQ = "\u0022"; // Double Quote "
8
+ // [1] document ::= prolog element Misc*
9
+ //
10
+ // Summary:
11
+ // - Single Root Element: There is exactly one root element that contains all other elements within the document.
12
+ // - Proper Nesting: All elements must be correctly nested, with start and end tags forming non-overlapping, paired structures.
13
+ // - Clear Parent-Child Hierarchy: Every non-root element has exactly one parent, creating a well-defined tree structure.
14
+ //
15
+ // cf: https://www.w3.org/TR/xml/#NT-document
16
+ g.rule("document", (0, grammar_1.seq)((0, grammar_1.ref)("prolog"), (0, grammar_1.ref)("element"), (0, grammar_1.rep)((0, grammar_1.ref)("Misc"))));
17
+ // [2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
18
+ //
19
+ // any Unicode character, excluding the surrogate blocks, FFFE, and FFFF.
20
+ //
21
+ // cf: https://www.w3.org/TR/xml/#NT-Char
22
+ g.rule("Char", (0, grammar_1.reg)("\t|\n|\r|[\u0020-\uD7FF]|[\uE000-\uFFFD]|[\uD800-\uDBFF][\uDC00-\uDFFF]"));
23
+ // [3] S ::= (#x20 | #x9 | #xD | #xA)+
24
+ // cf: https://www.w3.org/TR/xml/#NT-S
25
+ g.rule("S", (0, grammar_1.plus)((0, grammar_1.reg)("[\x20\t\r\n]")));
26
+ // [4] NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
27
+ // cf: https://www.w3.org/TR/xml/#NT-NameStartChar
28
+ g.rule("NameStartChar", (0, grammar_1.alt)((0, grammar_1.lit)(":"), (0, grammar_1.reg)("[A-Z]"), (0, grammar_1.lit)("_"), (0, grammar_1.reg)("[a-z]"), (0, grammar_1.reg)("[\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]"), (0, grammar_1.reg)("[\uD800-\uDB7F][\uDC00-\uDFFF]")));
29
+ // [4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
30
+ // cf: https://www.w3.org/TR/xml/#NT-NameChar
31
+ g.rule("NameChar", (0, grammar_1.alt)((0, grammar_1.ref)("NameStartChar"), (0, grammar_1.lit)("-"), (0, grammar_1.lit)("."), (0, grammar_1.reg)("[0-9]"), (0, grammar_1.lit)("\u00B7"), (0, grammar_1.reg)("[\u0300-\u036F\u203F-\u2040]")));
32
+ // [5] Name ::= NameStartChar (NameChar)*
33
+ // cf: https://www.w3.org/TR/xml/#NT-Name
34
+ g.rule("Name", (0, grammar_1.seq)((0, grammar_1.ref)("NameStartChar"), (0, grammar_1.rep)((0, grammar_1.ref)("NameChar"))));
35
+ // [6] Names ::= Name (#x20 Name)*
36
+ // cf: https://www.w3.org/TR/xml/#NT-Names
37
+ g.rule("Names", (0, grammar_1.seq)((0, grammar_1.ref)("Name"), (0, grammar_1.rep)((0, grammar_1.seq)((0, grammar_1.lit)("\x20"), (0, grammar_1.ref)("Name")))));
38
+ // [7] Nmtoken ::= (NameChar)+
39
+ // cf: https://www.w3.org/TR/xml/#NT-Nmtoken
40
+ g.rule("Nmtoken", (0, grammar_1.plus)((0, grammar_1.ref)("NameChar")));
41
+ // [8] Nmtokens ::= Nmtoken (#x20 Nmtoken)*
42
+ // cf: https://www.w3.org/TR/xml/#NT-Nmtokens
43
+ g.rule("Nmtokens", (0, grammar_1.seq)((0, grammar_1.ref)("Nmtoken"), (0, grammar_1.rep)((0, grammar_1.seq)((0, grammar_1.lit)(" "), (0, grammar_1.ref)("Nmtoken")))));
44
+ // [9] EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"' | "'" ([^%&'] | PEReference | Reference)* "'"
45
+ // cf: https://www.w3.org/TR/xml/#NT-EntityValue
46
+ g.rule("EntityValue", (0, grammar_1.alt)((0, grammar_1.seq)((0, grammar_1.lit)(DQ), (0, grammar_1.rep)((0, grammar_1.alt)((0, grammar_1.reg)("[^%&\\x22]"), (0, grammar_1.ref)("PEReference"), (0, grammar_1.ref)("Reference"))), (0, grammar_1.lit)(DQ)), (0, grammar_1.seq)((0, grammar_1.lit)(SQ), (0, grammar_1.rep)((0, grammar_1.alt)((0, grammar_1.reg)("[^%&\\x27]"), (0, grammar_1.ref)("PEReference"), (0, grammar_1.ref)("Reference"))), (0, grammar_1.lit)(SQ))));
47
+ // [10] AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'"
48
+ // cf: https://www.w3.org/TR/xml/#NT-AttValue
49
+ g.rule("AttValue", (0, grammar_1.alt)((0, grammar_1.seq)((0, grammar_1.lit)(DQ), (0, grammar_1.rep)((0, grammar_1.alt)((0, grammar_1.reg)("[^<&\\x22]"), (0, grammar_1.ref)("Reference"))), (0, grammar_1.lit)(DQ)), (0, grammar_1.seq)((0, grammar_1.lit)(SQ), (0, grammar_1.rep)((0, grammar_1.alt)((0, grammar_1.reg)("[^<&\\x27]"), (0, grammar_1.ref)("Reference"))), (0, grammar_1.lit)(SQ))));
50
+ // [11] SystemLiteral ::= ('"' [^\"]* "'") | ("'" [^']* "'")
51
+ // cf: https://www.w3.org/TR/xml/#NT-SystemLiteral
52
+ g.rule("SystemLiteral", (0, grammar_1.alt)((0, grammar_1.seq)((0, grammar_1.lit)(DQ), (0, grammar_1.reg)("[^\\x22]*"), (0, grammar_1.lit)(DQ)), (0, grammar_1.seq)((0, grammar_1.lit)(SQ), (0, grammar_1.reg)("[^\\x27]*"), (0, grammar_1.lit)(SQ))));
53
+ // [12] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'"
54
+ // cf: https://www.w3.org/TR/xml/#NT-PubidLiteral
55
+ g.rule("PubidLiteral", (0, grammar_1.alt)((0, grammar_1.seq)((0, grammar_1.lit)(DQ), (0, grammar_1.rep)((0, grammar_1.ref)("PubidChar")), (0, grammar_1.lit)(DQ)), (0, grammar_1.seq)((0, grammar_1.lit)(SQ), (0, grammar_1.rep)((0, grammar_1.exc)((0, grammar_1.ref)("PubidChar"), (0, grammar_1.lit)(SQ))), (0, grammar_1.lit)(SQ))));
56
+ // [13] PubidChar ::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]
57
+ // cf: https://www.w3.org/TR/xml/#NT-PubidChar
58
+ g.rule("PubidChar", (0, grammar_1.reg)("[\\x20\\r\\na-zA-Z0-9-&#039;()+,./:=?;!*#@$_%]"));
59
+ // [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)
60
+ // cf: https://www.w3.org/TR/xml/#NT-CharData
61
+ g.rule("CharData", (0, grammar_1.rep)((0, grammar_1.exc)((0, grammar_1.reg)("[^<&]"), (0, grammar_1.lit)("]]\x3E"))));
62
+ // [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'
63
+ // cf: https://www.w3.org/TR/xml/#NT-Comment
64
+ g.rule("Comment", (0, grammar_1.seq)((0, grammar_1.lit)("<!--"), (0, grammar_1.rep)((0, grammar_1.alt)((0, grammar_1.exc)((0, grammar_1.ref)("Char"), (0, grammar_1.lit)("-")), (0, grammar_1.seq)((0, grammar_1.lit)("-"), (0, grammar_1.exc)((0, grammar_1.ref)("Char"), (0, grammar_1.lit)("-"))))), (0, grammar_1.lit)("-->")));
65
+ // [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
66
+ // cf: https://www.w3.org/TR/xml/#NT-PI
67
+ g.rule("PI", (0, grammar_1.seq)((0, grammar_1.lit)("<?"), (0, grammar_1.ref)("PITarget"), (0, grammar_1.opt)((0, grammar_1.seq)((0, grammar_1.ref)("S"), (0, grammar_1.rep)((0, grammar_1.exc)((0, grammar_1.ref)("Char"), (0, grammar_1.lit)("?>"))))), (0, grammar_1.lit)("?>")));
68
+ // [17] PITarget ::= Name - ((('X' | 'x') ('M' | 'm') ('L' | 'l')))
69
+ // cf: https://www.w3.org/TR/xml/#NT-PITarget
70
+ g.rule("PITarget", (0, grammar_1.exc)((0, grammar_1.ref)("Name"), (0, grammar_1.reg)("([Xx][Mm][Ll])")));
71
+ // [18] CDSect ::= CDStart CData CDEnd
72
+ // cf: https://www.w3.org/TR/xml/#NT-CDSect
73
+ g.rule("CDSect", (0, grammar_1.seq)((0, grammar_1.ref)("CDStart"), (0, grammar_1.ref)("CData"), (0, grammar_1.ref)("CDEnd")));
74
+ // [19] CDStart ::= '<![CDATA['
75
+ // cf: https://www.w3.org/TR/xml/#NT-CDStart
76
+ g.rule("CDStart", (0, grammar_1.lit)("<![CDATA["));
77
+ // [20] CData ::= (Char* - (Char* ']]>' Char*))
78
+ // cf: https://www.w3.org/TR/xml/#NT-CData
79
+ g.rule("CData", (0, grammar_1.rep)((0, grammar_1.exc)((0, grammar_1.ref)("Char"), (0, grammar_1.lit)("]]\x3E"))));
80
+ // [21] CDEnd ::= ']]>'
81
+ // cf: https://www.w3.org/TR/xml/#NT-CDEnd
82
+ g.rule("CDEnd", (0, grammar_1.lit)("]]\x3E"));
83
+ // [22] prolog ::= XMLDecl? Misc* (doctypedecl Misc*)?
84
+ // cf: https://www.w3.org/TR/xml/#NT-prolog
85
+ g.rule("prolog", (0, grammar_1.seq)((0, grammar_1.opt)((0, grammar_1.ref)("XMLDecl")), (0, grammar_1.rep)((0, grammar_1.ref)("Misc")), (0, grammar_1.opt)((0, grammar_1.seq)((0, grammar_1.ref)("doctypedecl"), (0, grammar_1.rep)((0, grammar_1.ref)("Misc"))))));
86
+ // [23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'
87
+ // cf: https://www.w3.org/TR/xml/#NT-XMLDecl
88
+ g.rule("XMLDecl", (0, grammar_1.seq)((0, grammar_1.lit)("<?xml"), (0, grammar_1.ref)("VersionInfo"), (0, grammar_1.opt)((0, grammar_1.ref)("EncodingDecl")), (0, grammar_1.opt)((0, grammar_1.ref)("SDDecl")), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)("?>")));
89
+ // [24] VersionInfo ::= S 'version' Eq (("'" VersionNum "'") | ('"' VersionNum "'"))
90
+ // cf: https://www.w3.org/TR/xml/#NT-VersionInfo
91
+ g.rule("VersionInfo", (0, grammar_1.seq)((0, grammar_1.ref)("S"), (0, grammar_1.lit)("version"), (0, grammar_1.ref)("Eq"), (0, grammar_1.alt)((0, grammar_1.seq)((0, grammar_1.lit)(SQ), (0, grammar_1.ref)("VersionNum"), (0, grammar_1.lit)(SQ)), (0, grammar_1.seq)((0, grammar_1.lit)(DQ), (0, grammar_1.ref)("VersionNum"), (0, grammar_1.lit)(DQ)))));
92
+ // [25] Eq ::= S? '=' S?
93
+ // cf: https://www.w3.org/TR/xml/#NT-Eq
94
+ g.rule("Eq", (0, grammar_1.seq)((0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)("="), (0, grammar_1.opt)((0, grammar_1.ref)("S"))));
95
+ // [26] VersionNum ::= '1.' [0-9]+
96
+ // cf: https://www.w3.org/TR/xml/#NT-VersionNum
97
+ g.rule("VersionNum", (0, grammar_1.seq)((0, grammar_1.lit)("1."), (0, grammar_1.plus)((0, grammar_1.reg)("[0-9]"))));
98
+ // [27] Misc ::= Comment | PI | S
99
+ // cf: https://www.w3.org/TR/xml/#NT-Misc
100
+ g.rule("Misc", (0, grammar_1.alt)((0, grammar_1.ref)("Comment"), (0, grammar_1.ref)("PI"), (0, grammar_1.ref)("S")));
101
+ // [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? ('[' intSubset ']' S?)? '>'
102
+ // cf: https://www.w3.org/TR/xml/#NT-doctypedecl
103
+ g.rule("doctypedecl", (0, grammar_1.seq)((0, grammar_1.lit)("<!DOCTYPE"), (0, grammar_1.ref)("S"), (0, grammar_1.ref)("Name"), (0, grammar_1.opt)((0, grammar_1.seq)((0, grammar_1.ref)("S"), (0, grammar_1.ref)("ExternalID"))), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.opt)((0, grammar_1.seq)((0, grammar_1.lit)("["), (0, grammar_1.ref)("intSubset"), (0, grammar_1.lit)("]"), (0, grammar_1.opt)((0, grammar_1.ref)("S")))), (0, grammar_1.lit)(">")));
104
+ // [28a] DeclSep ::= PEReference | S
105
+ // cf: https://www.w3.org/TR/xml/#NT-DeclSep
106
+ g.rule("DeclSep", (0, grammar_1.alt)((0, grammar_1.ref)("PEReference"), (0, grammar_1.ref)("S")));
107
+ // [28b] intSubset ::= (markupdecl | DeclSep)*
108
+ // cf: https://www.w3.org/TR/xml/#NT-intSubset
109
+ g.rule("intSubset", (0, grammar_1.rep)((0, grammar_1.alt)((0, grammar_1.ref)("markupdecl"), (0, grammar_1.ref)("DeclSep"))));
110
+ // [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl | NotationDecl | PI | Comment
111
+ // cf: https://www.w3.org/TR/xml/#NT-markupdecl
112
+ g.rule("markupdecl", (0, grammar_1.alt)((0, grammar_1.ref)("elementdecl"), (0, grammar_1.ref)("AttlistDecl"), (0, grammar_1.ref)("EntityDecl"), (0, grammar_1.ref)("NotationDecl"), (0, grammar_1.ref)("PI"), (0, grammar_1.ref)("Comment")));
113
+ // [30] extSubset ::= TextDecl? extSubsetDecl
114
+ // cf: https://www.w3.org/TR/xml/#NT-extSubset
115
+ g.rule("extSubset", (0, grammar_1.seq)((0, grammar_1.opt)((0, grammar_1.ref)("TextDecl")), (0, grammar_1.ref)("extSubsetDecl")));
116
+ // [31] extSubsetDecl ::= ( markupdecl | conditionalSect | DeclSep)*
117
+ // cf: https://www.w3.org/TR/xml/#NT-extSubsetDecl
118
+ g.rule("extSubsetDecl", (0, grammar_1.rep)((0, grammar_1.alt)((0, grammar_1.ref)("markupdecl"), (0, grammar_1.ref)("conditionalSect"), (0, grammar_1.ref)("DeclSep"))));
119
+ // [32] SDDecl ::= S 'standalone' Eq (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') "'"))
120
+ // cf: https://www.w3.org/TR/xml/#NT-SDDecl
121
+ g.rule("SDDecl", (0, grammar_1.seq)((0, grammar_1.ref)("S"), (0, grammar_1.lit)("standalone"), (0, grammar_1.ref)("Eq"), (0, grammar_1.alt)((0, grammar_1.seq)((0, grammar_1.lit)(SQ), (0, grammar_1.alt)((0, grammar_1.lit)("yes"), (0, grammar_1.lit)("no")), (0, grammar_1.lit)(SQ)), (0, grammar_1.seq)((0, grammar_1.lit)(DQ), (0, grammar_1.alt)((0, grammar_1.lit)("yes"), (0, grammar_1.lit)("no")), (0, grammar_1.lit)(DQ)))));
122
+ // [39] element ::= EmptyElemTag | STag content ETag
123
+ // cf: https://www.w3.org/TR/xml/#NT-element
124
+ g.rule("element", (0, grammar_1.alt)((0, grammar_1.ref)("EmptyElemTag"), (0, grammar_1.seq)((0, grammar_1.ref)("STag"), (0, grammar_1.ref)("content"), (0, grammar_1.ref)("ETag"))));
125
+ // Well-formedness constraint: Element Type Match
126
+ function validateElementTypeMatch(node, input) {
127
+ const structuralNode = node.unwrap();
128
+ // Case 1: EmptyElemTag (always well-formed regarding tag match)
129
+ if (structuralNode.children.length > 0 &&
130
+ structuralNode.children[0].type === "literal") {
131
+ return true;
132
+ }
133
+ // Case 2: Sequence [STag, content, ETag]
134
+ if (structuralNode.children.length === 3 &&
135
+ structuralNode.children[0].name === "STag" &&
136
+ structuralNode.children[2].name === "ETag") {
137
+ const stag = structuralNode.children[0];
138
+ const etag = structuralNode.children[2];
139
+ const startName = stag.unwrap().children[1].getText(input);
140
+ const endName = etag.unwrap().children[1].getText(input);
141
+ return startName === endName;
142
+ }
143
+ throw new Error(`Validation error: unexpected node structure in validateElementTypeMatch. Children types: ${structuralNode.children.map((c) => c.type).join(", ")}`);
144
+ }
145
+ g.verifyRule("element", validateElementTypeMatch);
146
+ // Helper for Unique Att Spec check
147
+ function validateUniqueAttributes(node, input) {
148
+ const seen = new Set();
149
+ const structuralNode = node.unwrap();
150
+ // STag/EmptyElemTag structure:
151
+ // 0: "<"
152
+ // 1: Name
153
+ // 2: rep(seq(S, Attribute))
154
+ // ...
155
+ const repNode = structuralNode.children[2];
156
+ if (!repNode || repNode.type !== "repeat")
157
+ return true;
158
+ for (const seqNode of repNode.children) {
159
+ // seqNode children: [S, Attribute]
160
+ const attrNode = seqNode.children[1];
161
+ if (attrNode && attrNode.name === "Attribute") {
162
+ const attrStructural = attrNode.unwrap();
163
+ const nameNode = attrStructural.children[0];
164
+ const name = nameNode.getText(input);
165
+ if (seen.has(name))
166
+ return false;
167
+ seen.add(name);
168
+ }
169
+ }
170
+ return true;
171
+ }
172
+ // [40] STag ::= '<' Name (S Attribute)* S? '>'
173
+ // cf: https://www.w3.org/TR/xml/#NT-STag
174
+ g.rule("STag", (0, grammar_1.seq)((0, grammar_1.lit)("<"), (0, grammar_1.ref)("Name"), (0, grammar_1.rep)((0, grammar_1.seq)((0, grammar_1.ref)("S"), (0, grammar_1.ref)("Attribute"))), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)(">")));
175
+ // Well-formedness constraint: Unique Att Spec
176
+ g.verifyRule("STag", validateUniqueAttributes);
177
+ // [41] Attribute ::= Name Eq AttValue
178
+ // cf: https://www.w3.org/TR/xml/#NT-Attribute
179
+ g.rule("Attribute", (0, grammar_1.seq)((0, grammar_1.ref)("Name"), (0, grammar_1.ref)("Eq"), (0, grammar_1.ref)("AttValue")));
180
+ // [42] ETag ::= '</' Name S? '>'
181
+ // cf: https://www.w3.org/TR/xml/#NT-ETag
182
+ g.rule("ETag", (0, grammar_1.seq)((0, grammar_1.lit)("</"), (0, grammar_1.ref)("Name"), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)(">")));
183
+ // [43] content ::= CharData? ((element | Reference | CDSect | PI | Comment) CharData?)*
184
+ // cf: https://www.w3.org/TR/xml/#NT-content
185
+ g.rule("content", (0, grammar_1.seq)((0, grammar_1.opt)((0, grammar_1.ref)("CharData")), (0, grammar_1.rep)((0, grammar_1.seq)((0, grammar_1.alt)((0, grammar_1.ref)("element"), (0, grammar_1.ref)("Reference"), (0, grammar_1.ref)("CDSect"), (0, grammar_1.ref)("PI"), (0, grammar_1.ref)("Comment")), (0, grammar_1.opt)((0, grammar_1.ref)("CharData"))))));
186
+ // [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
187
+ // cf: https://www.w3.org/TR/xml/#NT-EmptyElemTag
188
+ g.rule("EmptyElemTag", (0, grammar_1.seq)((0, grammar_1.lit)("<"), (0, grammar_1.ref)("Name"), (0, grammar_1.rep)((0, grammar_1.seq)((0, grammar_1.ref)("S"), (0, grammar_1.ref)("Attribute"))), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)("/>")));
189
+ // Well-formedness constraint: Unique Att Spec
190
+ g.verifyRule("EmptyElemTag", validateUniqueAttributes);
191
+ // [45] elementdecl ::= '<!ELEMENT' S Name S contentspec S? '>'
192
+ // cf: https://www.w3.org/TR/xml/#NT-elementdecl
193
+ g.rule("elementdecl", (0, grammar_1.seq)((0, grammar_1.lit)("<!ELEMENT"), (0, grammar_1.ref)("S"), (0, grammar_1.ref)("Name"), (0, grammar_1.ref)("S"), (0, grammar_1.ref)("contentspec"), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)(">")));
194
+ // [46] contentspec ::= 'EMPTY' | 'ANY' | Mixed | children
195
+ // cf: https://www.w3.org/TR/xml/#NT-contentspec
196
+ g.rule("contentspec", (0, grammar_1.alt)((0, grammar_1.lit)("EMPTY"), (0, grammar_1.lit)("ANY"), (0, grammar_1.ref)("Mixed"), (0, grammar_1.ref)("children")));
197
+ // [47] children ::= (choice | seq) ('?' | '*' | '+')?
198
+ // cf: https://www.w3.org/TR/xml/#NT-children
199
+ g.rule("children", (0, grammar_1.seq)((0, grammar_1.alt)((0, grammar_1.ref)("choice"), (0, grammar_1.ref)("seq")), (0, grammar_1.opt)((0, grammar_1.reg)("[?*+]?"))));
200
+ // [48] cp ::= (Name | choice | seq) ('?' | '*' | '+')?
201
+ // cf: https://www.w3.org/TR/xml/#NT-cp
202
+ g.rule("cp", (0, grammar_1.seq)((0, grammar_1.alt)((0, grammar_1.ref)("Name"), (0, grammar_1.ref)("choice"), (0, grammar_1.ref)("seq")), (0, grammar_1.opt)((0, grammar_1.reg)("[?*+]?"))));
203
+ // [49] choice ::= '(' S? cp ( S? '|' S? cp )+ S? ')'
204
+ // cf: https://www.w3.org/TR/xml/#NT-choice
205
+ g.rule("choice", (0, grammar_1.seq)((0, grammar_1.lit)("("), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.ref)("cp"), (0, grammar_1.plus)((0, grammar_1.seq)((0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)("|"), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.ref)("cp"))), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)(")")));
206
+ // [50] seq ::= '(' S? cp ( S? ',' S? cp )* S? ')'
207
+ // cf: https://www.w3.org/TR/xml/#NT-seq
208
+ g.rule("seq", (0, grammar_1.seq)((0, grammar_1.lit)("("), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.ref)("cp"), (0, grammar_1.rep)((0, grammar_1.seq)((0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)(","), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.ref)("cp"))), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)(")")));
209
+ // [51] Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*' | '(' S? '#PCDATA' S? ')'
210
+ // cf: https://www.w3.org/TR/xml/#NT-Mixed
211
+ g.rule("Mixed", (0, grammar_1.alt)((0, grammar_1.seq)((0, grammar_1.lit)("("), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)("#PCDATA"), (0, grammar_1.rep)((0, grammar_1.seq)((0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)("|"), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.ref)("Name"))), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)(")*")), (0, grammar_1.seq)((0, grammar_1.lit)("("), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)("#PCDATA"), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)(")"))));
212
+ // [52] AttlistDecl ::= '<!ATTLIST' S Name AttDef* S? '>'
213
+ // cf: https://www.w3.org/TR/xml/#NT-AttlistDecl
214
+ g.rule("AttlistDecl", (0, grammar_1.seq)((0, grammar_1.lit)("<!ATTLIST"), (0, grammar_1.ref)("S"), (0, grammar_1.ref)("Name"), (0, grammar_1.rep)((0, grammar_1.ref)("AttDef")), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)(">")));
215
+ // [53] AttDef ::= S Name S AttType S DefaultDecl
216
+ // cf: https://www.w3.org/TR/xml/#NT-AttDef
217
+ g.rule("AttDef", (0, grammar_1.seq)((0, grammar_1.ref)("S"), (0, grammar_1.ref)("Name"), (0, grammar_1.ref)("S"), (0, grammar_1.ref)("AttType"), (0, grammar_1.ref)("S"), (0, grammar_1.ref)("DefaultDecl")));
218
+ // [54] AttType ::= StringType | TokenizedType | EnumeratedType
219
+ // cf: https://www.w3.org/TR/xml/#NT-AttType
220
+ g.rule("AttType", (0, grammar_1.alt)((0, grammar_1.ref)("StringType"), (0, grammar_1.ref)("TokenizedType"), (0, grammar_1.ref)("EnumeratedType")));
221
+ // [55] StringType ::= 'CDATA'
222
+ // cf: https://www.w3.org/TR/xml/#NT-StringType
223
+ g.rule("StringType", (0, grammar_1.lit)("CDATA"));
224
+ // [56] TokenizedType ::= 'ID' | 'IDREF' | 'IDREFS' | 'ENTITY' | 'ENTITIES' | 'NMTOKEN' | 'NMTOKENS'
225
+ // cf: https://www.w3.org/TR/xml/#NT-TokenizedType
226
+ g.rule("TokenizedType", (0, grammar_1.alt)((0, grammar_1.lit)("ID"), (0, grammar_1.lit)("IDREF"), (0, grammar_1.lit)("IDREFS"), (0, grammar_1.lit)("ENTITY"), (0, grammar_1.lit)("ENTITIES"), (0, grammar_1.lit)("NMTOKEN"), (0, grammar_1.lit)("NMTOKENS")));
227
+ // [57] EnumeratedType ::= NotationType | Enumeration
228
+ // cf: https://www.w3.org/TR/xml/#NT-EnumeratedType
229
+ g.rule("EnumeratedType", (0, grammar_1.alt)((0, grammar_1.ref)("NotationType"), (0, grammar_1.ref)("Enumeration")));
230
+ // [58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')'
231
+ // cf: https://www.w3.org/TR/xml/#NT-NotationType
232
+ g.rule("NotationType", (0, grammar_1.seq)((0, grammar_1.lit)("NOTATION"), (0, grammar_1.ref)("S"), (0, grammar_1.lit)("("), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.ref)("Name"), (0, grammar_1.rep)((0, grammar_1.seq)((0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)("|"), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.ref)("Name"))), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)(")")));
233
+ // [59] Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')'
234
+ // cf: https://www.w3.org/TR/xml/#NT-Enumeration
235
+ g.rule("Enumeration", (0, grammar_1.seq)((0, grammar_1.lit)("("), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.ref)("Nmtoken"), (0, grammar_1.rep)((0, grammar_1.seq)((0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)("|"), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.ref)("Nmtoken"))), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)(")")));
236
+ // [60] DefaultDecl ::= '#REQUIRED' | '#IMPLIED' | (('#FIXED' S)? AttValue)
237
+ // cf: https://www.w3.org/TR/xml/#NT-DefaultDecl
238
+ g.rule("DefaultDecl", (0, grammar_1.alt)((0, grammar_1.lit)("#REQUIRED"), (0, grammar_1.lit)("#IMPLIED"), (0, grammar_1.seq)((0, grammar_1.opt)((0, grammar_1.seq)((0, grammar_1.lit)("#FIXED"), (0, grammar_1.ref)("S"))), (0, grammar_1.ref)("AttValue"))));
239
+ // [61] conditionalSect ::= includeSect | ignoreSect
240
+ // cf: https://www.w3.org/TR/xml/#NT-conditionalSect
241
+ g.rule("conditionalSect", (0, grammar_1.alt)((0, grammar_1.ref)("includeSect"), (0, grammar_1.ref)("ignoreSect")));
242
+ // [62] includeSect ::= '<![' S? 'INCLUDE' S? '[' extSubsetDecl ']]>'
243
+ // cf: https://www.w3.org/TR/xml/#NT-includeSect
244
+ g.rule("includeSect", (0, grammar_1.seq)((0, grammar_1.lit)("<!["), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)("INCLUDE"), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)("["), (0, grammar_1.ref)("extSubsetDecl"), (0, grammar_1.lit)("]]\x3E")));
245
+ // [63] ignoreSect ::= '<![' S? 'IGNORE' S? '[' ignoreSectContents* ']]>'
246
+ // cf: https://www.w3.org/TR/xml/#NT-ignoreSect
247
+ g.rule("ignoreSect", (0, grammar_1.seq)((0, grammar_1.lit)("<!["), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)("IGNORE"), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)("["), (0, grammar_1.rep)((0, grammar_1.ref)("ignoreSectContents")), (0, grammar_1.lit)("]]\x3E")));
248
+ // [64] ignoreSectContents ::= Ignore ('<![' ignoreSectContents ']]>' Ignore)*
249
+ // cf: https://www.w3.org/TR/xml/#NT-ignoreSectContents
250
+ g.rule("ignoreSectContents", (0, grammar_1.seq)((0, grammar_1.ref)("Ignore"), (0, grammar_1.rep)((0, grammar_1.seq)((0, grammar_1.lit)("<!["), (0, grammar_1.ref)("ignoreSectContents"), (0, grammar_1.lit)("]]\x3E"), (0, grammar_1.ref)("Ignore")))));
251
+ // [65] Ignore ::= Char* - (Char* ('<![' | ']]>') Char*)
252
+ // cf: https://www.w3.org/TR/xml/#NT-Ignore
253
+ g.rule("Ignore", (0, grammar_1.rep)((0, grammar_1.exc)((0, grammar_1.ref)("Char"), (0, grammar_1.reg)("(<![|]]\\x3E)"))));
254
+ // [66] CharRef ::= '&#' [0-9]+ ';' | '&#x' [0-9a-fA-F]+ ';'
255
+ // cf: https://www.w3.org/TR/xml/#NT-CharRef
256
+ g.rule("CharRef", (0, grammar_1.alt)((0, grammar_1.seq)((0, grammar_1.lit)("&#"), (0, grammar_1.plus)((0, grammar_1.reg)("[0-9]")), (0, grammar_1.lit)(";")), (0, grammar_1.seq)((0, grammar_1.lit)("&#x"), (0, grammar_1.plus)((0, grammar_1.reg)("[0-9a-fA-F]")), (0, grammar_1.lit)(";"))));
257
+ // Well-formedness constraint: Legal Character
258
+ // Characters referred to using character references MUST match the production for Char.
259
+ g.verifyRule("CharRef", (node, input) => {
260
+ const text = node.getText(input);
261
+ let code;
262
+ if (text.startsWith("&#x")) {
263
+ code = parseInt(text.slice(3, -1), 16);
264
+ }
265
+ else {
266
+ code = parseInt(text.slice(2, -1), 10);
267
+ }
268
+ return (code === 0x9 ||
269
+ code === 0xa ||
270
+ code === 0xd ||
271
+ (code >= 0x20 && code <= 0xd7ff) ||
272
+ (code >= 0xe000 && code <= 0xfffd) ||
273
+ (code >= 0x10000 && code <= 0x10ffff));
274
+ });
275
+ // [67] Reference ::= EntityRef | CharRef
276
+ // cf: https://www.w3.org/TR/xml/#NT-Reference
277
+ g.rule("Reference", (0, grammar_1.alt)((0, grammar_1.ref)("EntityRef"), (0, grammar_1.ref)("CharRef")));
278
+ // [68] EntityRef ::= '&' Name ';'
279
+ // cf: https://www.w3.org/TR/xml/#NT-EntityRef
280
+ g.rule("EntityRef", (0, grammar_1.seq)((0, grammar_1.lit)("&"), (0, grammar_1.ref)("Name"), (0, grammar_1.lit)(";")));
281
+ // [69] PEReference ::= '%' Name ';'
282
+ // cf: https://www.w3.org/TR/xml/#NT-PEReference
283
+ g.rule("PEReference", (0, grammar_1.seq)((0, grammar_1.lit)("%"), (0, grammar_1.ref)("Name"), (0, grammar_1.lit)(";")));
284
+ // [70] EntityDecl ::= GEDecl | PEDecl
285
+ // cf: https://www.w3.org/TR/xml/#NT-EntityDecl
286
+ g.rule("EntityDecl", (0, grammar_1.alt)((0, grammar_1.ref)("GEDecl"), (0, grammar_1.ref)("PEDecl")));
287
+ // [71] GEDecl ::= '<!ENTITY' S Name S EntityDef S? '>'
288
+ // cf: https://www.w3.org/TR/xml/#NT-GEDecl
289
+ g.rule("GEDecl", (0, grammar_1.seq)((0, grammar_1.lit)("<!ENTITY"), (0, grammar_1.ref)("S"), (0, grammar_1.ref)("Name"), (0, grammar_1.ref)("S"), (0, grammar_1.ref)("EntityDef"), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)(">")));
290
+ // [72] PEDecl ::= '<!ENTITY' S '%' S Name S PEDef S? '>'
291
+ // cf: https://www.w3.org/TR/xml/#NT-PEDecl
292
+ g.rule("PEDecl", (0, grammar_1.seq)((0, grammar_1.lit)("<!ENTITY"), (0, grammar_1.ref)("S"), (0, grammar_1.lit)("%"), (0, grammar_1.ref)("S"), (0, grammar_1.ref)("Name"), (0, grammar_1.ref)("S"), (0, grammar_1.ref)("PEDef"), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)(">")));
293
+ // [73] EntityDef ::= EntityValue | (ExternalID NDataDecl?)
294
+ // cf: https://www.w3.org/TR/xml/#NT-EntityDef
295
+ g.rule("EntityDef", (0, grammar_1.alt)((0, grammar_1.ref)("EntityValue"), (0, grammar_1.seq)((0, grammar_1.ref)("ExternalID"), (0, grammar_1.opt)((0, grammar_1.ref)("NDataDecl")))));
296
+ // [74] PEDef ::= EntityValue | ExternalID
297
+ // cf: https://www.w3.org/TR/xml/#NT-PEDef
298
+ g.rule("PEDef", (0, grammar_1.alt)((0, grammar_1.ref)("EntityValue"), (0, grammar_1.ref)("ExternalID")));
299
+ // [75] ExternalID ::= 'SYSTEM' S SystemLiteral | 'PUBLIC' S PubidLiteral S SystemLiteral
300
+ // cf: https://www.w3.org/TR/xml/#NT-ExternalID
301
+ g.rule("ExternalID", (0, grammar_1.alt)((0, grammar_1.seq)((0, grammar_1.lit)("SYSTEM"), (0, grammar_1.ref)("S"), (0, grammar_1.ref)("SystemLiteral")), (0, grammar_1.seq)((0, grammar_1.lit)("PUBLIC"), (0, grammar_1.ref)("S"), (0, grammar_1.ref)("PubidLiteral"), (0, grammar_1.ref)("S"), (0, grammar_1.ref)("SystemLiteral"))));
302
+ // [76] NDataDecl ::= S 'NDATA' S Name
303
+ // cf: https://www.w3.org/TR/xml/#NT-NDataDecl
304
+ g.rule("NDataDecl", (0, grammar_1.seq)((0, grammar_1.ref)("S"), (0, grammar_1.lit)("NDATA"), (0, grammar_1.ref)("S"), (0, grammar_1.ref)("Name")));
305
+ // [77] TextDecl ::= '<?xml' VersionInfo? EncodingDecl S? '?>'
306
+ // cf: https://www.w3.org/TR/xml/#NT-TextDecl
307
+ g.rule("TextDecl", (0, grammar_1.seq)((0, grammar_1.lit)("<?xml"), (0, grammar_1.opt)((0, grammar_1.ref)("VersionInfo")), (0, grammar_1.ref)("EncodingDecl"), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)("?>")));
308
+ // [78] extParsedEnt ::= TextDecl? content
309
+ // cf: https://www.w3.org/TR/xml/#NT-extParsedEnt
310
+ g.rule("extParsedEnt", (0, grammar_1.seq)((0, grammar_1.opt)((0, grammar_1.ref)("TextDecl")), (0, grammar_1.ref)("content")));
311
+ // [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName "'" | "'" EncName "'")
312
+ // cf: https://www.w3.org/TR/xml/#NT-EncodingDecl
313
+ g.rule("EncodingDecl", (0, grammar_1.seq)((0, grammar_1.ref)("S"), (0, grammar_1.lit)("encoding"), (0, grammar_1.ref)("Eq"), (0, grammar_1.alt)((0, grammar_1.seq)((0, grammar_1.lit)(DQ), (0, grammar_1.ref)("EncName"), (0, grammar_1.lit)(DQ)), (0, grammar_1.seq)((0, grammar_1.lit)(SQ), (0, grammar_1.ref)("EncName"), (0, grammar_1.lit)(SQ)))));
314
+ // [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
315
+ // cf: https://www.w3.org/TR/xml/#NT-EncName
316
+ g.rule("EncName", (0, grammar_1.seq)((0, grammar_1.reg)("[A-Za-z]"), (0, grammar_1.rep)((0, grammar_1.reg)("[A-Za-z0-9._-]"))));
317
+ // [82] NotationDecl ::= '<!NOTATION' S Name S (ExternalID | PublicID) S? '>'
318
+ // cf: https://www.w3.org/TR/xml/#NT-NotationDecl
319
+ g.rule("NotationDecl", (0, grammar_1.seq)((0, grammar_1.lit)("<!NOTATION"), (0, grammar_1.ref)("S"), (0, grammar_1.ref)("Name"), (0, grammar_1.ref)("S"), (0, grammar_1.alt)((0, grammar_1.ref)("ExternalID"), (0, grammar_1.ref)("PublicID")), (0, grammar_1.opt)((0, grammar_1.ref)("S")), (0, grammar_1.lit)(">")));
320
+ // [83] PublicID ::= 'PUBLIC' S PubidLiteral
321
+ // cf: https://www.w3.org/TR/xml/#NT-PublicID
322
+ g.rule("PublicID", (0, grammar_1.seq)((0, grammar_1.lit)("PUBLIC"), (0, grammar_1.ref)("S"), (0, grammar_1.ref)("PubidLiteral")));
323
+ /**
324
+ * Unimplemented Well-formedness Constraints (WFC)
325
+ *
326
+ * The following constraints are currently not enforced by this parser.
327
+ * Implementation would require an Entity Manager, DTD Processor, and extended Context.
328
+ *
329
+ * - [WFC: PEs in Internal Subset]
330
+ * "In the internal DTD subset, parameter-entity references MUST NOT occur within markup declarations..."
331
+ * https://www.w3.org/TR/xml/#wfc-PEinInternalSubset
332
+ *
333
+ * - [WFC: External Subset]
334
+ * "The external subset, if any, MUST match the production for extSubset."
335
+ * https://www.w3.org/TR/xml/#ExtSubset
336
+ *
337
+ * - [WFC: PE Between Declarations]
338
+ * "The replacement text of a parameter entity reference in a DeclSep MUST match the production extSubsetDecl."
339
+ * https://www.w3.org/TR/xml/#PE-between-Decls
340
+ *
341
+ * - [WFC: No External Entity References]
342
+ * "Attribute values MUST NOT contain direct or indirect entity references to external entities."
343
+ * https://www.w3.org/TR/xml/#NoExternalRefs
344
+ *
345
+ * - [WFC: No < in Attribute Values]
346
+ * "The replacement text of any entity referred to directly or indirectly in an attribute value MUST NOT contain a <."
347
+ * https://www.w3.org/TR/xml/#CleanAttrVals
348
+ *
349
+ * - [WFC: Entity Declared]
350
+ * "In a document without any DTD, a document with only an internal DTD subset which contains no parameter entity references, or a document with standalone='yes', for an entity reference that does not occur within the external subset or a parameter entity, the Name given in the entity reference MUST match that in an entity declaration..."
351
+ * https://www.w3.org/TR/xml/#wf-entdeclared
352
+ *
353
+ * - [WFC: Parsed Entity]
354
+ * "An internal general parsed entity MUST match the production content."
355
+ * https://www.w3.org/TR/xml/#textent
356
+ *
357
+ * - [WFC: No Recursion]
358
+ * "A parsed entity MUST NOT contain a recursive reference to itself, either directly or indirectly."
359
+ * https://www.w3.org/TR/xml/#norecursion
360
+ *
361
+ * - [WFC: In DTD]
362
+ * "Parameter-entity references MUST NOT occur outside the DTD."
363
+ * https://www.w3.org/TR/xml/#indtd
364
+ */
365
+ exports.grammar = g.build();
366
+ exports.g_deprecated = g;