You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a new 'CST Structure' subsection under 'Usage' with a concrete
JSON example showing the Chevrotain CST output for a self-closing
element (<xs:element name="api" />). The example accurately reflects
the grammar rules in parser.js and the type definitions in api.d.ts.
Closes#470
The parser outputs a Concrete Syntax Tree (CST) using **Chevrotain**.
49
+
50
+
For example, given the following XML input:
51
+
52
+
```xml
53
+
<root>
54
+
<childattr="value">Hello World</child>
55
+
<empty/>
56
+
</root>
57
+
```
58
+
59
+
The resulting `cst` object for the document has the following structure (whitespace `chardata` nodes omitted for brevity):
60
+
61
+
```jsonc
62
+
{
63
+
"name":"document",
64
+
"children": {
65
+
"element": [
66
+
// top-level element(s)
67
+
{
68
+
"name":"element",
69
+
"children": {
70
+
"OPEN": [{ "image":"<" }],
71
+
"Name": [{ "image":"root" }],
72
+
"START_CLOSE": [{ "image":">" }],
73
+
74
+
"content": [
75
+
// child content lives here
76
+
{
77
+
"name":"content",
78
+
"children": {
79
+
"element": [
80
+
// nested child elements
81
+
{
82
+
"name":"element",
83
+
"children": {
84
+
"OPEN": [{ "image":"<" }],
85
+
"Name": [{ "image":"child" }],
86
+
"attribute": [
87
+
{
88
+
"name":"attribute",
89
+
"children": {
90
+
"Name": [{ "image":"attr" }],
91
+
"EQUALS": [{ "image":"=" }],
92
+
"STRING": [{ "image":"\"value\"" }],
93
+
},
94
+
},
95
+
],
96
+
"START_CLOSE": [{ "image":">" }],
97
+
"content": [
98
+
{
99
+
"name":"content",
100
+
"children": {
101
+
"chardata": [
102
+
{
103
+
"name":"chardata",
104
+
"children": {
105
+
"TEXT": [{ "image":"Hello World" }],
106
+
},
107
+
},
108
+
],
109
+
},
110
+
},
111
+
],
112
+
"SLASH_OPEN": [{ "image":"</" }],
113
+
"END_NAME": [{ "image":"child" }],
114
+
"END": [{ "image":">" }],
115
+
},
116
+
},
117
+
{
118
+
"name":"element", // self-closing: <empty/>
119
+
"children": {
120
+
"OPEN": [{ "image":"<" }],
121
+
"Name": [{ "image":"empty" }],
122
+
"SLASH_CLOSE": [{ "image":"/>" }],
123
+
},
124
+
},
125
+
],
126
+
},
127
+
},
128
+
],
129
+
130
+
"SLASH_OPEN": [{ "image":"</" }],
131
+
"END_NAME": [{ "image":"root" }],
132
+
"END": [{ "image":">" }],
133
+
},
134
+
},
135
+
],
136
+
},
137
+
}
138
+
```
139
+
140
+
Every property in `children` is an array of matched tokens (`IToken`) or nested rule nodes (`CstNode`). For full details on all node types (such as `prolog`, `docTypeDecl`, `content`, and `chardata`), see the [TypeScript Definitions](./api.d.ts).
141
+
46
142
## Support
47
143
48
144
Please open [issues](https://github.com/SAP/xml-tols/issues) on github.
0 commit comments