-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathdemo.html
207 lines (186 loc) · 10.6 KB
/
demo.html
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<script type="text/javascript" src="antlr3-all-min.js"></script>
<script type="text/javascript" src="output/LinqToQuerystringLexer.js"></script>
<script type="text/javascript" src="output/LinqToQuerystringParser.js"></script>
<script type="text/javascript">
var forceDynamicProperties = false;
var buildHtml = "";
function TopNode (inputType, token) { this.inputType = inputType; this.token = token };
function SkipNode (inputType, token) { this.inputType = inputType; this.token = token };
function OrderByNode (inputType, token) { this.inputType = inputType; this.token = token };
function FilterNode (inputType, token) { this.inputType = inputType; this.token = token };
function SelectNode (inputType, token) { this.inputType = inputType; this.token = token };
function InlineCountNode (inputType, token) { this.inputType = inputType; this.token = token };
function ExpandNode (inputType, token) { this.inputType = inputType; this.token = token };
function NotNode (inputType, token) { this.inputType = inputType; this.token = token };
function AndNode (inputType, token) { this.inputType = inputType; this.token = token };
function OrNode (inputType, token) { this.inputType = inputType; this.token = token };
function EqualsNode (inputType, token) { this.inputType = inputType; this.token = token };
function NotEqualsNode (inputType, token) { this.inputType = inputType; this.token = token };
function GreaterThanNode (inputType, token) { this.inputType = inputType; this.token = token };
function GreaterThanOrEqualNode (inputType, token) { this.inputType = inputType; this.token = token };
function LessThanNode (inputType, token) { this.inputType = inputType; this.token = token };
function LessThanOrEqualNode (inputType, token) { this.inputType = inputType; this.token = token };
function StartsWithNode (inputType, token) { this.inputType = inputType; this.token = token };
function EndsWithNode (inputType, token) { this.inputType = inputType; this.token = token };
function SubstringOfNode (inputType, token) { this.inputType = inputType; this.token = token };
function ToLowerNode (inputType, token) { this.inputType = inputType; this.token = token };
function AnyNode (inputType, token) { this.inputType = inputType; this.token = token };
function AllNode (inputType, token) { this.inputType = inputType; this.token = token };
function CountNode (inputType, token) { this.inputType = inputType; this.token = token };
function AverageNode (inputType, token) { this.inputType = inputType; this.token = token };
function MaxNode (inputType, token) { this.inputType = inputType; this.token = token };
function MinNode (inputType, token) { this.inputType = inputType; this.token = token };
function SumNode (inputType, token) { this.inputType = inputType; this.token = token };
function AliasNode (inputType, token) { this.inputType = inputType; this.token = token };
function DynamicIdentifierNode (inputType, token) { this.inputType = inputType; this.token = token };
function IdentifierNode (inputType, token) { this.inputType = inputType; this.token = token };
function StringNode (inputType, token) { this.inputType = inputType; this.token = token };
function BoolNode (inputType, token) { this.inputType = inputType; this.token = token };
function IntNode (inputType, token) { this.inputType = inputType; this.token = token };
function DateTimeNode (inputType, token) { this.inputType = inputType; this.token = token };
function DoubleNode (inputType, token) { this.inputType = inputType; this.token = token };
function SingleNode (inputType, token) { this.inputType = inputType; this.token = token };
function LongNode (inputType, token) { this.inputType = inputType; this.token = token };
function ByteNode (inputType, token) { this.inputType = inputType; this.token = token };
function GuidNode (inputType, token) { this.inputType = inputType; this.token = token };
function DescNode (inputType, token) { this.inputType = inputType; this.token = token };
function AscNode (inputType, token) { this.inputType = inputType; this.token = token };
var processNode = function (input)
{
var node;
var token = input.token;
if (!input.token)
{
node = {};
}
else
{
var inputType = input.token.type;
switch (inputType)
{
case LinqToQuerystringLexer.TOP:
node = new TopNode(inputType, token); break;
case LinqToQuerystringLexer.SKIP:
node = new SkipNode(inputType, token); break;
case LinqToQuerystringLexer.ORDERBY:
node = new OrderByNode(inputType, token); break;
case LinqToQuerystringLexer.FILTER:
node = new FilterNode(inputType, token); break;
case LinqToQuerystringLexer.SELECT:
node = new SelectNode(inputType, token); break;
case LinqToQuerystringLexer.INLINECOUNT:
node = new InlineCountNode(inputType, token); break;
case LinqToQuerystringLexer.EXPAND:
node = new ExpandNode(inputType, token); break;
case LinqToQuerystringLexer.NOT:
node = new NotNode(inputType, token); break;
case LinqToQuerystringLexer.AND:
node = new AndNode(inputType, token); break;
case LinqToQuerystringLexer.OR:
node = new OrNode(inputType, token); break;
case LinqToQuerystringLexer.EQUALS:
node = new EqualsNode(inputType, token); break;
case LinqToQuerystringLexer.NOTEQUALS:
node = new NotEqualsNode(inputType, token); break;
case LinqToQuerystringLexer.GREATERTHAN:
node = new GreaterThanNode(inputType, token); break;
case LinqToQuerystringLexer.GREATERTHANOREQUAL:
node = new GreaterThanOrEqualNode(inputType, token); break;
case LinqToQuerystringLexer.LESSTHAN:
node = new LessThanNode(inputType, token); break;
case LinqToQuerystringLexer.LESSTHANOREQUAL:
node = new LessThanOrEqualNode(inputType, token); break;
case LinqToQuerystringLexer.STARTSWITH:
node = new StartsWithNode(inputType, token); break;
case LinqToQuerystringLexer.ENDSWITH:
node = new EndsWithNode(inputType, token); break;
case LinqToQuerystringLexer.SUBSTRINGOF:
node = new SubstringOfNode(inputType, token); break;
case LinqToQuerystringLexer.TOLOWER:
node = new ToLowerNode(inputType, token); break;
case LinqToQuerystringLexer.ANY:
node = new AnyNode(inputType, token); break;
case LinqToQuerystringLexer.ALL:
node = new AllNode(inputType, token); break;
case LinqToQuerystringLexer.COUNT:
node = new CountNode(inputType, token); break;
case LinqToQuerystringLexer.AVERAGE:
node = new AverageNode(inputType, token); break;
case LinqToQuerystringLexer.MAX:
node = new MaxNode(inputType, token); break;
case LinqToQuerystringLexer.MIN:
node = new MinNode(inputType, token); break;
case LinqToQuerystringLexer.SUM:
node = new SumNode(inputType, token); break;
case LinqToQuerystringLexer.ALIAS:
node = new AliasNode(inputType, token); break;
case LinqToQuerystringLexer.DYNAMICIDENTIFIER:
node = new DynamicIdentifierNode(inputType, token); break;
case LinqToQuerystringLexer.IDENTIFIER:
if (forceDynamicProperties)
{
node = new DynamicIdentifierNode(inputType, token); break;
}
node = new IdentifierNode(inputType, token); break;
case LinqToQuerystringLexer.STRING:
node = new StringNode(inputType, token); break;
case LinqToQuerystringLexer.BOOL:
node = new BoolNode(inputType, token); break;
case LinqToQuerystringLexer.INT:
node = new IntNode(inputType, token); break;
case LinqToQuerystringLexer.DATETIME:
node = new DateTimeNode(inputType, token); break;
case LinqToQuerystringLexer.DOUBLE:
node = new DoubleNode(inputType, token); break;
case LinqToQuerystringLexer.SINGLE:
node = new SingleNode(inputType, token); break;
case LinqToQuerystringLexer.LONG:
node = new LongNode(inputType, token); break;
case LinqToQuerystringLexer.BYTE:
node = new ByteNode(inputType, token); break;
case LinqToQuerystringLexer.GUID:
node = new GuidNode(inputType, token); break;
case LinqToQuerystringLexer.DESC:
node = new DescNode(inputType, token); break;
case LinqToQuerystringLexer.ASC:
node = new AscNode(inputType, token); break;
default:
return null;
}
}
node.Children = [];
var text = "";
if (node.token)
{
text = node.token.text;
}
buildHtml = buildHtml + "<li><span>" + node.constructor.name + " : " + text + "</span>";
buildHtml = buildHtml + "<ul>";
for (index in input.children)
{
var child = input.children[index];
node.Children.push(processNode(child));
}
buildHtml = buildHtml + "</ul>";
buildHtml = buildHtml + "</li>"
return node
};
var go = function () {
// Program
var input = document.getElementById("query").value;
cstream = new org.antlr.runtime.ANTLRStringStream(input),
lexer = new LinqToQuerystringLexer(cstream),
tstream = new org.antlr.runtime.CommonTokenStream(lexer),
parser = new LinqToQuerystringParser(tstream);
buildHtml = "";
var output = document.getElementById("output");
var entryPoint = parser.prog().tree;
var result = processNode(entryPoint);
console.log(result);
output.innerHTML = buildHtml;
}
</script>
<input type="text" name="query" id="query" value="$filter=[Name] eq 'Test'" style="width:500px;"></input>
<button onclick="go();">Process</button>
<div id="output">
</div>