diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg index f2476a2588..01947f0745 100644 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/JavaScript/JavaScript.stg @@ -466,9 +466,9 @@ TestSetInline(s) ::= << }; separator=" || "> >> -// Java language spec 15.19 - shift operators mask operands rather than overflow to 0... need range test +// Javascript language spec - shift operators are 32 bits long max testShiftInRange(shiftAmount) ::= << -(() & ~0x3f) == 0 +(() & ~0x1f) == 0 >> // produces smaller bytecode only when bits.ttypes contains more than two items diff --git a/tool/src/org/antlr/v4/codegen/JavaScriptTarget.java b/tool/src/org/antlr/v4/codegen/JavaScriptTarget.java index 68701e284c..28b13d58dc 100644 --- a/tool/src/org/antlr/v4/codegen/JavaScriptTarget.java +++ b/tool/src/org/antlr/v4/codegen/JavaScriptTarget.java @@ -41,7 +41,7 @@ /** * - * @author Sam Harwell + * @author Eric Vergnaud */ public class JavaScriptTarget extends Target { diff --git a/tool/test/org/antlr/v4/test/rt/js/node/TestBitSetWordSize.java b/tool/test/org/antlr/v4/test/rt/js/node/TestBitSetWordSize.java new file mode 100644 index 0000000000..b082a73e57 --- /dev/null +++ b/tool/test/org/antlr/v4/test/rt/js/node/TestBitSetWordSize.java @@ -0,0 +1,35 @@ +package org.antlr.v4.test.rt.js.node; + +import org.junit.Test; +import static org.junit.Assert.*; + +public class TestBitSetWordSize extends BaseTest { + + @Test + public void testBitSetWordSize() throws Exception { + StringBuilder sb = new StringBuilder(); + sb.append("grammar T;\n"); + // create 40 tokens so we exceed 32 bits size + for(int i=1;i<=40;i++) { + sb.append("T"); + sb.append(i); + sb.append(" : 'x"); + sb.append(i); + sb.append("';\n"); + } + // create a rule which will generate bit set test + sb.append("o : T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8;\n"); + // create a rule where expected token - 32 uses same bit than optional token + sb.append("a : o? T36 {console.log('ok');};\n"); + sb.append("WS : (' '|'\\n') -> skip ;"); + String grammar = sb.toString(); + // use input which triggers bug when word size is 64 + String input = "x36"; + String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "a", input, false); + assertEquals("ok\n", found); + assertNull(this.stderrDuringParse); + } + + + +} \ No newline at end of file