-
Notifications
You must be signed in to change notification settings - Fork 2
/
JspSyntaxTreeSerializer.g
executable file
·68 lines (57 loc) · 1.24 KB
/
JspSyntaxTreeSerializer.g
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
57
58
59
60
61
62
63
64
65
66
67
68
tree grammar JspSyntaxTreeSerializer;
options {
tokenVocab = Jsp;
ASTLabelType = Tree;
rewrite = true;
}
@header {
package com.nohup.tool.jsp2jspx.parser;
}
@members {
private java.io.PrintStream out;
public JspSyntaxTreeSerializer(TreeNodeStream input, java.io.PrintStream out) {
super(input);
this.out = out;
}
private void out(String text) {
out.print(text);
}
}
document
: (
child
| t=PROCESSING_INSTRUCTION { out( "<?" + $t.text + "?>" ); }
| t=DOCTYPE_DEFINITION { out( $t.text ); }
)*
;
text
: t=PCDATA { out( $t.text ); }
| t=CDATA { out( "<![CDATA[" + $t.text + "]]>" ); }
;
element
: ^( ELEMENT
GENERIC_ID { out( "<" + $GENERIC_ID.text ); }
^( ATTRIBUTES ( { out( " " ); } attribute )* )
(
{ out( ">" ); } child+ { out( "</" + $GENERIC_ID.text + ">" ); }
| { out( "/>" ); }
)
)
;
child
: element
| text
| comment
;
comment
: t=COMMENT { out( "<!--" + $t.text + "-->" ); }
;
attribute
: ^(
ATTRIBUTE
t=GENERIC_ID
{ out( $t.text + "=\"" ); }
text*
{ out( "\"" ); }
)
;