Bring chrisheller-patch-1 branch up to date
This commit is contained in:
commit
bba03383d2
|
@ -64,3 +64,4 @@ tool-testsuite/target
|
|||
runtime/Cpp/demo/generated
|
||||
xcuserdata
|
||||
*.jar
|
||||
.vscode
|
||||
|
|
|
@ -94,3 +94,5 @@ YYYY/MM/DD, github id, Full name, email
|
|||
2016/03/29, msteiger, Martin Steiger, antlr@martin-steiger.de
|
||||
2016/03/28, gagern, Martin von Gagern, gagern@ma.tum.de
|
||||
2016/07/20, chrisheller, Chris Heller, chris.heller.greyheller@gmail.com
|
||||
2016/07/20, nburles, Nathan Burles, nburles@gmail.com
|
||||
2016/07/20, kosl90, Li Liqiang, kos1990l@gmail.com
|
||||
|
|
|
@ -18,6 +18,8 @@ if(NOT WITH_DEMO)
|
|||
FORCE)
|
||||
endif(NOT WITH_DEMO)
|
||||
|
||||
option(WITH_LIBCXX "Building with clang++ and libc++(in Linux). To enable with: -DWITH_LIBCXX=On" On)
|
||||
|
||||
project(LIBANTLR4)
|
||||
|
||||
if(CMAKE_VERSION VERSION_EQUAL "3.0.0" OR
|
||||
|
@ -36,11 +38,12 @@ if(APPLE)
|
|||
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
|
||||
endif()
|
||||
|
||||
find_package(Java REQUIRED)
|
||||
|
||||
file(STRINGS "VERSION" ANTLR_VERSION)
|
||||
|
||||
if (WITH_DEMO)
|
||||
# Java is not necessary if building without demos.
|
||||
find_package(Java REQUIRED)
|
||||
|
||||
if (NOT ANTLR_JAR_LOCATION)
|
||||
message(FATAL_ERROR "Missing antlr4.jar location. You can specify it's path using: -DANTLR_JAR_LOCATION=<path>")
|
||||
else()
|
||||
|
@ -56,18 +59,21 @@ endif(WITH_DEMO)
|
|||
set(MY_CXX_WARNING_FLAGS " -Wall -pedantic -W")
|
||||
|
||||
# Initialize CXXFLAGS.
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11 ${MY_CXX_WARNING_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g -std=c++11 ${MY_CXX_WARNING_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -Os -DNDEBUG -std=c++11 ${MY_CXX_WARNING_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG -std=c++11 ${MY_CXX_WARNING_FLGAS}")
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O2 -g -std=c++11 ${MY_CXX_WARNING_FLAGS}")
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${MY_CXX_WARNING_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g ${MY_CXX_WARNING_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -Os -DNDEBUG ${MY_CXX_WARNING_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG ${MY_CXX_WARNING_FLGAS}")
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O2 -g ${MY_CXX_WARNING_FLAGS}")
|
||||
|
||||
# Compiler-specific C++11 activation.
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
|
||||
if (NOT (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7))
|
||||
message(FATAL_ERROR "${PROJECT_NAME} requires g++ 4.7 or greater.")
|
||||
# Just g++-5.0 and greater contain <codecvt> header. (test in ubuntu)
|
||||
if (NOT (GCC_VERSION VERSION_GREATER 5.0 OR GCC_VERSION VERSION_EQUAL 5.0))
|
||||
message(FATAL_ERROR "${PROJECT_NAME} requires g++ 5.0 or greater.")
|
||||
endif ()
|
||||
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND APPLE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
||||
|
@ -77,6 +83,10 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND CMAKE_SYSTEM_NAME MATCHES
|
|||
if (NOT (CLANG_VERSION VERSION_GREATER 4.2.1 OR CLANG_VERSION VERSION_EQUAL 4.2.1))
|
||||
message(FATAL_ERROR "${PROJECT_NAME} requires clang 4.2.1 or greater.")
|
||||
endif ()
|
||||
# You can use libc++ to compile this project when g++ is NOT greater than or equal to 5.0.
|
||||
if (WITH_LIBCXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
||||
endif()
|
||||
else ()
|
||||
message(FATAL_ERROR "Your C++ compiler does not support C++11.")
|
||||
endif ()
|
||||
|
|
|
@ -38,7 +38,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.
|
||||
|
||||
If you are compiling with cmake, the minimum version required is cmake 3.3.
|
||||
If you are compiling with cmake, the minimum version required is cmake 2.8.
|
||||
|
||||
#### Compiling on Windows
|
||||
Simply open the VS solution (VS 2013+) and build it.
|
||||
|
|
|
@ -35,7 +35,7 @@ void myBarLexerAction() { /* do something*/ };
|
|||
// Appears in line with the other class member definitions in the cpp file.
|
||||
@lexer::definitions {/* lexer definitions section */}
|
||||
|
||||
channels { COMMENTS_CHANNEL, DIRECTIVE }
|
||||
channels { CommentsChannel, DirectiveChannel }
|
||||
|
||||
tokens {
|
||||
DUMMY
|
||||
|
@ -65,7 +65,7 @@ ClosePar: ')';
|
|||
OpenCurly: '{' -> pushMode(Mode1);
|
||||
CloseCurly: '}' -> popMode;
|
||||
QuestionMark: '?';
|
||||
Comma: ',';
|
||||
Comma: ',' -> skip;
|
||||
Dollar: '$' -> more, mode(Mode1), type(DUMMY);
|
||||
|
||||
String: '"' .*? '"';
|
||||
|
@ -73,7 +73,7 @@ Foo: {canTestFoo()}? 'foo' {isItFoo()}? { myFooLexerAction(); };
|
|||
Bar: 'bar' {isItBar()}? { myBarLexerAction(); };
|
||||
Any: Foo Dot Bar? DotDot Baz;
|
||||
|
||||
Comment : '#' ~[\r\n]* '\r'? '\n' -> skip ;
|
||||
Comment : '#' ~[\r\n]* '\r'? '\n' -> channel(CommentsChannel);
|
||||
WS: [ \t\r\n]+ -> channel(99);
|
||||
|
||||
fragment Baz: 'Baz';
|
||||
|
|
|
@ -24,6 +24,16 @@ file(GLOB libantlrcpp_SRC
|
|||
add_library(antlr4_shared SHARED ${libantlrcpp_SRC})
|
||||
add_library(antlr4_static STATIC ${libantlrcpp_SRC})
|
||||
|
||||
set(LIB_OUTPUT_DIR "${CMAKE_HOME_DIRECTORY}/dist") # put generated libraries here.
|
||||
message(STATUS "Output libraries to ${LIB_OUTPUT_DIR}")
|
||||
|
||||
# make sure 'make' works fine even if ${LIB_OUTPUT_DIR} is deleted.
|
||||
add_custom_target(make_lib_output_dir ALL
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIB_OUTPUT_DIR}
|
||||
)
|
||||
|
||||
add_dependencies(antlr4_shared make_lib_output_dir)
|
||||
add_dependencies(antlr4_static make_lib_output_dir)
|
||||
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||
target_link_libraries(antlr4_shared ${UUID_LIBRARIES})
|
||||
|
@ -44,13 +54,18 @@ endif()
|
|||
set_target_properties(antlr4_shared
|
||||
PROPERTIES VERSION ${ANTLR_VERSION}
|
||||
SOVERSION ${ANTLR_VERSION}
|
||||
OUTPUT_NAME libantlr4-runtime
|
||||
OUTPUT_NAME antlr4-runtime
|
||||
LIBRARY_OUTPUT_DIRECTORY ${LIB_OUTPUT_DIR}
|
||||
# TODO: test in windows. DLL is treated as runtime.
|
||||
# see https://cmake.org/cmake/help/v3.0/prop_tgt/LIBRARY_OUTPUT_DIRECTORY.html
|
||||
RUNTIME_OUTPUT_DIRECTORY ${LIB_OUTPUT_DIR}
|
||||
COMPILE_FLAGS "${disabled_compile_warnings}")
|
||||
|
||||
set_target_properties(antlr4_static
|
||||
PROPERTIES VERSION ${ANTLR_VERSION}
|
||||
SOVERSION ${ANTLR_VERSION}
|
||||
OUTPUT_NAME libantlr4-runtime
|
||||
OUTPUT_NAME antlr4-runtime
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${LIB_OUTPUT_DIR}
|
||||
COMPILE_FLAGS "${disabled_compile_warnings}")
|
||||
|
||||
install(TARGETS antlr4_shared
|
||||
|
|
|
@ -57,7 +57,12 @@ ANTLRInputStream::ANTLRInputStream(std::istream &stream) {
|
|||
}
|
||||
|
||||
void ANTLRInputStream::load(const std::string &input) {
|
||||
_data = utfConverter.from_bytes(input);
|
||||
// Remove the UTF-8 BOM if present.
|
||||
const char bom[4] = "\xef\xbb\xbf";
|
||||
if (input.compare(0, 3, bom, 3) == 0)
|
||||
_data = antlrcpp::utfConverter.from_bytes(input.substr(3, std::string::npos));
|
||||
else
|
||||
_data = antlrcpp::utfConverter.from_bytes(input);
|
||||
p = 0;
|
||||
}
|
||||
|
||||
|
@ -66,10 +71,9 @@ void ANTLRInputStream::load(std::istream &stream) {
|
|||
return;
|
||||
|
||||
_data.clear();
|
||||
p = 0;
|
||||
|
||||
std::string s((std::istreambuf_iterator<char>(stream)), std::istreambuf_iterator<char>());
|
||||
_data = antlrcpp::utfConverter.from_bytes(s);
|
||||
load(s);
|
||||
}
|
||||
|
||||
void ANTLRInputStream::reset() {
|
||||
|
@ -157,7 +161,7 @@ std::string ANTLRInputStream::getText(const Interval &interval) {
|
|||
return "";
|
||||
}
|
||||
|
||||
return utfConverter.to_bytes(_data.substr(start, count));
|
||||
return antlrcpp::utfConverter.to_bytes(_data.substr(start, count));
|
||||
}
|
||||
|
||||
std::string ANTLRInputStream::getSourceName() const {
|
||||
|
@ -168,7 +172,7 @@ std::string ANTLRInputStream::getSourceName() const {
|
|||
}
|
||||
|
||||
std::string ANTLRInputStream::toString() const {
|
||||
return utfConverter.to_bytes(_data);
|
||||
return antlrcpp::utfConverter.to_bytes(_data);
|
||||
}
|
||||
|
||||
void ANTLRInputStream::InitializeInstanceFields() {
|
||||
|
|
|
@ -718,16 +718,16 @@ Ref<LexerAction> ATNDeserializer::lexerActionFactory(LexerActionType type, int d
|
|||
return std::make_shared< LexerModeAction>(data1);
|
||||
|
||||
case LexerActionType::MORE:
|
||||
return LexerMoreAction::INSTANCE;
|
||||
return LexerMoreAction::getInstance();
|
||||
|
||||
case LexerActionType::POP_MODE:
|
||||
return LexerPopModeAction::INSTANCE;
|
||||
return LexerPopModeAction::getInstance();
|
||||
|
||||
case LexerActionType::PUSH_MODE:
|
||||
return std::make_shared<LexerPushModeAction>(data1);
|
||||
|
||||
case LexerActionType::SKIP:
|
||||
return LexerSkipAction::INSTANCE;
|
||||
return LexerSkipAction::getInstance();
|
||||
|
||||
case LexerActionType::TYPE:
|
||||
return std::make_shared<LexerTypeAction>(data1);
|
||||
|
|
|
@ -78,7 +78,7 @@ bool ArrayPredictionContext::operator == (PredictionContext const& o) const {
|
|||
antlrcpp::Arrays::equals(parents, other->parents);
|
||||
}
|
||||
|
||||
std::string ArrayPredictionContext::toString() {
|
||||
std::string ArrayPredictionContext::toString() const {
|
||||
if (isEmpty()) {
|
||||
return "[]";
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ namespace atn {
|
|||
virtual int getReturnState(size_t index) const override;
|
||||
bool operator == (const PredictionContext &o) const override;
|
||||
|
||||
virtual std::string toString();
|
||||
virtual std::string toString() const override;
|
||||
private:
|
||||
std::vector<Ref<PredictionContext>> makeRef(const std::vector<std::weak_ptr<PredictionContext>> &input);
|
||||
};
|
||||
|
|
|
@ -38,7 +38,10 @@ using namespace antlr4;
|
|||
using namespace antlr4::atn;
|
||||
using namespace antlr4::misc;
|
||||
|
||||
const Ref<LexerMoreAction> LexerMoreAction::INSTANCE { new LexerMoreAction() };
|
||||
const Ref<LexerMoreAction> LexerMoreAction::getInstance() {
|
||||
static Ref<LexerMoreAction> instance(new LexerMoreAction());
|
||||
return instance;
|
||||
}
|
||||
|
||||
LexerMoreAction::LexerMoreAction() {
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace atn {
|
|||
/// <summary>
|
||||
/// Provides a singleton instance of this parameterless lexer action.
|
||||
/// </summary>
|
||||
static const Ref<LexerMoreAction> INSTANCE;
|
||||
static const Ref<LexerMoreAction> getInstance();
|
||||
|
||||
/// <summary>
|
||||
/// {@inheritDoc} </summary>
|
||||
|
|
|
@ -38,7 +38,10 @@ using namespace antlr4;
|
|||
using namespace antlr4::atn;
|
||||
using namespace antlr4::misc;
|
||||
|
||||
const Ref<LexerPopModeAction> LexerPopModeAction::INSTANCE { new LexerPopModeAction() };
|
||||
const Ref<LexerPopModeAction> LexerPopModeAction::getInstance() {
|
||||
static Ref<LexerPopModeAction> instance(new LexerPopModeAction());
|
||||
return instance;
|
||||
}
|
||||
|
||||
LexerPopModeAction::LexerPopModeAction() {
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace atn {
|
|||
/// <summary>
|
||||
/// Provides a singleton instance of this parameterless lexer action.
|
||||
/// </summary>
|
||||
static const Ref<LexerPopModeAction> INSTANCE;
|
||||
static const Ref<LexerPopModeAction> getInstance();
|
||||
|
||||
/// <summary>
|
||||
/// {@inheritDoc} </summary>
|
||||
|
|
|
@ -38,7 +38,10 @@ using namespace antlr4;
|
|||
using namespace antlr4::atn;
|
||||
using namespace antlr4::misc;
|
||||
|
||||
const Ref<LexerSkipAction> LexerSkipAction::INSTANCE { new LexerSkipAction() };
|
||||
const Ref<LexerSkipAction> LexerSkipAction::getInstance() {
|
||||
static Ref<LexerSkipAction> instance(new LexerSkipAction());
|
||||
return instance;
|
||||
}
|
||||
|
||||
LexerSkipAction::LexerSkipAction() {
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ namespace atn {
|
|||
class ANTLR4CPP_PUBLIC LexerSkipAction final : public LexerAction {
|
||||
public:
|
||||
/// Provides a singleton instance of this parameterless lexer action.
|
||||
static const Ref<LexerSkipAction> INSTANCE;
|
||||
static const Ref<LexerSkipAction> getInstance();
|
||||
|
||||
/// <summary>
|
||||
/// {@inheritDoc} </summary>
|
||||
|
|
|
@ -128,7 +128,7 @@ void IntervalSet::add(const Interval &addition) {
|
|||
}
|
||||
|
||||
// if we bump up against or overlap next, merge
|
||||
_intervals.erase(iterator);// remove this one
|
||||
iterator = _intervals.erase(iterator);// remove this one
|
||||
--iterator; // move backwards to what we just set
|
||||
*iterator = bigger.Union(next); // set to 3 merged ones
|
||||
// ml: no need to advance iterator, we do that in the next round anyway. ++iterator; // first call to next after previous duplicates the result
|
||||
|
|
|
@ -67,6 +67,7 @@ namespace tree {
|
|||
/// based upon the parser.
|
||||
/// </summary>
|
||||
virtual std::string toStringTree(Parser *parser) = 0;
|
||||
using Tree::toStringTree;
|
||||
};
|
||||
|
||||
} // namespace tree
|
||||
|
|
|
@ -45,13 +45,14 @@ namespace tree {
|
|||
/// operations with no return type. </param>
|
||||
template<typename T>
|
||||
class ANTLR4CPP_PUBLIC ParseTreeVisitor {
|
||||
|
||||
public:
|
||||
virtual ~ParseTreeVisitor() {}
|
||||
|
||||
/// <summary>
|
||||
/// Visit a parse tree, and return a user-defined result of the operation.
|
||||
/// </summary>
|
||||
/// <param name="tree"> The <seealso cref="ParseTree"/> to visit. </param>
|
||||
/// <returns> The result of visiting the parse tree. </returns>
|
||||
public:
|
||||
virtual T* visit(ParseTree *tree) = 0;
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -101,7 +101,7 @@ ParseTreeMatch ParseTreePatternMatcher::match(Ref<ParseTree> const& tree, const
|
|||
}
|
||||
|
||||
ParseTreePattern ParseTreePatternMatcher::compile(const std::string &pattern, int patternRuleIndex) {
|
||||
ListTokenSource tokenSrc(std::move(tokenize(pattern)));
|
||||
ListTokenSource tokenSrc(tokenize(pattern));
|
||||
CommonTokenStream tokens(&tokenSrc);
|
||||
|
||||
ParserInterpreter parserInterp(_parser->getGrammarFileName(), _parser->getVocabulary(),
|
||||
|
|
|
@ -51,6 +51,12 @@ public:
|
|||
};
|
||||
<endif>
|
||||
|
||||
<if (lexer.channels)>
|
||||
enum {
|
||||
<lexer.channels: {k | <k> = <lexer.channels.(k)>}; separator=", ", wrap, anchor>
|
||||
};
|
||||
<endif>
|
||||
|
||||
<if (rest(lexer.modes))>
|
||||
enum {
|
||||
<rest(lexer.modes): {m | <m> = <i>,}; separator="\n", anchor>
|
||||
|
|
Loading…
Reference in New Issue