1324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/** XML parser by Oliver Zeigermann October 10, 2005 */
2324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverlexer grammar t012lexerXML;
3324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruveroptions {
4324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  language = JavaScript;
5324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver}
6324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
7324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@lexer::members {
8324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverthis.lout = [];
9324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverthis.output = function(line) {
10324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    this.lout.push(line);
11324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver};
12324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver}
13324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
14324c4644fee44b9898524c09511bd33c3f12e2dfBen GruverDOCUMENT
15324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    :  XMLDECL? WS? DOCTYPE? WS? ELEMENT WS?
16324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ;
17324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
18324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverfragment DOCTYPE
19324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    :
20324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        '<!DOCTYPE' WS rootElementName=GENERIC_ID
21324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {this.output("ROOTELEMENT: "+$rootElementName.text)}
22324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        WS
23324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        (
24324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            ( 'SYSTEM' WS sys1=VALUE
25324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver                {this.output("SYSTEM: "+$sys1.text)}
26324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
27324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            | 'PUBLIC' WS pub=VALUE WS sys2=VALUE
28324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver                {this.output("PUBLIC: "+$pub.text)}
29324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver                {this.output("SYSTEM: "+$sys2.text)}
30324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            )
31324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            ( WS )?
32324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        )?
33324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        ( dtd=INTERNAL_DTD
34324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            {this.output("INTERNAL DTD: "+$dtd.text)}
35324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        )?
36324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver		'>'
37324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	;
38324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
39324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverfragment INTERNAL_DTD : '[' (options {greedy=false;} : .)* ']' ;
40324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
41324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverfragment PI :
42324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        '<?' target=GENERIC_ID WS?
43324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver          {this.output("PI: "+$target.text)}
44324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        ( ATTRIBUTE WS? )*  '?>'
45324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	;
46324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
47324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverfragment XMLDECL :
48324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        '<?' ('x'|'X') ('m'|'M') ('l'|'L') WS?
49324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver          {this.output("XML declaration")}
50324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        ( ATTRIBUTE WS? )*  '?>'
51324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	;
52324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
53324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
54324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverfragment ELEMENT
55324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    : ( START_TAG
56324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            (ELEMENT
57324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            | t=PCDATA
58324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver                {this.output("PCDATA: \""+$t.text+"\"")}
59324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            | t=CDATA
60324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver                {this.output("CDATA: \""+$t.text+"\"")}
61324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            | t=COMMENT
62324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver                {this.output("Comment: \""+$t.text+"\"")}
63324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            | pi=PI
64324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            )*
65324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            END_TAG
66324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        | EMPTY_ELEMENT
67324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        )
68324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ;
69324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
70324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverfragment START_TAG
71324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    : '<' WS? name=GENERIC_ID WS?
72324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver          {this.output("Start Tag: "+$name.text)}
73324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        ( ATTRIBUTE WS? )* '>'
74324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ;
75324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
76324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverfragment EMPTY_ELEMENT
77324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    : '<' WS? name=GENERIC_ID WS?
78324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver          {this.output("Empty Element: "+$name.text)}
79324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        ( ATTRIBUTE WS? )* '/>'
80324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ;
81324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
82324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverfragment ATTRIBUTE
83324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    : name=GENERIC_ID WS? '=' WS? value=VALUE
84324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {this.output("Attr: "+$name.text+"="+$value.text)}
85324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ;
86324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
87324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverfragment END_TAG
88324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    : '</' WS? name=GENERIC_ID WS? '>'
89324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {this.output("End Tag: "+$name.text)}
90324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ;
91324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
92324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverfragment COMMENT
93324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	:	'<!--' (options {greedy=false;} : .)* '-->'
94324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	;
95324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
96324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverfragment CDATA
97324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	:	'<![CDATA[' (options {greedy=false;} : .)* ']]>'
98324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	;
99324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
100324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverfragment PCDATA : (~'<')+ ;
101324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
102324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverfragment VALUE :
103324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        ( '\"' (~'\"')* '\"'
104324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        | '\'' (~'\'')* '\''
105324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        )
106324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	;
107324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
108324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverfragment GENERIC_ID
109324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    : ( LETTER | '_' | ':')
110324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        ( options {greedy=true;} : LETTER | '0'..'9' | '.' | '-' | '_' | ':' )*
111324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	;
112324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
113324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverfragment LETTER
114324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	: 'a'..'z'
115324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	| 'A'..'Z'
116324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	;
117324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
118324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverfragment WS  :
119324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        (   ' '
120324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        |   '\t'
121324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        |  ( '\n'
122324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            |	'\r\n'
123324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            |	'\r'
124324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            )
125324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        )+
126324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ;
127324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
128