FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
processing/java/src/antlr/ExtendedCommonASTWithHiddenTokens.java at master · 6zm/processing · GitHub
6zm
processing
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
processing
/
java
/
src
/
antlr
/
ExtendedCommonASTWithHiddenTokens.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
130 lines (102 loc) · 3.51 KB
Breadcrumbs
processing
/
java
/
src
/
antlr
/
ExtendedCommonASTWithHiddenTokens.java
Copy path
File metadata and controls
130 lines (102 loc) · 3.51 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package
antlr
;
/* ANTLR Translator Generator
* Project led by Terence Parr at http://www.jGuru.com
* Software rights: http://www.antlr.org/RIGHTS.html
*
* $Id$
*/
import
java
.
io
.*;
import
antlr
.
collections
.*;
/** A CommonAST whose initialization copies hidden token
* information from the Token used to create a node.
*/
public
class
ExtendedCommonASTWithHiddenTokens
extends
CommonASTWithHiddenTokens
{
public
ExtendedCommonASTWithHiddenTokens
() {
super
();
}
public
ExtendedCommonASTWithHiddenTokens
(
Token
tok
) {
super
(
tok
);
}
public
void
initialize
(
AST
ast
) {
ExtendedCommonASTWithHiddenTokens
a
=
(
ExtendedCommonASTWithHiddenTokens
)
ast
;
super
.
initialize
(
a
);
hiddenBefore
=
a
.
getHiddenBefore
();
hiddenAfter
=
a
.
getHiddenAfter
();
}
public
String
getHiddenAfterString
() {
CommonHiddenStreamToken
t
;
StringBuilder
hiddenAfterString
=
new
StringBuilder
(
100
);
for
(
t
=
hiddenAfter
;
t
!=
null
;
t
=
t
.
getHiddenAfter
() ) {
hiddenAfterString
.
append
(
t
.
getText
());
}
return
hiddenAfterString
.
toString
();
}
public
String
getHiddenBeforeString
() {
antlr
.
CommonHiddenStreamToken
child
=
null
,
parent
=
hiddenBefore
;
// if there aren't any hidden tokens here, quietly return
//
if
(
parent
==
null
) {
return
""
;
}
// traverse back to the head of the list of tokens before this node
do
{
child
=
parent
;
parent
=
child
.
getHiddenBefore
();
}
while
(
parent
!=
null
);
// dump that list
StringBuilder
hiddenBeforeString
=
new
StringBuilder
(
100
);
for
(
CommonHiddenStreamToken
t
=
child
;
t
!=
null
;
t
=
t
.
getHiddenAfter
() ) {
hiddenBeforeString
.
append
(
t
.
getText
());
}
return
hiddenBeforeString
.
toString
();
}
public
void
xmlSerializeNode
(
Writer
out
)
throws
IOException
{
StringBuilder
sb
=
new
StringBuilder
(
100
);
sb
.
append
(
"<"
);
sb
.
append
(
getClass
().
getName
() +
" "
);
sb
.
append
(
"hiddenBeforeString=
\"
"
+
encode
(
getHiddenBeforeString
()) +
"
\"
text=
\"
"
+
encode
(
getText
()) +
"
\"
type=
\"
"
+
getType
() +
"
\"
hiddenAfterString=
\"
"
+
encode
(
getHiddenAfterString
()) +
"
\"
/>"
);
out
.
write
(
sb
.
toString
());
}
public
void
xmlSerializeRootOpen
(
Writer
out
)
throws
IOException
{
StringBuilder
sb
=
new
StringBuilder
(
100
);
sb
.
append
(
"<"
);
sb
.
append
(
getClass
().
getName
() +
" "
);
sb
.
append
(
"hiddenBeforeString=
\"
"
+
encode
(
getHiddenBeforeString
()) +
"
\"
text=
\"
"
+
encode
(
getText
()) +
"
\"
type=
\"
"
+
getType
() +
"
\"
hiddenAfterString=
\"
"
+
encode
(
getHiddenAfterString
()) +
"
\"
>
\n
"
);
out
.
write
(
sb
.
toString
());
}
public
void
xmlSerializeRootClose
(
Writer
out
)
throws
IOException
{
out
.
write
(
"</"
+
getClass
().
getName
() +
">
\n
"
);
}
public
void
xmlSerialize
(
Writer
out
)
throws
IOException
{
// print out this node and all siblings
for
(
AST
node
=
this
;
node
!=
null
;
node
=
node
.
getNextSibling
()) {
if
(
node
.
getFirstChild
() ==
null
) {
// print guts (class name, attributes)
((
BaseAST
)
node
).
xmlSerializeNode
(
out
);
}
else
{
((
BaseAST
)
node
).
xmlSerializeRootOpen
(
out
);
// print children
((
BaseAST
)
node
.
getFirstChild
()).
xmlSerialize
(
out
);
// print end tag
((
BaseAST
)
node
).
xmlSerializeRootClose
(
out
);
}
}
}
}
Back
|
FazBrowse Home
|
New Git URL