forked from nez-peg/nez-grammar
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxml-sym.nez
56 lines (52 loc) · 1.71 KB
/
xml-sym.nez
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// XML Standard 1.0 expressed by using SymbolTable
//
File = PROLOG? DTD? Xml
Chunk = Xml
Expr = Xml
PROLOG = '<?xml' ( !'?>' . )* '?>' S*
DTD = '<!' ( !'>' . )* '>' S*
Xml = { '<' <local Name $key(<symbol Name>) S* $(Attribute)* ('/>' / '>' S* ( $value(Content) / COMMENT )* '</' <is Name> '>') > #Element } S*
Name = { NAME #Name }
NAME = [A-Z_a-z:] ( '-' / [.0-9:A-Z_a-z] )*
Attribute = { $key(Name) S* '=' S* $value(String) #Attr } S*
String = '"' { ( !'"' . )* #Value } '"'
Content = Xml
/ CDataSec
/ Text
CDataSec = '<![CDATA[' { CDATA #CDATA } ']]>' S*
CDATA = ( !']]>' !'<![CDATA[' . )* ( '<![CDATA[' CDATA ']]>' CDATA )?
COMMENT = '<!--' ( !'-->' . )* '-->' S*
Text = { ( !'<' . )+ #Text }
S = [ \t\r\n]
/* Example */
/* from https://en.wikipedia.org/wiki/XML */
example File ~da656af '''
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
</catalog>
'''
example Xml '''
<p>
<!--- <test pattern="SECAM" /><test pattern="NTSC" /> -->
</p>
'''
// formatted by $ nez format