0

ルールの属性にアクセスしようとしています。このダミー ルール スタブは機能しますが、次のようになります。

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]

ルールの選択肢にラベルを付けることも試みましたが、効果はありません。

4

0 に答える 0