Merge branch 'master-upstream'

This commit is contained in:
Mike Lischke 2021-03-09 09:44:28 +01:00
commit faa64fdfa7
11 changed files with 45 additions and 39 deletions

View File

@ -55,7 +55,7 @@ import java.util.Set;
name = "antlr4", name = "antlr4",
defaultPhase = LifecyclePhase.GENERATE_SOURCES, defaultPhase = LifecyclePhase.GENERATE_SOURCES,
requiresDependencyResolution = ResolutionScope.COMPILE, requiresDependencyResolution = ResolutionScope.COMPILE,
requiresProject = true) requiresProject = true, threadSafe = true)
public class Antlr4Mojo extends AbstractMojo { public class Antlr4Mojo extends AbstractMojo {
// First, let's deal with the options that the ANTLR tool itself // First, let's deal with the options that the ANTLR tool itself

View File

@ -286,3 +286,7 @@ YYYY/MM/DD, github id, Full name, email
2020/12/03, electrum, David Phillips, david@acz.org 2020/12/03, electrum, David Phillips, david@acz.org
2021/01/25, l215884529, Qiheng Liu, 13607681+l215884529@users.noreply.github.com 2021/01/25, l215884529, Qiheng Liu, 13607681+l215884529@users.noreply.github.com
2021/02/02, tsotnikov, Taras Sotnikov, taras.sotnikov@gmail.com 2021/02/02, tsotnikov, Taras Sotnikov, taras.sotnikov@gmail.com
2021/02/21, namasikanam, Xingyu Xie, namasikanam@gmail.com
2021/02/27, khmarbaise, Karl Heinz Marbaise, github@soebes.com
2021/03/02, hackeris
2021/03/03, xTachyon, Damian Andrei, xTachyon@users.noreply.github.com

View File

@ -36,7 +36,7 @@ using Antlr4.Runtime.Tree;
public void MyParseMethod() { public void MyParseMethod() {
String input = "your text to parse here"; String input = "your text to parse here";
ICharStream stream = CharStreams.fromstring(input); ICharStream stream = CharStreams.fromString(input);
ITokenSource lexer = new MyGrammarLexer(stream); ITokenSource lexer = new MyGrammarLexer(stream);
ITokenStream tokens = new CommonTokenStream(lexer); ITokenStream tokens = new CommonTokenStream(lexer);
MyGrammarParser parser = new MyGrammarParser(tokens); MyGrammarParser parser = new MyGrammarParser(tokens);

View File

@ -91,7 +91,7 @@ Now a fully functioning script might look like the following:
```javascript ```javascript
import antlr4 from 'antlr4'; import antlr4 from 'antlr4';
import MyGrammarLexer from './MyGrammarLexer.js'); import MyGrammarLexer from './MyGrammarLexer.js';
import MyGrammarParser from './MyGrammarParser.js'; import MyGrammarParser from './MyGrammarParser.js';
import MyGrammarListener from './MyGrammarListener.js'; import MyGrammarListener from './MyGrammarListener.js';

View File

@ -76,8 +76,13 @@ endif()
# Initialize CXXFLAGS. # Initialize CXXFLAGS.
if("${CMAKE_VERSION}" VERSION_GREATER 3.1.0) if("${CMAKE_VERSION}" VERSION_GREATER 3.1.0)
set(CMAKE_CXX_STANDARD 11) if(NOT DEFINED CMAKE_CXX_STANDARD)
# only set CMAKE_CXX_STANDARD if not already set
# this allows the standard to be set by the caller, for example with -DCMAKE_CXX_STANDARD:STRING=17
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
else() else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11")

View File

@ -5,11 +5,11 @@ This folder contains the C++ runtime support for ANTLR. See [the canonical antl
## Authors and major contributors ## Authors and major contributors
ANTLR 4 is the result of substantial effort of the following people: ANTLR 4 is the result of substantial effort of the following people:
* [Terence Parr](http://www.cs.usfca.edu/~parrt/), parrt@cs.usfca.edu * [Terence Parr](http://www.cs.usfca.edu/~parrt/), parrt@cs.usfca.edu
ANTLR project lead and supreme dictator for life ANTLR project lead and supreme dictator for life
[University of San Francisco](http://www.usfca.edu/) [University of San Francisco](http://www.usfca.edu/)
* [Sam Harwell](http://tunnelvisionlabs.com/) * [Sam Harwell](http://tunnelvisionlabs.com/)
Tool co-author, Java and C# target) Tool co-author, Java and C# target)
The C++ target has been the work of the following people: The C++ target has been the work of the following people:
@ -40,6 +40,7 @@ The minimum C++ version to compile the ANTLR C++ runtime with is C++11. The supp
Include the antlr4-runtime.h umbrella header in your target application to get everything needed to use the library. 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. 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`.
#### Compiling on Windows with Visual Studio using he Visual Studio projects #### Compiling on Windows with Visual Studio using he Visual Studio projects
Simply open the VS project from the runtime folder (VS 2013+) and build it. Simply open the VS project from the runtime folder (VS 2013+) and build it.
@ -69,5 +70,3 @@ If the CMake variable 'ANTLR4_INSTALL' is set, CMake Packages will be build and
They expose two packages: antlr4_runtime and antlr4_generator which can be referenced to ease up the use of the They expose two packages: antlr4_runtime and antlr4_generator which can be referenced to ease up the use of the
ANTLR Generator and runtime. ANTLR Generator and runtime.
Use and Sample can be found [here](cmake/Antlr4Package.md) Use and Sample can be found [here](cmake/Antlr4Package.md)

View File

@ -2,17 +2,17 @@
## The `antlr4-generator` Package ## The `antlr4-generator` Package
To use the Package you must insert a To use the Package you must insert a
```cmake ```cmake
find_package(antlr4-generator REQUIRED) find_package(antlr4-generator REQUIRED)
``` ```
line in your `CMakeList.txt` file. line in your `CMakeList.txt` file.
The package exposes a function `antlr4_generate` that generates the required setup to call ANTLR for a The package exposes a function `antlr4_generate` that generates the required setup to call ANTLR for a
given input file during build. given input file during build.
The following table lists the parameters that can be used with the function: The following table lists the parameters that can be used with the function:
Argument# | Required | Default | Use Argument# | Required | Default | Use
----------|-----------|---------|--- ----------|-----------|---------|---
0 | Yes | n/a | Unique target name. It is used to generate CMake Variables to reference the various outputs of the generation 0 | Yes | n/a | Unique target name. It is used to generate CMake Variables to reference the various outputs of the generation
@ -42,7 +42,7 @@ Output variable | Meaning
```cmake ```cmake
# generate parser with visitor classes. # generate parser with visitor classes.
# put the classes in C++ namespace 'antlrcpptest::' # put the classes in C++ namespace 'antlrcpptest::'
antlr4_generate( antlr4_generate(
antlrcpptest_parser antlrcpptest_parser
${CMAKE_CURRENT_SOURCE_DIR}/TLexer.g4 ${CMAKE_CURRENT_SOURCE_DIR}/TLexer.g4
LEXER LEXER
@ -56,7 +56,7 @@ Output variable | Meaning
## The `antlr4-runtime` Package ## The `antlr4-runtime` Package
To use the Package you must insert a To use the Package you must insert a
```cmake ```cmake
find_package(antlr4-runtime REQUIRED) find_package(antlr4-runtime REQUIRED)
``` ```
@ -85,7 +85,7 @@ include_directories( ${ANTLR4_INCLUDE_DIR} )
add_dependencies( Parsertest antlr4_shared ) add_dependencies( Parsertest antlr4_shared )
# add runtime to project link libraries # add runtime to project link libraries
target_link_libraries( Parsertest PRIVATE target_link_libraries( Parsertest PRIVATE
antlr4_shared) antlr4_shared)
``` ```
@ -94,12 +94,12 @@ target_link_libraries( Parsertest PRIVATE
# Bring in the required packages # Bring in the required packages
find_package(antlr4-runtime REQUIRED) find_package(antlr4-runtime REQUIRED)
find_package(antlr4-generator REQUIRED) find_package(antlr4-generator REQUIRED)
# Set path to generator # Set path to generator
set(ANTLR4_JAR_LOCATION ${PROJECT_SOURCE_DIR}/thirdparty/antlr/antlr-4.9.1-complete.jar) set(ANTLR4_JAR_LOCATION ${PROJECT_SOURCE_DIR}/thirdparty/antlr/antlr-4.9.1-complete.jar)
# generate lexer # generate lexer
antlr4_generate( antlr4_generate(
antlrcpptest_lexer antlrcpptest_lexer
${CMAKE_CURRENT_SOURCE_DIR}/TLexer.g4 ${CMAKE_CURRENT_SOURCE_DIR}/TLexer.g4
LEXER LEXER
@ -107,9 +107,9 @@ target_link_libraries( Parsertest PRIVATE
FALSE FALSE
"antlrcpptest" "antlrcpptest"
) )
# generate parser # generate parser
antlr4_generate( antlr4_generate(
antlrcpptest_parser antlrcpptest_parser
${CMAKE_CURRENT_SOURCE_DIR}/TParser.g4 ${CMAKE_CURRENT_SOURCE_DIR}/TParser.g4
PARSER PARSER
@ -119,18 +119,18 @@ target_link_libraries( Parsertest PRIVATE
"${ANTLR4_TOKEN_FILES_antlrcpptest_lexer}" "${ANTLR4_TOKEN_FILES_antlrcpptest_lexer}"
"${ANTLR4_TOKEN_DIRECTORY_antlrcpptest_lexer}" "${ANTLR4_TOKEN_DIRECTORY_antlrcpptest_lexer}"
) )
# add directories for generated include files # add directories for generated include files
include_directories( ${PROJECT_BINARY_DIR} ${ANTLR4_INCLUDE_DIR} ${ANTLR4_INCLUDE_DIR_antlrcpptest_lexer} ${ANTLR4_INCLUDE_DIR_antlrcpptest_parser} ) include_directories( ${PROJECT_BINARY_DIR} ${ANTLR4_INCLUDE_DIR} ${ANTLR4_INCLUDE_DIR_antlrcpptest_lexer} ${ANTLR4_INCLUDE_DIR_antlrcpptest_parser} )
# add generated source files # add generated source files
add_executable( Parsertest main.cpp ${ANTLR4_SRC_FILES_antlrcpptest_lexer} ${ANTLR4_SRC_FILES_antlrcpptest_parser} ) add_executable( Parsertest main.cpp ${ANTLR4_SRC_FILES_antlrcpptest_lexer} ${ANTLR4_SRC_FILES_antlrcpptest_parser} )
# add required runtime library # add required runtime library
add_dependencies( Parsertest antlr4_shared ) add_dependencies( Parsertest antlr4_shared )
target_link_libraries( Parsertest PRIVATE target_link_libraries( Parsertest PRIVATE
antlr4_shared) antlr4_shared)
``` ```

View File

@ -88,6 +88,8 @@ if(ANTLR4_ZIP_REPOSITORY)
CMAKE_CACHE_ARGS CMAKE_CACHE_ARGS
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DWITH_STATIC_CRT:BOOL=${ANTLR4_WITH_STATIC_CRT} -DWITH_STATIC_CRT:BOOL=${ANTLR4_WITH_STATIC_CRT}
# -DCMAKE_CXX_STANDARD:STRING=17 # if desired, compile the runtime with a different C++ standard
# -DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD} # alternatively, compile the runtime with the same C++ standard as the outer project
INSTALL_COMMAND "" INSTALL_COMMAND ""
EXCLUDE_FROM_ALL 1) EXCLUDE_FROM_ALL 1)
else() else()
@ -104,6 +106,8 @@ else()
CMAKE_CACHE_ARGS CMAKE_CACHE_ARGS
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DWITH_STATIC_CRT:BOOL=${ANTLR4_WITH_STATIC_CRT} -DWITH_STATIC_CRT:BOOL=${ANTLR4_WITH_STATIC_CRT}
# -DCMAKE_CXX_STANDARD:STRING=17 # if desired, compile the runtime with a different C++ standard
# -DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD} # alternatively, compile the runtime with the same C++ standard as the outer project
INSTALL_COMMAND "" INSTALL_COMMAND ""
EXCLUDE_FROM_ALL 1) EXCLUDE_FROM_ALL 1)
endif() endif()

View File

@ -129,6 +129,8 @@ The ANTLR C++ runtime source is downloaded from GitHub by default. However, user
Visual C++ compiler users may want to additionally define `ANTLR4_WITH_STATIC_CRT` before including the file. Set `ANTLR4_WITH_STATIC_CRT` to true if ANTLR4 C++ runtime library should be compiled with `/MT` flag, otherwise will be compiled with `/MD` flag. This variable has a default value of `OFF`. Changing `ANTLR4_WITH_STATIC_CRT` after building the library may require reinitialization of CMake or `clean` for the library to get rebuilt. Visual C++ compiler users may want to additionally define `ANTLR4_WITH_STATIC_CRT` before including the file. Set `ANTLR4_WITH_STATIC_CRT` to true if ANTLR4 C++ runtime library should be compiled with `/MT` flag, otherwise will be compiled with `/MD` flag. This variable has a default value of `OFF`. Changing `ANTLR4_WITH_STATIC_CRT` after building the library may require reinitialization of CMake or `clean` for the library to get rebuilt.
You may need to modify your local copy of ExternalAntlr4Cpp.cpp to modify some build settings. For example, to specify the C++ standard to use when building the runtime, add `-DCMAKE_CXX_STANDARD:STRING=17` to `CMAKE_CACHE_ARGS`.
### Examples ### Examples
To build and link ANTLR4 static library to a target one may call: To build and link ANTLR4 static library to a target one may call:

View File

@ -88,7 +88,7 @@ function(antlr4_generate
else() else()
set(Antlr4_BuildListenerOption "-no-listener") set(Antlr4_BuildListenerOption "-no-listener")
endif () endif ()
if ( ( ARGC GREATER_EQUAL 5 ) AND ARGV4 ) if ( ( ARGC GREATER_EQUAL 5 ) AND ARGV4 )
set(Antlr4_BuildVisitorOption "-visitor") set(Antlr4_BuildVisitorOption "-visitor")
@ -101,7 +101,7 @@ function(antlr4_generate
else() else()
set(Antlr4_BuildVisitorOption "-no-visitor") set(Antlr4_BuildVisitorOption "-no-visitor")
endif () endif ()
if ( (ARGC GREATER_EQUAL 6 ) AND (NOT ${ARGV5} STREQUAL "") ) if ( (ARGC GREATER_EQUAL 6 ) AND (NOT ${ARGV5} STREQUAL "") )
set(Antlr4_NamespaceOption "-package;${ARGV5}") set(Antlr4_NamespaceOption "-package;${ARGV5}")
@ -109,7 +109,7 @@ function(antlr4_generate
else() else()
set(Antlr4_NamespaceOption "") set(Antlr4_NamespaceOption "")
endif () endif ()
if ( (ARGC GREATER_EQUAL 7 ) AND (NOT ${ARGV6} STREQUAL "") ) if ( (ARGC GREATER_EQUAL 7 ) AND (NOT ${ARGV6} STREQUAL "") )
set(Antlr4_AdditionalDependencies ${ARGV6}) set(Antlr4_AdditionalDependencies ${ARGV6})
else() else()
@ -157,7 +157,7 @@ function(antlr4_generate
# export generated cpp files into list # export generated cpp files into list
foreach(generated_file ${Antlr4_GeneratedTargets}) foreach(generated_file ${Antlr4_GeneratedTargets})
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC") if (NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set_source_files_properties( set_source_files_properties(
${generated_file} ${generated_file}

View File

@ -422,8 +422,7 @@ static std::vector\<uint16_t> _serializedATN;
// Constructs the serialized ATN and writes init code for static member vars. // Constructs the serialized ATN and writes init code for static member vars.
SerializedATN(model) ::= << SerializedATN(model) ::= <<
<if (rest(model.segments))> <model.segments: {segment | static const uint16_t serializedATNSegment<i0>[] = {
<model.segments: {segment | static uint16_t serializedATNSegment<i0>[] = {
<segment; wrap={<\n> }> <segment; wrap={<\n> }>
\};}; separator="\n"> \};}; separator="\n">
@ -431,13 +430,6 @@ SerializedATN(model) ::= <<
serializedATNSegment<i0> + sizeof(serializedATNSegment<i0>) / sizeof(serializedATNSegment<i0>[0])); serializedATNSegment<i0> + sizeof(serializedATNSegment<i0>) / sizeof(serializedATNSegment<i0>[0]));
}> }>
<else>
<! only one segment, can be inlined !>
_serializedATN = {
<model.serialized; wrap = {<\n>}>
};
<endif>
atn::ATNDeserializer deserializer; atn::ATNDeserializer deserializer;
_atn = deserializer.deserialize(_serializedATN); _atn = deserializer.deserialize(_serializedATN);