diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/LexerExec/ReservedWordsEscaping_NULL.txt b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/LexerExec/ReservedWordsEscaping_NULL.txt new file mode 100644 index 0000000000..cd09169580 --- /dev/null +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/descriptors/LexerExec/ReservedWordsEscaping_NULL.txt @@ -0,0 +1,17 @@ +[notes] +https://github.com/antlr/antlr4/pull/3889 + +[type] +Lexer + +[grammar] +lexer grammar L; + +NULL : ('N' | 'n')('U' | 'u')('L' | 'l')('L' | 'l') ; + +[input] +NULL + +[output] +[@0,0:3='NULL',<1>,1:0] +[@1,4:3='',<-1>,1:4] diff --git a/runtime/Cpp/README.md b/runtime/Cpp/README.md index 622289ba77..fb5b22da4e 100644 --- a/runtime/Cpp/README.md +++ b/runtime/Cpp/README.md @@ -35,12 +35,12 @@ The C++ target has been the work of the following people: ### Build + Usage Notes -The minimum C++ version to compile the ANTLR C++ runtime with is C++11. The supplied projects can built the runtime either as static or dynamic library, as both 32bit and 64bit arch. The macOS project contains a target for iOS and can also be built using cmake (instead of XCode). +The minimum C++ version to compile the ANTLR C++ runtime with is C++17. The supplied projects can built the runtime either as static or dynamic library, as both 32bit and 64bit arch. The macOS project contains a target for iOS and can also be built using cmake (instead of XCode). Include the antlr4-runtime.h umbrella header in your target application to get everything needed to use the library. If you are compiling with cmake, the minimum version required is cmake 2.8. -By default, the libraries produced by the CMake build target C++11. If you want to target a different C++ standard, you can explicitly pass the standard - e.g. `-DCMAKE_CXX_STANDARD=17`. +By default, the libraries produced by the CMake build target C++17. If you want to target a different C++ standard, you can explicitly pass the standard - e.g. `-DCMAKE_CXX_STANDARD=17`. #### Compiling on Windows with Visual Studio using he Visual Studio projects Simply open the VS project from the runtime folder (VS 2019+) and build it. diff --git a/tool/src/org/antlr/v4/codegen/Target.java b/tool/src/org/antlr/v4/codegen/Target.java index 2d89281030..e109850309 100644 --- a/tool/src/org/antlr/v4/codegen/Target.java +++ b/tool/src/org/antlr/v4/codegen/Target.java @@ -126,7 +126,7 @@ protected void genFile(Grammar g, ST outputFileST, String fileName) * to a token type in the generated code. */ public String getTokenTypeAsTargetLabel(Grammar g, int ttype) { - String name = g.getTokenName(ttype); + String name = this.escapeIfNeeded(g.getTokenName(ttype)); // If name is not valid, return the token type instead if ( Grammar.INVALID_TOKEN_NAME.equals(name) ) { return String.valueOf(ttype); diff --git a/tool/src/org/antlr/v4/codegen/model/Recognizer.java b/tool/src/org/antlr/v4/codegen/model/Recognizer.java index 8e07c29d2f..732f50fb20 100644 --- a/tool/src/org/antlr/v4/codegen/model/Recognizer.java +++ b/tool/src/org/antlr/v4/codegen/model/Recognizer.java @@ -59,7 +59,7 @@ public Recognizer(OutputModelFactory factory) { for (Map.Entry entry : g.tokenNameToTypeMap.entrySet()) { Integer ttype = entry.getValue(); if ( ttype>0 ) { - tokens.put(entry.getKey(), ttype); + tokens.put(gen.getTarget().escapeIfNeeded(entry.getKey()), ttype); } } diff --git a/tool/src/org/antlr/v4/codegen/target/CppTarget.java b/tool/src/org/antlr/v4/codegen/target/CppTarget.java index f8fc4d2702..b45fa91ef9 100644 --- a/tool/src/org/antlr/v4/codegen/target/CppTarget.java +++ b/tool/src/org/antlr/v4/codegen/target/CppTarget.java @@ -39,14 +39,14 @@ public class CppTarget extends Target { "double", "dynamic_cast", "else", "enum", "explicit", "export", "extern", "false", "float", "for", "friend", "goto", "if", "inline", "int", "long", "mutable", "namespace", "new", - "noexcept", "not", "not_eq", "nullptr", "operator", "or", + "noexcept", "not", "not_eq", "nullptr", "NULL", "operator", "or", "or_eq", "private", "protected", "public", "register", "reinterpret_cast", "requires", "return", "short", "signed", "sizeof", "static", "static_assert", "static_cast", "struct", "switch", "template", "this", "thread_local", "throw", "true", "try", "typedef", "typeid", "typename", "union", "unsigned", "using", "virtual", "void", "volatile", "wchar_t", "while", - "xor", "xor_eq", + "xor", "xor_eq", "rule", "parserRule" ));