public void TestTwoChildrenOfNilRoot() /*throws Exception*/ { CommonTree root_0 = (CommonTree)adaptor.Nil(); CommonTree t = new V(101, 2); CommonTree u = new V(new CommonToken(102, "102")); adaptor.AddChild(root_0, t); adaptor.AddChild(root_0, u); Assert.IsNull(root_0.Parent); Assert.AreEqual(-1, root_0.ChildIndex); Assert.AreEqual(0, t.ChildIndex); Assert.AreEqual(1, u.ChildIndex); }
// $ANTLR start "id" // ..\\Plugin.EffiProz\\AntlrParser\\EffiProz.g:14:1: id : ( T_IDENT | T_QUOTED_IDENT ); public EffiProzParser.id_return id() // throws RecognitionException [1] { EffiProzParser.id_return retval = new EffiProzParser.id_return(); retval.Start = input.LT(1); object root_0 = null; IToken set1 = null; object set1_tree = null; try { // ..\\Plugin.EffiProz\\AntlrParser\\EffiProz.g:14:3: ( T_IDENT | T_QUOTED_IDENT ) // ..\\Plugin.EffiProz\\AntlrParser\\EffiProz.g: { root_0 = (object)adaptor.GetNilNode(); set1 = (IToken)input.LT(1); if ((input.LA(1) >= T_IDENT && input.LA(1) <= T_QUOTED_IDENT)) { input.Consume(); adaptor.AddChild(root_0, (object)adaptor.Create(set1)); state.errorRecovery = false; } else { MismatchedSetException mse = new MismatchedSetException(null, input); throw mse; } } retval.Stop = input.LT(-1); retval.Tree = (object)adaptor.RulePostProcessing(root_0); adaptor.SetTokenBoundaries(retval.Tree, (IToken)retval.Start, (IToken)retval.Stop); } catch (RecognitionException re) { ReportError(re); Recover(input, re); // Conversion of the second argument necessary, but harmless retval.Tree = (object)adaptor.ErrorNode(input, (IToken)retval.Start, input.LT(-1), re); } finally { } return(retval); }
public virtual object ParseTree() { if (ttype != TreePatternLexer.Begin) { throw new InvalidOperationException("No beginning."); } ttype = tokenizer.NextToken(); object root = ParseNode(); if (root == null) { return(null); } while (ttype == TreePatternLexer.Begin || ttype == TreePatternLexer.Id || ttype == TreePatternLexer.Percent || ttype == TreePatternLexer.Dot) { if (ttype == TreePatternLexer.Begin) { object subtree = ParseTree(); adaptor.AddChild(root, subtree); } else { object child = ParseNode(); if (child == null) { return(null); } adaptor.AddChild(root, child); } } if (ttype != TreePatternLexer.End) { throw new InvalidOperationException("No end."); } ttype = tokenizer.NextToken(); return(root); }
public object ParseTree() { if (ttype != TreePatternLexer.BEGIN) { Console.Out.WriteLine("no BEGIN"); return(null); } ttype = tokenizer.NextToken(); object root = ParseNode(); if (root == null) { return(null); } while (ttype == TreePatternLexer.BEGIN || ttype == TreePatternLexer.ID || ttype == TreePatternLexer.PERCENT || ttype == TreePatternLexer.DOT) { if (ttype == TreePatternLexer.BEGIN) { object subtree = ParseTree(); adaptor.AddChild(root, subtree); } else { object child = ParseNode(); if (child == null) { return(null); } adaptor.AddChild(root, child); } } if (ttype != TreePatternLexer.END) { Console.Out.WriteLine("no END"); return(null); } ttype = tokenizer.NextToken(); return(root); }
public TreeVisualizerViewModel(ITreeAdaptor adaptor, object tree, ITokenStream tokenStream, string sourceText) { if (adaptor == null) throw new ArgumentNullException("adaptor"); if (tree == null) throw new ArgumentNullException("tree"); _adaptor = adaptor; _tree = tree; _tokenStream = tokenStream; _sourceText = sourceText; object root = adaptor.Nil(); adaptor.AddChild(root, tree); _treeViewModel = new TreeViewModel(_adaptor, root); }
// $ANTLR start "start" // D:\\Szkolenia\\Artykuł ProgramistaMag - DSL\\Code\\DSLSamples\\SimpleDSL\\Simple.g:8:0: start : additiveExpression ; public SimpleParser.start_return start() // throws RecognitionException [1] { SimpleParser.start_return retval = new SimpleParser.start_return(); retval.Start = input.LT(1); CommonTree root_0 = null; SimpleParser.additiveExpression_return additiveExpression1 = default(SimpleParser.additiveExpression_return); try { // D:\\Szkolenia\\Artykuł ProgramistaMag - DSL\\Code\\DSLSamples\\SimpleDSL\\Simple.g:9:2: ( additiveExpression ) // D:\\Szkolenia\\Artykuł ProgramistaMag - DSL\\Code\\DSLSamples\\SimpleDSL\\Simple.g:9:2: additiveExpression { root_0 = (CommonTree)adaptor.GetNilNode(); PushFollow(FOLLOW_additiveExpression_in_start43); additiveExpression1 = additiveExpression(); state.followingStackPointer--; adaptor.AddChild(root_0, additiveExpression1.Tree); } retval.Stop = input.LT(-1); retval.Tree = (CommonTree)adaptor.RulePostProcessing(root_0); adaptor.SetTokenBoundaries(retval.Tree, (IToken)retval.Start, (IToken)retval.Stop); } catch (RecognitionException re) { ReportError(re); Recover(input, re); // Conversion of the second argument necessary, but harmless retval.Tree = (CommonTree)adaptor.ErrorNode(input, (IToken)retval.Start, input.LT(-1), re); } finally { } return(retval); }
public TreeVisualizerViewModel(ITreeAdaptor adaptor, object tree, ITokenStream tokenStream, string sourceText) { if (adaptor == null) { throw new ArgumentNullException("adaptor"); } if (tree == null) { throw new ArgumentNullException("tree"); } _adaptor = adaptor; _tree = tree; _tokenStream = tokenStream; _sourceText = sourceText; object root = adaptor.Nil(); adaptor.AddChild(root, tree); _treeViewModel = new TreeViewModel(_adaptor, root); }
// $ANTLR start "start" // D:\\Szkolenia\\Artykuł ProgramistaMag - DSL\\Code\\DSLSamples\\HelloWorld\\Simple.g:13:0: start : ID EOF -> ^( START ID ) ; public SimpleParser.start_return start() // throws RecognitionException [1] { SimpleParser.start_return retval = new SimpleParser.start_return(); retval.Start = input.LT(1); CommonTree root_0 = null; IToken ID1 = null; IToken EOF2 = null; CommonTree ID1_tree = null; CommonTree EOF2_tree = null; RewriteRuleTokenStream stream_ID = new RewriteRuleTokenStream(adaptor, "token ID"); RewriteRuleTokenStream stream_EOF = new RewriteRuleTokenStream(adaptor, "token EOF"); try { // D:\\Szkolenia\\Artykuł ProgramistaMag - DSL\\Code\\DSLSamples\\HelloWorld\\Simple.g:13:8: ( ID EOF -> ^( START ID ) ) // D:\\Szkolenia\\Artykuł ProgramistaMag - DSL\\Code\\DSLSamples\\HelloWorld\\Simple.g:13:8: ID EOF { ID1 = (IToken)Match(input, ID, FOLLOW_ID_in_start50); stream_ID.Add(ID1); EOF2 = (IToken)Match(input, EOF, FOLLOW_EOF_in_start52); stream_EOF.Add(EOF2); // AST REWRITE // elements: ID // token labels: // rule labels: retval // token list labels: // rule list labels: // wildcard labels: retval.Tree = root_0; RewriteRuleSubtreeStream stream_retval = new RewriteRuleSubtreeStream(adaptor, "rule retval", retval != null ? retval.Tree : null); root_0 = (CommonTree)adaptor.GetNilNode(); // 13:15: -> ^( START ID ) { // D:\\Szkolenia\\Artykuł ProgramistaMag - DSL\\Code\\DSLSamples\\HelloWorld\\Simple.g:13:18: ^( START ID ) { CommonTree root_1 = (CommonTree)adaptor.GetNilNode(); root_1 = (CommonTree)adaptor.BecomeRoot((CommonTree)adaptor.Create(START, "START"), root_1); adaptor.AddChild(root_1, stream_ID.NextNode()); adaptor.AddChild(root_0, root_1); } } retval.Tree = root_0; retval.Tree = root_0; } retval.Stop = input.LT(-1); retval.Tree = (CommonTree)adaptor.RulePostProcessing(root_0); adaptor.SetTokenBoundaries(retval.Tree, (IToken)retval.Start, (IToken)retval.Stop); } catch (RecognitionException re) { ReportError(re); Recover(input, re); // Conversion of the second argument necessary, but harmless retval.Tree = (CommonTree)adaptor.ErrorNode(input, (IToken)retval.Start, input.LT(-1), re); } finally { } return(retval); }
// $ANTLR start "create_index" // ..\\Plugin.postgre\\AntlrParser\\PostgreSQL.g:14:1: create_index[IndexConstraint index] : CREATE ( UNIQUE )? INDEX ( CONCURRENTLY )? name= index_name ON table_name ( USING id )? LPAREN index_column[index] ( COMMA index_column[index] )* RPAREN ; public PostgreSQLParser.create_index_return create_index(IndexConstraint index) // throws RecognitionException [1] { PostgreSQLParser.create_index_return retval = new PostgreSQLParser.create_index_return(); retval.Start = input.LT(1); object root_0 = null; IToken CREATE1 = null; IToken UNIQUE2 = null; IToken INDEX3 = null; IToken CONCURRENTLY4 = null; IToken ON5 = null; IToken USING7 = null; IToken LPAREN9 = null; IToken COMMA11 = null; IToken RPAREN13 = null; PostgreSQLParser.index_name_return name = default(PostgreSQLParser.index_name_return); PostgreSQLParser.table_name_return table_name6 = default(PostgreSQLParser.table_name_return); PostgreSQLParser.id_return id8 = default(PostgreSQLParser.id_return); PostgreSQLParser.index_column_return index_column10 = default(PostgreSQLParser.index_column_return); PostgreSQLParser.index_column_return index_column12 = default(PostgreSQLParser.index_column_return); object CREATE1_tree = null; object UNIQUE2_tree = null; object INDEX3_tree = null; object CONCURRENTLY4_tree = null; object ON5_tree = null; object USING7_tree = null; object LPAREN9_tree = null; object COMMA11_tree = null; object RPAREN13_tree = null; try { // ..\\Plugin.postgre\\AntlrParser\\PostgreSQL.g:14:36: ( CREATE ( UNIQUE )? INDEX ( CONCURRENTLY )? name= index_name ON table_name ( USING id )? LPAREN index_column[index] ( COMMA index_column[index] )* RPAREN ) // ..\\Plugin.postgre\\AntlrParser\\PostgreSQL.g:15:5: CREATE ( UNIQUE )? INDEX ( CONCURRENTLY )? name= index_name ON table_name ( USING id )? LPAREN index_column[index] ( COMMA index_column[index] )* RPAREN { root_0 = (object)adaptor.GetNilNode(); CREATE1 = (IToken)Match(input, CREATE, FOLLOW_CREATE_in_create_index37); CREATE1_tree = (object)adaptor.Create(CREATE1); adaptor.AddChild(root_0, CREATE1_tree); // ..\\Plugin.postgre\\AntlrParser\\PostgreSQL.g:16:5: ( UNIQUE )? int alt1 = 2; int LA1_0 = input.LA(1); if ((LA1_0 == UNIQUE)) { alt1 = 1; } switch (alt1) { case 1: // ..\\Plugin.postgre\\AntlrParser\\PostgreSQL.g:16:6: UNIQUE { UNIQUE2 = (IToken)Match(input, UNIQUE, FOLLOW_UNIQUE_in_create_index44); UNIQUE2_tree = (object)adaptor.Create(UNIQUE2); adaptor.AddChild(root_0, UNIQUE2_tree); index.IsUnique = true; } break; } INDEX3 = (IToken)Match(input, INDEX, FOLLOW_INDEX_in_create_index54); INDEX3_tree = (object)adaptor.Create(INDEX3); adaptor.AddChild(root_0, INDEX3_tree); // ..\\Plugin.postgre\\AntlrParser\\PostgreSQL.g:18:5: ( CONCURRENTLY )? int alt2 = 2; int LA2_0 = input.LA(1); if ((LA2_0 == CONCURRENTLY)) { alt2 = 1; } switch (alt2) { case 1: // ..\\Plugin.postgre\\AntlrParser\\PostgreSQL.g:18:5: CONCURRENTLY { CONCURRENTLY4 = (IToken)Match(input, CONCURRENTLY, FOLLOW_CONCURRENTLY_in_create_index60); CONCURRENTLY4_tree = (object)adaptor.Create(CONCURRENTLY4); adaptor.AddChild(root_0, CONCURRENTLY4_tree); } break; } PushFollow(FOLLOW_index_name_in_create_index70); name = index_name(); state.followingStackPointer--; adaptor.AddChild(root_0, name.Tree); index.Name = UnquoteName(((name != null) ? input.ToString((IToken)(name.Start), (IToken)(name.Stop)) : null)); ON5 = (IToken)Match(input, ON, FOLLOW_ON_in_create_index79); ON5_tree = (object)adaptor.Create(ON5); adaptor.AddChild(root_0, ON5_tree); PushFollow(FOLLOW_table_name_in_create_index81); table_name6 = table_name(); state.followingStackPointer--; adaptor.AddChild(root_0, table_name6.Tree); index.SetDummyTable(((table_name6 != null) ? table_name6.result : default(NameWithSchema))); // ..\\Plugin.postgre\\AntlrParser\\PostgreSQL.g:21:5: ( USING id )? int alt3 = 2; int LA3_0 = input.LA(1); if ((LA3_0 == USING)) { alt3 = 1; } switch (alt3) { case 1: // ..\\Plugin.postgre\\AntlrParser\\PostgreSQL.g:21:6: USING id { USING7 = (IToken)Match(input, USING, FOLLOW_USING_in_create_index90); USING7_tree = (object)adaptor.Create(USING7); adaptor.AddChild(root_0, USING7_tree); PushFollow(FOLLOW_id_in_create_index92); id8 = id(); state.followingStackPointer--; adaptor.AddChild(root_0, id8.Tree); } break; } LPAREN9 = (IToken)Match(input, LPAREN, FOLLOW_LPAREN_in_create_index100); LPAREN9_tree = (object)adaptor.Create(LPAREN9); adaptor.AddChild(root_0, LPAREN9_tree); PushFollow(FOLLOW_index_column_in_create_index102); index_column10 = index_column(index); state.followingStackPointer--; adaptor.AddChild(root_0, index_column10.Tree); // ..\\Plugin.postgre\\AntlrParser\\PostgreSQL.g:22:32: ( COMMA index_column[index] )* do { int alt4 = 2; int LA4_0 = input.LA(1); if ((LA4_0 == COMMA)) { alt4 = 1; } switch (alt4) { case 1: // ..\\Plugin.postgre\\AntlrParser\\PostgreSQL.g:22:33: COMMA index_column[index] { COMMA11 = (IToken)Match(input, COMMA, FOLLOW_COMMA_in_create_index106); COMMA11_tree = (object)adaptor.Create(COMMA11); adaptor.AddChild(root_0, COMMA11_tree); PushFollow(FOLLOW_index_column_in_create_index108); index_column12 = index_column(index); state.followingStackPointer--; adaptor.AddChild(root_0, index_column12.Tree); } break; default: goto loop4; } } while (true); loop4: ; // Stops C# compiler whining that label 'loop4' has no statements RPAREN13 = (IToken)Match(input, RPAREN, FOLLOW_RPAREN_in_create_index113); RPAREN13_tree = (object)adaptor.Create(RPAREN13); adaptor.AddChild(root_0, RPAREN13_tree); } retval.Stop = input.LT(-1); retval.Tree = (object)adaptor.RulePostProcessing(root_0); adaptor.SetTokenBoundaries(retval.Tree, (IToken)retval.Start, (IToken)retval.Stop); } catch (RecognitionException re) { ReportError(re); Recover(input, re); // Conversion of the second argument necessary, but harmless retval.Tree = (object)adaptor.ErrorNode(input, (IToken)retval.Start, input.LT(-1), re); } finally { } return(retval); }
// $ANTLR start "find_deps" // ..\\Plugin.mssql\\AntlrParser\\MSSQL.g:14:1: find_deps[DepsCollector dc] : ( find_dep_item[dc] )* ; public MSSQLParser.find_deps_return find_deps(DepsCollector dc) // throws RecognitionException [1] { MSSQLParser.find_deps_return retval = new MSSQLParser.find_deps_return(); retval.Start = input.LT(1); object root_0 = null; MSSQLParser.find_dep_item_return find_dep_item1 = default(MSSQLParser.find_dep_item_return); try { // ..\\Plugin.mssql\\AntlrParser\\MSSQL.g:15:5: ( ( find_dep_item[dc] )* ) // ..\\Plugin.mssql\\AntlrParser\\MSSQL.g:15:7: ( find_dep_item[dc] )* { root_0 = (object)adaptor.GetNilNode(); // ..\\Plugin.mssql\\AntlrParser\\MSSQL.g:15:7: ( find_dep_item[dc] )* do { int alt1 = 2; int LA1_0 = input.LA(1); if (((LA1_0 >= T_NSTRING && LA1_0 <= T_BLOB) || (LA1_0 >= ASTERISK && LA1_0 <= ARROW_UP) || (LA1_0 >= ADD && LA1_0 <= XOR))) { alt1 = 1; } switch (alt1) { case 1: // ..\\Plugin.mssql\\AntlrParser\\MSSQL.g:15:7: find_dep_item[dc] { PushFollow(FOLLOW_find_dep_item_in_find_deps38); find_dep_item1 = find_dep_item(dc); state.followingStackPointer--; adaptor.AddChild(root_0, find_dep_item1.Tree); } break; default: goto loop1; } } while (true); loop1: ; // Stops C# compiler whining that label 'loop1' has no statements } retval.Stop = input.LT(-1); retval.Tree = (object)adaptor.RulePostProcessing(root_0); adaptor.SetTokenBoundaries(retval.Tree, (IToken)retval.Start, (IToken)retval.Stop); } catch (RecognitionException re) { ReportError(re); Recover(input, re); // Conversion of the second argument necessary, but harmless retval.Tree = (object)adaptor.ErrorNode(input, (IToken)retval.Start, input.LT(-1), re); } finally { } return(retval); }