-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTMLStructureParser.java
More file actions
557 lines (528 loc) · 17.8 KB
/
Copy pathHTMLStructureParser.java
File metadata and controls
557 lines (528 loc) · 17.8 KB
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
// Generated from HTMLStructure.g4 by ANTLR 4.13.2
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.misc.*;
import org.antlr.v4.runtime.tree.*;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue", "this-escape"})
public class HTMLStructureParser extends Parser {
static { RuntimeMetaData.checkVersion("4.13.2", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, T__6=7, T__7=8, IDENTIFIER=9,
STRING=10, WS=11, LINE_COMMENT=12, BLOCK_COMMENT=13;
public static final int
RULE_htmlDoc = 0, RULE_element = 1, RULE_tagElement = 2, RULE_attributeList = 3,
RULE_attribute = 4, RULE_textElement = 5;
private static String[] makeRuleNames() {
return new String[] {
"htmlDoc", "element", "tagElement", "attributeList", "attribute", "textElement"
};
}
public static final String[] ruleNames = makeRuleNames();
private static String[] makeLiteralNames() {
return new String[] {
null, "'#'", "'.'", "'['", "']'", "'{'", "'}'", "','", "'='"
};
}
private static final String[] _LITERAL_NAMES = makeLiteralNames();
private static String[] makeSymbolicNames() {
return new String[] {
null, null, null, null, null, null, null, null, null, "IDENTIFIER", "STRING",
"WS", "LINE_COMMENT", "BLOCK_COMMENT"
};
}
private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames();
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
@Override
public String getGrammarFileName() { return "HTMLStructure.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public ATN getATN() { return _ATN; }
public HTMLStructureParser(TokenStream input) {
super(input);
_interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
@SuppressWarnings("CheckReturnValue")
public static class HtmlDocContext extends ParserRuleContext {
public TerminalNode EOF() { return getToken(HTMLStructureParser.EOF, 0); }
public List<ElementContext> element() {
return getRuleContexts(ElementContext.class);
}
public ElementContext element(int i) {
return getRuleContext(ElementContext.class,i);
}
public HtmlDocContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_htmlDoc; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof HTMLStructureListener ) ((HTMLStructureListener)listener).enterHtmlDoc(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof HTMLStructureListener ) ((HTMLStructureListener)listener).exitHtmlDoc(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof HTMLStructureVisitor ) return ((HTMLStructureVisitor<? extends T>)visitor).visitHtmlDoc(this);
else return visitor.visitChildren(this);
}
}
public final HtmlDocContext htmlDoc() throws RecognitionException {
HtmlDocContext _localctx = new HtmlDocContext(_ctx, getState());
enterRule(_localctx, 0, RULE_htmlDoc);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(15);
_errHandler.sync(this);
_la = _input.LA(1);
while (_la==IDENTIFIER || _la==STRING) {
{
{
setState(12);
element();
}
}
setState(17);
_errHandler.sync(this);
_la = _input.LA(1);
}
setState(18);
match(EOF);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
@SuppressWarnings("CheckReturnValue")
public static class ElementContext extends ParserRuleContext {
public TagElementContext tagElement() {
return getRuleContext(TagElementContext.class,0);
}
public TextElementContext textElement() {
return getRuleContext(TextElementContext.class,0);
}
public ElementContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_element; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof HTMLStructureListener ) ((HTMLStructureListener)listener).enterElement(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof HTMLStructureListener ) ((HTMLStructureListener)listener).exitElement(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof HTMLStructureVisitor ) return ((HTMLStructureVisitor<? extends T>)visitor).visitElement(this);
else return visitor.visitChildren(this);
}
}
public final ElementContext element() throws RecognitionException {
ElementContext _localctx = new ElementContext(_ctx, getState());
enterRule(_localctx, 2, RULE_element);
try {
setState(22);
_errHandler.sync(this);
switch (_input.LA(1)) {
case IDENTIFIER:
enterOuterAlt(_localctx, 1);
{
setState(20);
tagElement();
}
break;
case STRING:
enterOuterAlt(_localctx, 2);
{
setState(21);
textElement();
}
break;
default:
throw new NoViableAltException(this);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
@SuppressWarnings("CheckReturnValue")
public static class TagElementContext extends ParserRuleContext {
public Token id;
public Token IDENTIFIER;
public List<Token> className = new ArrayList<Token>();
public List<TerminalNode> IDENTIFIER() { return getTokens(HTMLStructureParser.IDENTIFIER); }
public TerminalNode IDENTIFIER(int i) {
return getToken(HTMLStructureParser.IDENTIFIER, i);
}
public AttributeListContext attributeList() {
return getRuleContext(AttributeListContext.class,0);
}
public List<ElementContext> element() {
return getRuleContexts(ElementContext.class);
}
public ElementContext element(int i) {
return getRuleContext(ElementContext.class,i);
}
public TagElementContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_tagElement; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof HTMLStructureListener ) ((HTMLStructureListener)listener).enterTagElement(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof HTMLStructureListener ) ((HTMLStructureListener)listener).exitTagElement(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof HTMLStructureVisitor ) return ((HTMLStructureVisitor<? extends T>)visitor).visitTagElement(this);
else return visitor.visitChildren(this);
}
}
public final TagElementContext tagElement() throws RecognitionException {
TagElementContext _localctx = new TagElementContext(_ctx, getState());
enterRule(_localctx, 4, RULE_tagElement);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(24);
match(IDENTIFIER);
setState(27);
_errHandler.sync(this);
_la = _input.LA(1);
if (_la==T__0) {
{
setState(25);
match(T__0);
setState(26);
((TagElementContext)_localctx).id = match(IDENTIFIER);
}
}
setState(33);
_errHandler.sync(this);
_la = _input.LA(1);
while (_la==T__1) {
{
{
setState(29);
match(T__1);
setState(30);
((TagElementContext)_localctx).IDENTIFIER = match(IDENTIFIER);
((TagElementContext)_localctx).className.add(((TagElementContext)_localctx).IDENTIFIER);
}
}
setState(35);
_errHandler.sync(this);
_la = _input.LA(1);
}
setState(40);
_errHandler.sync(this);
_la = _input.LA(1);
if (_la==T__2) {
{
setState(36);
match(T__2);
setState(37);
attributeList();
setState(38);
match(T__3);
}
}
setState(50);
_errHandler.sync(this);
_la = _input.LA(1);
if (_la==T__4) {
{
setState(42);
match(T__4);
setState(46);
_errHandler.sync(this);
_la = _input.LA(1);
while (_la==IDENTIFIER || _la==STRING) {
{
{
setState(43);
element();
}
}
setState(48);
_errHandler.sync(this);
_la = _input.LA(1);
}
setState(49);
match(T__5);
}
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
@SuppressWarnings("CheckReturnValue")
public static class AttributeListContext extends ParserRuleContext {
public List<AttributeContext> attribute() {
return getRuleContexts(AttributeContext.class);
}
public AttributeContext attribute(int i) {
return getRuleContext(AttributeContext.class,i);
}
public AttributeListContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_attributeList; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof HTMLStructureListener ) ((HTMLStructureListener)listener).enterAttributeList(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof HTMLStructureListener ) ((HTMLStructureListener)listener).exitAttributeList(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof HTMLStructureVisitor ) return ((HTMLStructureVisitor<? extends T>)visitor).visitAttributeList(this);
else return visitor.visitChildren(this);
}
}
public final AttributeListContext attributeList() throws RecognitionException {
AttributeListContext _localctx = new AttributeListContext(_ctx, getState());
enterRule(_localctx, 6, RULE_attributeList);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(52);
attribute();
setState(57);
_errHandler.sync(this);
_la = _input.LA(1);
while (_la==T__6) {
{
{
setState(53);
match(T__6);
setState(54);
attribute();
}
}
setState(59);
_errHandler.sync(this);
_la = _input.LA(1);
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
@SuppressWarnings("CheckReturnValue")
public static class AttributeContext extends ParserRuleContext {
public Token name;
public Token value;
public TerminalNode IDENTIFIER() { return getToken(HTMLStructureParser.IDENTIFIER, 0); }
public TerminalNode STRING() { return getToken(HTMLStructureParser.STRING, 0); }
public AttributeContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_attribute; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof HTMLStructureListener ) ((HTMLStructureListener)listener).enterAttribute(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof HTMLStructureListener ) ((HTMLStructureListener)listener).exitAttribute(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof HTMLStructureVisitor ) return ((HTMLStructureVisitor<? extends T>)visitor).visitAttribute(this);
else return visitor.visitChildren(this);
}
}
public final AttributeContext attribute() throws RecognitionException {
AttributeContext _localctx = new AttributeContext(_ctx, getState());
enterRule(_localctx, 8, RULE_attribute);
try {
enterOuterAlt(_localctx, 1);
{
setState(60);
((AttributeContext)_localctx).name = match(IDENTIFIER);
setState(61);
match(T__7);
setState(62);
((AttributeContext)_localctx).value = match(STRING);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
@SuppressWarnings("CheckReturnValue")
public static class TextElementContext extends ParserRuleContext {
public Token value;
public TerminalNode STRING() { return getToken(HTMLStructureParser.STRING, 0); }
public TextElementContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_textElement; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof HTMLStructureListener ) ((HTMLStructureListener)listener).enterTextElement(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof HTMLStructureListener ) ((HTMLStructureListener)listener).exitTextElement(this);
}
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof HTMLStructureVisitor ) return ((HTMLStructureVisitor<? extends T>)visitor).visitTextElement(this);
else return visitor.visitChildren(this);
}
}
public final TextElementContext textElement() throws RecognitionException {
TextElementContext _localctx = new TextElementContext(_ctx, getState());
enterRule(_localctx, 10, RULE_textElement);
try {
enterOuterAlt(_localctx, 1);
{
setState(64);
((TextElementContext)_localctx).value = match(STRING);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static final String _serializedATN =
"\u0004\u0001\rC\u0002\u0000\u0007\u0000\u0002\u0001\u0007\u0001\u0002"+
"\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002\u0004\u0007\u0004\u0002"+
"\u0005\u0007\u0005\u0001\u0000\u0005\u0000\u000e\b\u0000\n\u0000\f\u0000"+
"\u0011\t\u0000\u0001\u0000\u0001\u0000\u0001\u0001\u0001\u0001\u0003\u0001"+
"\u0017\b\u0001\u0001\u0002\u0001\u0002\u0001\u0002\u0003\u0002\u001c\b"+
"\u0002\u0001\u0002\u0001\u0002\u0005\u0002 \b\u0002\n\u0002\f\u0002#\t"+
"\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0003\u0002)\b"+
"\u0002\u0001\u0002\u0001\u0002\u0005\u0002-\b\u0002\n\u0002\f\u00020\t"+
"\u0002\u0001\u0002\u0003\u00023\b\u0002\u0001\u0003\u0001\u0003\u0001"+
"\u0003\u0005\u00038\b\u0003\n\u0003\f\u0003;\t\u0003\u0001\u0004\u0001"+
"\u0004\u0001\u0004\u0001\u0004\u0001\u0005\u0001\u0005\u0001\u0005\u0000"+
"\u0000\u0006\u0000\u0002\u0004\u0006\b\n\u0000\u0000D\u0000\u000f\u0001"+
"\u0000\u0000\u0000\u0002\u0016\u0001\u0000\u0000\u0000\u0004\u0018\u0001"+
"\u0000\u0000\u0000\u00064\u0001\u0000\u0000\u0000\b<\u0001\u0000\u0000"+
"\u0000\n@\u0001\u0000\u0000\u0000\f\u000e\u0003\u0002\u0001\u0000\r\f"+
"\u0001\u0000\u0000\u0000\u000e\u0011\u0001\u0000\u0000\u0000\u000f\r\u0001"+
"\u0000\u0000\u0000\u000f\u0010\u0001\u0000\u0000\u0000\u0010\u0012\u0001"+
"\u0000\u0000\u0000\u0011\u000f\u0001\u0000\u0000\u0000\u0012\u0013\u0005"+
"\u0000\u0000\u0001\u0013\u0001\u0001\u0000\u0000\u0000\u0014\u0017\u0003"+
"\u0004\u0002\u0000\u0015\u0017\u0003\n\u0005\u0000\u0016\u0014\u0001\u0000"+
"\u0000\u0000\u0016\u0015\u0001\u0000\u0000\u0000\u0017\u0003\u0001\u0000"+
"\u0000\u0000\u0018\u001b\u0005\t\u0000\u0000\u0019\u001a\u0005\u0001\u0000"+
"\u0000\u001a\u001c\u0005\t\u0000\u0000\u001b\u0019\u0001\u0000\u0000\u0000"+
"\u001b\u001c\u0001\u0000\u0000\u0000\u001c!\u0001\u0000\u0000\u0000\u001d"+
"\u001e\u0005\u0002\u0000\u0000\u001e \u0005\t\u0000\u0000\u001f\u001d"+
"\u0001\u0000\u0000\u0000 #\u0001\u0000\u0000\u0000!\u001f\u0001\u0000"+
"\u0000\u0000!\"\u0001\u0000\u0000\u0000\"(\u0001\u0000\u0000\u0000#!\u0001"+
"\u0000\u0000\u0000$%\u0005\u0003\u0000\u0000%&\u0003\u0006\u0003\u0000"+
"&\'\u0005\u0004\u0000\u0000\')\u0001\u0000\u0000\u0000($\u0001\u0000\u0000"+
"\u0000()\u0001\u0000\u0000\u0000)2\u0001\u0000\u0000\u0000*.\u0005\u0005"+
"\u0000\u0000+-\u0003\u0002\u0001\u0000,+\u0001\u0000\u0000\u0000-0\u0001"+
"\u0000\u0000\u0000.,\u0001\u0000\u0000\u0000./\u0001\u0000\u0000\u0000"+
"/1\u0001\u0000\u0000\u00000.\u0001\u0000\u0000\u000013\u0005\u0006\u0000"+
"\u00002*\u0001\u0000\u0000\u000023\u0001\u0000\u0000\u00003\u0005\u0001"+
"\u0000\u0000\u000049\u0003\b\u0004\u000056\u0005\u0007\u0000\u000068\u0003"+
"\b\u0004\u000075\u0001\u0000\u0000\u00008;\u0001\u0000\u0000\u000097\u0001"+
"\u0000\u0000\u00009:\u0001\u0000\u0000\u0000:\u0007\u0001\u0000\u0000"+
"\u0000;9\u0001\u0000\u0000\u0000<=\u0005\t\u0000\u0000=>\u0005\b\u0000"+
"\u0000>?\u0005\n\u0000\u0000?\t\u0001\u0000\u0000\u0000@A\u0005\n\u0000"+
"\u0000A\u000b\u0001\u0000\u0000\u0000\b\u000f\u0016\u001b!(.29";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
}
}
}