本文整理汇总了C#中Antlr3.Tool.Grammar.GetRule方法的典型用法代码示例。如果您正苦于以下问题:C# Antlr3.Tool.Grammar.GetRule方法的具体用法?C# Antlr3.Tool.Grammar.GetRule怎么用?C# Antlr3.Tool.Grammar.GetRule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Antlr3.Tool.Grammar
的用法示例。
在下文中一共展示了Antlr3.Tool.Grammar.GetRule方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestA
public void TestA()
{
Grammar g = new Grammar(
"parser grammar P;\n" +
"a : A;" );
string expecting =
"(rule a ARG RET scope (BLOCK (ALT A <end-of-alt>) <end-of-block>) <end-of-rule>)";
string found = g.GetRule( "a" ).tree.ToStringTree();
assertEquals( expecting, found );
}
示例2: TestActionInStarLoop
public void TestActionInStarLoop()
{
Grammar g = new Grammar(
"grammar Expr;\n" +
"options { backtrack=true; }\n" +
"a : ({blort} 'x')* ;\n" ); // bug: the synpred had nothing in it
string expecting =
"(rule synpred1_Expr ARG RET scope (BLOCK (ALT blort 'x' <end-of-alt>) <end-of-block>) <end-of-rule>)";
string found = g.GetRule( "synpred1_Expr" ).tree.ToStringTree();
assertEquals( expecting, found );
}
示例3: TestStringStar
public void TestStringStar()
{
Grammar g = new Grammar(
"grammar P;\n" +
"a : 'while'*;" );
string expecting =
"(rule a ARG RET scope (BLOCK (ALT (* (BLOCK (ALT 'while' <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
string found = g.GetRule( "a" ).tree.ToStringTree();
assertEquals( expecting, found );
}
示例4: TestSetLabel
public void TestSetLabel()
{
Grammar g = new Grammar(
"grammar P;\n" +
"a : x=(A|B);\n" );
string expecting =
"(rule a ARG RET scope (BLOCK (ALT (= x (BLOCK (ALT A <end-of-alt>) (ALT B <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
string found = g.GetRule( "a" ).tree.ToStringTree();
assertEquals( expecting, found );
}
示例5: TestRuleListLabelOfPositiveClosure
public void TestRuleListLabelOfPositiveClosure()
{
Grammar g = new Grammar(
"grammar P;\n" +
"options {output=AST;}\n" +
"a : x+=b+;\n" +
"b : ID;\n" );
string expecting =
"(rule a ARG RET scope (BLOCK (ALT (+ (BLOCK (ALT (+= x b) <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
string found = g.GetRule( "a" ).tree.ToStringTree();
assertEquals( expecting, found );
}
示例6: TestNakeRulePlusInLexer
public void TestNakeRulePlusInLexer()
{
Grammar g = new Grammar(
"lexer grammar P;\n" +
"A : B+;\n" +
"B : 'a';" );
string expecting =
"(rule A ARG RET scope (BLOCK (ALT (+ (BLOCK (ALT B <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
string found = g.GetRule( "A" ).tree.ToStringTree();
assertEquals( expecting, found );
}
示例7: TestNakedRuleOptional
public void TestNakedRuleOptional()
{
Grammar g = new Grammar(
"parser grammar P;\n" +
"a : b?;\n" +
"b : B;" );
string expecting =
"(rule a ARG RET scope (BLOCK (ALT (? (BLOCK (ALT b <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
string found = g.GetRule( "a" ).tree.ToStringTree();
assertEquals( expecting, found );
}
示例8: TestEmptyAlt
public void TestEmptyAlt()
{
Grammar g = new Grammar(
"parser grammar P;\n" +
"a : ;");
string expecting =
"(rule a ARG RET scope (BLOCK (ALT epsilon <end-of-alt>) <end-of-block>) <end-of-rule>)";
string found = g.GetRule("a").Tree.ToStringTree();
Assert.AreEqual(expecting, found);
}
示例9: TestCharOptional
public void TestCharOptional()
{
Grammar g = new Grammar(
"grammar P;\n" +
"a : 'a'?;" );
string expecting =
"(rule a ARG RET scope (BLOCK (ALT (? (BLOCK (ALT 'a' <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
string found = g.GetRule( "a" ).tree.ToStringTree();
assertEquals( expecting, found );
}
示例10: ActionTranslator
public ActionTranslator( CodeGenerator generator,
string ruleName,
IToken actionToken,
int outerAltNum )
: this(new ANTLRStringStream( actionToken.Text ))
{
this.generator = generator;
grammar = generator.grammar;
this.enclosingRule = grammar.GetRule( ruleName );
this.actionToken = actionToken;
this.outerAltNum = outerAltNum;
}
示例11: TestStringStarInLexer
public void TestStringStarInLexer()
{
Grammar g = new Grammar(
"lexer grammar P;\n" +
"B : 'while'*;" );
string expecting =
"(rule B ARG RET scope (BLOCK (ALT (* (BLOCK (ALT 'while' <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
string found = g.GetRule( "B" ).Tree.ToStringTree();
Assert.AreEqual( expecting, found );
}
示例12: TestRuleStar
public void TestRuleStar()
{
Grammar g = new Grammar(
"parser grammar P;\n" +
"a : (b)*;\n" +
"b : B;" );
string expecting =
"(rule a ARG RET scope (BLOCK (ALT (* (BLOCK (ALT b <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
string found = g.GetRule( "a" ).Tree.ToStringTree();
Assert.AreEqual( expecting, found );
}
示例13: TestRuleLabelOfPositiveClosure
public void TestRuleLabelOfPositiveClosure()
{
Grammar g = new Grammar(
"grammar P;\n" +
"a : x=b+;\n" +
"b : ID;\n" );
string expecting =
"(rule a ARG RET scope (BLOCK (ALT (+ (BLOCK (ALT (= x b) <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
string found = g.GetRule( "a" ).Tree.ToStringTree();
Assert.AreEqual( expecting, found );
}
示例14: TestRootTokenInStarLoop
public void TestRootTokenInStarLoop()
{
Grammar g = new Grammar(
"grammar Expr;\n" +
"options { backtrack=true; }\n" +
"a : ('*'^)* ;\n" ); // bug: the synpred had nothing in it
string expecting =
"(rule synpred1_Expr ARG RET scope (BLOCK (ALT '*' <end-of-alt>) <end-of-block>) <end-of-rule>)";
string found = g.GetRule( "synpred1_Expr" ).Tree.ToStringTree();
Assert.AreEqual( expecting, found );
}
示例15: TestNotSetListLabelInLoop
public void TestNotSetListLabelInLoop()
{
Grammar g = new Grammar(
"grammar P;\n" +
"a : x+=~(A|B)+;\n" );
string expecting =
"(rule a ARG RET scope (BLOCK (ALT (+ (BLOCK (ALT (+= x (~ (BLOCK (ALT A <end-of-alt>) (ALT B <end-of-alt>) <end-of-block>))) <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
string found = g.GetRule( "a" ).Tree.ToStringTree();
Assert.AreEqual( expecting, found );
}