标记术语以访问其属性时抛出ArrayOutOfBoundsException

时间:2013-09-26 10:40:51

标签: antlr4

我正在尝试访问规则的属性。虽然这个虚拟规则存根有效:

statement returns [List listOfTerms]
        : statement booleanOperator statement  {$listOfTerms=new ArrayList();}
        | delimited                            {$listOfTerms=getTerms($delimited.text);}
        ;

抛出一个ArrayOutOfBoundsException:

statement returns [List listOfTerms]
        : a=statement booleanOperator b=statement  {$listOfTerms=new ArrayList();}
        | delimited                            {$listOfTerms=getTerms($delimited.text);}
        ;

引发的异常:

java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.antlr.v4.parse.GrammarTreeVisitor.visit(GrammarTreeVisitor.java:206)
        at org.antlr.v4.parse.GrammarTreeVisitor.visitGrammar(GrammarTreeVisitor.java:200)
        at org.antlr.v4.semantics.SymbolCollector.process(SymbolCollector.java:76)
        at org.antlr.v4.semantics.SemanticPipeline.process(SemanticPipeline.java:103)
        at org.antlr.v4.Tool.processNonCombinedGrammar(Tool.java:399)
        at org.antlr.v4.Tool.process(Tool.java:384)
        at org.antlr.mojo.antlr4.Antlr4Mojo$CustomTool.process(Antlr4Mojo.java:461)
        at org.antlr.v4.Tool.processGrammarsOnCommandLine(Tool.java:343)
        at org.antlr.mojo.antlr4.Antlr4Mojo.execute(Antlr4Mojo.java:272)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 2
        at org.antlr.v4.semantics.SymbolCollector.discoverOuterAlt(SymbolCollector.java:111)
        at org.antlr.v4.parse.GrammarTreeVisitor.outerAlternative(GrammarTreeVisitor.java:2284)
        at org.antlr.v4.parse.GrammarTreeVisitor.ruleBlock(GrammarTreeVisitor.java:2197)
        at org.antlr.v4.parse.GrammarTreeVisitor.rule(GrammarTreeVisitor.java:1663)
        at org.antlr.v4.parse.GrammarTreeVisitor.rules(GrammarTreeVisitor.java:1241)
        at org.antlr.v4.parse.GrammarTreeVisitor.grammarSpec(GrammarTreeVisitor.java:480)
        ... 34 more

这也会抛出一个ArrayoutOfBoundsException:

statement returns [List listOfTerms]
        : st+=statement booleanOperator st+=statement  {$listOfTerms=new ArrayList();}
        | delimited                            {$listOfTerms=getTerms($delimited.text);}
        ;

如果我尝试单独访问语句而不标记它们,我会得到一个ISOLATED_RULE_REF:

errorType=ISOLATED_RULE_REF, args=[statement, $statement]

我也试过标记规则备选方案,但这没有效果。

0 个答案:

没有答案