Skip to content

Commit

Permalink
add test and a guard in action translator. minor. Relates to antlr#1143
Browse files Browse the repository at this point in the history
  • Loading branch information
parrt committed Mar 30, 2016
1 parent cbef19c commit b78e0e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
package org.antlr.v4.test.tool;

import org.antlr.v4.test.runtime.java.BaseTest;
import org.antlr.v4.tool.Grammar;
import org.junit.Test;

/** */
Expand Down Expand Up @@ -180,6 +181,15 @@ public class TestActionTranslation extends BaseTest {
testActions(attributeTemplate, "finally", action, expected);
}

@Test public void testEmptyActions() throws Exception {
String gS =
"grammar A;\n"+
"a[] : 'a' ;\n" +
"c : a[] c[] ;\n";
Grammar g = new Grammar(gS);
}


@Test public void testDynamicRuleScopeRefInSubrule() throws Exception {
String action = "$a::n;";
}
Expand Down
4 changes: 2 additions & 2 deletions tool/src/org/antlr/v4/codegen/ActionTranslator.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static List<ActionChunk> translateAction(OutputModelFactory factory,
ActionAST node)
{
String action = tokenWithinAction.getText();
if ( action.charAt(0)=='{' ) {
if ( action!=null && action.length()>0 && action.charAt(0)=='{' ) {
int firstCurly = action.indexOf('{');
int lastCurly = action.lastIndexOf('}');
if ( firstCurly>=0 && lastCurly>=0 ) {
Expand All @@ -158,7 +158,7 @@ public static List<ActionChunk> translateActionChunk(OutputModelFactory factory,
translator.rf = rf;
factory.getGrammar().tool.log("action-translator", "translate " + action);
String altLabel = node.getAltLabel();
if ( rf!=null ) {
if ( rf!=null ) {
translator.nodeContext = rf.ruleCtx;
if ( altLabel!=null ) translator.nodeContext = rf.altLabelCtxs.get(altLabel);
}
Expand Down

0 comments on commit b78e0e9

Please sign in to comment.