diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserExec/ListLabelForClosureContext.txt b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserExec/ListLabelForClosureContext.txt index 6b964f0a9c..e6c01d50a2 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserExec/ListLabelForClosureContext.txt +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserExec/ListLabelForClosureContext.txt @@ -33,3 +33,5 @@ expression [input] a +[skip] +Go \ No newline at end of file diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserExec/ListLabelsOnRuleRefStartOfAlt.txt b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserExec/ListLabelsOnRuleRefStartOfAlt.txt new file mode 100644 index 0000000000..c9dca5ecab --- /dev/null +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/ParserExec/ListLabelsOnRuleRefStartOfAlt.txt @@ -0,0 +1,34 @@ +[notes] +Checks that this compiles; see https://github.com/antlr/antlr4/issues/2016 + +[type] +Parser + +[grammar] +grammar Test; + +expression +@after { + +} + : op=NOT args+=expression + | args+=expression (op=AND args+=expression)+ + | args+=expression (op=OR args+=expression)+ + | IDENTIFIER + ; + +AND : 'and' ; +OR : 'or' ; +NOT : 'not' ; +IDENTIFIER : [a-zA-Z_][a-zA-Z0-9_]* ; +WS : [ \t\r\n]+ -> skip ; + +[start] +expression + +[input] +a and b + +[skip] +Go +Cpp \ No newline at end of file diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/CSharp.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/CSharp.test.stg index 14def7e03d..5d9cb986fc 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/CSharp.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/CSharp.test.stg @@ -18,7 +18,7 @@ AppendStr(a,b) ::= <%%> Concat(a,b) ::= "" -AssertIsList(v) ::= "System.Collections.IList __ttt__ = ;" // just use static type system +AssertIsList(v) ::= "System.Collections.IList __ttt__ = (System.Collections.IList);" // just use static type system AssignLocal(s,v) ::= " = ;" diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/Go.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/Go.test.stg index c1f62e6f9e..fba2da58f8 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/Go.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/Go.test.stg @@ -18,7 +18,7 @@ AppendStr(a,b) ::= " + " Concat(a,b) ::= "" -AssertIsList(v) ::= "" +AssertIsList(v) ::= "TODO!!" AssignLocal(s, v) ::= " = ;" diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/JavaScript.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/JavaScript.test.stg index 709f13e39a..5f4f534053 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/JavaScript.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/JavaScript.test.stg @@ -18,7 +18,7 @@ AppendStr(a,b) ::= <%%> Concat(a,b) ::= "" -AssertIsList(v) ::= <> +AssertIsList(v) ::= < instanceof Array) ) {throw "value is not an array";}>> AssignLocal(s,v) ::= " = ;" diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/Python2.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/Python2.test.stg index 2292cafe7b..67e93f814f 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/Python2.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/Python2.test.stg @@ -18,7 +18,7 @@ AppendStr(a,b) ::= " + " Concat(a,b) ::= "" -AssertIsList(v) ::= "assert isinstance(v, (list, tuple))" +AssertIsList(v) ::= "assert isinstance(, (list, tuple))" AssignLocal(s,v) ::= " = " diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/Python3.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/Python3.test.stg index 65dcdcd83a..8ea28c57cf 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/Python3.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/Python3.test.stg @@ -18,7 +18,7 @@ AppendStr(a,b) ::= " + " Concat(a,b) ::= "" -AssertIsList(v) ::= "assert isinstance(v, (list, tuple))" +AssertIsList(v) ::= "assert isinstance(, (list, tuple))" AssignLocal(s,v) ::= " = " diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/Processor.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/Processor.java index b53d5dbc98..cd136642e6 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/Processor.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/Processor.java @@ -19,8 +19,9 @@ public class Processor { public final Map environmentVariables; public final boolean throwOnNonZeroErrorCode; - public static ProcessorResult run(String[] arguments, String workingDirectory, Map environmentVariables - ) throws InterruptedException, IOException { + public static ProcessorResult run(String[] arguments, String workingDirectory, Map environmentVariables) + throws InterruptedException, IOException + { return new Processor(arguments, workingDirectory, environmentVariables, true).start(); } diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/CppRunner.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/CppRunner.java index 5159891095..dec7336ec1 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/CppRunner.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/CppRunner.java @@ -21,6 +21,25 @@ import static org.antlr.v4.test.runtime.RuntimeTestUtils.getOS; import static org.antlr.v4.test.runtime.RuntimeTestUtils.isWindows; +/** + * For my own information on I'm recording what I needed to do to get a unit test to compile and run in C++ on the Mac. + * I got a segmentation violation and couldn't figure out how to get information about it, so I turned on debugging + * and then figured out lldb enough to create this issue: https://github.com/antlr/antlr4/issues/3845 on a bug. + * + * cd ~/antlr/code/antlr4/runtime/Cpp + * cmake . -D CMAKE_OSX_ARCHITECTURES="arm64; x86_64" -DCMAKE_BUILD_TYPE=Debug + * make -j 8 + * + * In test dir with generated test code: + * + * clang++ -g -std=c++17 -I /Users/parrt/antlr/code/antlr4/runtime/Cpp/runtime/src -L. -lantlr4-runtime *.cpp + * ./a.out input + * + * $ lldb ./a.out input + * (lldb) run + * ... crash ... + * (lldb) thread backtrace + */ public class CppRunner extends RuntimeRunner { @Override public String getLanguage() { diff --git a/runtime/Dart/lib/src/prediction_context.dart b/runtime/Dart/lib/src/prediction_context.dart index c069200ac6..11b601ea74 100644 --- a/runtime/Dart/lib/src/prediction_context.dart +++ b/runtime/Dart/lib/src/prediction_context.dart @@ -427,7 +427,7 @@ abstract class PredictionContext { return a_; } - mergedParents = List.generate(k, (n) => mergedParents[n]!); + mergedParents = List.generate(k, (n) => mergedParents[n]); mergedReturnStates = List.generate(k, (n) => mergedReturnStates[n]); } diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg index b81f8bc783..8d352f0d6c 100644 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Cpp/Cpp.stg @@ -1104,9 +1104,15 @@ recRuleAltPredicate(ruleName,opPrec) ::= "precpred(_ctx, )" recRuleSetReturnAction(src,name) ::= "recRuleSetReturnAction(src,name) $=$.;" recRuleSetStopToken() ::= "_ctx->stop = _input->LT(-1);" -recRuleAltStartAction(ruleName, ctxName, label) ::= << +recRuleAltStartAction(ruleName, ctxName, label, isListLabel) ::= << _localctx = _tracker.createInstance\<Context>(parentContext, parentState); -_localctx->