Merge branch 'master' of https://github.com/DanMcLaughlin/antlr4 into feature/addtests

This commit is contained in:
David Sisson 2016-05-14 10:55:42 -07:00
commit 03024cb466
185 changed files with 2041 additions and 1624 deletions

View File

@ -24,12 +24,15 @@ The C++ target has been the work of the following people:
## Project Status
* Building on OS X, Windows, and Linux (Ubuntu)
* Building on OS X, Windows, and Linux (all major Linux flavours)
* No errors and warnings
* Library linking
* Simple running (e.g. heap objects initialize properly)
* Simple testing (creating significiant objects)
* Some unit tests in the OSX project, for important base classes with almost 100% code coverage.
* All memory allocations checked
* Simple demo application on OS X, Windows and Linux
* Simple command line demo application working on all supported platforms.
### Build 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 OSX project contains a target for iOS and can also be built using cmake (instead of XCode).
In order to maximize build speed and keep the runtime interface as clean as possible there are only the absolutely necessary header files included in runtime .h files. The runtime is prepared to build with precompiled headers. For platform neutrality there is no fixed header included in *.cpp files (like the typical stdafx.h on Windows), but instead a forced include is used. The precompiled header file is antlrcpp-Prefix.h and used by all build systems (Visual Studio, XCode and CMake). It includes all needed STL headers, so you won't find any STL include in the library itself. This however requires that you have to add those includes explicitly in your project which uses the ANTLR C++ runtime (something you have probably anyway already). You can do this again with a forced include or use antlrcpp-Prefix.h in your own precompile header, if you have any.

View File

@ -12,21 +12,25 @@
#include "TLexer.h"
#include "TParser.h"
#include "Strings.h"
using namespace antlrcpptest;
using namespace org::antlr::v4::runtime;
int main(int , const char **) {
ANTLRInputStream input(L"(((x))) * y + z; a + (x * (y ? 0 : 1) + z);");
ANTLRInputStream input(u8"🍴 = 🍐 + \"😎\";(((x * π))) * µ + ∰; a + (x * (y ? 0 : 1) + z);");
TLexer lexer(&input);
CommonTokenStream tokens(&lexer);
/*
tokens.fill();
for (auto token : tokens.getTokens()) {
std::cout << token->toString() << std::endl;
}
*/
TParser parser(&tokens);
Ref<tree::ParseTree> tree = parser.main();
std::cout << antlrcpp::ws2s(tree->toStringTree(&parser)) << std::endl;
std::cout << tree->toStringTree(&parser) << std::endl;
std::fstream("test.txt") << tree->toStringTree(&parser);
return 0;
}

View File

@ -33,7 +33,9 @@
#include "Exceptions.h"
#include "Interval.h"
#include "UnbufferedTokenStream.h"
#include "StringUtils.h"
using namespace antlrcpp;
using namespace org::antlr::v4::runtime;
using namespace org::antlr::v4::runtime::misc;
@ -58,38 +60,41 @@ using namespace org::antlr::v4::runtime::misc;
XCTAssert(stream1.toString().empty());
XCTAssertEqual(stream1.index(), 0U);
ANTLRInputStream stream2(L"To be or not to be");
XCTAssert(stream2.toString() == L"To be or not to be");
ANTLRInputStream stream2("To be or not to be");
XCTAssert(stream2.toString() == "To be or not to be");
XCTAssertEqual(stream2.index(), 0U);
XCTAssertEqual(stream2.size(), 18U);
wchar_t data[] = L"Lorem ipsum dolor sit amet";
char data[] = "Lorem ipsum dolor sit amet";
ANTLRInputStream stream3(data, sizeof(data) / sizeof(data[0]));
XCTAssert(stream3.toString() == std::wstring(L"Lorem ipsum dolor sit amet\0", 27));
XCTAssert(stream3.toString() == std::string("Lorem ipsum dolor sit amet\0", 27));
XCTAssertEqual(stream3.index(), 0U);
XCTAssertEqual(stream3.size(), 27U);
std::wstringstream input(data, sizeof(data) / sizeof(data[0]));
std::wstringstream input(L"Lorem ipsum dolor sit amet");
ANTLRInputStream stream4(input);
std::string content = stream4.toString();
XCTAssertEqual(content, "Lorem ipsum dolor sit amet"); // Now as utf-8 string.
XCTAssertEqual(stream4.index(), 0U);
XCTAssertEqual(stream4.size(), 26U);
std::wstring longString(33333, L'a');
std::wstring longString(33333, 'a');
input.str(longString);
stream4.load(input, 0);
stream4.load(input);
XCTAssertEqual(stream4.index(), 0U);
XCTAssertEqual(stream4.size(), 26U); // Nothing changed as the stream is still at eof.
input.clear();
stream4.load(input, 0);
stream4.load(input);
XCTAssertEqual(stream4.size(), 33333U);
}
- (void)testANTLRInputStreamUse {
std::wstring text(L"🚧Lorem ipsum dolor sit amet🕶");
std::string text(u8"🚧Lorem ipsum dolor sit amet🕶");
std::u32string wtext = utfConverter.from_bytes(text); // Convert to UTF-32.
ANTLRInputStream stream(text);
XCTAssertEqual(stream.index(), 0U);
XCTAssertEqual(stream.size(), text.size());
XCTAssertEqual(stream.size(), wtext.size());
for (size_t i = 0; i < stream.size(); ++i) {
stream.consume();
@ -105,31 +110,31 @@ using namespace org::antlr::v4::runtime::misc;
XCTAssertEqual(message, "cannot consume EOF");
}
XCTAssertEqual(stream.index(), text.size());
XCTAssertEqual(stream.index(), wtext.size());
stream.reset();
XCTAssertEqual(stream.index(), 0U);
XCTAssertEqual(stream.LA(0), 0);
for (size_t i = 1; i < text.size(); ++i) {
XCTAssertEqual(stream.LA((ssize_t)i), text[i - 1]); // LA(1) means: current char.
XCTAssertEqual(stream.LT((ssize_t)i), text[i - 1]); // LT is mapped to LA.
for (size_t i = 1; i < wtext.size(); ++i) {
XCTAssertEqual(stream.LA((ssize_t)i), wtext[i - 1]); // LA(1) means: current char.
XCTAssertEqual(stream.LT((ssize_t)i), wtext[i - 1]); // LT is mapped to LA.
XCTAssertEqual(stream.index(), 0U); // No consumption when looking ahead.
}
stream.seek(text.size() - 1);
XCTAssertEqual(stream.index(), text.size() - 1);
stream.seek(wtext.size() - 1);
XCTAssertEqual(stream.index(), wtext.size() - 1);
stream.seek(text.size() / 2);
XCTAssertEqual(stream.index(), text.size() / 2);
stream.seek(wtext.size() / 2);
XCTAssertEqual(stream.index(), wtext.size() / 2);
stream.seek(text.size() - 1);
for (size_t i = 1; i < text.size() - 1; ++i) {
XCTAssertEqual(stream.LA((ssize_t)-i), text[text.size() - i - 1]); // LA(-1) means: previous char.
XCTAssertEqual(stream.LT((ssize_t)-i), text[text.size() - i - 1]); // LT is mapped to LA.
XCTAssertEqual(stream.index(), text.size() - 1); // No consumption when looking ahead.
stream.seek(wtext.size() - 1);
for (ssize_t i = 1; i < (ssize_t)wtext.size() - 1; ++i) {
XCTAssertEqual(stream.LA(-i), wtext[wtext.size() - i - 1]); // LA(-1) means: previous char.
XCTAssertEqual(stream.LT(-i), wtext[wtext.size() - i - 1]); // LT is mapped to LA.
XCTAssertEqual(stream.index(), wtext.size() - 1); // No consumption when looking ahead.
}
XCTAssertEqual((int)stream.LA(-10000), EOF);
XCTAssertEqual((int)stream.LA(-10000), IntStream::EOF);
// Mark and release do nothing.
stream.reset();
@ -144,8 +149,9 @@ using namespace org::antlr::v4::runtime::misc;
XCTAssertEqual(stream.index(), 10U);
misc::Interval interval1(2, 10); // From - to, inclusive.
std::wstring output = stream.getText(interval1);
XCTAssertEqual(output, text.substr(2, 9));
std::string output = stream.getText(interval1);
std::string sub = utfConverter.to_bytes(wtext.substr(2, 9));
XCTAssertEqual(output, sub);
misc::Interval interval2(200, 10); // Start beyond bounds.
output = stream.getText(interval2);

View File

@ -48,7 +48,7 @@ INT: Digit+;
Digit: [0-9];
ID: LETTER (LETTER | '0'..'9')*;
fragment LETTER : [a-zA-Z\u0080-\uFFFD] ;
fragment LETTER : [a-zA-Z\u0080-\uFFFF];
LessThan: '<';
GreaterThan: '>';
@ -68,6 +68,7 @@ QuestionMark: '?';
Comma: ',';
Dollar: '$' -> more, mode(Mode1), type(DUMMY);
String: '"' .*? '"';
Foo: {canTestFoo()}? 'foo' {isItFoo()}? { myFooLexerAction(); };
Bar: 'bar' {isItBar()}? { myBarLexerAction(); };
Any: Foo Dot Bar? DotDot Baz;

View File

@ -105,6 +105,7 @@ expr: expr Star expr
| identifier = id
| flowControl
| INT
| String
;
flowControl:

View File

@ -258,6 +258,8 @@
<ClCompile Include="src\RecognitionException.cpp" />
<ClCompile Include="src\Recognizer.cpp" />
<ClCompile Include="src\RuleContext.cpp" />
<ClCompile Include="src\RuleContextWithAltNum.cpp" />
<ClCompile Include="src\RuntimeMetaData.cpp" />
<ClCompile Include="src\support\Arrays.cpp" />
<ClCompile Include="src\support\CPPUtils.cpp" />
<ClCompile Include="src\support\guid.cpp" />
@ -398,6 +400,8 @@
<ClInclude Include="src\RecognitionException.h" />
<ClInclude Include="src\Recognizer.h" />
<ClInclude Include="src\RuleContext.h" />
<ClInclude Include="src\RuleContextWithAltNum.h" />
<ClInclude Include="src\RuntimeMetaData.h" />
<ClInclude Include="src\support\Arrays.h" />
<ClInclude Include="src\support\BitSet.h" />
<ClInclude Include="src\support\CPPUtils.h" />

View File

@ -502,6 +502,12 @@
<Filter>Header Files\misc</Filter>
</ClInclude>
<ClInclude Include="src\antlrcpp-Prefix.h" />
<ClInclude Include="src\RuleContextWithAltNum.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\RuntimeMetaData.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="antlrcpp-Prefix.cpp" />
@ -868,5 +874,11 @@
<ClCompile Include="src\atn\ProfilingATNSimulator.cpp">
<Filter>Source Files\atn</Filter>
</ClCompile>
<ClCompile Include="src\RuleContextWithAltNum.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\RuntimeMetaData.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -663,12 +663,12 @@
276E5FC21CDB57AA003FF4B4 /* guid.h in Headers */ = {isa = PBXBuildFile; fileRef = 276E5CEC1CDB57AA003FF4B4 /* guid.h */; };
276E5FC31CDB57AA003FF4B4 /* guid.h in Headers */ = {isa = PBXBuildFile; fileRef = 276E5CEC1CDB57AA003FF4B4 /* guid.h */; };
276E5FC41CDB57AA003FF4B4 /* guid.h in Headers */ = {isa = PBXBuildFile; fileRef = 276E5CEC1CDB57AA003FF4B4 /* guid.h */; settings = {ATTRIBUTES = (Public, ); }; };
276E5FC51CDB57AA003FF4B4 /* Strings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 276E5CED1CDB57AA003FF4B4 /* Strings.cpp */; };
276E5FC61CDB57AA003FF4B4 /* Strings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 276E5CED1CDB57AA003FF4B4 /* Strings.cpp */; };
276E5FC71CDB57AA003FF4B4 /* Strings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 276E5CED1CDB57AA003FF4B4 /* Strings.cpp */; };
276E5FC81CDB57AA003FF4B4 /* Strings.h in Headers */ = {isa = PBXBuildFile; fileRef = 276E5CEE1CDB57AA003FF4B4 /* Strings.h */; };
276E5FC91CDB57AA003FF4B4 /* Strings.h in Headers */ = {isa = PBXBuildFile; fileRef = 276E5CEE1CDB57AA003FF4B4 /* Strings.h */; };
276E5FCA1CDB57AA003FF4B4 /* Strings.h in Headers */ = {isa = PBXBuildFile; fileRef = 276E5CEE1CDB57AA003FF4B4 /* Strings.h */; settings = {ATTRIBUTES = (Public, ); }; };
276E5FC51CDB57AA003FF4B4 /* StringUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 276E5CED1CDB57AA003FF4B4 /* StringUtils.cpp */; };
276E5FC61CDB57AA003FF4B4 /* StringUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 276E5CED1CDB57AA003FF4B4 /* StringUtils.cpp */; };
276E5FC71CDB57AA003FF4B4 /* StringUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 276E5CED1CDB57AA003FF4B4 /* StringUtils.cpp */; };
276E5FC81CDB57AA003FF4B4 /* StringUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 276E5CEE1CDB57AA003FF4B4 /* StringUtils.h */; };
276E5FC91CDB57AA003FF4B4 /* StringUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 276E5CEE1CDB57AA003FF4B4 /* StringUtils.h */; };
276E5FCA1CDB57AA003FF4B4 /* StringUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 276E5CEE1CDB57AA003FF4B4 /* StringUtils.h */; settings = {ATTRIBUTES = (Public, ); }; };
276E5FCB1CDB57AA003FF4B4 /* Token.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 276E5CEF1CDB57AA003FF4B4 /* Token.cpp */; };
276E5FCC1CDB57AA003FF4B4 /* Token.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 276E5CEF1CDB57AA003FF4B4 /* Token.cpp */; };
276E5FCD1CDB57AA003FF4B4 /* Token.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 276E5CEF1CDB57AA003FF4B4 /* Token.cpp */; };
@ -819,6 +819,18 @@
276E60731CDB57AA003FF4B4 /* WritableToken.h in Headers */ = {isa = PBXBuildFile; fileRef = 276E5D2A1CDB57AA003FF4B4 /* WritableToken.h */; };
276E60741CDB57AA003FF4B4 /* WritableToken.h in Headers */ = {isa = PBXBuildFile; fileRef = 276E5D2A1CDB57AA003FF4B4 /* WritableToken.h */; };
276E60751CDB57AA003FF4B4 /* WritableToken.h in Headers */ = {isa = PBXBuildFile; fileRef = 276E5D2A1CDB57AA003FF4B4 /* WritableToken.h */; settings = {ATTRIBUTES = (Public, ); }; };
27745EFD1CE49C000067C6A3 /* RuleContextWithAltNum.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27745EF91CE49C000067C6A3 /* RuleContextWithAltNum.cpp */; };
27745EFE1CE49C000067C6A3 /* RuleContextWithAltNum.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27745EF91CE49C000067C6A3 /* RuleContextWithAltNum.cpp */; };
27745EFF1CE49C000067C6A3 /* RuleContextWithAltNum.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27745EF91CE49C000067C6A3 /* RuleContextWithAltNum.cpp */; };
27745F001CE49C000067C6A3 /* RuleContextWithAltNum.h in Headers */ = {isa = PBXBuildFile; fileRef = 27745EFA1CE49C000067C6A3 /* RuleContextWithAltNum.h */; };
27745F011CE49C000067C6A3 /* RuleContextWithAltNum.h in Headers */ = {isa = PBXBuildFile; fileRef = 27745EFA1CE49C000067C6A3 /* RuleContextWithAltNum.h */; };
27745F021CE49C000067C6A3 /* RuleContextWithAltNum.h in Headers */ = {isa = PBXBuildFile; fileRef = 27745EFA1CE49C000067C6A3 /* RuleContextWithAltNum.h */; };
27745F031CE49C000067C6A3 /* RuntimeMetaData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27745EFB1CE49C000067C6A3 /* RuntimeMetaData.cpp */; };
27745F041CE49C000067C6A3 /* RuntimeMetaData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27745EFB1CE49C000067C6A3 /* RuntimeMetaData.cpp */; };
27745F051CE49C000067C6A3 /* RuntimeMetaData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27745EFB1CE49C000067C6A3 /* RuntimeMetaData.cpp */; };
27745F061CE49C000067C6A3 /* RuntimeMetaData.h in Headers */ = {isa = PBXBuildFile; fileRef = 27745EFC1CE49C000067C6A3 /* RuntimeMetaData.h */; };
27745F071CE49C000067C6A3 /* RuntimeMetaData.h in Headers */ = {isa = PBXBuildFile; fileRef = 27745EFC1CE49C000067C6A3 /* RuntimeMetaData.h */; };
27745F081CE49C000067C6A3 /* RuntimeMetaData.h in Headers */ = {isa = PBXBuildFile; fileRef = 27745EFC1CE49C000067C6A3 /* RuntimeMetaData.h */; };
27874F1E1CCB7A0700AF1C53 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 27874F1D1CCB7A0700AF1C53 /* CoreFoundation.framework */; };
27874F211CCB7B1700AF1C53 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 27874F1D1CCB7A0700AF1C53 /* CoreFoundation.framework */; };
/* End PBXBuildFile section */
@ -832,7 +844,7 @@
276E5C0C1CDB57AA003FF4B4 /* ANTLRErrorListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANTLRErrorListener.h; sourceTree = "<group>"; };
276E5C0D1CDB57AA003FF4B4 /* ANTLRErrorStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANTLRErrorStrategy.h; sourceTree = "<group>"; };
276E5C0E1CDB57AA003FF4B4 /* ANTLRFileStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ANTLRFileStream.cpp; sourceTree = "<group>"; };
276E5C0F1CDB57AA003FF4B4 /* ANTLRFileStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANTLRFileStream.h; sourceTree = "<group>"; };
276E5C0F1CDB57AA003FF4B4 /* ANTLRFileStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANTLRFileStream.h; sourceTree = "<group>"; wrapsLines = 0; };
276E5C101CDB57AA003FF4B4 /* ANTLRInputStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ANTLRInputStream.cpp; sourceTree = "<group>"; };
276E5C111CDB57AA003FF4B4 /* ANTLRInputStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANTLRInputStream.h; sourceTree = "<group>"; };
276E5C131CDB57AA003FF4B4 /* AbstractPredicateTransition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AbstractPredicateTransition.cpp; sourceTree = "<group>"; };
@ -841,7 +853,7 @@
276E5C161CDB57AA003FF4B4 /* ActionTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ActionTransition.h; sourceTree = "<group>"; };
276E5C171CDB57AA003FF4B4 /* AmbiguityInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AmbiguityInfo.cpp; sourceTree = "<group>"; };
276E5C181CDB57AA003FF4B4 /* AmbiguityInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AmbiguityInfo.h; sourceTree = "<group>"; };
276E5C191CDB57AA003FF4B4 /* ArrayPredictionContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ArrayPredictionContext.cpp; sourceTree = "<group>"; };
276E5C191CDB57AA003FF4B4 /* ArrayPredictionContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ArrayPredictionContext.cpp; sourceTree = "<group>"; wrapsLines = 0; };
276E5C1A1CDB57AA003FF4B4 /* ArrayPredictionContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArrayPredictionContext.h; sourceTree = "<group>"; };
276E5C1B1CDB57AA003FF4B4 /* ATN.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ATN.cpp; sourceTree = "<group>"; };
276E5C1C1CDB57AA003FF4B4 /* ATN.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ATN.h; sourceTree = "<group>"; };
@ -890,7 +902,7 @@
276E5C491CDB57AA003FF4B4 /* LexerActionType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LexerActionType.h; sourceTree = "<group>"; };
276E5C4A1CDB57AA003FF4B4 /* LexerATNConfig.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LexerATNConfig.cpp; sourceTree = "<group>"; wrapsLines = 0; };
276E5C4B1CDB57AA003FF4B4 /* LexerATNConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LexerATNConfig.h; sourceTree = "<group>"; };
276E5C4C1CDB57AA003FF4B4 /* LexerATNSimulator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LexerATNSimulator.cpp; sourceTree = "<group>"; };
276E5C4C1CDB57AA003FF4B4 /* LexerATNSimulator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LexerATNSimulator.cpp; sourceTree = "<group>"; wrapsLines = 0; };
276E5C4D1CDB57AA003FF4B4 /* LexerATNSimulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LexerATNSimulator.h; sourceTree = "<group>"; };
276E5C4E1CDB57AA003FF4B4 /* LexerChannelAction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LexerChannelAction.cpp; sourceTree = "<group>"; };
276E5C4F1CDB57AA003FF4B4 /* LexerChannelAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LexerChannelAction.h; sourceTree = "<group>"; };
@ -916,7 +928,7 @@
276E5C631CDB57AA003FF4B4 /* LookaheadEventInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LookaheadEventInfo.h; sourceTree = "<group>"; };
276E5C641CDB57AA003FF4B4 /* LoopEndState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LoopEndState.cpp; sourceTree = "<group>"; };
276E5C651CDB57AA003FF4B4 /* LoopEndState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoopEndState.h; sourceTree = "<group>"; };
276E5C671CDB57AA003FF4B4 /* NotSetTransition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NotSetTransition.cpp; sourceTree = "<group>"; };
276E5C671CDB57AA003FF4B4 /* NotSetTransition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NotSetTransition.cpp; sourceTree = "<group>"; wrapsLines = 0; };
276E5C681CDB57AA003FF4B4 /* NotSetTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NotSetTransition.h; sourceTree = "<group>"; };
276E5C691CDB57AA003FF4B4 /* OrderedATNConfigSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OrderedATNConfigSet.cpp; sourceTree = "<group>"; };
276E5C6A1CDB57AA003FF4B4 /* OrderedATNConfigSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OrderedATNConfigSet.h; sourceTree = "<group>"; };
@ -928,7 +940,7 @@
276E5C701CDB57AA003FF4B4 /* PlusBlockStartState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlusBlockStartState.h; sourceTree = "<group>"; };
276E5C711CDB57AA003FF4B4 /* PlusLoopbackState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlusLoopbackState.cpp; sourceTree = "<group>"; };
276E5C721CDB57AA003FF4B4 /* PlusLoopbackState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlusLoopbackState.h; sourceTree = "<group>"; };
276E5C731CDB57AA003FF4B4 /* PrecedencePredicateTransition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PrecedencePredicateTransition.cpp; sourceTree = "<group>"; };
276E5C731CDB57AA003FF4B4 /* PrecedencePredicateTransition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PrecedencePredicateTransition.cpp; sourceTree = "<group>"; wrapsLines = 0; };
276E5C741CDB57AA003FF4B4 /* PrecedencePredicateTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrecedencePredicateTransition.h; sourceTree = "<group>"; };
276E5C751CDB57AA003FF4B4 /* PredicateEvalInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PredicateEvalInfo.cpp; sourceTree = "<group>"; };
276E5C761CDB57AA003FF4B4 /* PredicateEvalInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PredicateEvalInfo.h; sourceTree = "<group>"; };
@ -953,7 +965,7 @@
276E5C891CDB57AA003FF4B4 /* SetTransition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SetTransition.cpp; sourceTree = "<group>"; };
276E5C8A1CDB57AA003FF4B4 /* SetTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SetTransition.h; sourceTree = "<group>"; };
276E5C8B1CDB57AA003FF4B4 /* SingletonPredictionContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SingletonPredictionContext.cpp; sourceTree = "<group>"; };
276E5C8C1CDB57AA003FF4B4 /* SingletonPredictionContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SingletonPredictionContext.h; sourceTree = "<group>"; };
276E5C8C1CDB57AA003FF4B4 /* SingletonPredictionContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SingletonPredictionContext.h; sourceTree = "<group>"; wrapsLines = 0; };
276E5C8D1CDB57AA003FF4B4 /* StarBlockStartState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StarBlockStartState.cpp; sourceTree = "<group>"; };
276E5C8E1CDB57AA003FF4B4 /* StarBlockStartState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StarBlockStartState.h; sourceTree = "<group>"; };
276E5C8F1CDB57AA003FF4B4 /* StarLoopbackState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StarLoopbackState.cpp; sourceTree = "<group>"; };
@ -1046,15 +1058,15 @@
276E5CEA1CDB57AA003FF4B4 /* Declarations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Declarations.h; sourceTree = "<group>"; };
276E5CEB1CDB57AA003FF4B4 /* guid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = guid.cpp; sourceTree = "<group>"; };
276E5CEC1CDB57AA003FF4B4 /* guid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = guid.h; sourceTree = "<group>"; };
276E5CED1CDB57AA003FF4B4 /* Strings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Strings.cpp; sourceTree = "<group>"; };
276E5CEE1CDB57AA003FF4B4 /* Strings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Strings.h; sourceTree = "<group>"; };
276E5CED1CDB57AA003FF4B4 /* StringUtils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringUtils.cpp; sourceTree = "<group>"; };
276E5CEE1CDB57AA003FF4B4 /* StringUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringUtils.h; sourceTree = "<group>"; };
276E5CEF1CDB57AA003FF4B4 /* Token.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Token.cpp; sourceTree = "<group>"; };
276E5CF01CDB57AA003FF4B4 /* Token.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Token.h; sourceTree = "<group>"; };
276E5CF21CDB57AA003FF4B4 /* TokenFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TokenFactory.h; sourceTree = "<group>"; };
276E5CF41CDB57AA003FF4B4 /* TokenSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TokenSource.h; sourceTree = "<group>"; };
276E5CF51CDB57AA003FF4B4 /* TokenStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TokenStream.cpp; sourceTree = "<group>"; };
276E5CF61CDB57AA003FF4B4 /* TokenStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TokenStream.h; sourceTree = "<group>"; };
276E5CF71CDB57AA003FF4B4 /* TokenStreamRewriter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TokenStreamRewriter.cpp; sourceTree = "<group>"; };
276E5CF71CDB57AA003FF4B4 /* TokenStreamRewriter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TokenStreamRewriter.cpp; sourceTree = "<group>"; wrapsLines = 0; };
276E5CF81CDB57AA003FF4B4 /* TokenStreamRewriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TokenStreamRewriter.h; sourceTree = "<group>"; wrapsLines = 0; };
276E5CFA1CDB57AA003FF4B4 /* AbstractParseTreeVisitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AbstractParseTreeVisitor.h; sourceTree = "<group>"; };
276E5CFB1CDB57AA003FF4B4 /* ErrorNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ErrorNode.h; sourceTree = "<group>"; };
@ -1071,7 +1083,7 @@
276E5D091CDB57AA003FF4B4 /* ParseTreeMatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ParseTreeMatch.h; sourceTree = "<group>"; };
276E5D0A1CDB57AA003FF4B4 /* ParseTreePattern.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParseTreePattern.cpp; sourceTree = "<group>"; };
276E5D0B1CDB57AA003FF4B4 /* ParseTreePattern.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ParseTreePattern.h; sourceTree = "<group>"; };
276E5D0C1CDB57AA003FF4B4 /* ParseTreePatternMatcher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParseTreePatternMatcher.cpp; sourceTree = "<group>"; };
276E5D0C1CDB57AA003FF4B4 /* ParseTreePatternMatcher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParseTreePatternMatcher.cpp; sourceTree = "<group>"; wrapsLines = 0; };
276E5D0D1CDB57AA003FF4B4 /* ParseTreePatternMatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ParseTreePatternMatcher.h; sourceTree = "<group>"; };
276E5D0E1CDB57AA003FF4B4 /* RuleTagToken.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RuleTagToken.cpp; sourceTree = "<group>"; wrapsLines = 0; };
276E5D0F1CDB57AA003FF4B4 /* RuleTagToken.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RuleTagToken.h; sourceTree = "<group>"; };
@ -1090,7 +1102,7 @@
276E5D1C1CDB57AA003FF4B4 /* Tree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Tree.h; sourceTree = "<group>"; };
276E5D1D1CDB57AA003FF4B4 /* Trees.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Trees.cpp; sourceTree = "<group>"; };
276E5D1E1CDB57AA003FF4B4 /* Trees.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Trees.h; sourceTree = "<group>"; };
276E5D221CDB57AA003FF4B4 /* UnbufferedCharStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UnbufferedCharStream.cpp; sourceTree = "<group>"; };
276E5D221CDB57AA003FF4B4 /* UnbufferedCharStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UnbufferedCharStream.cpp; sourceTree = "<group>"; wrapsLines = 0; };
276E5D231CDB57AA003FF4B4 /* UnbufferedCharStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnbufferedCharStream.h; sourceTree = "<group>"; };
276E5D241CDB57AA003FF4B4 /* UnbufferedTokenStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UnbufferedTokenStream.cpp; sourceTree = "<group>"; };
276E5D251CDB57AA003FF4B4 /* UnbufferedTokenStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnbufferedTokenStream.h; sourceTree = "<group>"; };
@ -1098,6 +1110,10 @@
276E5D271CDB57AA003FF4B4 /* VocabularyImpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VocabularyImpl.cpp; sourceTree = "<group>"; };
276E5D281CDB57AA003FF4B4 /* VocabularyImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VocabularyImpl.h; sourceTree = "<group>"; };
276E5D2A1CDB57AA003FF4B4 /* WritableToken.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WritableToken.h; sourceTree = "<group>"; };
27745EF91CE49C000067C6A3 /* RuleContextWithAltNum.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RuleContextWithAltNum.cpp; sourceTree = "<group>"; wrapsLines = 0; };
27745EFA1CE49C000067C6A3 /* RuleContextWithAltNum.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RuleContextWithAltNum.h; sourceTree = "<group>"; wrapsLines = 0; };
27745EFB1CE49C000067C6A3 /* RuntimeMetaData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RuntimeMetaData.cpp; sourceTree = "<group>"; wrapsLines = 0; };
27745EFC1CE49C000067C6A3 /* RuntimeMetaData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RuntimeMetaData.h; sourceTree = "<group>"; };
27874F1D1CCB7A0700AF1C53 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; };
37C147171B4D5A04008EDDDB /* libantlrcpp_static.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libantlrcpp_static.a; sourceTree = BUILT_PRODUCTS_DIR; };
37D727AA1867AF1E007B6D10 /* antlrcpp.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = antlrcpp.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
@ -1210,6 +1226,10 @@
276E5CE11CDB57AA003FF4B4 /* Recognizer.h */,
276E5CE21CDB57AA003FF4B4 /* RuleContext.cpp */,
276E5CE31CDB57AA003FF4B4 /* RuleContext.h */,
27745EF91CE49C000067C6A3 /* RuleContextWithAltNum.cpp */,
27745EFA1CE49C000067C6A3 /* RuleContextWithAltNum.h */,
27745EFB1CE49C000067C6A3 /* RuntimeMetaData.cpp */,
27745EFC1CE49C000067C6A3 /* RuntimeMetaData.h */,
276E5CEF1CDB57AA003FF4B4 /* Token.cpp */,
276E5CF01CDB57AA003FF4B4 /* Token.h */,
276E5CF21CDB57AA003FF4B4 /* TokenFactory.h */,
@ -1411,8 +1431,8 @@
276E5CEA1CDB57AA003FF4B4 /* Declarations.h */,
276E5CEB1CDB57AA003FF4B4 /* guid.cpp */,
276E5CEC1CDB57AA003FF4B4 /* guid.h */,
276E5CED1CDB57AA003FF4B4 /* Strings.cpp */,
276E5CEE1CDB57AA003FF4B4 /* Strings.h */,
276E5CED1CDB57AA003FF4B4 /* StringUtils.cpp */,
276E5CEE1CDB57AA003FF4B4 /* StringUtils.h */,
);
path = support;
sourceTree = "<group>";
@ -1546,7 +1566,7 @@
276E5D691CDB57AA003FF4B4 /* ATNConfigSet.h in Headers */,
276E5D391CDB57AA003FF4B4 /* ANTLRFileStream.h in Headers */,
276E5D301CDB57AA003FF4B4 /* ANTLRErrorListener.h in Headers */,
276E5FCA1CDB57AA003FF4B4 /* Strings.h in Headers */,
276E5FCA1CDB57AA003FF4B4 /* StringUtils.h in Headers */,
276E5EF51CDB57AA003FF4B4 /* CommonTokenFactory.h in Headers */,
276E5F191CDB57AA003FF4B4 /* DFAState.h in Headers */,
276E5FA61CDB57AA003FF4B4 /* Recognizer.h in Headers */,
@ -1567,6 +1587,7 @@
276E5F821CDB57AA003FF4B4 /* NoViableAltException.h in Headers */,
276E5DEA1CDB57AA003FF4B4 /* LexerATNConfig.h in Headers */,
276E60481CDB57AA003FF4B4 /* TerminalNodeImpl.h in Headers */,
27745F081CE49C000067C6A3 /* RuntimeMetaData.h in Headers */,
276E5FF41CDB57AA003FF4B4 /* ErrorNodeImpl.h in Headers */,
276E5EC51CDB57AA003FF4B4 /* TokensStartState.h in Headers */,
276E5DC91CDB57AA003FF4B4 /* EmptyPredictionContext.h in Headers */,
@ -1591,6 +1612,7 @@
276E5F941CDB57AA003FF4B4 /* ParserRuleContext.h in Headers */,
276E5FEE1CDB57AA003FF4B4 /* ErrorNode.h in Headers */,
276E5EB91CDB57AA003FF4B4 /* StarLoopbackState.h in Headers */,
27745F021CE49C000067C6A3 /* RuleContextWithAltNum.h in Headers */,
276E5E5F1CDB57AA003FF4B4 /* PlusLoopbackState.h in Headers */,
276E5E081CDB57AA003FF4B4 /* LexerModeAction.h in Headers */,
276E5E591CDB57AA003FF4B4 /* PlusBlockStartState.h in Headers */,
@ -1659,6 +1681,7 @@
buildActionMask = 2147483647;
files = (
276E5FEA1CDB57AA003FF4B4 /* AbstractParseTreeVisitor.h in Headers */,
27745F011CE49C000067C6A3 /* RuleContextWithAltNum.h in Headers */,
276E60321CDB57AA003FF4B4 /* TextChunk.h in Headers */,
276E5F421CDB57AA003FF4B4 /* IntStream.h in Headers */,
276E5D5C1CDB57AA003FF4B4 /* ATN.h in Headers */,
@ -1702,7 +1725,7 @@
276E5D681CDB57AA003FF4B4 /* ATNConfigSet.h in Headers */,
276E5D381CDB57AA003FF4B4 /* ANTLRFileStream.h in Headers */,
276E5D2F1CDB57AA003FF4B4 /* ANTLRErrorListener.h in Headers */,
276E5FC91CDB57AA003FF4B4 /* Strings.h in Headers */,
276E5FC91CDB57AA003FF4B4 /* StringUtils.h in Headers */,
276E5EF41CDB57AA003FF4B4 /* CommonTokenFactory.h in Headers */,
276E5F181CDB57AA003FF4B4 /* DFAState.h in Headers */,
276E5FA51CDB57AA003FF4B4 /* Recognizer.h in Headers */,
@ -1715,6 +1738,7 @@
276E5E7C1CDB57AA003FF4B4 /* PredictionMode.h in Headers */,
276E5EBE1CDB57AA003FF4B4 /* StarLoopEntryState.h in Headers */,
276E5F9F1CDB57AA003FF4B4 /* RecognitionException.h in Headers */,
27745F071CE49C000067C6A3 /* RuntimeMetaData.h in Headers */,
276E5EA61CDB57AA003FF4B4 /* SetTransition.h in Headers */,
276E5F1E1CDB57AA003FF4B4 /* LexerDFASerializer.h in Headers */,
276E5E461CDB57AA003FF4B4 /* OrderedATNConfigSet.h in Headers */,
@ -1814,6 +1838,7 @@
buildActionMask = 2147483647;
files = (
276E5FE91CDB57AA003FF4B4 /* AbstractParseTreeVisitor.h in Headers */,
27745F001CE49C000067C6A3 /* RuleContextWithAltNum.h in Headers */,
276E60311CDB57AA003FF4B4 /* TextChunk.h in Headers */,
276E5F411CDB57AA003FF4B4 /* IntStream.h in Headers */,
276E5D5B1CDB57AA003FF4B4 /* ATN.h in Headers */,
@ -1857,7 +1882,7 @@
276E5D671CDB57AA003FF4B4 /* ATNConfigSet.h in Headers */,
276E5D371CDB57AA003FF4B4 /* ANTLRFileStream.h in Headers */,
276E5D2E1CDB57AA003FF4B4 /* ANTLRErrorListener.h in Headers */,
276E5FC81CDB57AA003FF4B4 /* Strings.h in Headers */,
276E5FC81CDB57AA003FF4B4 /* StringUtils.h in Headers */,
276E5EF31CDB57AA003FF4B4 /* CommonTokenFactory.h in Headers */,
276E5F171CDB57AA003FF4B4 /* DFAState.h in Headers */,
276E5FA41CDB57AA003FF4B4 /* Recognizer.h in Headers */,
@ -1870,6 +1895,7 @@
276E5E7B1CDB57AA003FF4B4 /* PredictionMode.h in Headers */,
276E5EBD1CDB57AA003FF4B4 /* StarLoopEntryState.h in Headers */,
276E5F9E1CDB57AA003FF4B4 /* RecognitionException.h in Headers */,
27745F061CE49C000067C6A3 /* RuntimeMetaData.h in Headers */,
276E5EA51CDB57AA003FF4B4 /* SetTransition.h in Headers */,
276E5F1D1CDB57AA003FF4B4 /* LexerDFASerializer.h in Headers */,
276E5E451CDB57AA003FF4B4 /* OrderedATNConfigSet.h in Headers */,
@ -2070,9 +2096,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
27745EFF1CE49C000067C6A3 /* RuleContextWithAltNum.cpp in Sources */,
276E5F671CDB57AA003FF4B4 /* IntervalSet.cpp in Sources */,
276E5D3C1CDB57AA003FF4B4 /* ANTLRInputStream.cpp in Sources */,
276E5FC71CDB57AA003FF4B4 /* Strings.cpp in Sources */,
276E5FC71CDB57AA003FF4B4 /* StringUtils.cpp in Sources */,
276E5D361CDB57AA003FF4B4 /* ANTLRFileStream.cpp in Sources */,
276E5D541CDB57AA003FF4B4 /* ArrayPredictionContext.cpp in Sources */,
276E5F0A1CDB57AA003FF4B4 /* DFA.cpp in Sources */,
@ -2142,6 +2169,7 @@
276E602A1CDB57AA003FF4B4 /* TagChunk.cpp in Sources */,
276E5F7F1CDB57AA003FF4B4 /* NoViableAltException.cpp in Sources */,
276E5D781CDB57AA003FF4B4 /* ATNSerializer.cpp in Sources */,
27745F051CE49C000067C6A3 /* RuntimeMetaData.cpp in Sources */,
276E5DAE1CDB57AA003FF4B4 /* ContextSensitivityInfo.cpp in Sources */,
276E5D661CDB57AA003FF4B4 /* ATNConfigSet.cpp in Sources */,
276E5FAF1CDB57AA003FF4B4 /* Arrays.cpp in Sources */,
@ -2199,9 +2227,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
27745EFE1CE49C000067C6A3 /* RuleContextWithAltNum.cpp in Sources */,
276E5F661CDB57AA003FF4B4 /* IntervalSet.cpp in Sources */,
276E5D3B1CDB57AA003FF4B4 /* ANTLRInputStream.cpp in Sources */,
276E5FC61CDB57AA003FF4B4 /* Strings.cpp in Sources */,
276E5FC61CDB57AA003FF4B4 /* StringUtils.cpp in Sources */,
276E5D351CDB57AA003FF4B4 /* ANTLRFileStream.cpp in Sources */,
276E5D531CDB57AA003FF4B4 /* ArrayPredictionContext.cpp in Sources */,
276E5F091CDB57AA003FF4B4 /* DFA.cpp in Sources */,
@ -2271,6 +2300,7 @@
276E60291CDB57AA003FF4B4 /* TagChunk.cpp in Sources */,
276E5F7E1CDB57AA003FF4B4 /* NoViableAltException.cpp in Sources */,
276E5D771CDB57AA003FF4B4 /* ATNSerializer.cpp in Sources */,
27745F041CE49C000067C6A3 /* RuntimeMetaData.cpp in Sources */,
276E5DAD1CDB57AA003FF4B4 /* ContextSensitivityInfo.cpp in Sources */,
276E5D651CDB57AA003FF4B4 /* ATNConfigSet.cpp in Sources */,
276E5FAE1CDB57AA003FF4B4 /* Arrays.cpp in Sources */,
@ -2328,9 +2358,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
27745EFD1CE49C000067C6A3 /* RuleContextWithAltNum.cpp in Sources */,
276E5F651CDB57AA003FF4B4 /* IntervalSet.cpp in Sources */,
276E5D3A1CDB57AA003FF4B4 /* ANTLRInputStream.cpp in Sources */,
276E5FC51CDB57AA003FF4B4 /* Strings.cpp in Sources */,
276E5FC51CDB57AA003FF4B4 /* StringUtils.cpp in Sources */,
276E5D341CDB57AA003FF4B4 /* ANTLRFileStream.cpp in Sources */,
276E5D521CDB57AA003FF4B4 /* ArrayPredictionContext.cpp in Sources */,
276E5F081CDB57AA003FF4B4 /* DFA.cpp in Sources */,
@ -2400,6 +2431,7 @@
276E60281CDB57AA003FF4B4 /* TagChunk.cpp in Sources */,
276E5F7D1CDB57AA003FF4B4 /* NoViableAltException.cpp in Sources */,
276E5D761CDB57AA003FF4B4 /* ATNSerializer.cpp in Sources */,
27745F031CE49C000067C6A3 /* RuntimeMetaData.cpp in Sources */,
276E5DAC1CDB57AA003FF4B4 /* ContextSensitivityInfo.cpp in Sources */,
276E5D641CDB57AA003FF4B4 /* ATNConfigSet.cpp in Sources */,
276E5FAD1CDB57AA003FF4B4 /* Arrays.cpp in Sources */,

View File

@ -80,7 +80,7 @@ namespace runtime {
/// the parser was able to recover in line without exiting the
/// surrounding rule. </param>
virtual void syntaxError(IRecognizer *recognizer, Ref<Token> offendingSymbol, size_t line, int charPositionInLine,
const std::wstring &msg, std::exception_ptr e) = 0;
const std::string &msg, std::exception_ptr e) = 0;
/**
* This method is called by the parser when a full-context prediction

View File

@ -29,61 +29,23 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "Exceptions.h"
#include "Strings.h"
#include "ANTLRFileStream.h"
using namespace org::antlr::v4::runtime;
ANTLRFileStream::ANTLRFileStream(const std::string &fileName, const std::string &encoding) {
ANTLRFileStream::ANTLRFileStream(const std::string &fileName) {
_fileName = fileName;
load(fileName, encoding);
load(fileName);
}
void ANTLRFileStream::load(const std::string &fileName, const std::string &/*encoding*/) {
void ANTLRFileStream::load(const std::string &fileName) {
_fileName = fileName;
if (_fileName.empty()) {
return;
}
enum Encoding { ANSI, UTF8, UTF16LE } encodingType = ANSI;
#ifdef _WIN32
std::ifstream stream(antlrcpp::s2ws(fileName).c_str(), std::ios::binary);
#else
std::ifstream stream(_fileName.c_str(), std::ifstream::binary);
#endif
std::stringstream ss;
if (!stream.is_open() || stream.eof())
return;
int ch1 = stream.get();
int ch2 = stream.get();
if (ch1 == 0xff && ch2 == 0xfe)
encodingType = UTF16LE;
else
if (ch1 == 0xfe && ch2 == 0xff)
return; // UTF-16BE not supported;
else
{
int ch3 = stream.get();
if (ch1 == 0xef && ch2 == 0xbb && ch3 == 0xbf)
encodingType = UTF8;
else
stream.seekg(0);
}
ss << stream.rdbuf() << '\0';
switch (encodingType)
{
case UTF16LE:
data = (wchar_t *)ss.str().c_str();
default:
data = antlrcpp::s2ws(ss.str());
}
std::wifstream stream(fileName, std::ios::binary);
ANTLRInputStream::load(stream);
}
std::string ANTLRFileStream::getSourceName() const {

View File

@ -39,19 +39,17 @@ namespace v4 {
namespace runtime {
/// This is an ANTLRInputStream that is loaded from a file all at once
/// when you construct the object.
/// when you construct the object (or call load()).
// TODO: this class needs testing.
class ANTLR4CPP_PUBLIC ANTLRFileStream : public ANTLRInputStream {
protected:
std::string _fileName; // UTF-8 encoded file name.
public:
// Assumes a file name encoded in UTF-8. The file content encoding is detected automatically
// but must be one of ANSI, UTF-8 or UTF-16 (LE). A possible Unicode BOM is used to help auto detection.
// The encoding paramater is currently being ignored.
ANTLRFileStream(const std::string &fileName, const std::string &encoding = "");
virtual void load(const std::string &fileName, const std::string &encoding);
// Assumes a file name encoded in UTF-8 and file content in the same encoding (with or w/o BOM).
ANTLRFileStream(const std::string &fileName);
virtual void load(const std::string &fileName);
virtual std::string getSourceName() const override;
};

View File

@ -33,7 +33,7 @@
#include "Interval.h"
#include "IntStream.h"
#include "Arrays.h"
#include "StringUtils.h"
#include "CPPUtils.h"
#include "ANTLRInputStream.h"
@ -43,41 +43,39 @@ using namespace antlrcpp;
using misc::Interval;
ANTLRInputStream::ANTLRInputStream(const std::wstring &input) : data(input) {
ANTLRInputStream::ANTLRInputStream(const std::string &input) {
InitializeInstanceFields();
data = utfConverter.from_bytes(input);
}
ANTLRInputStream::ANTLRInputStream(const wchar_t data[], size_t numberOfActualCharsInArray)
: ANTLRInputStream(std::wstring(data, numberOfActualCharsInArray)) {
ANTLRInputStream::ANTLRInputStream(const char data[], size_t numberOfActualCharsInArray)
: ANTLRInputStream(std::string(data, numberOfActualCharsInArray)) {
}
ANTLRInputStream::ANTLRInputStream(std::wistream &stream) : ANTLRInputStream(stream, READ_BUFFER_SIZE) {
ANTLRInputStream::ANTLRInputStream(std::wistream &stream) {
load(stream);
}
ANTLRInputStream::ANTLRInputStream(std::wistream &stream, std::streamsize readChunkSize) : ANTLRInputStream() {
load(stream, readChunkSize);
}
void ANTLRInputStream::load(std::wistream &stream, std::streamsize readChunkSize) {
stream.seekg(0, stream.beg);
if (!stream.good()) // No fail, bad or EOF.
void ANTLRInputStream::load(std::wistream &stream) {
if (!stream.good() || stream.eof()) // No fail, bad or EOF.
return;
data.clear();
p = 0;
std::streampos startPosition = stream.tellg();
stream.seekg(0, std::ios::end);
data.reserve(stream.tellg() - startPosition);
stream.seekg(startPosition, std::ios::beg);
if (readChunkSize == 0) {
readChunkSize = READ_BUFFER_SIZE;
}
stream.imbue(std::locale(stream.getloc(), new std::codecvt_utf8<char32_t>));
wchar_t c;
stream >> std::noskipws >> c;
if (c != 0xFFFE) // Ignore BOM if theres one.
data += c;
wchar_t *buffer = new wchar_t[readChunkSize]; /* mem check: freed in finally block */
auto onExit = finally([buffer] {
delete[] buffer;
});
while (!stream.eof()) {
stream.read(buffer, readChunkSize);
data.append(buffer, (size_t)std::min(stream.gcount(), readChunkSize));
}
for ( ; stream >> c; )
data += c;
}
void ANTLRInputStream::reset() {
@ -147,7 +145,7 @@ void ANTLRInputStream::seek(size_t index) {
}
}
std::wstring ANTLRInputStream::getText(const Interval &interval) {
std::string ANTLRInputStream::getText(const Interval &interval) {
size_t start = (size_t)interval.a;
size_t stop = (size_t)interval.b;
@ -157,10 +155,10 @@ std::wstring ANTLRInputStream::getText(const Interval &interval) {
size_t count = stop - start + 1;
if (start >= data.size()) {
return L"";
return "";
}
return data.substr(start, count);
return utfConverter.to_bytes(data.substr(start, count));
}
std::string ANTLRInputStream::getSourceName() const {
@ -170,8 +168,8 @@ std::string ANTLRInputStream::getSourceName() const {
return name;
}
std::wstring ANTLRInputStream::toString() const {
return data;
std::string ANTLRInputStream::toString() const {
return utfConverter.to_bytes(data);
}
void ANTLRInputStream::InitializeInstanceFields() {

View File

@ -38,15 +38,13 @@ namespace antlr {
namespace v4 {
namespace runtime {
/// Vacuum all input from a stream and then treat it
/// like a string. Can also pass in a string or char[] to use.
// Vacuum all input from a stream and then treat it
// like a string. Can also pass in a string or char[] to use.
// Input is expected to be encoded in UTF-8 and converted to UTF-32 internally.
class ANTLR4CPP_PUBLIC ANTLRInputStream : public CharStream {
public:
static const int READ_BUFFER_SIZE = 1024;
protected:
/// The data being scanned.
std::wstring data; // XXX: move to std::string and UTF-8 to support input beyond the Unicode BMP.
std::u32string data; // UTF-32
/// 0..n-1 index into string of next char </summary>
size_t p;
@ -55,12 +53,11 @@ namespace runtime {
/// What is name or source of this char stream?
std::string name;
ANTLRInputStream(const std::wstring &input = L"");
ANTLRInputStream(const wchar_t data[], size_t numberOfActualCharsInArray);
ANTLRInputStream(const std::string &input = "");
ANTLRInputStream(const char data[], size_t numberOfActualCharsInArray);
ANTLRInputStream(std::wistream &stream);
ANTLRInputStream(std::wistream &stream, std::streamsize readChunkSize);
virtual void load(std::wistream &stream, std::streamsize readChunkSize);
virtual void load(std::wistream &stream);
/// Reset the stream so that it's in the same state it was
/// when the object was created *except* the data array is not
@ -88,9 +85,9 @@ namespace runtime {
/// update line and charPositionInLine. If we seek backwards, just set p
/// </summary>
virtual void seek(size_t index) override;
virtual std::wstring getText(const misc::Interval &interval) override;
virtual std::string getText(const misc::Interval &interval) override;
virtual std::string getSourceName() const override;
virtual std::wstring toString() const override;
virtual std::string toString() const override;
private:
void InitializeInstanceFields();

View File

@ -35,7 +35,7 @@
using namespace org::antlr::v4::runtime;
void BaseErrorListener::syntaxError(IRecognizer * /*recognizer*/, Ref<Token> /*offendingSymbol*/, size_t /*line*/,
int /*charPositionInLine*/, const std::wstring &/*msg*/, std::exception_ptr /*e*/) {
int /*charPositionInLine*/, const std::string &/*msg*/, std::exception_ptr /*e*/) {
}
void BaseErrorListener::reportAmbiguity(Parser * /*recognizer*/, const dfa::DFA &/*dfa*/, size_t /*startIndex*/,

View File

@ -50,7 +50,7 @@ namespace runtime {
class ANTLR4CPP_PUBLIC BaseErrorListener : public ANTLRErrorListener {
virtual void syntaxError(IRecognizer *recognizer, Ref<Token> offendingSymbol, size_t line, int charPositionInLine,
const std::wstring &msg, std::exception_ptr e) override;
const std::string &msg, std::exception_ptr e) override;
virtual void reportAmbiguity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, bool exact,
const antlrcpp::BitSet &ambigAlts, Ref<atn::ATNConfigSet> configs) override;

View File

@ -375,24 +375,24 @@ std::string BufferedTokenStream::getSourceName() const
return _tokenSource->getSourceName();
}
std::wstring BufferedTokenStream::getText() {
std::string BufferedTokenStream::getText() {
lazyInit();
fill();
return getText(misc::Interval(0, (int)size() - 1));
}
std::wstring BufferedTokenStream::getText(const misc::Interval &interval) {
std::string BufferedTokenStream::getText(const misc::Interval &interval) {
int start = interval.a;
int stop = interval.b;
if (start < 0 || stop < 0) {
return L"";
return "";
}
lazyInit();
if (stop >= (int)_tokens.size()) {
stop = (int)_tokens.size() - 1;
}
std::wstringstream ss;
std::stringstream ss;
for (size_t i = (size_t)start; i <= (size_t)stop; i++) {
Ref<Token> t = _tokens[i];
if (t->getType() == Token::EOF) {
@ -403,16 +403,16 @@ std::wstring BufferedTokenStream::getText(const misc::Interval &interval) {
return ss.str();
}
std::wstring BufferedTokenStream::getText(RuleContext *ctx) {
std::string BufferedTokenStream::getText(RuleContext *ctx) {
return getText(ctx->getSourceInterval());
}
std::wstring BufferedTokenStream::getText(Ref<Token> start, Ref<Token> stop) {
std::string BufferedTokenStream::getText(Ref<Token> start, Ref<Token> stop) {
if (start != nullptr && stop != nullptr) {
return getText(misc::Interval(start->getTokenIndex(), stop->getTokenIndex()));
}
return L"";
return "";
}
void BufferedTokenStream::fill() {

View File

@ -112,10 +112,10 @@ namespace runtime {
virtual std::vector<Ref<Token>> getHiddenTokensToLeft(size_t tokenIndex);
virtual std::string getSourceName() const override;
virtual std::wstring getText() override;
virtual std::wstring getText(const misc::Interval &interval) override;
virtual std::wstring getText(RuleContext *ctx) override;
virtual std::wstring getText(Ref<Token> start, Ref<Token> stop) override;
virtual std::string getText() override;
virtual std::string getText(const misc::Interval &interval) override;
virtual std::string getText(RuleContext *ctx) override;
virtual std::string getText(Ref<Token> start, Ref<Token> stop) override;
/// <summary>
/// Get all tokens from lexer until EOF </summary>

View File

@ -58,9 +58,9 @@ namespace runtime {
/// past the end of the stream </exception>
/// <exception cref="UnsupportedOperationException"> if the stream does not support
/// getting the text of the specified interval </exception>
virtual std::wstring getText(const misc::Interval &interval) = 0;
virtual std::string getText(const misc::Interval &interval) = 0;
virtual std::wstring toString() const = 0;
virtual std::string toString() const = 0;
};
} // namespace runtime

View File

@ -31,7 +31,7 @@
#include "Interval.h"
#include "TokenSource.h"
#include "Strings.h"
#include "StringUtils.h"
#include "CharStream.h"
#include "CPPUtils.h"
@ -60,7 +60,7 @@ CommonToken::CommonToken(std::pair<TokenSource*, CharStream*> source, int type,
}
}
CommonToken::CommonToken(int type, const std::wstring &text) {
CommonToken::CommonToken(int type, const std::string &text) {
InitializeInstanceFields();
_type = type;
_channel = DEFAULT_CHANNEL;
@ -95,24 +95,24 @@ void CommonToken::setLine(int line) {
_line = line;
}
std::wstring CommonToken::getText() {
std::string CommonToken::getText() {
if (!_text.empty()) {
return _text;
}
CharStream *input = getInputStream();
if (input == nullptr) {
return L"";
return "";
}
size_t n = input->size();
if ((size_t)_start < n && (size_t)_stop < n) {
return input->getText(misc::Interval(_start, _stop));
} else {
return L"<EOF>";
return "<EOF>";
}
}
void CommonToken::setText(const std::wstring &text) {
void CommonToken::setText(const std::string &text) {
_text = text;
}

View File

@ -87,7 +87,7 @@ namespace runtime {
*
* @see #getText()
*/
std::wstring _text;
std::string _text;
/**
* This is the backing field for {@link #getTokenIndex} and
@ -123,7 +123,7 @@ namespace runtime {
* @param type The token type.
* @param text The text of the token.
*/
CommonToken(int type, const std::wstring &text);
CommonToken(int type, const std::string &text);
/**
* Constructs a new {@link CommonToken} as a copy of another {@link Token}.
@ -151,8 +151,8 @@ namespace runtime {
* should be obtained from the input along with the start and stop indexes
* of the token.
*/
virtual void setText(const std::wstring &text) override;
virtual std::wstring getText() override;
virtual void setText(const std::string &text) override;
virtual std::string getText() override;
virtual void setLine(int line) override;
virtual int getLine() override;

View File

@ -46,12 +46,12 @@ CommonTokenFactory::CommonTokenFactory() : CommonTokenFactory(false) {
}
Ref<CommonToken> CommonTokenFactory::create(std::pair<TokenSource*, CharStream*> source, int type,
const std::wstring &text, int channel, int start, int stop, int line, int charPositionInLine) {
const std::string &text, int channel, int start, int stop, int line, int charPositionInLine) {
Ref<CommonToken> t = std::make_shared<CommonToken>(source, type, channel, start, stop);
t->setLine(line);
t->setCharPositionInLine(charPositionInLine);
if (text != L"") {
if (text != "") {
t->setText(text);
} else if (copyText && source.second != nullptr) {
t->setText(source.second->getText(misc::Interval(start, stop)));
@ -60,6 +60,6 @@ Ref<CommonToken> CommonTokenFactory::create(std::pair<TokenSource*, CharStream*>
return t;
}
Ref<CommonToken> CommonTokenFactory::create(int type, const std::wstring &text) {
Ref<CommonToken> CommonTokenFactory::create(int type, const std::string &text) {
return std::make_shared<CommonToken>(type, text);
}

View File

@ -95,9 +95,9 @@ namespace runtime {
CommonTokenFactory();
virtual Ref<CommonToken> create(std::pair<TokenSource*, CharStream*> source, int type,
const std::wstring &text, int channel, int start, int stop, int line, int charPositionInLine) override;
const std::string &text, int channel, int start, int stop, int line, int charPositionInLine) override;
virtual Ref<CommonToken> create(int type, const std::wstring &text) override;
virtual Ref<CommonToken> create(int type, const std::string &text) override;
};
} // namespace runtime

View File

@ -36,6 +36,6 @@ using namespace org::antlr::v4::runtime;
ConsoleErrorListener ConsoleErrorListener::INSTANCE;
void ConsoleErrorListener::syntaxError(IRecognizer * /*recognizer*/, Ref<Token> /*offendingSymbol*/,
size_t line, int charPositionInLine, const std::wstring &msg, std::exception_ptr /*e*/) {
std::wcerr << L"line " << line << L":" << charPositionInLine << L" " << msg << std::endl;
size_t line, int charPositionInLine, const std::string &msg, std::exception_ptr /*e*/) {
std::cerr << "line " << line << ":" << charPositionInLine << " " << msg << std::endl;
}

View File

@ -58,7 +58,7 @@ namespace runtime {
* </pre>
*/
virtual void syntaxError(IRecognizer *recognizer, Ref<Token> offendingSymbol, size_t line, int charPositionInLine,
const std::wstring &msg, std::exception_ptr e) override;
const std::string &msg, std::exception_ptr e) override;
};
} // namespace runtime

View File

@ -39,9 +39,9 @@
#include "ATN.h"
#include "ATNState.h"
#include "Parser.h"
#include "Strings.h"
#include "CommonToken.h"
#include "Vocabulary.h"
#include "StringUtils.h"
#include "DefaultErrorStrategy.h"
@ -88,7 +88,7 @@ void DefaultErrorStrategy::reportError(Parser *recognizer, const RecognitionExce
// This is really bush league, I hate libraries that gratuitiously print stuff out.
std::cerr << std::string("unknown recognition error type: ") << typeid(e).name() << std::endl;
recognizer->notifyErrorListeners(e.getOffendingToken(), antlrcpp::s2ws(e.what()), std::make_exception_ptr(e));
recognizer->notifyErrorListeners(e.getOffendingToken(), e.what(), std::make_exception_ptr(e));
}
}
@ -159,29 +159,29 @@ void DefaultErrorStrategy::sync(Parser *recognizer) {
void DefaultErrorStrategy::reportNoViableAlternative(Parser *recognizer, const NoViableAltException &e) {
TokenStream *tokens = recognizer->getTokenStream();
std::wstring input;
std::string input;
if (tokens != nullptr) {
if (e.getStartToken()->getType() == Token::EOF) {
input = L"<EOF>";
input = "<EOF>";
} else {
input = tokens->getText(e.getStartToken(), e.getOffendingToken());
}
} else {
input = L"<unknown input>";
input = "<unknown input>";
}
std::wstring msg = std::wstring(L"no viable alternative at input ") + escapeWSAndQuote(input);
std::string msg = std::string("no viable alternative at input ") + escapeWSAndQuote(input);
recognizer->notifyErrorListeners(e.getOffendingToken(), msg, std::make_exception_ptr(e));
}
void DefaultErrorStrategy::reportInputMismatch(Parser *recognizer, const InputMismatchException &e) {
std::wstring msg = std::wstring(L"mismatched input ") + getTokenErrorDisplay(e.getOffendingToken()) +
std::wstring(L" expecting ") + e.getExpectedTokens().toString(recognizer->getVocabulary());
std::string msg = std::string("mismatched input ") + getTokenErrorDisplay(e.getOffendingToken()) +
std::string(" expecting ") + e.getExpectedTokens().toString(recognizer->getVocabulary());
recognizer->notifyErrorListeners(e.getOffendingToken(), msg, std::make_exception_ptr(e));
}
void DefaultErrorStrategy::reportFailedPredicate(Parser *recognizer, const FailedPredicateException &e) {
const std::wstring& ruleName = recognizer->getRuleNames()[(size_t)recognizer->getContext()->getRuleIndex()];
std::wstring msg = std::wstring(L"rule ") + ruleName + std::wstring(L" ") + antlrcpp::s2ws(e.what());
const std::string& ruleName = recognizer->getRuleNames()[(size_t)recognizer->getContext()->getRuleIndex()];
std::string msg = "rule " + ruleName + " " + e.what();
recognizer->notifyErrorListeners(e.getOffendingToken(), msg, std::make_exception_ptr(e));
}
@ -193,10 +193,10 @@ void DefaultErrorStrategy::reportUnwantedToken(Parser *recognizer) {
beginErrorCondition(recognizer);
Ref<Token> t = recognizer->getCurrentToken();
std::wstring tokenName = getTokenErrorDisplay(t);
std::string tokenName = getTokenErrorDisplay(t);
misc::IntervalSet expecting = getExpectedTokens(recognizer);
std::wstring msg = std::wstring(L"extraneous input ") + tokenName + std::wstring(L" expecting ") +
std::string msg = std::string("extraneous input ") + tokenName + std::string(" expecting ") +
expecting.toString(recognizer->getVocabulary());
recognizer->notifyErrorListeners(t, msg, nullptr);
}
@ -210,7 +210,7 @@ void DefaultErrorStrategy::reportMissingToken(Parser *recognizer) {
Ref<Token> t = recognizer->getCurrentToken();
misc::IntervalSet expecting = getExpectedTokens(recognizer);
std::wstring msg = L"missing " + expecting.toString(recognizer->getVocabulary()) + L" at " + getTokenErrorDisplay(t);
std::string msg = "missing " + expecting.toString(recognizer->getVocabulary()) + " at " + getTokenErrorDisplay(t);
recognizer->notifyErrorListeners(t, msg, nullptr);
}
@ -269,11 +269,11 @@ Ref<Token> DefaultErrorStrategy::getMissingSymbol(Parser *recognizer) {
Ref<Token> currentSymbol = recognizer->getCurrentToken();
misc::IntervalSet expecting = getExpectedTokens(recognizer);
ssize_t expectedTokenType = expecting.getMinElement(); // get any element
std::wstring tokenText;
std::string tokenText;
if (expectedTokenType == Token::EOF) {
tokenText = L"<missing EOF>";
tokenText = "<missing EOF>";
} else {
tokenText = L"<missing " + recognizer->getVocabulary()->getDisplayName(expectedTokenType) + L">";
tokenText = "<missing " + recognizer->getVocabulary()->getDisplayName(expectedTokenType) + ">";
}
Ref<Token> current = currentSymbol;
Ref<Token> lookback = recognizer->getTokenStream()->LT(-1);
@ -289,22 +289,22 @@ misc::IntervalSet DefaultErrorStrategy::getExpectedTokens(Parser *recognizer) {
return recognizer->getExpectedTokens();
}
std::wstring DefaultErrorStrategy::getTokenErrorDisplay(Ref<Token> t) {
std::string DefaultErrorStrategy::getTokenErrorDisplay(Ref<Token> t) {
if (t == nullptr) {
return L"<no Token>";
return "<no Token>";
}
std::wstring s = getSymbolText(t);
if (s == L"") {
std::string s = getSymbolText(t);
if (s == "") {
if (getSymbolType(t) == Token::EOF) {
s = L"<EOF>";
s = "<EOF>";
} else {
s = std::wstring(L"<") + std::to_wstring(getSymbolType(t)) + std::wstring(L">");
s = std::string("<") + std::to_string(getSymbolType(t)) + std::string(">");
}
}
return escapeWSAndQuote(s);
}
std::wstring DefaultErrorStrategy::getSymbolText(Ref<Token> symbol) {
std::string DefaultErrorStrategy::getSymbolText(Ref<Token> symbol) {
return symbol->getText();
}
@ -312,12 +312,12 @@ int DefaultErrorStrategy::getSymbolType(Ref<Token> symbol) {
return symbol->getType();
}
std::wstring DefaultErrorStrategy::escapeWSAndQuote(std::wstring &s) {
std::string DefaultErrorStrategy::escapeWSAndQuote(std::string &s) {
// if ( s==null ) return s;
antlrcpp::replaceAll(s, L"\n", L"\\n");
antlrcpp::replaceAll(s, L"\r",L"\\r");
antlrcpp::replaceAll(s, L"\t",L"\\t");
return std::wstring(L"'") + s + std::wstring(L"'");
antlrcpp::replaceAll(s, "\n", "\\n");
antlrcpp::replaceAll(s, "\r","\\r");
antlrcpp::replaceAll(s, "\t","\\t");
return std::string("'") + s + std::string("'");
}
misc::IntervalSet DefaultErrorStrategy::getErrorRecoverySet(Parser *recognizer) {

View File

@ -381,13 +381,13 @@ namespace runtime {
/// your token objects because you don't have to go modify your lexer
/// so that it creates a new class.
/// </summary>
virtual std::wstring getTokenErrorDisplay(Ref<Token> t);
virtual std::string getTokenErrorDisplay(Ref<Token> t);
virtual std::wstring getSymbolText(Ref<Token> symbol);
virtual std::string getSymbolText(Ref<Token> symbol);
virtual int getSymbolType(Ref<Token> symbol);
virtual std::wstring escapeWSAndQuote(std::wstring &s);
virtual std::string escapeWSAndQuote(std::string &s);
/* Compute the error recovery set for the current rule. During
* rule invocation, the parser pushes the set of tokens that can

View File

@ -52,46 +52,46 @@ void DiagnosticErrorListener::reportAmbiguity(Parser *recognizer, const dfa::DFA
return;
}
std::wstring decision = getDecisionDescription(recognizer, dfa);
std::string decision = getDecisionDescription(recognizer, dfa);
antlrcpp::BitSet conflictingAlts = getConflictingAlts(ambigAlts, configs);
std::wstring text = recognizer->getTokenStream()->getText(misc::Interval((int)startIndex, (int)stopIndex));
std::wstring message = L"reportAmbiguity d = " + decision + L": ambigAlts = " + conflictingAlts.toString() +
L", input = '" + text + L"'";
std::string text = recognizer->getTokenStream()->getText(misc::Interval((int)startIndex, (int)stopIndex));
std::string message = "reportAmbiguity d = " + decision + ": ambigAlts = " + conflictingAlts.toString() +
", input = '" + text + "'";
recognizer->notifyErrorListeners(message);
}
void DiagnosticErrorListener::reportAttemptingFullContext(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex,
size_t stopIndex, const antlrcpp::BitSet &/*conflictingAlts*/, Ref<atn::ATNConfigSet> /*configs*/) {
std::wstring decision = getDecisionDescription(recognizer, dfa);
std::wstring text = recognizer->getTokenStream()->getText(misc::Interval((int)startIndex, (int)stopIndex));
std::wstring message = L"reportAttemptingFullContext d = " + decision + L", input = '" + text + L"'";
std::string decision = getDecisionDescription(recognizer, dfa);
std::string text = recognizer->getTokenStream()->getText(misc::Interval((int)startIndex, (int)stopIndex));
std::string message = "reportAttemptingFullContext d = " + decision + ", input = '" + text + "'";
recognizer->notifyErrorListeners(message);
}
void DiagnosticErrorListener::reportContextSensitivity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex,
size_t stopIndex, int /*prediction*/, Ref<atn::ATNConfigSet> /*configs*/) {
std::wstring decision = getDecisionDescription(recognizer, dfa);
std::wstring text = recognizer->getTokenStream()->getText(misc::Interval((int)startIndex, (int)stopIndex));
std::wstring message = L"reportContextSensitivity d = " + decision + L", input = '" + text + L"'";
std::string decision = getDecisionDescription(recognizer, dfa);
std::string text = recognizer->getTokenStream()->getText(misc::Interval((int)startIndex, (int)stopIndex));
std::string message = "reportContextSensitivity d = " + decision + ", input = '" + text + "'";
recognizer->notifyErrorListeners(message);
}
std::wstring DiagnosticErrorListener::getDecisionDescription(Parser *recognizer, const dfa::DFA &dfa) {
std::string DiagnosticErrorListener::getDecisionDescription(Parser *recognizer, const dfa::DFA &dfa) {
int decision = dfa.decision;
int ruleIndex = ((atn::ATNState*)dfa.atnStartState)->ruleIndex;
const std::vector<std::wstring>& ruleNames = recognizer->getRuleNames();
const std::vector<std::string>& ruleNames = recognizer->getRuleNames();
if (ruleIndex < 0 || ruleIndex >= (int)ruleNames.size()) {
return std::to_wstring(decision);
return std::to_string(decision);
}
std::wstring ruleName = ruleNames[(size_t)ruleIndex];
if (ruleName == L"" || ruleName.empty()) {
return std::to_wstring(decision);
std::string ruleName = ruleNames[(size_t)ruleIndex];
if (ruleName == "" || ruleName.empty()) {
return std::to_string(decision);
}
return std::to_wstring(decision) + L"(" + ruleName + L")";
return std::to_string(decision) + "(" + ruleName + ")";
}
antlrcpp::BitSet DiagnosticErrorListener::getConflictingAlts(const antlrcpp::BitSet &reportedAlts,

View File

@ -91,7 +91,7 @@ namespace runtime {
int prediction, Ref<atn::ATNConfigSet> configs) override;
protected:
virtual std::wstring getDecisionDescription(Parser *recognizer, const dfa::DFA &dfa);
virtual std::string getDecisionDescription(Parser *recognizer, const dfa::DFA &dfa);
/// <summary>
/// Computes the set of conflicting or ambiguous alternatives from a

View File

@ -37,6 +37,7 @@
#include "ANTLRErrorListener.h"
#include "CPPUtils.h"
#include "CommonToken.h"
#include "StringUtils.h"
#include "Lexer.h"
@ -55,9 +56,9 @@ void Lexer::reset() {
type = Token::INVALID_TYPE;
channel = Token::DEFAULT_CHANNEL;
tokenStartCharIndex = -1;
tokenStartCharPositionInLine = -1;
tokenStartLine = -1;
text = L"";
tokenStartCharPositionInLine = 0;
tokenStartLine = 0;
text = "";
hitEOF = false;
mode = Lexer::DEFAULT_MODE;
@ -89,7 +90,7 @@ Ref<Token> Lexer::nextToken() {
tokenStartCharIndex = (int)_input->index();
tokenStartCharPositionInLine = getInterpreter<atn::LexerATNSimulator>()->getCharPositionInLine();
tokenStartLine = (int)getInterpreter<atn::LexerATNSimulator>()->getLine();
text = L"";
text = "";
do {
type = Token::INVALID_TYPE;
int ttype;
@ -131,7 +132,7 @@ void Lexer::setMode(size_t m) {
void Lexer::pushMode(size_t m) {
if (atn::LexerATNSimulator::debug) {
std::wcout << std::wstring(L"pushMode ") << m << std::endl;
std::cout << "pushMode " << m << std::endl;
}
modeStack.push_back(mode);
setMode(m);
@ -142,7 +143,7 @@ size_t Lexer::popMode() {
throw EmptyStackException();
}
if (atn::LexerATNSimulator::debug) {
std::wcout << std::wstring(L"popMode back to ") << modeStack.back() << std::endl;
std::cout << std::string("popMode back to ") << modeStack.back() << std::endl;
}
setMode(modeStack.back());
modeStack.pop_back();
@ -181,7 +182,7 @@ Ref<Token> Lexer::emit() {
Ref<Token> Lexer::emitEOF() {
int cpos = getCharPositionInLine();
size_t line = getLine();
Ref<Token> eof = std::dynamic_pointer_cast<Token>(_factory->create({ this, _input }, EOF, L"", Token::DEFAULT_CHANNEL,
Ref<Token> eof = std::dynamic_pointer_cast<Token>(_factory->create({ this, _input }, EOF, "", Token::DEFAULT_CHANNEL,
(int)_input->index(), (int)_input->index() - 1, (int)line, cpos));
emit(eof);
return eof;
@ -207,14 +208,14 @@ int Lexer::getCharIndex() {
return (int)_input->index();
}
std::wstring Lexer::getText() {
std::string Lexer::getText() {
if (!text.empty()) {
return text;
}
return getInterpreter<atn::LexerATNSimulator>()->getText(_input);
}
void Lexer::setText(const std::wstring &text) {
void Lexer::setText(const std::string &text) {
this->text = text;
}
@ -260,47 +261,48 @@ void Lexer::recover(const LexerNoViableAltException &/*e*/) {
}
void Lexer::notifyListeners(const LexerNoViableAltException &e) {
std::wstring text = _input->getText(misc::Interval(tokenStartCharIndex, (int)_input->index()));
std::wstring msg = std::wstring(L"token recognition error at: '") + getErrorDisplay(text) + std::wstring(L"'");
std::string text = _input->getText(misc::Interval(tokenStartCharIndex, (int)_input->index()));
std::string msg = std::string("token recognition error at: '") + getErrorDisplay(text) + std::string("'");
ProxyErrorListener &listener = getErrorListenerDispatch();
listener.syntaxError(this, nullptr, tokenStartLine, tokenStartCharPositionInLine, msg,
std::make_exception_ptr(e));
}
std::wstring Lexer::getErrorDisplay(const std::wstring &s) {
std::wstringstream ss;
for (auto c : s) {
std::string Lexer::getErrorDisplay(const std::string &s) {
std::u32string temp = utfConverter.from_bytes(s);
std::stringstream ss;
for (auto c : temp) {
ss << getErrorDisplay(c);
}
return ss.str();
}
std::wstring Lexer::getErrorDisplay(int c) {
std::wstring s;
std::string Lexer::getErrorDisplay(ssize_t c) {
std::string s;
switch (c) {
case EOF :
s = L"<EOF>";
s = "<EOF>";
break;
case L'\n' :
s = L"\\n";
case '\n' :
s = "\\n";
break;
case L'\t' :
s = L"\\t";
case '\t' :
s = "\\t";
break;
case L'\r' :
s = L"\\r";
case '\r' :
s = "\\r";
break;
default:
s = c;
s = utfConverter.to_bytes((char32_t)c);
break;
}
return s;
}
std::wstring Lexer::getCharErrorDisplay(int c) {
std::wstring s = getErrorDisplay(c);
return std::wstring(L"'") + s + std::wstring(L"'");
std::string Lexer::getCharErrorDisplay(ssize_t c) {
std::string s = getErrorDisplay(c);
return "'" + s + "'";
}
void Lexer::recover(RecognitionException * /*re*/) {

View File

@ -53,8 +53,8 @@ namespace runtime {
static const size_t DEFAULT_TOKEN_CHANNEL = Token::DEFAULT_CHANNEL;
static const int HIDDEN = Token::HIDDEN_CHANNEL;
static const wchar_t MIN_CHAR_VALUE = L'\0';
static const wchar_t MAX_CHAR_VALUE = L'\uFFFE';
static const size_t MIN_CHAR_VALUE = 0;
static const size_t MAX_CHAR_VALUE = 0x10FFFF;
CharStream *_input; // Pure reference, usually from statically allocated instance.
protected:
@ -107,7 +107,7 @@ namespace runtime {
/// You can set the text for the current token to override what is in
/// the input char buffer. Use setText() or can set this instance var.
std::wstring text;
std::string text;
Lexer(CharStream *input);
@ -177,13 +177,13 @@ namespace runtime {
/// Return the text matched so far for the current token or any
/// text override.
/// </summary>
virtual std::wstring getText();
virtual std::string getText();
/// <summary>
/// Set the complete text of this token; it wipes any previous
/// changes to the text.
/// </summary>
virtual void setText(const std::wstring &text);
virtual void setText(const std::string &text);
/// <summary>
/// Override if emitting multiple tokens. </summary>
@ -199,7 +199,7 @@ namespace runtime {
virtual int getChannel();
virtual const std::vector<std::wstring>& getModeNames() const = 0;
virtual const std::vector<std::string>& getModeNames() const = 0;
/// Return a list of all Token objects in input char stream.
/// Forces load of all tokens. Does not include EOF token.
@ -209,11 +209,11 @@ namespace runtime {
virtual void notifyListeners(const LexerNoViableAltException &e);
virtual std::wstring getErrorDisplay(const std::wstring &s);
virtual std::string getErrorDisplay(const std::string &s);
virtual std::wstring getErrorDisplay(int c);
virtual std::string getErrorDisplay(ssize_t c);
virtual std::wstring getCharErrorDisplay(int c);
virtual std::string getCharErrorDisplay(ssize_t c);
/// <summary>
/// Lexers can normally match any char in it's vocabulary after matching

View File

@ -40,14 +40,14 @@
using namespace org::antlr::v4::runtime;
LexerInterpreter::LexerInterpreter(const std::wstring &grammarFileName, const std::vector<std::wstring> &tokenNames,
const std::vector<std::wstring> &ruleNames, const std::vector<std::wstring> &modeNames, const atn::ATN &atn,
LexerInterpreter::LexerInterpreter(const std::string &grammarFileName, const std::vector<std::string> &tokenNames,
const std::vector<std::string> &ruleNames, const std::vector<std::string> &modeNames, const atn::ATN &atn,
CharStream *input)
: LexerInterpreter(grammarFileName, dfa::VocabularyImpl::fromTokenNames(tokenNames), ruleNames, modeNames, atn, input) {
}
LexerInterpreter::LexerInterpreter(const std::wstring &grammarFileName, Ref<dfa::Vocabulary> vocabulary,
const std::vector<std::wstring> &ruleNames, const std::vector<std::wstring> &modeNames, const atn::ATN &atn,
LexerInterpreter::LexerInterpreter(const std::string &grammarFileName, Ref<dfa::Vocabulary> vocabulary,
const std::vector<std::string> &ruleNames, const std::vector<std::string> &modeNames, const atn::ATN &atn,
CharStream *input)
: Lexer(input), _grammarFileName(grammarFileName), _atn(atn), _ruleNames(ruleNames), _modeNames(modeNames),
_vocabulary(vocabulary) {
@ -76,19 +76,19 @@ const atn::ATN& LexerInterpreter::getATN() const {
return _atn;
}
std::wstring LexerInterpreter::getGrammarFileName() const {
std::string LexerInterpreter::getGrammarFileName() const {
return _grammarFileName;
}
const std::vector<std::wstring>& LexerInterpreter::getTokenNames() const {
const std::vector<std::string>& LexerInterpreter::getTokenNames() const {
return _tokenNames;
}
const std::vector<std::wstring>& LexerInterpreter::getRuleNames() const {
const std::vector<std::string>& LexerInterpreter::getRuleNames() const {
return _ruleNames;
}
const std::vector<std::wstring>& LexerInterpreter::getModeNames() const {
const std::vector<std::string>& LexerInterpreter::getModeNames() const {
return _modeNames;
}

View File

@ -41,31 +41,31 @@ namespace runtime {
class ANTLR4CPP_PUBLIC LexerInterpreter : public Lexer {
public:
// @deprecated
LexerInterpreter(const std::wstring &grammarFileName, const std::vector<std::wstring> &tokenNames,
const std::vector<std::wstring> &ruleNames, const std::vector<std::wstring> &modeNames,
LexerInterpreter(const std::string &grammarFileName, const std::vector<std::string> &tokenNames,
const std::vector<std::string> &ruleNames, const std::vector<std::string> &modeNames,
const atn::ATN &atn, CharStream *input);
LexerInterpreter(const std::wstring &grammarFileName, Ref<dfa::Vocabulary> vocabulary,
const std::vector<std::wstring> &ruleNames, const std::vector<std::wstring> &modeNames,
LexerInterpreter(const std::string &grammarFileName, Ref<dfa::Vocabulary> vocabulary,
const std::vector<std::string> &ruleNames, const std::vector<std::string> &modeNames,
const atn::ATN &atn, CharStream *input);
~LexerInterpreter();
virtual const atn::ATN& getATN() const override;
virtual std::wstring getGrammarFileName() const override;
virtual const std::vector<std::wstring>& getTokenNames() const override;
virtual const std::vector<std::wstring>& getRuleNames() const override;
virtual const std::vector<std::wstring>& getModeNames() const override;
virtual std::string getGrammarFileName() const override;
virtual const std::vector<std::string>& getTokenNames() const override;
virtual const std::vector<std::string>& getRuleNames() const override;
virtual const std::vector<std::string>& getModeNames() const override;
virtual Ref<dfa::Vocabulary> getVocabulary() const override;
protected:
const std::wstring _grammarFileName;
const std::string _grammarFileName;
const atn::ATN &_atn;
// @deprecated
std::vector<std::wstring> _tokenNames;
const std::vector<std::wstring> &_ruleNames;
const std::vector<std::wstring> &_modeNames;
std::vector<std::string> _tokenNames;
const std::vector<std::string> &_ruleNames;
const std::vector<std::string> &_modeNames;
std::vector<dfa::DFA> _decisionToDFA;
Ref<atn::PredictionContextCache> _sharedContextCache;

View File

@ -51,12 +51,12 @@ Ref<atn::ATNConfigSet> LexerNoViableAltException::getDeadEndConfigs() {
return _deadEndConfigs;
}
std::wstring LexerNoViableAltException::toString() {
std::wstring symbol;
std::string LexerNoViableAltException::toString() {
std::string symbol;
if (_startIndex < getInputStream()->size()) {
symbol = ((CharStream *)getInputStream())->getText(misc::Interval((int)_startIndex, (int)_startIndex));
symbol = antlrcpp::escapeWhitespace(symbol, false);
}
std::wstring format = L"LexerNoViableAltException('" + symbol + L"')";
std::string format = "LexerNoViableAltException('" + symbol + "')";
return format;
}

View File

@ -46,7 +46,7 @@ namespace runtime {
virtual size_t getStartIndex();
virtual Ref<atn::ATNConfigSet> getDeadEndConfigs();
virtual std::wstring toString();
virtual std::string toString();
private:
/// Matching attempted at what input index?

View File

@ -46,9 +46,9 @@ int ListTokenSource::getCharPositionInLine() {
// have to calculate the result from the line/column of the previous
// token, along with the text of the token.
Ref<Token> lastToken = tokens.back();
std::wstring tokenText = lastToken->getText();
if (tokenText != L"") {
int lastNewLine = (int)tokenText.rfind(L'\n');
std::string tokenText = lastToken->getText();
if (tokenText != "") {
int lastNewLine = (int)tokenText.rfind('\n');
if (lastNewLine >= 0) {
return (int)tokenText.length() - lastNewLine - 1;
}
@ -74,7 +74,7 @@ Ref<Token> ListTokenSource::nextToken() {
}
int stop = std::max(-1, start - 1);
eofToken = std::dynamic_pointer_cast<Token>(_factory->create({ this, getInputStream() }, Token::EOF, L"EOF",
eofToken = std::dynamic_pointer_cast<Token>(_factory->create({ this, getInputStream() }, Token::EOF, "EOF",
Token::DEFAULT_CHANNEL, start, stop, (int)getLine(), getCharPositionInLine()));
}
@ -101,10 +101,10 @@ size_t ListTokenSource::getLine() const {
Ref<Token> lastToken = tokens.back();
int line = lastToken->getLine();
std::wstring tokenText = lastToken->getText();
if (tokenText != L"") {
std::string tokenText = lastToken->getText();
if (tokenText != "") {
for (size_t i = 0; i < tokenText.length(); i++) {
if (tokenText[i] == L'\n') {
if (tokenText[i] == '\n') {
line++;
}
}

View File

@ -109,7 +109,7 @@ namespace runtime {
ListTokenSource(std::vector<T1> tokens, const std::string &/*sourceName*/) {
InitializeInstanceFields();
if (tokens.empty()) {
throw L"tokens cannot be null";
throw "tokens cannot be nul";
}
}

View File

@ -42,7 +42,6 @@
#include "ATNDeserializer.h"
#include "RuleTransition.h"
#include "ATN.h"
#include "Strings.h"
#include "Exceptions.h"
#include "ANTLRErrorListener.h"
#include "ParseTreePattern.h"
@ -55,33 +54,27 @@
using namespace org::antlr::v4::runtime;
using namespace antlrcpp;
std::map<std::wstring, atn::ATN> Parser::bypassAltsAtnCache;
std::map<std::vector<uint16_t>, atn::ATN> Parser::bypassAltsAtnCache;
Parser::TraceListener::TraceListener(Parser *outerInstance) : outerInstance(outerInstance) {
}
void Parser::TraceListener::enterEveryRule(Ref<ParserRuleContext> ctx) {
std::cout << "enter "
<< antlrcpp::ws2s(outerInstance->getRuleNames()[(size_t)ctx->getRuleIndex()])
<< ", LT(1)=" << antlrcpp::ws2s(outerInstance->_input->LT(1)->getText())
<< std::endl;
std::cout << "enter " << outerInstance->getRuleNames()[(size_t)ctx->getRuleIndex()]
<< ", LT(1)=" << outerInstance->_input->LT(1)->getText() << std::endl;
}
void Parser::TraceListener::visitTerminal(Ref<tree::TerminalNode> node) {
std::cout << "consume "
<< node->getSymbol() << " rule "
<< antlrcpp::ws2s(outerInstance->getRuleNames()[(size_t)outerInstance->getContext()->getRuleIndex()])
<< std::endl;
std::cout << "consume " << node->getSymbol() << " rule "
<< outerInstance->getRuleNames()[(size_t)outerInstance->getContext()->getRuleIndex()] << std::endl;
}
void Parser::TraceListener::visitErrorNode(Ref<tree::ErrorNode> /*node*/) {
}
void Parser::TraceListener::exitEveryRule(Ref<ParserRuleContext> ctx) {
std::cout << "exit "
<< antlrcpp::ws2s(outerInstance->getRuleNames()[(size_t)ctx->getRuleIndex()])
<< ", LT(1)=" << antlrcpp::ws2s(outerInstance->_input->LT(1)->getText())
<< std::endl;
std::cout << "exit " << outerInstance->getRuleNames()[(size_t)ctx->getRuleIndex()]
<< ", LT(1)=" << outerInstance->_input->LT(1)->getText() << std::endl;
}
const Ref<Parser::TrimToSizeListener> Parser::TrimToSizeListener::INSTANCE =
@ -233,7 +226,7 @@ Ref<TokenFactory<CommonToken>> Parser::getTokenFactory() {
const atn::ATN& Parser::getATNWithBypassAlts() {
std::wstring serializedAtn = getSerializedATN();
std::vector<uint16_t> serializedAtn = getSerializedATN();
if (serializedAtn.empty()) {
throw UnsupportedOperationException("The current parser does not support an ATN with bypass alternatives.");
}
@ -254,7 +247,7 @@ const atn::ATN& Parser::getATNWithBypassAlts() {
return bypassAltsAtnCache[serializedAtn];
}
tree::pattern::ParseTreePattern Parser::compileParseTreePattern(const std::wstring &pattern, int patternRuleIndex) {
tree::pattern::ParseTreePattern Parser::compileParseTreePattern(const std::string &pattern, int patternRuleIndex) {
if (getTokenStream() != nullptr) {
TokenSource *tokenSource = getTokenStream()->getTokenSource();
if (is<Lexer*>(tokenSource)) {
@ -265,7 +258,7 @@ tree::pattern::ParseTreePattern Parser::compileParseTreePattern(const std::wstri
throw UnsupportedOperationException("Parser can't discover a lexer to use");
}
tree::pattern::ParseTreePattern Parser::compileParseTreePattern(const std::wstring &pattern, int patternRuleIndex,
tree::pattern::ParseTreePattern Parser::compileParseTreePattern(const std::string &pattern, int patternRuleIndex,
Lexer *lexer) {
tree::pattern::ParseTreePatternMatcher m(lexer, this);
return m.compile(pattern, patternRuleIndex);
@ -301,11 +294,11 @@ Ref<Token> Parser::getCurrentToken() {
return _input->LT(1);
}
void Parser::notifyErrorListeners(const std::wstring &msg) {
void Parser::notifyErrorListeners(const std::string &msg) {
notifyErrorListeners(getCurrentToken(), msg, nullptr);
}
void Parser::notifyErrorListeners(Ref<Token> offendingToken, const std::wstring &msg, std::exception_ptr e) {
void Parser::notifyErrorListeners(Ref<Token> offendingToken, const std::string &msg, std::exception_ptr e) {
_syntaxErrors++;
int line = -1;
int charPositionInLine = -1;
@ -483,7 +476,7 @@ bool Parser::precpred(Ref<RuleContext> /*localctx*/, int precedence) {
return precedence >= _precedenceStack.back();
}
bool Parser::inContext(const std::wstring &/*context*/) {
bool Parser::inContext(const std::string &/*context*/) {
// TO_DO: useful in parser?
return false;
}
@ -534,8 +527,8 @@ misc::IntervalSet Parser::getExpectedTokensWithinCurrentRule() {
return atn.nextTokens(s);
}
ssize_t Parser::getRuleIndex(const std::wstring &ruleName) {
const std::map<std::wstring, size_t> &m = getRuleIndexMap();
ssize_t Parser::getRuleIndex(const std::string &ruleName) {
const std::map<std::string, size_t> &m = getRuleIndexMap();
auto iterator = m.find(ruleName);
if (iterator == m.end()) {
return -1;
@ -547,18 +540,18 @@ Ref<ParserRuleContext> Parser::getRuleContext() {
return _ctx;
}
std::vector<std::wstring> Parser::getRuleInvocationStack() {
std::vector<std::string> Parser::getRuleInvocationStack() {
return getRuleInvocationStack(_ctx);
}
std::vector<std::wstring> Parser::getRuleInvocationStack(Ref<RuleContext> p) {
std::vector<std::wstring> ruleNames = getRuleNames();
std::vector<std::wstring> stack = std::vector<std::wstring>();
std::vector<std::string> Parser::getRuleInvocationStack(Ref<RuleContext> p) {
std::vector<std::string> ruleNames = getRuleNames();
std::vector<std::string> stack = std::vector<std::string>();
while (p) {
// compute what follows who invoked us
ssize_t ruleIndex = p->getRuleIndex();
if (ruleIndex < 0) {
stack.push_back(L"n/a");
stack.push_back("n/a");
} else {
stack.push_back(ruleNames[(size_t)ruleIndex]);
}
@ -569,19 +562,19 @@ std::vector<std::wstring> Parser::getRuleInvocationStack(Ref<RuleContext> p) {
return stack;
}
std::vector<std::wstring> Parser::getDFAStrings() {
std::vector<std::string> Parser::getDFAStrings() {
atn::ParserATNSimulator *simulator = getInterpreter<atn::ParserATNSimulator>();
if (!simulator->decisionToDFA.empty()) {
std::lock_guard<std::recursive_mutex> lck(mtx);
std::vector<std::wstring> s;
std::vector<std::string> s;
for (size_t d = 0; d < simulator->decisionToDFA.size(); d++) {
dfa::DFA &dfa = simulator->decisionToDFA[d];
s.push_back(dfa.toString(getVocabulary()));
}
return s;
}
return std::vector<std::wstring>();
return std::vector<std::string>();
}
void Parser::dumpDFA() {
@ -595,9 +588,9 @@ void Parser::dumpDFA() {
if (seenOne) {
std::cout << std::endl;
}
std::cout << L"Decision " << dfa.decision << L":" << std::endl;
std::cout << "Decision " << dfa.decision << ":" << std::endl;
dfa.toString(getTokenNames());
std::wcout << dfa.toString(getVocabulary());
std::cout << dfa.toString(getVocabulary());
seenOne = true;
}
}

View File

@ -245,13 +245,13 @@ namespace runtime {
/// String id = m.get("ID");
/// </pre>
/// </summary>
virtual tree::pattern::ParseTreePattern compileParseTreePattern(const std::wstring &pattern, int patternRuleIndex);
virtual tree::pattern::ParseTreePattern compileParseTreePattern(const std::string &pattern, int patternRuleIndex);
/// <summary>
/// The same as <seealso cref="#compileParseTreePattern(String, int)"/> but specify a
/// <seealso cref="Lexer"/> rather than trying to deduce it from this parser.
/// </summary>
virtual tree::pattern::ParseTreePattern compileParseTreePattern(const std::wstring &pattern, int patternRuleIndex,
virtual tree::pattern::ParseTreePattern compileParseTreePattern(const std::string &pattern, int patternRuleIndex,
Lexer *lexer);
virtual Ref<ANTLRErrorStrategy> getErrorHandler();
@ -271,9 +271,9 @@ namespace runtime {
/// </summary>
virtual Ref<Token> getCurrentToken();
void notifyErrorListeners(const std::wstring &msg);
void notifyErrorListeners(const std::string &msg);
virtual void notifyErrorListeners(Ref<Token> offendingToken, const std::wstring &msg, std::exception_ptr e);
virtual void notifyErrorListeners(Ref<Token> offendingToken, const std::string &msg, std::exception_ptr e);
/// <summary>
/// Consume and return the <seealso cref="#getCurrentToken current symbol"/>.
@ -330,7 +330,7 @@ namespace runtime {
virtual Ref<ParserRuleContext> getContext();
virtual void setContext(Ref<ParserRuleContext> ctx);
virtual bool precpred(Ref<RuleContext> localctx, int precedence) override;
virtual bool inContext(const std::wstring &context);
virtual bool inContext(const std::string &context);
/// <summary>
/// Checks whether or not {@code symbol} can follow the current state in the
@ -361,7 +361,7 @@ namespace runtime {
/// <summary>
/// Get a rule's index (i.e., {@code RULE_ruleName} field) or -1 if not found. </summary>
virtual ssize_t getRuleIndex(const std::wstring &ruleName);
virtual ssize_t getRuleIndex(const std::string &ruleName);
virtual Ref<ParserRuleContext> getRuleContext();
@ -373,13 +373,13 @@ namespace runtime {
///
/// This is very useful for error messages.
/// </summary>
virtual std::vector<std::wstring> getRuleInvocationStack();
virtual std::vector<std::string> getRuleInvocationStack();
virtual std::vector<std::wstring> getRuleInvocationStack(Ref<RuleContext> p);
virtual std::vector<std::string> getRuleInvocationStack(Ref<RuleContext> p);
/// <summary>
/// For debugging and other purposes. </summary>
virtual std::vector<std::wstring> getDFAStrings();
virtual std::vector<std::string> getDFAStrings();
/// <summary>
/// For debugging and other purposes. </summary>
@ -460,7 +460,7 @@ namespace runtime {
/// bypass alternatives.
///
/// <seealso cref= ATNDeserializationOptions#isGenerateRuleBypassTransitions() </seealso>
static std::map<std::wstring, atn::ATN> bypassAltsAtnCache;
static std::map<std::vector<uint16_t>, atn::ATN> bypassAltsAtnCache;
/// When setTrace(true) is called, a reference to the
/// TraceListener is stored here so it can be easily removed in a

View File

@ -57,13 +57,13 @@ using namespace org::antlr::v4::runtime;
using namespace org::antlr::v4::runtime::atn;
using namespace antlrcpp;
ParserInterpreter::ParserInterpreter(const std::wstring &grammarFileName, const std::vector<std::wstring>& tokenNames,
const std::vector<std::wstring>& ruleNames, const atn::ATN &atn, TokenStream *input)
ParserInterpreter::ParserInterpreter(const std::string &grammarFileName, const std::vector<std::string>& tokenNames,
const std::vector<std::string>& ruleNames, const atn::ATN &atn, TokenStream *input)
: ParserInterpreter(grammarFileName, dfa::VocabularyImpl::fromTokenNames(tokenNames), ruleNames, atn, input) {
}
ParserInterpreter::ParserInterpreter(const std::wstring &grammarFileName, Ref<dfa::Vocabulary> vocabulary,
const std::vector<std::wstring> &ruleNames, const atn::ATN &atn, TokenStream *input)
ParserInterpreter::ParserInterpreter(const std::string &grammarFileName, Ref<dfa::Vocabulary> vocabulary,
const std::vector<std::string> &ruleNames, const atn::ATN &atn, TokenStream *input)
: Parser(input), _grammarFileName(grammarFileName), _atn(atn), _ruleNames(ruleNames), _vocabulary(vocabulary) {
_sharedContextCache = std::make_shared<atn::PredictionContextCache>();
@ -95,7 +95,7 @@ const atn::ATN& ParserInterpreter::getATN() const {
return _atn;
}
const std::vector<std::wstring>& ParserInterpreter::getTokenNames() const {
const std::vector<std::string>& ParserInterpreter::getTokenNames() const {
return _tokenNames;
}
@ -103,11 +103,11 @@ Ref<dfa::Vocabulary> ParserInterpreter::getVocabulary() const {
return _vocabulary;
}
const std::vector<std::wstring>& ParserInterpreter::getRuleNames() const {
const std::vector<std::string>& ParserInterpreter::getRuleNames() const {
return _ruleNames;
}
std::wstring ParserInterpreter::getGrammarFileName() const {
std::string ParserInterpreter::getGrammarFileName() const {
return _grammarFileName;
}
@ -203,7 +203,7 @@ void ParserInterpreter::visitState(atn::ATNState *p) {
break;
case atn::Transition::ATOM:
match(((atn::AtomTransition*)(transition))->_label);
match((int)((atn::AtomTransition*)(transition))->_label);
break;
case atn::Transition::RANGE:

View File

@ -58,10 +58,10 @@ namespace runtime {
class ANTLR4CPP_PUBLIC ParserInterpreter : public Parser {
public:
// @deprecated
ParserInterpreter(const std::wstring &grammarFileName, const std::vector<std::wstring>& tokenNames,
const std::vector<std::wstring>& ruleNames, const atn::ATN &atn, TokenStream *input);
ParserInterpreter(const std::wstring &grammarFileName, Ref<dfa::Vocabulary> vocabulary,
const std::vector<std::wstring> &ruleNames, const atn::ATN &atn, TokenStream *input);
ParserInterpreter(const std::string &grammarFileName, const std::vector<std::string>& tokenNames,
const std::vector<std::string>& ruleNames, const atn::ATN &atn, TokenStream *input);
ParserInterpreter(const std::string &grammarFileName, Ref<dfa::Vocabulary> vocabulary,
const std::vector<std::string> &ruleNames, const atn::ATN &atn, TokenStream *input);
~ParserInterpreter();
virtual void reset() override;
@ -69,12 +69,12 @@ namespace runtime {
virtual const atn::ATN& getATN() const override;
// @deprecated
virtual const std::vector<std::wstring>& getTokenNames() const override;
virtual const std::vector<std::string>& getTokenNames() const override;
virtual Ref<dfa::Vocabulary> getVocabulary() const override;
virtual const std::vector<std::wstring>& getRuleNames() const override;
virtual std::wstring getGrammarFileName() const override;
virtual const std::vector<std::string>& getRuleNames() const override;
virtual std::string getGrammarFileName() const override;
/// Begin parsing at startRuleIndex
virtual Ref<ParserRuleContext> parse(int startRuleIndex);
@ -137,11 +137,11 @@ namespace runtime {
Ref<InterpreterRuleContext> getRootContext();
protected:
const std::wstring _grammarFileName;
std::vector<std::wstring> _tokenNames;
const std::string _grammarFileName;
std::vector<std::string> _tokenNames;
const atn::ATN &_atn;
std::vector<std::wstring> _ruleNames;
std::vector<std::string> _ruleNames;
std::vector<dfa::DFA> _decisionToDFA; // not shared like it is for generated parsers
Ref<atn::PredictionContextCache> _sharedContextCache;

View File

@ -155,12 +155,12 @@ Ref<Token> ParserRuleContext::getStop() {
return stop;
}
std::wstring ParserRuleContext::toInfoString(Parser *recognizer) {
std::vector<std::wstring> rules = recognizer->getRuleInvocationStack(shared_from_this());
std::string ParserRuleContext::toInfoString(Parser *recognizer) {
std::vector<std::string> rules = recognizer->getRuleInvocationStack(shared_from_this());
std::reverse(rules.begin(), rules.end());
std::wstring rulesStr = antlrcpp::arrayToString(rules);
return std::wstring(L"ParserRuleContext") + rulesStr + std::wstring(L"{") + std::wstring(L"start=") +
std::to_wstring(start->getTokenIndex()) + std::wstring(L", stop=") +
std::to_wstring(stop->getTokenIndex()) + L'}';
std::string rulesStr = antlrcpp::arrayToString(rules);
return std::string("ParserRuleContext") + rulesStr + std::string("{") + std::string("start=") +
std::to_string(start->getTokenIndex()) + std::string(", stop=") +
std::to_string(stop->getTokenIndex()) + '}';
}

View File

@ -180,7 +180,7 @@ namespace runtime {
/// <summary>
/// Used for rule context info debugging during parse-time, not so much for ATN debugging </summary>
virtual std::wstring toInfoString(Parser *recognizer);
virtual std::string toInfoString(Parser *recognizer);
protected:
virtual Ref<Tree> getChildReference(size_t i) override;

View File

@ -35,7 +35,7 @@ using namespace org::antlr::v4::runtime;
void ProxyErrorListener::addErrorListener(ANTLRErrorListener *listener) {
if (listener == nullptr) {
throw L"listener cannot be null.";
throw "listener cannot be null.";
}
_delegates.insert(listener);
@ -50,7 +50,7 @@ void ProxyErrorListener::removeErrorListeners() {
}
void ProxyErrorListener::syntaxError(IRecognizer *recognizer, Ref<Token> offendingSymbol, size_t line,
int charPositionInLine, const std::wstring &msg, std::exception_ptr e) {
int charPositionInLine, const std::string &msg, std::exception_ptr e) {
for (auto listener : _delegates) {
listener->syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e);

View File

@ -52,7 +52,7 @@ namespace runtime {
void removeErrorListeners();
void syntaxError(IRecognizer *recognizer, Ref<Token> offendingSymbol, size_t line, int charPositionInLine,
const std::wstring &msg, std::exception_ptr e) override;
const std::string &msg, std::exception_ptr e) override;
virtual void reportAmbiguity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, bool exact,
const antlrcpp::BitSet &ambigAlts, Ref<atn::ATNConfigSet> configs) override;

View File

@ -31,7 +31,7 @@
#include "ATN.h"
#include "Recognizer.h"
#include "Strings.h"
#include "StringUtils.h"
#include "ParserRuleContext.h"
#include "IntervalSet.h"

View File

@ -32,7 +32,7 @@
#include "ConsoleErrorListener.h"
#include "RecognitionException.h"
#include "CPPUtils.h"
#include "Strings.h"
#include "StringUtils.h"
#include "Token.h"
#include "ATN.h"
#include "ATNSimulator.h"
@ -45,8 +45,8 @@
using namespace org::antlr::v4::runtime;
std::map<Ref<dfa::Vocabulary>, std::map<std::wstring, size_t>> Recognizer::_tokenTypeMapCache;
std::map<std::vector<std::wstring>, std::map<std::wstring, size_t>> Recognizer::_ruleIndexMapCache;
std::map<Ref<dfa::Vocabulary>, std::map<std::string, size_t>> Recognizer::_tokenTypeMapCache;
std::map<std::vector<std::string>, std::map<std::string, size_t>> Recognizer::_ruleIndexMapCache;
Recognizer::Recognizer() {
InitializeInstanceFields();
@ -57,41 +57,41 @@ Ref<dfa::Vocabulary> Recognizer::getVocabulary() const {
return dfa::VocabularyImpl::fromTokenNames(getTokenNames());
}
std::map<std::wstring, size_t> Recognizer::getTokenTypeMap() {
std::map<std::string, size_t> Recognizer::getTokenTypeMap() {
Ref<dfa::Vocabulary> vocabulary = getVocabulary();
std::lock_guard<std::recursive_mutex> lck(mtx);
std::map<std::wstring, size_t> result;
std::map<std::string, size_t> result;
auto iterator = _tokenTypeMapCache.find(vocabulary);
if (iterator != _tokenTypeMapCache.end()) {
result = iterator->second;
} else {
for (size_t i = 0; i < getATN().maxTokenType; ++i) {
std::wstring literalName = vocabulary->getLiteralName(i);
std::string literalName = vocabulary->getLiteralName(i);
if (!literalName.empty()) {
result[literalName] = i;
}
std::wstring symbolicName = vocabulary->getSymbolicName(i);
std::string symbolicName = vocabulary->getSymbolicName(i);
if (!symbolicName.empty()) {
result[symbolicName] = i;
}
}
result[L"EOF"] = EOF;
result["EOF"] = EOF;
_tokenTypeMapCache[vocabulary] = result;
}
return result;
}
std::map<std::wstring, size_t> Recognizer::getRuleIndexMap() {
const std::vector<std::wstring>& ruleNames = getRuleNames();
std::map<std::string, size_t> Recognizer::getRuleIndexMap() {
const std::vector<std::string>& ruleNames = getRuleNames();
if (ruleNames.empty()) {
throw L"The current recognizer does not provide a list of rule names.";
throw "The current recognizer does not provide a list of rule names.";
}
std::lock_guard<std::recursive_mutex> lck(mtx);
std::map<std::wstring, size_t> result;
std::map<std::string, size_t> result;
auto iterator = _ruleIndexMapCache.find(ruleNames);
if (iterator != _ruleIndexMapCache.end()) {
result = iterator->second;
@ -102,8 +102,8 @@ std::map<std::wstring, size_t> Recognizer::getRuleIndexMap() {
return result;
}
size_t Recognizer::getTokenType(const std::wstring &tokenName) {
const std::map<std::wstring, size_t> &map = getTokenTypeMap();
size_t Recognizer::getTokenType(const std::string &tokenName) {
const std::map<std::string, size_t> &map = getTokenTypeMap();
auto iterator = map.find(tokenName);
if (iterator == map.end())
return Token::INVALID_TYPE;
@ -122,33 +122,33 @@ void Recognizer::setInterpreter(atn::ATNSimulator *interpreter) {
_interpreter = interpreter;
}
std::wstring Recognizer::getErrorHeader(RecognitionException *e) {
std::string Recognizer::getErrorHeader(RecognitionException *e) {
// We're having issues with cross header dependencies, these two classes will need to be
// rewritten to remove that.
int line = e->getOffendingToken()->getLine();
int charPositionInLine = e->getOffendingToken()->getCharPositionInLine();
return std::wstring(L"line ") + std::to_wstring(line) + std::wstring(L":") + std::to_wstring(charPositionInLine);
return std::string("line ") + std::to_string(line) + std::string(":") + std::to_string(charPositionInLine);
}
std::wstring Recognizer::getTokenErrorDisplay(Token *t) {
std::string Recognizer::getTokenErrorDisplay(Token *t) {
if (t == nullptr) {
return L"<no Token>";
return "<no Token>";
}
std::wstring s = t->getText();
if (s == L"") {
std::string s = t->getText();
if (s == "") {
if (t->getType() == EOF) {
s = L"<EOF>";
s = "<EOF>";
} else {
s = std::wstring(L"<") + std::to_wstring(t->getType()) + std::wstring(L">");
s = std::string("<") + std::to_string(t->getType()) + std::string(">");
}
}
antlrcpp::replaceAll(s, L"\n", L"\\n");
antlrcpp::replaceAll(s, L"\r",L"\\r");
antlrcpp::replaceAll(s, L"\t", L"\\t");
antlrcpp::replaceAll(s, "\n", "\\n");
antlrcpp::replaceAll(s, "\r","\\r");
antlrcpp::replaceAll(s, "\t", "\\t");
return std::wstring(L"'") + s + std::wstring(L"'");
return std::string("'") + s + std::string("'");
}
void Recognizer::addErrorListener(ANTLRErrorListener *listener) {

View File

@ -52,8 +52,8 @@ namespace runtime {
*
* @deprecated Use {@link #getVocabulary()} instead.
*/
virtual const std::vector<std::wstring>& getTokenNames() const = 0;
virtual const std::vector<std::wstring>& getRuleNames() const = 0;
virtual const std::vector<std::string>& getTokenNames() const = 0;
virtual const std::vector<std::string>& getRuleNames() const = 0;
/**
* Get the vocabulary used by the recognizer.
@ -68,16 +68,16 @@ namespace runtime {
/// <p/>
/// Used for XPath and tree pattern compilation.
/// </summary>
virtual std::map<std::wstring, size_t> getTokenTypeMap();
virtual std::map<std::string, size_t> getTokenTypeMap();
/// <summary>
/// Get a map from rule names to rule indexes.
/// <p/>
/// Used for XPath and tree pattern compilation.
/// </summary>
virtual std::map<std::wstring, size_t> getRuleIndexMap();
virtual std::map<std::string, size_t> getRuleIndexMap();
virtual size_t getTokenType(const std::wstring &tokenName);
virtual size_t getTokenType(const std::string &tokenName);
/// <summary>
/// If this recognizer was generated, it will have a serialized ATN
@ -86,15 +86,15 @@ namespace runtime {
/// For interpreters, we don't know their serialized ATN despite having
/// created the interpreter from it.
/// </summary>
virtual std::wstring getSerializedATN() {
throw L"there is no serialized ATN";
virtual std::vector<uint16_t> getSerializedATN() {
throw "there is no serialized ATN";
}
/// <summary>
/// For debugging and other purposes, might want the grammar name.
/// Have ANTLR generate an implementation for this method.
/// </summary>
virtual std::wstring getGrammarFileName() const = 0;
virtual std::string getGrammarFileName() const = 0;
/// Get the ATN interpreter (in fact one of it's descendants) used by the recognizer for prediction.
/// @returns The ATN interpreter used by the recognizer for prediction.
@ -119,7 +119,7 @@ namespace runtime {
void setInterpreter(atn::ATNSimulator *interpreter);
/// What is the error header, normally line/character position information?
virtual std::wstring getErrorHeader(RecognitionException *e);
virtual std::string getErrorHeader(RecognitionException *e);
/** How should a token be displayed in an error message? The default
* is to display just the text, but during development you might
@ -134,7 +134,7 @@ namespace runtime {
* feature when necessary. For example, see
* {@link DefaultErrorStrategy#getTokenErrorDisplay}.
*/
virtual std::wstring getTokenErrorDisplay(Token *t);
virtual std::string getTokenErrorDisplay(Token *t);
/// <exception cref="NullPointerException"> if {@code listener} is {@code null}. </exception>
virtual void addErrorListener(ANTLRErrorListener *listener);
@ -178,8 +178,8 @@ namespace runtime {
atn::ATNSimulator *_interpreter; // Set and deleted in descendants (or the profiler).
private:
static std::map<Ref<dfa::Vocabulary>, std::map<std::wstring, size_t>> _tokenTypeMapCache;
static std::map<std::vector<std::wstring>, std::map<std::wstring, size_t>> _ruleIndexMapCache;
static std::map<Ref<dfa::Vocabulary>, std::map<std::string, size_t>> _tokenTypeMapCache;
static std::map<std::vector<std::string>, std::map<std::string, size_t>> _ruleIndexMapCache;
ProxyErrorListener _proxListener; // Manages a collection of listeners.

View File

@ -79,15 +79,15 @@ std::weak_ptr<tree::Tree> RuleContext::getParentReference()
return std::dynamic_pointer_cast<tree::Tree>(parent.lock());
}
std::wstring RuleContext::getText() {
std::string RuleContext::getText() {
if (getChildCount() == 0) {
return L"";
return "";
}
std::wstringstream ss;
std::stringstream ss;
for (size_t i = 0; i < getChildCount(); i++) {
if (i > 0)
ss << L", ";
ss << ", ";
ss << getChild(i)->getText();
}
@ -114,29 +114,29 @@ std::size_t RuleContext::getChildCount() {
return 0;
}
std::wstring RuleContext::toStringTree(Parser *recog) {
std::string RuleContext::toStringTree(Parser *recog) {
return tree::Trees::toStringTree(shared_from_this(), recog);
}
std::wstring RuleContext::toStringTree(std::vector<std::wstring> &ruleNames) {
std::string RuleContext::toStringTree(std::vector<std::string> &ruleNames) {
return tree::Trees::toStringTree(shared_from_this(), ruleNames);
}
std::wstring RuleContext::toStringTree() {
std::string RuleContext::toStringTree() {
return toStringTree(nullptr);
}
std::wstring RuleContext::toString(const std::vector<std::wstring> &ruleNames) {
std::string RuleContext::toString(const std::vector<std::string> &ruleNames) {
return toString(ruleNames, Ref<RuleContext>());
}
std::wstring RuleContext::toString(const std::vector<std::wstring> &ruleNames, Ref<RuleContext> stop) {
std::wstringstream ss;
std::string RuleContext::toString(const std::vector<std::string> &ruleNames, Ref<RuleContext> stop) {
std::stringstream ss;
Ref<RuleContext> parent = shared_from_this();
ss << L"[";
ss << "[";
while (parent != stop) {
if (ruleNames.empty()) {
if (!parent->isEmpty()) {
@ -145,7 +145,7 @@ std::wstring RuleContext::toString(const std::vector<std::wstring> &ruleNames, R
} else {
ssize_t ruleIndex = parent->getRuleIndex();
std::wstring ruleName = (ruleIndex >= 0 && ruleIndex < (ssize_t)ruleNames.size()) ? ruleNames[(size_t)ruleIndex] : std::to_wstring(ruleIndex);
std::string ruleName = (ruleIndex >= 0 && ruleIndex < (ssize_t)ruleNames.size()) ? ruleNames[(size_t)ruleIndex] : std::to_string(ruleIndex);
ss << ruleName;
}
@ -153,24 +153,24 @@ std::wstring RuleContext::toString(const std::vector<std::wstring> &ruleNames, R
break;
parent = parent->parent.lock();
if (!ruleNames.empty() || !parent->isEmpty()) {
ss << L" ";
ss << " ";
}
}
ss << L"]";
ss << "]";
return ss.str();
}
std::wstring RuleContext::toString() {
std::string RuleContext::toString() {
return toString(nullptr);
}
std::wstring RuleContext::toString(Recognizer *recog) {
std::string RuleContext::toString(Recognizer *recog) {
return toString(recog, ParserRuleContext::EMPTY);
}
std::wstring RuleContext::toString(Recognizer *recog, Ref<RuleContext> stop) {
std::string RuleContext::toString(Recognizer *recog, Ref<RuleContext> stop) {
if (recog == nullptr)
return toString({}, stop);
return toString(recog->getRuleNames(), stop);

View File

@ -114,7 +114,7 @@ namespace runtime {
virtual misc::Interval getSourceInterval() override;
virtual Ref<RuleContext> getRuleContext() override;
virtual std::wstring getText() override;
virtual std::string getText() override;
virtual ssize_t getRuleIndex() const;
@ -151,23 +151,23 @@ namespace runtime {
/// (root child1 .. childN). Print just a node if this is a leaf.
/// We have to know the recognizer so we can get rule names.
/// </summary>
virtual std::wstring toStringTree(Parser *recog) override;
virtual std::string toStringTree(Parser *recog) override;
/// <summary>
/// Print out a whole tree, not just a node, in LISP format
/// (root child1 .. childN). Print just a node if this is a leaf.
/// </summary>
virtual std::wstring toStringTree(std::vector<std::wstring> &ruleNames);
virtual std::string toStringTree(std::vector<std::string> &ruleNames);
virtual std::wstring toStringTree() override;
virtual std::wstring toString() override;
std::wstring toString(Recognizer *recog);
std::wstring toString(const std::vector<std::wstring> &ruleNames);
virtual std::string toStringTree() override;
virtual std::string toString() override;
std::string toString(Recognizer *recog);
std::string toString(const std::vector<std::string> &ruleNames);
// recog null unless ParserRuleContext, in which case we use subclass toString(...)
std::wstring toString(Recognizer *recog, Ref<RuleContext> stop);
std::string toString(Recognizer *recog, Ref<RuleContext> stop);
virtual std::wstring toString(const std::vector<std::wstring> &ruleNames, Ref<RuleContext> stop);
virtual std::string toString(const std::vector<std::string> &ruleNames, Ref<RuleContext> stop);
bool operator == (const RuleContext &other) { return this == &other; } // Simple address comparison.

View File

@ -0,0 +1,52 @@
/*
* [The "BSD license"]
* Copyright (c) 2016 Mike Lischke
* Copyright (c) 2016 Terence Parr
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ATN.h"
#include "RuleContextWithAltNum.h"
using namespace org::antlr::v4::runtime;
using namespace org::antlr::v4::runtime::atn;
RuleContextWithAltNum::RuleContextWithAltNum() : ParserRuleContext() {
altNum = ATN::INVALID_ALT_NUMBER;
}
RuleContextWithAltNum::RuleContextWithAltNum(Ref<ParserRuleContext> parent, int invokingStateNumber)
: ParserRuleContext(parent, invokingStateNumber) {
}
int RuleContextWithAltNum::getAltNumber() const {
return altNum;
}
void RuleContextWithAltNum::setAltNumber(int altNum) {
this->altNum = altNum;
}

View File

@ -0,0 +1,63 @@
/*
* [The "BSD license"]
* Copyright (c) 2016 Mike Lischke
* Copyright (c) 2016 Terence Parr
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "ParserRuleContext.h"
namespace org {
namespace antlr {
namespace v4 {
namespace runtime {
/// A handy class for use with
///
/// options {contextSuperClass=org.antlr.v4.runtime.RuleContextWithAltNum;}
///
/// that provides a backing field / impl for the outer alternative number
/// matched for an internal parse tree node.
///
/// I'm only putting into Java runtime as I'm certain I'm the only one that
/// will really every use this.
class ANTLR4CPP_PUBLIC RuleContextWithAltNum : public ParserRuleContext {
public:
int altNum = 0;
RuleContextWithAltNum();
RuleContextWithAltNum(Ref<ParserRuleContext> parent, int invokingStateNumber);
virtual int getAltNumber() const override;
virtual void setAltNumber(int altNum) override;
};
} // namespace runtime
} // namespace v4
} // namespace antlr
} // namespace org

View File

@ -0,0 +1,79 @@
/*
* [The "BSD license"]
* Copyright (c) 2016 Mike Lischke
* Copyright (c) 2014 Terence Parr
* Copyright (c) 2014 Sam Harwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "RuntimeMetaData.h"
using namespace org::antlr::v4::runtime;
const std::string RuntimeMetaData::VERSION = "4.5.3";
std::string RuntimeMetaData::getRuntimeVersion() {
return VERSION;
}
void RuntimeMetaData::checkVersion(const std::string &generatingToolVersion, const std::string &compileTimeVersion) {
std::string runtimeVersion = VERSION;
bool runtimeConflictsWithGeneratingTool = false;
bool runtimeConflictsWithCompileTimeTool = false;
if (generatingToolVersion != "") {
runtimeConflictsWithGeneratingTool = runtimeVersion != generatingToolVersion
&& getMajorMinorVersion(runtimeVersion) != getMajorMinorVersion(generatingToolVersion);
}
runtimeConflictsWithCompileTimeTool = runtimeVersion != compileTimeVersion
&& getMajorMinorVersion(runtimeVersion) != getMajorMinorVersion(compileTimeVersion);
if (runtimeConflictsWithGeneratingTool) {
std::cerr << "ANTLR Tool version " << generatingToolVersion << " used for code generation does not match "
"the current runtime version " << runtimeVersion << std::endl;
}
if (runtimeConflictsWithCompileTimeTool) {
std::cerr << "ANTLR Runtime version " << compileTimeVersion << " used for parser compilation does not match "
"the current runtime version " << runtimeVersion << std::endl;
}
}
std::string RuntimeMetaData::getMajorMinorVersion(const std::string &version) {
size_t firstDot = version.find('.');
size_t secondDot = firstDot != std::string::npos ? version.find('.', firstDot + 1) : std::string::npos;
size_t firstDash = version.find('-');
size_t referenceLength = version.size();
if (secondDot != std::string::npos) {
referenceLength = std::min(referenceLength, secondDot);
}
if (firstDash != std::string::npos) {
referenceLength = std::min(referenceLength, firstDash);
}
return version.substr(0, referenceLength);
}

View File

@ -0,0 +1,185 @@
/*
* [The "BSD license"]
* Copyright (c) 2016 Mike Lischke
* Copyright (c) 2014 Terence Parr
* Copyright (c) 2014 Sam Harwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
namespace org {
namespace antlr {
namespace v4 {
namespace runtime {
/// <summary>
/// This class provides access to the current version of the ANTLR 4 runtime
/// library as compile-time and runtime constants, along with methods for
/// checking for matching version numbers and notifying listeners in the case
/// where a version mismatch is detected.
///
/// <para>
/// The runtime version information is provided by <seealso cref="#VERSION"/> and
/// <seealso cref="#getRuntimeVersion()"/>. Detailed information about these values is
/// provided in the documentation for each member.</para>
///
/// <para>
/// The runtime version check is implemented by <seealso cref="#checkVersion"/>. Detailed
/// information about incorporating this call into user code, as well as its use
/// in generated code, is provided in the documentation for the method.</para>
///
/// <para>
/// Version strings x.y and x.y.z are considered "compatible" and no error
/// would be generated. Likewise, version strings x.y-SNAPSHOT and x.y.z are
/// considered "compatible" because the major and minor components x.y
/// are the same in each.</para>
///
/// <para>
/// To trap any error messages issued by this code, use System.setErr()
/// in your main() startup code.
/// </para>
///
/// @since 4.3
/// </summary>
class ANTLR4CPP_PUBLIC RuntimeMetaData {
public:
/// A compile-time constant containing the current version of the ANTLR 4
/// runtime library.
///
/// <para>
/// This compile-time constant value allows generated parsers and other
/// libraries to include a literal reference to the version of the ANTLR 4
/// runtime library the code was compiled against. At each release, we
/// change this value.</para>
///
/// <para>Version numbers are assumed to have the form
///
/// <em>major</em>.<em>minor</em>.<em>patch</em>.<em>revision</em>-<em>suffix</em>,
///
/// with the individual components defined as follows.</para>
///
/// <ul>
/// <li><em>major</em> is a required non-negative integer, and is equal to
/// {@code 4} for ANTLR 4.</li>
/// <li><em>minor</em> is a required non-negative integer.</li>
/// <li><em>patch</em> is an optional non-negative integer. When
/// <em>patch</em> is omitted, the {@code .} (dot) appearing before it is
/// also omitted.</li>
/// <li><em>revision</em> is an optional non-negative integer, and may only
/// be included when <em>patch</em> is also included. When <em>revision</em>
/// is omitted, the {@code .} (dot) appearing before it is also omitted.</li>
/// <li><em>suffix</em> is an optional string. When <em>suffix</em> is
/// omitted, the {@code -} (hyphen-minus) appearing before it is also
/// omitted.</li>
/// </ul>
static const std::string VERSION;
/// <summary>
/// Gets the currently executing version of the ANTLR 4 runtime library.
///
/// <para>
/// This method provides runtime access to the <seealso cref="#VERSION"/> field, as
/// opposed to directly referencing the field as a compile-time constant.</para>
/// </summary>
/// <returns> The currently executing version of the ANTLR 4 library </returns>
static std::string getRuntimeVersion();
/// <summary>
/// This method provides the ability to detect mismatches between the version
/// of ANTLR 4 used to generate a parser, the version of the ANTLR runtime a
/// parser was compiled against, and the version of the ANTLR runtime which
/// is currently executing.
///
/// <para>
/// The version check is designed to detect the following two specific
/// scenarios.</para>
///
/// <ul>
/// <li>The ANTLR Tool version used for code generation does not match the
/// currently executing runtime version.</li>
/// <li>The ANTLR Runtime version referenced at the time a parser was
/// compiled does not match the currently executing runtime version.</li>
/// </ul>
///
/// <para>
/// Starting with ANTLR 4.3, the code generator emits a call to this method
/// using two constants in each generated lexer and parser: a hard-coded
/// constant indicating the version of the tool used to generate the parser
/// and a reference to the compile-time constant <seealso cref="#VERSION"/>. At
/// runtime, this method is called during the initialization of the generated
/// parser to detect mismatched versions, and notify the registered listeners
/// prior to creating instances of the parser.</para>
///
/// <para>
/// This method does not perform any detection or filtering of semantic
/// changes between tool and runtime versions. It simply checks for a
/// version match and emits an error to stderr if a difference
/// is detected.</para>
///
/// <para>
/// Note that some breaking changes between releases could result in other
/// types of runtime exceptions, such as a <seealso cref="LinkageError"/>, prior to
/// calling this method. In these cases, the underlying version mismatch will
/// not be reported here. This method is primarily intended to
/// notify users of potential semantic changes between releases that do not
/// result in binary compatibility problems which would be detected by the
/// class loader. As with semantic changes, changes that break binary
/// compatibility between releases are mentioned in the release notes
/// accompanying the affected release.</para>
///
/// <para>
/// <strong>Additional note for target developers:</strong> The version check
/// implemented by this class is designed to address specific compatibility
/// concerns that may arise during the execution of Java applications. Other
/// targets should consider the implementation of this method in the context
/// of that target's known execution environment, which may or may not
/// resemble the design provided for the Java target.</para>
/// </summary>
/// <param name="generatingToolVersion"> The version of the tool used to generate a parser.
/// This value may be null when called from user code that was not generated
/// by, and does not reference, the ANTLR 4 Tool itself. </param>
/// <param name="compileTimeVersion"> The version of the runtime the parser was
/// compiled against. This should always be passed using a direct reference
/// to <seealso cref="#VERSION"/>. </param>
static void checkVersion(const std::string &generatingToolVersion, const std::string &compileTimeVersion);
/// <summary>
/// Gets the major and minor version numbers from a version string. For
/// details about the syntax of the input {@code version}.
/// E.g., from x.y.z return x.y.
/// </summary>
/// <param name="version"> The complete version string. </param>
/// <returns> A string of the form <em>major</em>.<em>minor</em> containing
/// only the major and minor components of the version string. </returns>
static std::string getMajorMinorVersion(const std::string &version);
};
} // namespace runtime
} // namespace v4
} // namespace antlr
} // namespace org

View File

@ -29,28 +29,28 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "Strings.h"
#include "StringUtils.h"
#include "Token.h"
using namespace org::antlr::v4::runtime;
std::wstring Token::toString() {
std::wstringstream ss;
std::string Token::toString() {
std::stringstream ss;
std::wstring txt = getText();
std::string txt = getText();
if (!txt.empty()) {
antlrcpp::replaceAll(txt, L"\n", L"\\n");
antlrcpp::replaceAll(txt, L"\r", L"\\r");
antlrcpp::replaceAll(txt, L"\t", L"\\t");
antlrcpp::replaceAll(txt, "\n", "\\n");
antlrcpp::replaceAll(txt, "\r", "\\r");
antlrcpp::replaceAll(txt, "\t", "\\t");
} else {
txt = L"<no text>";
txt = "<no text>";
}
ss << L"{Token: " << txt << L", channel: " << getChannel() << L", type: " << getType() << L", start: " << getStartIndex() <<
L", stop: " << getStopIndex() << L", index: " << getTokenIndex() << L", line: " << getLine() << L", offset: " <<
getCharPositionInLine() << L"}";
ss << "{Token: " << txt << ", channel: " << getChannel() << ", type: " << getType() << ", start: " << getStartIndex() <<
", stop: " << getStopIndex() << ", index: " << getTokenIndex() << ", line: " << getLine() << ", offset: " <<
getCharPositionInLine() << "}";
return ss.str();
}

View File

@ -84,7 +84,7 @@ namespace runtime {
/// <summary>
/// Get the text of the token.
/// </summary>
virtual std::wstring getText() = 0;
virtual std::string getText() = 0;
/// <summary>
/// Get the token type of the token </summary>
@ -141,7 +141,7 @@ namespace runtime {
/// </summary>
virtual CharStream *getInputStream() = 0;
virtual std::wstring toString();
virtual std::string toString();
};
} // namespace runtime

View File

@ -47,11 +47,11 @@ namespace runtime {
/// This is the method used to create tokens in the lexer and in the
/// error handling strategy. If text!=null, than the start and stop positions
/// are wiped to -1 in the text override is set in the CommonToken.
virtual Ref<Symbol> create(std::pair<TokenSource *, CharStream *> source, int type, const std::wstring &text,
virtual Ref<Symbol> create(std::pair<TokenSource *, CharStream *> source, int type, const std::string &text,
int channel, int start, int stop, int line, int charPositionInLine) = 0;
/// Generically useful
virtual Ref<Symbol> create(int type, const std::wstring &text) = 0;
virtual Ref<Symbol> create(int type, const std::string &text) = 0;
};
} // namespace runtime

View File

@ -97,7 +97,7 @@ namespace runtime {
/// stream.
/// </returns>
/// <exception cref="NullPointerException"> if {@code interval} is {@code null} </exception>
virtual std::wstring getText(const misc::Interval &interval) = 0;
virtual std::string getText(const misc::Interval &interval) = 0;
/// <summary>
/// Return the text of all tokens in the stream. This method behaves like the
@ -111,7 +111,7 @@ namespace runtime {
/// </pre>
/// </summary>
/// <returns> The text of all tokens in the stream. </returns>
virtual std::wstring getText() = 0;
virtual std::string getText() = 0;
/// <summary>
/// Return the text of all tokens in the source interval of the specified
@ -130,7 +130,7 @@ namespace runtime {
/// <param name="ctx"> The context providing the source interval of tokens to get
/// text for. </param>
/// <returns> The text of all tokens within the source interval of {@code ctx}. </returns>
virtual std::wstring getText(RuleContext *ctx) = 0;
virtual std::string getText(RuleContext *ctx) = 0;
/// <summary>
/// Return the text of all tokens in this stream between {@code start} and
@ -160,7 +160,7 @@ namespace runtime {
/// </returns>
/// <exception cref="UnsupportedOperationException"> if this stream does not support
/// this method for the specified tokens </exception>
virtual std::wstring getText(Ref<Token> start, Ref<Token> stop) = 0;
virtual std::string getText(Ref<Token> start, Ref<Token> stop) = 0;
};
} // namespace runtime

View File

@ -33,7 +33,6 @@
#include "Interval.h"
#include "Token.h"
#include "TokenStream.h"
#include "Strings.h"
#include "CPPUtils.h"
#include "TokenStreamRewriter.h"
@ -49,22 +48,22 @@ TokenStreamRewriter::RewriteOperation::RewriteOperation(TokenStreamRewriter *out
this->index = index;
}
TokenStreamRewriter::RewriteOperation::RewriteOperation(TokenStreamRewriter *outerInstance, size_t index, const std::wstring& text) : outerInstance(outerInstance) {
TokenStreamRewriter::RewriteOperation::RewriteOperation(TokenStreamRewriter *outerInstance, size_t index, const std::string& text) : outerInstance(outerInstance) {
InitializeInstanceFields();
this->index = index;
this->text = text;
}
size_t TokenStreamRewriter::RewriteOperation::execute(std::wstring * /*buf*/) {
size_t TokenStreamRewriter::RewriteOperation::execute(std::string * /*buf*/) {
return index;
}
std::wstring TokenStreamRewriter::RewriteOperation::toString() {
std::wstring opName = L"TokenStreamRewriter";
size_t index = opName.find(L'$');
std::string TokenStreamRewriter::RewriteOperation::toString() {
std::string opName = "TokenStreamRewriter";
size_t index = opName.find('$');
opName = opName.substr(index + 1, opName.length() - (index + 1));
return L"<" + opName + L"@" + outerInstance->tokens->get(index)->getText() + L":\"" + text + L"\">";
return "<" + opName + "@" + outerInstance->tokens->get(index)->getText() + ":\"" + text + "\">";
}
void TokenStreamRewriter::RewriteOperation::InitializeInstanceFields() {
@ -72,11 +71,11 @@ void TokenStreamRewriter::RewriteOperation::InitializeInstanceFields() {
index = 0;
}
TokenStreamRewriter::InsertBeforeOp::InsertBeforeOp(TokenStreamRewriter *outerInstance, size_t index, const std::wstring& text)
TokenStreamRewriter::InsertBeforeOp::InsertBeforeOp(TokenStreamRewriter *outerInstance, size_t index, const std::string& text)
: RewriteOperation(outerInstance, index, text), outerInstance(outerInstance) {
}
size_t TokenStreamRewriter::InsertBeforeOp::execute(std::wstring *buf) {
size_t TokenStreamRewriter::InsertBeforeOp::execute(std::string *buf) {
buf->append(text);
if (outerInstance->tokens->get(index)->getType() != Token::EOF) {
buf->append(outerInstance->tokens->get(index)->getText());
@ -84,22 +83,22 @@ size_t TokenStreamRewriter::InsertBeforeOp::execute(std::wstring *buf) {
return index + 1;
}
TokenStreamRewriter::ReplaceOp::ReplaceOp(TokenStreamRewriter *outerInstance, size_t from, size_t to, const std::wstring& text) : RewriteOperation(outerInstance, from, text), outerInstance(outerInstance) {
TokenStreamRewriter::ReplaceOp::ReplaceOp(TokenStreamRewriter *outerInstance, size_t from, size_t to, const std::string& text) : RewriteOperation(outerInstance, from, text), outerInstance(outerInstance) {
InitializeInstanceFields();
lastIndex = to;
}
size_t TokenStreamRewriter::ReplaceOp::execute(std::wstring *buf) {
size_t TokenStreamRewriter::ReplaceOp::execute(std::string *buf) {
buf->append(text);
return lastIndex + 1;
}
std::wstring TokenStreamRewriter::ReplaceOp::toString() {
std::string TokenStreamRewriter::ReplaceOp::toString() {
if (text.empty()) {
return L"<DeleteOp@" + outerInstance->tokens->get(index)->getText() + L".." + outerInstance->tokens->get(lastIndex)->getText() + L">";
return "<DeleteOp@" + outerInstance->tokens->get(index)->getText() + ".." + outerInstance->tokens->get(lastIndex)->getText() + ">";
}
return L"<ReplaceOp@" + outerInstance->tokens->get(index)->getText() + L".." + outerInstance->tokens->get(lastIndex)->getText() + L":\"" + text + L"\">";
return "<ReplaceOp@" + outerInstance->tokens->get(index)->getText() + ".." + outerInstance->tokens->get(lastIndex)->getText() + ":\"" + text + "\">";
}
void TokenStreamRewriter::ReplaceOp::InitializeInstanceFields() {
@ -108,7 +107,7 @@ void TokenStreamRewriter::ReplaceOp::InitializeInstanceFields() {
//------------------ TokenStreamRewriter -------------------------------------------------------------------------------
const std::wstring TokenStreamRewriter::DEFAULT_PROGRAM_NAME = L"default";
const std::string TokenStreamRewriter::DEFAULT_PROGRAM_NAME = "default";
TokenStreamRewriter::TokenStreamRewriter(TokenStream *tokens) : tokens(tokens) {
_programs.insert({ DEFAULT_PROGRAM_NAME, std::vector<RewriteOperation*>(PROGRAM_INIT_SIZE) });
@ -130,7 +129,7 @@ void TokenStreamRewriter::rollback(int instructionIndex) {
rollback(DEFAULT_PROGRAM_NAME, instructionIndex);
}
void TokenStreamRewriter::rollback(const std::wstring &programName, int instructionIndex) {
void TokenStreamRewriter::rollback(const std::string &programName, int instructionIndex) {
std::vector<RewriteOperation*> is = _programs[programName];
if (is.size() > 0) {
_programs.insert({ programName, std::vector<RewriteOperation*>(is.begin() + MIN_TOKEN_INDEX, is.begin() + instructionIndex) });
@ -141,63 +140,63 @@ void TokenStreamRewriter::deleteProgram() {
deleteProgram(DEFAULT_PROGRAM_NAME);
}
void TokenStreamRewriter::deleteProgram(const std::wstring &programName) {
void TokenStreamRewriter::deleteProgram(const std::string &programName) {
rollback(programName, MIN_TOKEN_INDEX);
}
void TokenStreamRewriter::insertAfter(Token *t, const std::wstring& text) {
void TokenStreamRewriter::insertAfter(Token *t, const std::string& text) {
insertAfter(DEFAULT_PROGRAM_NAME, t, text);
}
void TokenStreamRewriter::insertAfter(size_t index, const std::wstring& text) {
void TokenStreamRewriter::insertAfter(size_t index, const std::string& text) {
insertAfter(DEFAULT_PROGRAM_NAME, index, text);
}
void TokenStreamRewriter::insertAfter(const std::wstring &programName, Token *t, const std::wstring& text) {
void TokenStreamRewriter::insertAfter(const std::string &programName, Token *t, const std::string& text) {
insertAfter(programName, (size_t)t->getTokenIndex(), text);
}
void TokenStreamRewriter::insertAfter(const std::wstring &programName, size_t index, const std::wstring& text) {
void TokenStreamRewriter::insertAfter(const std::string &programName, size_t index, const std::string& text) {
// to insert after, just insert before next index (even if past end)
insertBefore(programName, index + 1, text);
}
void TokenStreamRewriter::insertBefore(Token *t, const std::wstring& text) {
void TokenStreamRewriter::insertBefore(Token *t, const std::string& text) {
insertBefore(DEFAULT_PROGRAM_NAME, t, text);
}
void TokenStreamRewriter::insertBefore(size_t index, const std::wstring& text) {
void TokenStreamRewriter::insertBefore(size_t index, const std::string& text) {
insertBefore(DEFAULT_PROGRAM_NAME, index, text);
}
void TokenStreamRewriter::insertBefore(const std::wstring &programName, Token *t, const std::wstring& text) {
void TokenStreamRewriter::insertBefore(const std::string &programName, Token *t, const std::string& text) {
insertBefore(programName, (size_t)t->getTokenIndex(), text);
}
void TokenStreamRewriter::insertBefore(const std::wstring &programName, size_t index, const std::wstring& text) {
void TokenStreamRewriter::insertBefore(const std::string &programName, size_t index, const std::string& text) {
RewriteOperation *op = new InsertBeforeOp(this, index, text); /* mem-check: deleted in d-tor */
std::vector<RewriteOperation*> &rewrites = getProgram(programName);
op->instructionIndex = (int)rewrites.size();
rewrites.push_back(op);
}
void TokenStreamRewriter::replace(size_t index, const std::wstring& text) {
void TokenStreamRewriter::replace(size_t index, const std::string& text) {
replace(DEFAULT_PROGRAM_NAME, index, index, text);
}
void TokenStreamRewriter::replace(size_t from, size_t to, const std::wstring& text) {
void TokenStreamRewriter::replace(size_t from, size_t to, const std::string& text) {
replace(DEFAULT_PROGRAM_NAME, from, to, text);
}
void TokenStreamRewriter::replace(Token *indexT, const std::wstring& text) {
void TokenStreamRewriter::replace(Token *indexT, const std::string& text) {
replace(DEFAULT_PROGRAM_NAME, indexT, indexT, text);
}
void TokenStreamRewriter::replace(Token *from, Token *to, const std::wstring& text) {
void TokenStreamRewriter::replace(Token *from, Token *to, const std::string& text) {
replace(DEFAULT_PROGRAM_NAME, from, to, text);
}
void TokenStreamRewriter::replace(const std::wstring &programName, size_t from, size_t to, const std::wstring& text) {
void TokenStreamRewriter::replace(const std::string &programName, size_t from, size_t to, const std::string& text) {
if (from > to || to >= tokens->size()) {
throw IllegalArgumentException("replace: range invalid: " + std::to_string(from) + ".." + std::to_string(to) +
"(size = " + std::to_string(tokens->size()) + ")");
@ -208,7 +207,7 @@ void TokenStreamRewriter::replace(const std::wstring &programName, size_t from,
rewrites.push_back(op);
}
void TokenStreamRewriter::replace(const std::wstring &programName, Token *from, Token *to, const std::wstring& text) {
void TokenStreamRewriter::replace(const std::string &programName, Token *from, Token *to, const std::string& text) {
replace(programName, (size_t)from->getTokenIndex(), (size_t)to->getTokenIndex(), text);
}
@ -228,11 +227,11 @@ void TokenStreamRewriter::Delete(Token *from, Token *to) {
Delete(DEFAULT_PROGRAM_NAME, from, to);
}
void TokenStreamRewriter::Delete(const std::wstring &programName, size_t from, size_t to) {
void TokenStreamRewriter::Delete(const std::string &programName, size_t from, size_t to) {
replace(programName, from, to, nullptr);
}
void TokenStreamRewriter::Delete(const std::wstring &programName, Token *from, Token *to) {
void TokenStreamRewriter::Delete(const std::string &programName, Token *from, Token *to) {
replace(programName, from, to, nullptr);
}
@ -240,18 +239,18 @@ int TokenStreamRewriter::getLastRewriteTokenIndex() {
return getLastRewriteTokenIndex(DEFAULT_PROGRAM_NAME);
}
int TokenStreamRewriter::getLastRewriteTokenIndex(const std::wstring &programName) {
int TokenStreamRewriter::getLastRewriteTokenIndex(const std::string &programName) {
if (_lastRewriteTokenIndexes.find(programName) == _lastRewriteTokenIndexes.end()) {
return -1;
}
return _lastRewriteTokenIndexes[programName];
}
void TokenStreamRewriter::setLastRewriteTokenIndex(const std::wstring &programName, int i) {
void TokenStreamRewriter::setLastRewriteTokenIndex(const std::string &programName, int i) {
_lastRewriteTokenIndexes.insert({ programName, i });
}
std::vector<TokenStreamRewriter::RewriteOperation*>& TokenStreamRewriter::getProgram(const std::wstring &name) {
std::vector<TokenStreamRewriter::RewriteOperation*>& TokenStreamRewriter::getProgram(const std::string &name) {
std::vector<TokenStreamRewriter::RewriteOperation*> &is = _programs[name];
if (is.empty()) {
is = initializeProgram(name);
@ -259,25 +258,25 @@ std::vector<TokenStreamRewriter::RewriteOperation*>& TokenStreamRewriter::getPro
return is;
}
std::vector<TokenStreamRewriter::RewriteOperation*> TokenStreamRewriter::initializeProgram(const std::wstring &name) {
std::vector<TokenStreamRewriter::RewriteOperation*> TokenStreamRewriter::initializeProgram(const std::string &name) {
std::vector<TokenStreamRewriter::RewriteOperation*> is(PROGRAM_INIT_SIZE);
_programs.insert({ name, is });
return is;
}
std::wstring TokenStreamRewriter::getText() {
std::string TokenStreamRewriter::getText() {
return getText(DEFAULT_PROGRAM_NAME, Interval(0, (int)tokens->size() - 1));
}
std::wstring TokenStreamRewriter::getText(std::wstring programName) {
std::string TokenStreamRewriter::getText(std::string programName) {
return getText(programName, Interval(0, (int)tokens->size() - 1));
}
std::wstring TokenStreamRewriter::getText(const Interval &interval) {
std::string TokenStreamRewriter::getText(const Interval &interval) {
return getText(DEFAULT_PROGRAM_NAME, interval);
}
std::wstring TokenStreamRewriter::getText(const std::wstring &programName, const Interval &interval) {
std::string TokenStreamRewriter::getText(const std::string &programName, const Interval &interval) {
std::vector<TokenStreamRewriter::RewriteOperation*> rewrites = _programs[programName];
int start = interval.a;
int stop = interval.b;
@ -293,7 +292,7 @@ std::wstring TokenStreamRewriter::getText(const std::wstring &programName, const
if (rewrites.empty() || rewrites.empty()) {
return tokens->getText(interval); // no instructions to execute
}
std::wstring buf;
std::string buf;
// First, optimize instruction stream
std::unordered_map<size_t, TokenStreamRewriter::RewriteOperation*> indexToOp = reduceToSingleOperationPerIndex(rewrites);
@ -352,7 +351,7 @@ std::unordered_map<size_t, TokenStreamRewriter::RewriteOperation*> TokenStreamRe
// E.g., insert before 2, delete 2..2; update replace
// text to include insert before, kill insert
rewrites[(size_t)iop->instructionIndex] = nullptr;
rop->text = iop->text + (!rop->text.empty() ? rop->text : L"");
rop->text = iop->text + (!rop->text.empty() ? rop->text : "");
}
else if (iop->index > rop->index && iop->index <= rop->lastIndex) {
// delete insert as it's a no-op.
@ -378,11 +377,11 @@ std::unordered_map<size_t, TokenStreamRewriter::RewriteOperation*> TokenStreamRe
rewrites[(size_t)prevRop->instructionIndex] = nullptr; // kill first delete
rop->index = std::min(prevRop->index, rop->index);
rop->lastIndex = std::max(prevRop->lastIndex, rop->lastIndex);
std::wcout << L"new rop " << rop << std::endl;
std::cout << "new rop " << rop << std::endl;
}
else if (!disjoint && !same) {
throw IllegalArgumentException("replace op boundaries of " + antlrcpp::ws2s(rop->toString()) +
" overlap with previous " + antlrcpp::ws2s(prevRop->toString()));
throw IllegalArgumentException("replace op boundaries of " + rop->toString() +
" overlap with previous " + prevRop->toString());
}
}
}
@ -419,7 +418,7 @@ std::unordered_map<size_t, TokenStreamRewriter::RewriteOperation*> TokenStreamRe
continue;
}
if (iop->index >= rop->index && iop->index <= rop->lastIndex) {
throw IllegalArgumentException("insert op " + antlrcpp::ws2s(iop->toString()) + " within boundaries of previous " + antlrcpp::ws2s(rop->toString()));
throw IllegalArgumentException("insert op " + iop->toString() + " within boundaries of previous " + rop->toString());
}
}
}
@ -438,14 +437,14 @@ std::unordered_map<size_t, TokenStreamRewriter::RewriteOperation*> TokenStreamRe
return m;
}
std::wstring TokenStreamRewriter::catOpText(std::wstring *a, std::wstring *b) {
std::wstring x = L"";
std::wstring y = L"";
std::string TokenStreamRewriter::catOpText(std::string *a, std::string *b) {
std::string x = "";
std::string y = "";
if (a != nullptr) {
x = std::wstring(*a);
x = std::string(*a);
}
if (b != nullptr) {
y = std::wstring(*b);
y = std::string(*b);
}
return x + y;
}

View File

@ -114,7 +114,7 @@ namespace runtime {
*/
class ANTLR4CPP_PUBLIC TokenStreamRewriter {
public:
static const std::wstring DEFAULT_PROGRAM_NAME;
static const std::string DEFAULT_PROGRAM_NAME;
static const int PROGRAM_INIT_SIZE = 100;
static const int MIN_TOKEN_INDEX = 0;
@ -130,47 +130,47 @@ namespace runtime {
/// the indicated instruction (via instructionIndex) is no
/// longer in the stream. UNTESTED!
/// </summary>
virtual void rollback(const std::wstring &programName, int instructionIndex);
virtual void rollback(const std::string &programName, int instructionIndex);
virtual void deleteProgram();
/// <summary>
/// Reset the program so that no instructions exist </summary>
virtual void deleteProgram(const std::wstring &programName);
virtual void insertAfter(Token *t, const std::wstring& text);
virtual void insertAfter(size_t index, const std::wstring& text);
virtual void insertAfter(const std::wstring &programName, Token *t, const std::wstring& text);
virtual void insertAfter(const std::wstring &programName, size_t index, const std::wstring& text);
virtual void deleteProgram(const std::string &programName);
virtual void insertAfter(Token *t, const std::string& text);
virtual void insertAfter(size_t index, const std::string& text);
virtual void insertAfter(const std::string &programName, Token *t, const std::string& text);
virtual void insertAfter(const std::string &programName, size_t index, const std::string& text);
virtual void insertBefore(Token *t, const std::wstring& text);
virtual void insertBefore(size_t index, const std::wstring& text);
virtual void insertBefore(const std::wstring &programName, Token *t, const std::wstring& text);
virtual void insertBefore(const std::wstring &programName, size_t index, const std::wstring& text);
virtual void insertBefore(Token *t, const std::string& text);
virtual void insertBefore(size_t index, const std::string& text);
virtual void insertBefore(const std::string &programName, Token *t, const std::string& text);
virtual void insertBefore(const std::string &programName, size_t index, const std::string& text);
virtual void replace(size_t index, const std::wstring& text);
virtual void replace(size_t from, size_t to, const std::wstring& text);
virtual void replace(Token *indexT, const std::wstring& text);
virtual void replace(Token *from, Token *to, const std::wstring& text);
virtual void replace(const std::wstring &programName, size_t from, size_t to, const std::wstring& text);
virtual void replace(const std::wstring &programName, Token *from, Token *to, const std::wstring& text);
virtual void replace(size_t index, const std::string& text);
virtual void replace(size_t from, size_t to, const std::string& text);
virtual void replace(Token *indexT, const std::string& text);
virtual void replace(Token *from, Token *to, const std::string& text);
virtual void replace(const std::string &programName, size_t from, size_t to, const std::string& text);
virtual void replace(const std::string &programName, Token *from, Token *to, const std::string& text);
virtual void Delete(size_t index);
virtual void Delete(size_t from, size_t to);
virtual void Delete(Token *indexT);
virtual void Delete(Token *from, Token *to);
virtual void Delete(const std::wstring &programName, size_t from, size_t to);
virtual void Delete(const std::wstring &programName, Token *from, Token *to);
virtual void Delete(const std::string &programName, size_t from, size_t to);
virtual void Delete(const std::string &programName, Token *from, Token *to);
virtual int getLastRewriteTokenIndex();
/// Return the text from the original tokens altered per the
/// instructions given to this rewriter.
virtual std::wstring getText();
virtual std::string getText();
/** Return the text from the original tokens altered per the
* instructions given to this rewriter in programName.
*/
std::wstring getText(std::wstring programName);
std::string getText(std::string programName);
/// <summary>
/// Return the text associated with the tokens in the interval from the
@ -182,9 +182,9 @@ namespace runtime {
/// insertBefore on the first token, you would get that insertion.
/// The same is true if you do an insertAfter the stop token.
/// </summary>
virtual std::wstring getText(const misc::Interval &interval);
virtual std::string getText(const misc::Interval &interval);
virtual std::wstring getText(const std::wstring &programName, const misc::Interval &interval);
virtual std::string getText(const std::string &programName, const misc::Interval &interval);
protected:
class RewriteOperation {
@ -198,20 +198,20 @@ namespace runtime {
/// <summary>
/// Token buffer index. </summary>
size_t index;
std::wstring text;
std::string text;
RewriteOperation(TokenStreamRewriter *outerInstance, size_t index);
RewriteOperation(TokenStreamRewriter *outerInstance, size_t index, const std::wstring& text);
RewriteOperation(TokenStreamRewriter *outerInstance, size_t index, const std::string& text);
/// <summary>
/// Execute the rewrite operation by possibly adding to the buffer.
/// Return the index of the next token to operate on.
/// </summary>
int instructionIndex;
virtual size_t execute(std::wstring *buf);
virtual size_t execute(std::string *buf);
virtual std::wstring toString();
virtual std::string toString();
private:
void InitializeInstanceFields();
@ -222,9 +222,9 @@ namespace runtime {
TokenStreamRewriter *const outerInstance;
public:
InsertBeforeOp(TokenStreamRewriter *outerInstance, size_t index, const std::wstring& text);
InsertBeforeOp(TokenStreamRewriter *outerInstance, size_t index, const std::string& text);
virtual size_t execute(std::wstring *buf) override;
virtual size_t execute(std::string *buf) override;
};
class ReplaceOp : public RewriteOperation {
@ -234,9 +234,9 @@ namespace runtime {
public:
size_t lastIndex;
ReplaceOp(TokenStreamRewriter *outerInstance, size_t from, size_t to, const std::wstring& text);
virtual size_t execute(std::wstring *buf) override;
virtual std::wstring toString() override;
ReplaceOp(TokenStreamRewriter *outerInstance, size_t from, size_t to, const std::string& text);
virtual size_t execute(std::string *buf) override;
virtual std::string toString() override;
private:
void InitializeInstanceFields();
@ -248,14 +248,14 @@ namespace runtime {
/// You may have multiple, named streams of rewrite operations.
/// I'm calling these things "programs."
/// Maps String (name) -> rewrite (List)
std::map<std::wstring, std::vector<RewriteOperation*>> _programs;
std::map<std::string, std::vector<RewriteOperation*>> _programs;
/// <summary>
/// Map String (program name) -> Integer index </summary>
std::map<std::wstring, int> _lastRewriteTokenIndexes;
virtual int getLastRewriteTokenIndex(const std::wstring &programName);
virtual void setLastRewriteTokenIndex(const std::wstring &programName, int i);
virtual std::vector<RewriteOperation*>& getProgram(const std::wstring &name);
std::map<std::string, int> _lastRewriteTokenIndexes;
virtual int getLastRewriteTokenIndex(const std::string &programName);
virtual void setLastRewriteTokenIndex(const std::string &programName, int i);
virtual std::vector<RewriteOperation*>& getProgram(const std::string &name);
/// <summary>
/// We need to combine operations and report invalid operations (like
@ -309,7 +309,7 @@ namespace runtime {
/// </summary>
virtual std::unordered_map<size_t, RewriteOperation*> reduceToSingleOperationPerIndex(std::vector<RewriteOperation*> rewrites);
virtual std::wstring catOpText(std::wstring *a, std::wstring *b);
virtual std::string catOpText(std::string *a, std::string *b);
/// <summary>
/// Get all operations before an index of a particular kind </summary>
@ -329,7 +329,7 @@ namespace runtime {
}
private:
std::vector<RewriteOperation*> initializeProgram(const std::wstring &name);
std::vector<RewriteOperation*> initializeProgram(const std::string &name);
};

View File

@ -31,17 +31,17 @@
#include "Interval.h"
#include "Exceptions.h"
#include "StringUtils.h"
#include "UnbufferedCharStream.h"
using namespace antlrcpp;
using namespace org::antlr::v4::runtime;
UnbufferedCharStream::UnbufferedCharStream(std::wistream &input, size_t bufferSize) : input(input) {
UnbufferedCharStream::UnbufferedCharStream(std::wistream &input) : _input(input) {
InitializeInstanceFields();
// The vector's size is what used to be n in Java code, while the vector's capacity is the allocated
// buffer length in Java.
data.reserve(bufferSize);
// The vector's size is what used to be n in Java code.
fill(1); // prime
}
@ -51,25 +51,25 @@ void UnbufferedCharStream::consume() {
}
// buf always has at least data[p==0] in this method due to ctor
lastChar = data[p]; // track last char for LA(-1)
_lastChar = _data[_p]; // track last char for LA(-1)
if (p == data.size() - 1 && numMarkers == 0) {
size_t capacity = data.capacity();
data.clear();
data.reserve(capacity);
if (_p == _data.size() - 1 && _numMarkers == 0) {
size_t capacity = _data.capacity();
_data.clear();
_data.reserve(capacity);
p = 0;
lastCharBufferStart = lastChar;
_p = 0;
_lastCharBufferStart = _lastChar;
} else {
p++;
_p++;
}
currentCharIndex++;
_currentCharIndex++;
sync(1);
}
void UnbufferedCharStream::sync(size_t want) {
size_t need = (p + want - 1) - data.size() + 1; // how many more elements we need?
size_t need = (_p + want - 1) - _data.size() + 1; // how many more elements we need?
if (need > 0) {
fill(need);
}
@ -77,12 +77,12 @@ void UnbufferedCharStream::sync(size_t want) {
size_t UnbufferedCharStream::fill(size_t n) {
for (size_t i = 0; i < n; i++) {
if (data.size() > 0 && data.back() == static_cast<wchar_t>(EOF)) {
if (_data.size() > 0 && _data.back() == static_cast<char32_t>(EOF)) { // TODO: we cannot encode -1 as this is not a valid code point
return i;
}
try {
size_t c = nextChar();
char32_t c = nextChar();
add(c);
} catch (IOException &ioe) {
#if defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023026
@ -97,29 +97,31 @@ size_t UnbufferedCharStream::fill(size_t n) {
return n;
}
size_t UnbufferedCharStream::nextChar() {
return (size_t)input.get();
char32_t UnbufferedCharStream::nextChar() {
wchar_t result;
_input >> result;
return result;
}
void UnbufferedCharStream::add(size_t c) {
data.push_back(static_cast<wchar_t>(c));
void UnbufferedCharStream::add(char32_t c) {
_data += c;
}
ssize_t UnbufferedCharStream::LA(ssize_t i) {
if (i == -1) { // special case
return lastChar;
return _lastChar;
}
sync((size_t)i);
ssize_t index = (ssize_t)p + i - 1;
ssize_t index = (ssize_t)_p + i - 1;
if (index < 0) {
throw IndexOutOfBoundsException();
}
if ((size_t)index >= data.size()) {
if ((size_t)index >= _data.size()) {
return EOF;
}
ssize_t c = data[(size_t)index];
ssize_t c = _data[(size_t)index];
if (c == EOF) {
return EOF;
}
@ -127,59 +129,59 @@ ssize_t UnbufferedCharStream::LA(ssize_t i) {
}
ssize_t UnbufferedCharStream::mark() {
if (numMarkers == 0) {
lastCharBufferStart = lastChar;
if (_numMarkers == 0) {
_lastCharBufferStart = _lastChar;
}
ssize_t mark = -(ssize_t)numMarkers - 1;
numMarkers++;
ssize_t mark = -(ssize_t)_numMarkers - 1;
_numMarkers++;
return mark;
}
void UnbufferedCharStream::release(ssize_t marker) {
ssize_t expectedMark = -(ssize_t)numMarkers;
ssize_t expectedMark = -(ssize_t)_numMarkers;
if (marker != expectedMark) {
throw IllegalStateException("release() called with an invalid marker.");
}
numMarkers--;
if (numMarkers == 0 && p > 0) {
data.erase(0, p);
p = 0;
lastCharBufferStart = lastChar;
_numMarkers--;
if (_numMarkers == 0 && _p > 0) {
_data.erase(0, _p);
_p = 0;
_lastCharBufferStart = _lastChar;
}
}
size_t UnbufferedCharStream::index() {
return currentCharIndex;
return _currentCharIndex;
}
void UnbufferedCharStream::seek(size_t index) {
if (index == currentCharIndex) {
if (index == _currentCharIndex) {
return;
}
if (index > currentCharIndex) {
sync(index - currentCharIndex);
index = std::min(index, getBufferStartIndex() + data.size() - 1);
if (index > _currentCharIndex) {
sync(index - _currentCharIndex);
index = std::min(index, getBufferStartIndex() + _data.size() - 1);
}
// index == to bufferStartIndex should set p to 0
ssize_t i = (ssize_t)index - (ssize_t)getBufferStartIndex();
if (i < 0) {
throw IllegalArgumentException(std::string("cannot seek to negative index ") + std::to_string(index));
} else if (i >= (ssize_t)data.size()) {
throw UnsupportedOperationException(std::string("seek to index outside buffer: ") + std::to_string(index) +
std::string(" not in ") + std::to_string(getBufferStartIndex()) + ".." +
std::to_string(getBufferStartIndex() + data.size()));
} else if (i >= (ssize_t)_data.size()) {
throw UnsupportedOperationException("Seek to index outside buffer: " + std::to_string(index) +
" not in " + std::to_string(getBufferStartIndex()) + ".." +
std::to_string(getBufferStartIndex() + _data.size()));
}
p = (size_t)i;
currentCharIndex = index;
if (p == 0) {
lastChar = lastCharBufferStart;
_p = (size_t)i;
_currentCharIndex = index;
if (_p == 0) {
_lastChar = _lastCharBufferStart;
} else {
lastChar = data[p - 1];
_lastChar = _data[_p - 1];
}
}
@ -195,35 +197,35 @@ std::string UnbufferedCharStream::getSourceName() const {
return name;
}
std::wstring UnbufferedCharStream::getText(const misc::Interval &interval) {
std::string UnbufferedCharStream::getText(const misc::Interval &interval) {
if (interval.a < 0 || interval.b < interval.a - 1) {
throw IllegalArgumentException("invalid interval");
}
size_t bufferStartIndex = getBufferStartIndex();
if (!data.empty() && data.back() == WCHAR_MAX) {
if ((size_t)(interval.a + interval.length()) > bufferStartIndex + data.size()) {
if (!_data.empty() && _data.back() == 0xFFFF) {
if ((size_t)(interval.a + interval.length()) > bufferStartIndex + _data.size()) {
throw IllegalArgumentException("the interval extends past the end of the stream");
}
}
if ((size_t)interval.a < bufferStartIndex || (size_t)interval.b >= bufferStartIndex + data.size()) {
throw UnsupportedOperationException(std::string("interval ") + interval.toString() + " outside buffer: " +
std::to_string(bufferStartIndex) + ".." + std::to_string(bufferStartIndex + data.size() - 1));
if ((size_t)interval.a < bufferStartIndex || (size_t)interval.b >= bufferStartIndex + _data.size()) {
throw UnsupportedOperationException("interval " + interval.toString() + " outside buffer: " +
std::to_string(bufferStartIndex) + ".." + std::to_string(bufferStartIndex + _data.size() - 1));
}
// convert from absolute to local index
size_t i = (size_t)interval.a - bufferStartIndex;
return std::wstring(data, i, (size_t)interval.length());
return utfConverter.to_bytes(_data.substr(i, (size_t)interval.length()));
}
size_t UnbufferedCharStream::getBufferStartIndex() const {
return currentCharIndex - p;
return _currentCharIndex - _p;
}
void UnbufferedCharStream::InitializeInstanceFields() {
p = 0;
numMarkers = 0;
lastChar = -1;
lastCharBufferStart = 0;
currentCharIndex = 0;
_p = 0;
_numMarkers = 0;
_lastChar = -1;
_lastCharBufferStart = 0;
_currentCharIndex = 0;
}

View File

@ -38,92 +38,18 @@ namespace antlr {
namespace v4 {
namespace runtime {
/// <summary>
/// Do not buffer up the entire char stream. It does keep a small buffer
/// for efficiency and also buffers while a mark exists (set by the
/// lookahead prediction in parser). "Unbuffered" here refers to fact
/// that it doesn't buffer all data, not that's it's on demand loading of char.
/// </summary>
class ANTLR4CPP_PUBLIC UnbufferedCharStream : public CharStream {
protected:
/// <summary>
/// A moving window buffer of the data being scanned. While there's a marker,
/// we keep adding to buffer. Otherwise, <seealso cref="#consume consume()"/> resets so
/// we start filling at index 0 again.
/// </summary>
std::wstring data;
/// <summary>
/// 0..n-1 index into <seealso cref="#data data"/> of next character.
/// <p/>
/// The {@code LA(1)} character is {@code data[p]}. If {@code p == n}, we are
/// out of buffered characters.
/// </summary>
size_t p;
/// <summary>
/// Count up with <seealso cref="#mark mark()"/> and down with
/// <seealso cref="#release release()"/>. When we {@code release()} the last mark,
/// {@code numMarkers} reaches 0 and we reset the buffer. Copy
/// {@code data[p]..data[n-1]} to {@code data[0]..data[(n-1)-p]}.
/// </summary>
size_t numMarkers;
/// <summary>
/// This is the {@code LA(-1)} character for the current position.
/// </summary>
wchar_t lastChar;
/// <summary>
/// When {@code numMarkers > 0}, this is the {@code LA(-1)} character for the
/// first character in <seealso cref="#data data"/>. Otherwise, this is unspecified.
/// </summary>
wchar_t lastCharBufferStart;
/// <summary>
/// Absolute character index. It's the index of the character about to be
/// read via {@code LA(1)}. Goes from 0 to the number of characters in the
/// entire stream, although the stream size is unknown before the end is
/// reached.
/// </summary>
size_t currentCharIndex;
std::wistream &input;
/// <summary>
/// The name or source of this char stream. </summary>
public:
/// The name or source of this char stream.
std::string name;
UnbufferedCharStream(std::wistream &input, size_t bufferSize = 256);
UnbufferedCharStream(std::wistream &input);
virtual void consume() override;
/// <summary>
/// Make sure we have 'want' elements from current position <seealso cref="#p p"/>.
/// Last valid {@code p} index is {@code data.length-1}. {@code p+need-1} is
/// the char index 'need' elements ahead. If we need 1 element,
/// {@code (p+1-1)==p} must be less than {@code data.length}.
/// </summary>
protected:
virtual void sync(size_t want);
/// <summary>
/// Add {@code n} characters to the buffer. Returns the number of characters
/// actually added to the buffer. If the return value is less than {@code n},
/// then EOF was reached before {@code n} characters could be added.
/// </summary>
virtual size_t fill(size_t n);
/// <summary>
/// Override to provide different source of characters than
/// <seealso cref="#input input"/>.
/// </summary>
virtual size_t nextChar();
virtual void add(size_t c);
public:
virtual ssize_t LA(ssize_t i) override;
/// <summary>
@ -139,7 +65,6 @@ namespace runtime {
/// Decrement number of markers, resetting buffer if we hit 0. </summary>
/// <param name="marker"> </param>
virtual void release(ssize_t marker) override;
virtual size_t index() override;
/// <summary>
@ -149,9 +74,68 @@ namespace runtime {
virtual void seek(size_t index) override;
virtual size_t size() override;
virtual std::string getSourceName() const override;
virtual std::wstring getText(const misc::Interval &interval) override;
virtual std::string getText(const misc::Interval &interval) override;
protected:
/// A moving window buffer of the data being scanned. While there's a marker,
/// we keep adding to buffer. Otherwise, <seealso cref="#consume consume()"/> resets so
/// we start filling at index 0 again.
std::u32string _data; // UTF-32 encoded.
/// <summary>
/// 0..n-1 index into <seealso cref="#data data"/> of next character.
/// <p/>
/// The {@code LA(1)} character is {@code data[p]}. If {@code p == n}, we are
/// out of buffered characters.
/// </summary>
size_t _p;
/// <summary>
/// Count up with <seealso cref="#mark mark()"/> and down with
/// <seealso cref="#release release()"/>. When we {@code release()} the last mark,
/// {@code numMarkers} reaches 0 and we reset the buffer. Copy
/// {@code data[p]..data[n-1]} to {@code data[0]..data[(n-1)-p]}.
/// </summary>
size_t _numMarkers;
/// This is the {@code LA(-1)} character for the current position.
size_t _lastChar; // UTF-32
/// <summary>
/// When {@code numMarkers > 0}, this is the {@code LA(-1)} character for the
/// first character in <seealso cref="#data data"/>. Otherwise, this is unspecified.
/// </summary>
size_t _lastCharBufferStart; // UTF-32
/// <summary>
/// Absolute character index. It's the index of the character about to be
/// read via {@code LA(1)}. Goes from 0 to the number of characters in the
/// entire stream, although the stream size is unknown before the end is
/// reached.
/// </summary>
size_t _currentCharIndex;
std::wistream &_input;
/// <summary>
/// Make sure we have 'want' elements from current position <seealso cref="#p p"/>.
/// Last valid {@code p} index is {@code data.length-1}. {@code p+need-1} is
/// the char index 'need' elements ahead. If we need 1 element,
/// {@code (p+1-1)==p} must be less than {@code data.length}.
/// </summary>
virtual void sync(size_t want);
/// <summary>
/// Add {@code n} characters to the buffer. Returns the number of characters
/// actually added to the buffer. If the return value is less than {@code n},
/// then EOF was reached before {@code n} characters could be added.
/// </summary>
virtual size_t fill(size_t n);
/// Override to provide different source of characters than
/// <seealso cref="#input input"/>.
virtual char32_t nextChar();
virtual void add(char32_t c);
size_t getBufferStartIndex() const;
private:

View File

@ -94,17 +94,17 @@ TokenSource* UnbufferedTokenStream::getTokenSource() const
return _tokenSource;
}
std::wstring UnbufferedTokenStream::getText()
std::string UnbufferedTokenStream::getText()
{
return L"";
return "";
}
std::wstring UnbufferedTokenStream::getText(RuleContext* ctx)
std::string UnbufferedTokenStream::getText(RuleContext* ctx)
{
return getText(ctx->getSourceInterval());
}
std::wstring UnbufferedTokenStream::getText(Ref<Token> start, Ref<Token> stop)
std::string UnbufferedTokenStream::getText(Ref<Token> start, Ref<Token> stop)
{
return getText(misc::Interval(start->getTokenIndex(), stop->getTokenIndex()));
}
@ -257,7 +257,7 @@ std::string UnbufferedTokenStream::getSourceName() const
return _tokenSource->getSourceName();
}
std::wstring UnbufferedTokenStream::getText(const misc::Interval &interval)
std::string UnbufferedTokenStream::getText(const misc::Interval &interval)
{
size_t bufferStartIndex = getBufferStartIndex();
size_t bufferStopIndex = bufferStartIndex + _tokens.size() - 1;
@ -272,11 +272,11 @@ std::wstring UnbufferedTokenStream::getText(const misc::Interval &interval)
size_t a = start - bufferStartIndex;
size_t b = stop - bufferStartIndex;
std::wstringstream ss;
std::stringstream ss;
for (size_t i = a; i <= b; i++) {
Ref<Token> t = _tokens[i];
if (i > 0)
ss << L", ";
ss << ", ";
ss << t->getText();
}

View File

@ -50,10 +50,10 @@ namespace runtime {
virtual TokenSource* getTokenSource() const override;
virtual std::wstring getText(const misc::Interval &interval) override;
virtual std::wstring getText() override;
virtual std::wstring getText(RuleContext *ctx) override;
virtual std::wstring getText(Ref<Token> start, Ref<Token> stop) override;
virtual std::string getText(const misc::Interval &interval) override;
virtual std::string getText() override;
virtual std::string getText(RuleContext *ctx) override;
virtual std::string getText(Ref<Token> start, Ref<Token> stop) override;
virtual void consume() override;

View File

@ -87,7 +87,7 @@ namespace dfa {
/// </param>
/// <returns> The string literal associated with the specified token type, or
/// {@code null} if no string literal is associated with the type. </returns>
virtual std::wstring getLiteralName(ssize_t tokenType) const = 0;
virtual std::string getLiteralName(ssize_t tokenType) const = 0;
/// <summary>
/// Gets the symbolic name associated with a token type. The string returned
@ -131,7 +131,7 @@ namespace dfa {
/// </param>
/// <returns> The symbolic name associated with the specified token type, or
/// {@code null} if no symbolic name is associated with the type. </returns>
virtual std::wstring getSymbolicName(ssize_t tokenType) const = 0;
virtual std::string getSymbolicName(ssize_t tokenType) const = 0;
/// <summary>
/// Gets the display name of a token type.
@ -152,7 +152,7 @@ namespace dfa {
/// </param>
/// <returns> The display name of the token type, for use in error reporting or
/// other user-visible messages which reference specific token types. </returns>
virtual std::wstring getDisplayName(ssize_t tokenType) const = 0;
virtual std::string getDisplayName(ssize_t tokenType) const = 0;
};
} // namespace atn

View File

@ -35,15 +35,15 @@
using namespace org::antlr::v4::runtime::dfa;
const std::vector<std::wstring> VocabularyImpl::EMPTY_NAMES;
const std::vector<std::string> VocabularyImpl::EMPTY_NAMES;
const Ref<Vocabulary> VocabularyImpl::EMPTY_VOCABULARY = std::make_shared<VocabularyImpl>(EMPTY_NAMES, EMPTY_NAMES, EMPTY_NAMES);
VocabularyImpl::VocabularyImpl(const std::vector<std::wstring> &literalNames, const std::vector<std::wstring> &symbolicNames)
VocabularyImpl::VocabularyImpl(const std::vector<std::string> &literalNames, const std::vector<std::string> &symbolicNames)
: VocabularyImpl(literalNames, symbolicNames, {}) {
}
VocabularyImpl::VocabularyImpl(const std::vector<std::wstring> &literalNames,
const std::vector<std::wstring> &symbolicNames, const std::vector<std::wstring> &displayNames)
VocabularyImpl::VocabularyImpl(const std::vector<std::string> &literalNames,
const std::vector<std::string> &symbolicNames, const std::vector<std::string> &displayNames)
: _literalNames(!literalNames.empty() ? literalNames : EMPTY_NAMES),
_symbolicNames(!symbolicNames.empty() ? symbolicNames : EMPTY_NAMES),
_displayNames(!displayNames.empty() ? displayNames : EMPTY_NAMES),
@ -51,34 +51,34 @@ VocabularyImpl::VocabularyImpl(const std::vector<std::wstring> &literalNames,
// See note here on -1 part: https://github.com/antlr/antlr4/pull/1146
}
Ref<Vocabulary> VocabularyImpl::fromTokenNames(const std::vector<std::wstring> &tokenNames) {
Ref<Vocabulary> VocabularyImpl::fromTokenNames(const std::vector<std::string> &tokenNames) {
if (tokenNames.empty()) {
return EMPTY_VOCABULARY;
}
std::vector<std::wstring> literalNames = tokenNames;
std::vector<std::wstring> symbolicNames = tokenNames;
std::vector<std::string> literalNames = tokenNames;
std::vector<std::string> symbolicNames = tokenNames;
std::locale locale;
for (size_t i = 0; i < tokenNames.size(); i++) {
std::wstring tokenName = tokenNames[i];
if (tokenName == L"") {
std::string tokenName = tokenNames[i];
if (tokenName == "") {
continue;
}
if (!tokenName.empty()) {
wchar_t firstChar = tokenName[0];
if (firstChar == L'\'') {
symbolicNames[i] = L"";
char firstChar = tokenName[0];
if (firstChar == '\'') {
symbolicNames[i] = "";
continue;
} else if (std::isupper(firstChar, locale)) {
literalNames[i] = L"";
literalNames[i] = "";
continue;
}
}
// wasn't a literal or symbolic name
literalNames[i] = L"";
symbolicNames[i] = L"";
literalNames[i] = "";
symbolicNames[i] = "";
}
return std::make_shared<VocabularyImpl>(literalNames, symbolicNames, tokenNames);
@ -88,43 +88,43 @@ int VocabularyImpl::getMaxTokenType() const {
return _maxTokenType;
}
std::wstring VocabularyImpl::getLiteralName(ssize_t tokenType) const {
std::string VocabularyImpl::getLiteralName(ssize_t tokenType) const {
if (tokenType >= 0 && tokenType < (int)_literalNames.size()) {
return _literalNames[tokenType];
}
return L"";
return "";
}
std::wstring VocabularyImpl::getSymbolicName(ssize_t tokenType) const {
std::string VocabularyImpl::getSymbolicName(ssize_t tokenType) const {
if (tokenType >= 0 && tokenType < (int)_symbolicNames.size()) {
return _symbolicNames[tokenType];
}
if (tokenType == Token::EOF) {
return L"EOF";
return "EOF";
}
return L"";
return "";
}
std::wstring VocabularyImpl::getDisplayName(ssize_t tokenType) const {
std::string VocabularyImpl::getDisplayName(ssize_t tokenType) const {
if (tokenType >= 0 && tokenType < (int)_displayNames.size()) {
std::wstring displayName = _displayNames[tokenType];
std::string displayName = _displayNames[tokenType];
if (!displayName.empty()) {
return displayName;
}
}
std::wstring literalName = getLiteralName(tokenType);
std::string literalName = getLiteralName(tokenType);
if (!literalName.empty()) {
return literalName;
}
std::wstring symbolicName = getSymbolicName(tokenType);
std::string symbolicName = getSymbolicName(tokenType);
if (!symbolicName.empty()) {
return symbolicName;
}
return std::to_wstring(tokenType);
return std::to_string(tokenType);
}

View File

@ -64,7 +64,7 @@ namespace dfa {
/// </param>
/// <seealso cref= #getLiteralName(int) </seealso>
/// <seealso cref= #getSymbolicName(int) </seealso>
VocabularyImpl(const std::vector<std::wstring> &literalNames, const std::vector<std::wstring> &symbolicNames);
VocabularyImpl(const std::vector<std::string> &literalNames, const std::vector<std::string> &symbolicNames);
/// <summary>
/// Constructs a new instance of <seealso cref="VocabularyImpl"/> from the specified
@ -82,8 +82,8 @@ namespace dfa {
/// <seealso cref= #getLiteralName(int) </seealso>
/// <seealso cref= #getSymbolicName(int) </seealso>
/// <seealso cref= #getDisplayName(int) </seealso>
VocabularyImpl(const std::vector<std::wstring> &literalNames, const std::vector<std::wstring> &symbolicNames,
const std::vector<std::wstring> &displayNames);
VocabularyImpl(const std::vector<std::string> &literalNames, const std::vector<std::string> &symbolicNames,
const std::vector<std::string> &displayNames);
/// <summary>
/// Returns a <seealso cref="VocabularyImpl"/> instance from the specified set of token
@ -98,19 +98,19 @@ namespace dfa {
/// available. </param>
/// <returns> A <seealso cref="Vocabulary"/> instance which uses {@code tokenNames} for
/// the display names of tokens. </returns>
static Ref<Vocabulary> fromTokenNames(const std::vector<std::wstring> &tokenNames);
static Ref<Vocabulary> fromTokenNames(const std::vector<std::string> &tokenNames);
virtual int getMaxTokenType() const override;
virtual std::wstring getLiteralName(ssize_t tokenType) const override;
virtual std::wstring getSymbolicName(ssize_t tokenType) const override;
virtual std::wstring getDisplayName(ssize_t tokenType) const override;
virtual std::string getLiteralName(ssize_t tokenType) const override;
virtual std::string getSymbolicName(ssize_t tokenType) const override;
virtual std::string getDisplayName(ssize_t tokenType) const override;
private:
static std::vector<std::wstring> const EMPTY_NAMES;
static std::vector<std::string> const EMPTY_NAMES;
std::vector<std::wstring> const _literalNames;
std::vector<std::wstring> const _symbolicNames;
std::vector<std::wstring> const _displayNames;
std::vector<std::string> const _literalNames;
std::vector<std::string> const _symbolicNames;
std::vector<std::string> const _displayNames;
const int _maxTokenType;
};

View File

@ -40,7 +40,7 @@ namespace runtime {
class ANTLR4CPP_PUBLIC WritableToken : public Token {
public:
virtual void setText(const std::wstring &text) = 0;
virtual void setText(const std::string &text) = 0;
virtual void setType(int ttype) = 0;
virtual void setLine(int line) = 0;
virtual void setCharPositionInLine(int pos) = 0;

View File

@ -32,6 +32,8 @@
//
// Use this as (automatically included) precompiled header file.
#ifdef __cplusplus
#include <algorithm>
#include <assert.h>
#include <codecvt>
@ -122,3 +124,5 @@
#endif
template<class T> using Ref = std::shared_ptr<T>;
#endif

View File

@ -185,16 +185,16 @@ misc::IntervalSet ATN::getExpectedTokens(int stateNumber, Ref<RuleContext> conte
return expected;
}
std::wstring ATN::toString() const {
std::wstringstream ss;
std::wstring type;
std::string ATN::toString() const {
std::stringstream ss;
std::string type;
switch (grammarType) {
case ATNType::LEXER:
type = L"LEXER ";
type = "LEXER ";
break;
case ATNType::PARSER:
type = L"PARSER ";
type = "PARSER ";
break;
default:
@ -206,20 +206,20 @@ std::wstring ATN::toString() const {
size_t index = 0;
for (auto state : states) {
if (state == nullptr) {
ss << " " << index++ << ": null" << std::endl;
ss << " " << index++ << ": nul" << std::endl;
} else {
std::wstring text = state->toString();
ss << " " << index++ << ": " << indent(text, L" ", false) << std::endl;
std::string text = state->toString();
ss << " " << index++ << ": " << indent(text, " ", false) << std::endl;
}
}
index = 0;
for (auto state : decisionToState) {
if (state == nullptr) {
ss << " " << index++ << ": null" << std::endl;
ss << " " << index++ << ": nul" << std::endl;
} else {
std::wstring text = state->toString();
ss << " " << index++ << ": " << indent(text, L" ", false) << std::endl;
std::string text = state->toString();
ss << " " << index++ << ": " << indent(text, " ", false) << std::endl;
}
}

View File

@ -131,7 +131,7 @@ namespace atn {
/// number {@code stateNumber} </exception>
virtual misc::IntervalSet getExpectedTokens(int stateNumber, Ref<RuleContext> context) const;
std::wstring toString() const;
std::string toString() const;
};
} // namespace atn

View File

@ -108,28 +108,28 @@ bool ATNConfig::operator == (const ATNConfig &other) const
isPrecedenceFilterSuppressed() == other.isPrecedenceFilterSuppressed();
}
std::wstring ATNConfig::toString() {
std::string ATNConfig::toString() {
return toString(true);
}
std::wstring ATNConfig::toString(bool showAlt) {
std::wstringstream ss;
ss << L"(";
std::string ATNConfig::toString(bool showAlt) {
std::stringstream ss;
ss << "(";
ss << state->toString();
if (showAlt) {
ss << L"," << alt;
ss << "," << alt;
}
if (context) {
ss << L",[" << context->toString() << L"]";
ss << ",[" << context->toString() << "]";
}
if (semanticContext != nullptr && semanticContext != SemanticContext::NONE) {
ss << L"," << semanticContext.get();
ss << "," << semanticContext.get();
}
if (getOuterContextDepth() > 0) {
ss << L",up=" << getOuterContextDepth();
ss << ",up=" << getOuterContextDepth();
}
ss << L')';
ss << ')';
return ss.str();
}

View File

@ -136,8 +136,8 @@ namespace atn {
/// syntactic/semantic contexts are the same.
bool operator == (const ATNConfig &other) const;
virtual std::wstring toString();
std::wstring toString(bool showAlt);
virtual std::string toString();
std::string toString(bool showAlt);
private:
/**

View File

@ -249,28 +249,28 @@ void ATNConfigSet::setReadonly(bool readonly) {
configLookup.reset();
}
std::wstring ATNConfigSet::toString() {
std::wstringstream ss;
ss << L"[";
std::string ATNConfigSet::toString() {
std::stringstream ss;
ss << "[";
for (size_t i = 0; i < elements().size(); i++) {
ss << configs[i]->toString();
}
ss << L"]";
ss << "]";
if (hasSemanticContext) {
ss << L",hasSemanticContext = " << hasSemanticContext;
ss << ",hasSemanticContext = " << hasSemanticContext;
}
if (uniqueAlt != ATN::INVALID_ALT_NUMBER) {
ss << L",uniqueAlt = " << uniqueAlt;
ss << ",uniqueAlt = " << uniqueAlt;
}
if (conflictingAlts.size() > 0) {
ss << L",conflictingAlts = ";
ss << ",conflictingAlts = ";
ss << conflictingAlts.toString();
}
if (dipsIntoOuterContext) {
ss << L", dipsIntoOuterContext";
ss << ", dipsIntoOuterContext";
}
return ss.str();
}

View File

@ -136,7 +136,7 @@ namespace atn {
virtual void clear();
virtual bool isReadonly();
virtual void setReadonly(bool readonly);
virtual std::wstring toString();
virtual std::string toString();
virtual bool remove(void *o);
protected:

View File

@ -76,7 +76,7 @@ void ATNDeserializationOptions::setGenerateRuleBypassTransitions(bool generateRu
void ATNDeserializationOptions::throwIfReadOnly() {
if (isReadOnly()) {
throw L"The object is read only.";
throw "The object is read only.";
}
}

View File

@ -64,7 +64,7 @@
#include "IntervalSet.h"
#include "Exceptions.h"
#include "CPPUtils.h"
#include "Strings.h"
#include "StringUtils.h"
#include "LexerCustomAction.h"
#include "LexerChannelAction.h"
@ -127,12 +127,12 @@ bool ATNDeserializer::isFeatureSupported(const Guid &feature, const Guid &actual
return std::distance(featureIterator, actualIterator) >= 0;
}
ATN ATNDeserializer::deserialize(const std::wstring& input) {
ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
// Don't adjust the first value since that's the version number.
std::vector<uint16_t> data(input.size());
data[0] = (uint16_t)input[0];
data[0] = input[0];
for (size_t i = 1; i < input.size(); ++i) {
data[i] = (uint16_t)input[i] - 2;
data[i] = input[i] - 2;
}
int p = 0;
@ -175,7 +175,7 @@ ATN ATNDeserializer::deserialize(const std::wstring& input) {
}
int ruleIndex = data[p++];
if (ruleIndex == 0xFFFF) { // Not WCHAR_MAX as this can take a different value.
if (ruleIndex == 0xFFFF) { // Max Unicode char limit imposed by ANTLR.
ruleIndex = -1;
}

View File

@ -54,7 +54,7 @@ namespace atn {
static Guid toUUID(const unsigned short *data, int offset);
virtual ATN deserialize(const std::wstring &input);
virtual ATN deserialize(const std::vector<uint16_t> &input);
virtual void verifyATN(const ATN &atn);
static void checkCondition(bool condition);

View File

@ -71,7 +71,7 @@ using namespace org::antlr::v4::runtime::atn;
ATNSerializer::ATNSerializer(ATN *atn) { this->atn = atn; }
ATNSerializer::ATNSerializer(ATN *atn, const std::vector<std::wstring> &tokenNames) {
ATNSerializer::ATNSerializer(ATN *atn, const std::vector<std::string> &tokenNames) {
this->atn = atn;
_tokenNames = tokenNames;
}
@ -111,7 +111,7 @@ std::vector<size_t> ATNSerializer::serialize() {
data.push_back((size_t)stateType);
if (s->ruleIndex == -1) {
data.push_back(WCHAR_MAX);
data.push_back(0xFFFF);
}
else {
data.push_back((size_t)s->ruleIndex);
@ -162,7 +162,7 @@ std::vector<size_t> ATNSerializer::serialize() {
data.push_back((size_t)ruleStartState->stateNumber);
if (atn->grammarType == ATNType::LEXER) {
if (atn->ruleToTokenType[r] == Token::EOF) {
data.push_back(WCHAR_MAX);
data.push_back(0xFFFF);
}
else {
data.push_back((size_t)atn->ruleToTokenType[r]);
@ -253,8 +253,8 @@ std::vector<size_t> ATNSerializer::serialize() {
}
break;
case Transition::RANGE:
arg1 = (static_cast<RangeTransition *>(t))->from;
arg2 = (static_cast<RangeTransition *>(t))->to;
arg1 = (int)(static_cast<RangeTransition *>(t))->from;
arg2 = (int)(static_cast<RangeTransition *>(t))->to;
if (arg1 == Token::EOF) {
arg1 = 0;
arg3 = 1;
@ -262,7 +262,7 @@ std::vector<size_t> ATNSerializer::serialize() {
break;
case Transition::ATOM:
arg1 = (static_cast<AtomTransition *>(t))->_label;
arg1 = (int)(static_cast<AtomTransition *>(t))->_label;
if (arg1 == Token::EOF) {
arg1 = 0;
arg3 = 1;
@ -378,7 +378,7 @@ std::vector<size_t> ATNSerializer::serialize() {
// don't adjust the first value since that's the version number
for (size_t i = 1; i < data.size(); i++) {
if ((wchar_t)data.at(i) < WCHAR_MIN || data.at(i) > WCHAR_MAX) {
if (data.at(i) > 0xFFFF) {
throw UnsupportedOperationException("Serialized ATN data element out of range.");
}
@ -391,7 +391,7 @@ std::vector<size_t> ATNSerializer::serialize() {
//------------------------------------------------------------------------------------------------------------
std::wstring ATNSerializer::decode(const std::wstring &inpdata) {
std::string ATNSerializer::decode(const std::wstring &inpdata) {
if (inpdata.size() < 10)
throw IllegalArgumentException("Not enough data to decode");
@ -403,7 +403,7 @@ std::wstring ATNSerializer::decode(const std::wstring &inpdata) {
data[i] = (uint16_t)inpdata[i] - 2;
}
std::wstring buf;
std::string buf;
int p = 0;
size_t version = (size_t)data[p++];
if (version != ATNDeserializer::SERIALIZED_VERSION) {
@ -422,7 +422,7 @@ std::wstring ATNSerializer::decode(const std::wstring &inpdata) {
p++; // skip grammarType
int maxType = data[p++];
buf.append(L"max type ").append(std::to_wstring(maxType)).append(L"\n");
buf.append("max type ").append(std::to_string(maxType)).append("\n");
int nstates = data[p++];
for (int i = 0; i < nstates; i++) {
int stype = data[p++];
@ -430,28 +430,28 @@ std::wstring ATNSerializer::decode(const std::wstring &inpdata) {
continue;
}
int ruleIndex = data[p++];
if (ruleIndex == WCHAR_MAX) {
if (ruleIndex == 0xFFFF) {
ruleIndex = -1;
}
std::wstring arg = L"";
std::string arg = "";
if (stype == ATNState::LOOP_END) {
int loopBackStateNumber = data[p++];
arg = std::wstring(L" ") + std::to_wstring(loopBackStateNumber);
arg = std::string(" ") + std::to_string(loopBackStateNumber);
}
else if (stype == ATNState::PLUS_BLOCK_START ||
stype == ATNState::STAR_BLOCK_START ||
stype == ATNState::BLOCK_START) {
int endStateNumber = data[p++];
arg = std::wstring(L" ") + std::to_wstring(endStateNumber);
arg = std::string(" ") + std::to_string(endStateNumber);
}
buf.append(std::to_wstring(i))
.append(L":")
buf.append(std::to_string(i))
.append(":")
.append(ATNState::serializationNames[(size_t)stype])
.append(L" ")
.append(std::to_wstring(ruleIndex))
.append(" ")
.append(std::to_string(ruleIndex))
.append(arg)
.append(L"\n");
.append("\n");
}
int numNonGreedyStates = data[p++];
p += numNonGreedyStates; // Instead of that useless loop below.
@ -474,35 +474,35 @@ std::wstring ATNSerializer::decode(const std::wstring &inpdata) {
int s = data[p++];
if (atn->grammarType == ATNType::LEXER) {
int arg1 = data[p++];
buf.append(L"rule ")
.append(std::to_wstring(i))
.append(L":")
.append(std::to_wstring(s))
.append(L" ")
.append(std::to_wstring(arg1))
.append(L"\n");
buf.append("rule ")
.append(std::to_string(i))
.append(":")
.append(std::to_string(s))
.append(" ")
.append(std::to_string(arg1))
.append("\n");
}
else {
buf.append(L"rule ")
.append(std::to_wstring(i))
.append(L":")
.append(std::to_wstring(s))
.append(L"\n");
buf.append("rule ")
.append(std::to_string(i))
.append(":")
.append(std::to_string(s))
.append("\n");
}
}
int nmodes = data[p++];
for (int i = 0; i < nmodes; i++) {
int s = data[p++];
buf.append(L"mode ")
.append(std::to_wstring(i))
.append(L":")
.append(std::to_wstring(s))
.append(L"\n");
buf.append("mode ")
.append(std::to_string(i))
.append(":")
.append(std::to_string(s))
.append("\n");
}
int nsets = data[p++];
for (int i = 0; i < nsets; i++) {
int nintervals = data[p++];
buf.append(std::to_wstring(i)).append(L":");
buf.append(std::to_string(i)).append(":");
bool containsEof = data[p++] != 0;
if (containsEof) {
buf.append(getTokenName(Token::EOF));
@ -510,15 +510,15 @@ std::wstring ATNSerializer::decode(const std::wstring &inpdata) {
for (int j = 0; j < nintervals; j++) {
if (containsEof || j > 0) {
buf.append(L", ");
buf.append(", ");
}
buf.append(getTokenName(data[p]))
.append(L"..")
.append("..")
.append(getTokenName(data[p + 1]));
p += 2;
}
buf.append(L"\n");
buf.append("\n");
}
int nedges = data[p++];
for (int i = 0; i < nedges; i++) {
@ -528,24 +528,24 @@ std::wstring ATNSerializer::decode(const std::wstring &inpdata) {
int arg1 = data[p + 3];
int arg2 = data[p + 4];
int arg3 = data[p + 5];
buf.append(std::to_wstring(src))
.append(L"->")
.append(std::to_wstring(trg))
.append(L" ")
buf.append(std::to_string(src))
.append("->")
.append(std::to_string(trg))
.append(" ")
.append(Transition::serializationNames[(size_t)ttype])
.append(L" ")
.append(std::to_wstring(arg1))
.append(L",")
.append(std::to_wstring(arg2))
.append(L",")
.append(std::to_wstring(arg3))
.append(L"\n");
.append(" ")
.append(std::to_string(arg1))
.append(",")
.append(std::to_string(arg2))
.append(",")
.append(std::to_string(arg3))
.append("\n");
p += 6;
}
int ndecisions = data[p++];
for (int i = 0; i < ndecisions; i++) {
int s = data[p++];
buf.append(std::to_wstring(i)).append(L":").append(std::to_wstring(s)).append(L"\n");
buf.append(std::to_string(i)).append(":").append(std::to_string(s)).append("\n");
}
if (atn->grammarType == ATNType::LEXER) {
@ -564,38 +564,37 @@ std::wstring ATNSerializer::decode(const std::wstring &inpdata) {
return buf;
}
std::wstring ATNSerializer::getTokenName(ssize_t t) {
std::string ATNSerializer::getTokenName(ssize_t t) {
if (t == -1) {
return L"EOF";
return "EOF";
}
if (atn->grammarType == ATNType::LEXER && t >= WCHAR_MIN &&
t <= WCHAR_MAX) {
if (atn->grammarType == ATNType::LEXER && t >= 0 && t <= 0xFFFF) {
switch (t) {
case L'\n':
return L"'\\n'";
case L'\r':
return L"'\\r'";
case L'\t':
return L"'\\t'";
case L'\b':
return L"'\\b'";
case L'\f':
return L"'\\f'";
case L'\\':
return L"'\\\\'";
case L'\'':
return L"'\\''";
case '\n':
return "'\\n'";
case '\r':
return "'\\r'";
case '\t':
return "'\\t'";
case '\b':
return "'\\b'";
case '\f':
return "'\\f'";
case '\\':
return "'\\\\'";
case '\'':
return "'\\''";
default:
std::wstring s_hex = antlrcpp::toHexString((int)t);
if (s_hex >= L"0" && s_hex <= L"7F" &&
std::string s_hex = antlrcpp::toHexString((int)t);
if (s_hex >= "0" && s_hex <= "7F" &&
!iscntrl((int)t)) {
return L"'" + std::to_wstring(t) + L"'";
return "'" + std::to_string(t) + "'";
}
// turn on the bit above max "\uFFFF" value so that we pad with zeros
// then only take last 4 digits
std::wstring hex = antlrcpp::toHexString((int)t | 0x10000).substr(1, 4);
std::wstring unicodeStr = std::wstring(L"'\\u") + hex + std::wstring(L"'");
std::string hex = antlrcpp::toHexString((int)t | 0x10000).substr(1, 4);
std::string unicodeStr = std::string("'\\u") + hex + std::string("'");
return unicodeStr;
}
}
@ -604,7 +603,7 @@ std::wstring ATNSerializer::getTokenName(ssize_t t) {
return _tokenNames[(size_t)t];
}
return std::to_wstring(t);
return std::to_string(t);
}
std::wstring ATNSerializer::getSerializedAsString(ATN *atn) {
@ -620,7 +619,7 @@ std::vector<size_t> ATNSerializer::getSerialized(ATN *atn) {
return ATNSerializer(atn).serialize();
}
std::wstring ATNSerializer::getDecoded(ATN *atn, std::vector<std::wstring> &tokenNames) {
std::string ATNSerializer::getDecoded(ATN *atn, std::vector<std::string> &tokenNames) {
std::wstring serialized = getSerializedAsString(atn);
return ATNSerializer(atn, tokenNames).decode(serialized);
}

View File

@ -42,7 +42,7 @@ namespace atn {
ATN *atn;
ATNSerializer(ATN *atn);
ATNSerializer(ATN *atn, const std::vector<std::wstring> &tokenNames);
ATNSerializer(ATN *atn, const std::vector<std::string> &tokenNames);
virtual ~ATNSerializer() {};
/// <summary>
@ -71,18 +71,17 @@ namespace atn {
/// </summary>
virtual std::vector<size_t> serialize();
virtual std::wstring decode(const std::wstring& data);
virtual std::wstring getTokenName(ssize_t t);
virtual std::string decode(const std::wstring& data);
virtual std::string getTokenName(ssize_t t);
/// Used by Java target to encode short/int array as chars in string.
static std::wstring getSerializedAsString(ATN *atn);
static std::vector<size_t> getSerialized(ATN *atn);
static std::wstring getDecoded(ATN *atn, std::vector<std::wstring> &tokenNames);
static std::string getDecoded(ATN *atn, std::vector<std::string> &tokenNames);
private:
std::vector<std::wstring> _tokenNames;
std::vector<std::string> _tokenNames;
void serializeUUID(std::vector<size_t> &data, Guid uuid);
};

View File

@ -61,7 +61,7 @@ Ref<PredictionContext> ATNSimulator::getCachedContext(Ref<PredictionContext> con
return PredictionContext::getCachedContext(context, _sharedContextCache, visited);
}
ATN ATNSimulator::deserialize(const std::wstring &data) {
ATN ATNSimulator::deserialize(const std::vector<uint16_t> &data) {
ATNDeserializer deserializer;
return deserializer.deserialize(data);
}

View File

@ -68,7 +68,7 @@ namespace atn {
virtual Ref<PredictionContext> getCachedContext(Ref<PredictionContext> context);
/// @deprecated Use <seealso cref="ATNDeserializer#deserialize"/> instead.
static ATN deserialize(const std::wstring &data);
static ATN deserialize(const std::vector<uint16_t> &data);
/// @deprecated Use <seealso cref="ATNDeserializer#checkCondition(boolean)"/> instead.
static void checkCondition(bool condition);

View File

@ -48,10 +48,10 @@ ATNState::~ATNState() {
}
}
const std::vector<std::wstring> ATNState::serializationNames = {
L"INVALID", L"BASIC", L"RULE_START", L"BLOCK_START",
L"PLUS_BLOCK_START", L"STAR_BLOCK_START", L"TOKEN_START", L"RULE_STOP",
L"BLOCK_END", L"STAR_LOOP_BACK", L"STAR_LOOP_ENTRY", L"PLUS_LOOP_BACK", L"LOOP_END"
const std::vector<std::string> ATNState::serializationNames = {
"INVALID", "BASIC", "RULE_START", "BLOCK_START",
"PLUS_BLOCK_START", "STAR_BLOCK_START", "TOKEN_START", "RULE_STOP",
"BLOCK_END", "STAR_LOOP_BACK", "STAR_LOOP_ENTRY", "PLUS_LOOP_BACK", "LOOP_END"
};
size_t ATNState::hashCode() {
@ -66,8 +66,8 @@ bool ATNState::isNonGreedyExitState() {
return false;
}
std::wstring ATNState::toString() const {
std::wstringstream ss;
std::string ATNState::toString() const {
std::stringstream ss;
ss << "(ATNState " << std::hex << this << std::dec << ") {" << std::endl;
if (stateNumber < 0 || stateNumber >= (int)serializationNames.size())
ss << " state: INVALID ";
@ -78,7 +78,7 @@ std::wstring ATNState::toString() const {
ss << " transistions (" << transitions.size() << "):" << std::endl;
for (auto transition : transitions) {
ss << indent(transition->toString(), L" ") << std::endl;
ss << indent(transition->toString(), " ") << std::endl;
}
ss << "}";
@ -101,7 +101,7 @@ void ATNState::addTransition(int index, Transition *e) {
if (transitions.empty()) {
epsilonOnlyTransitions = e->isEpsilon();
} else if (epsilonOnlyTransitions != e->isEpsilon()) {
std::cerr << L"ATN state %d has both epsilon and non-epsilon transitions.\n" << stateNumber;
std::cerr << "ATN state %d has both epsilon and non-epsilon transitions.\n" << stateNumber;
epsilonOnlyTransitions = false;
}

View File

@ -122,7 +122,7 @@ namespace atn {
LOOP_END = 12
};
static const std::vector<std::wstring> serializationNames;
static const std::vector<std::string> serializationNames;
/// Which ATN are we in?
// ml: just a reference to the owner. Set when the state gets added to an ATN.
@ -143,7 +143,7 @@ namespace atn {
bool operator == (const ATNState &other);
virtual bool isNonGreedyExitState();
virtual std::wstring toString() const;
virtual std::string toString() const;
virtual std::vector<Transition*> getTransitions();
virtual size_t getNumberOfTransitions();
virtual void addTransition(Transition *e);

View File

@ -49,11 +49,11 @@ bool ActionTransition::isEpsilon() const {
return true; // we are to be ignored by analysis 'cept for predicates
}
bool ActionTransition::matches(int /*symbol*/, int /*minVocabSymbol*/, int /*maxVocabSymbol*/) const {
bool ActionTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const {
return false;
}
std::wstring ActionTransition::toString() const {
return L" ACTION " + Transition::toString() + L" { ruleIndex: " + std::to_wstring(ruleIndex) + L", actionIndex: " +
std::to_wstring(actionIndex) + L", isCtxDependent: " + std::to_wstring(isCtxDependent) + L" }";
std::string ActionTransition::toString() const {
return " ACTION " + Transition::toString() + " { ruleIndex: " + std::to_string(ruleIndex) + ", actionIndex: " +
std::to_string(actionIndex) + ", isCtxDependent: " + std::to_string(isCtxDependent) + " }";
}

View File

@ -53,9 +53,9 @@ namespace atn {
virtual bool isEpsilon() const override;
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const override;
virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override;
virtual std::wstring toString() const override;
virtual std::string toString() const override;
};
} // namespace atn

View File

@ -40,9 +40,9 @@ ArrayPredictionContext::ArrayPredictionContext(Ref<SingletonPredictionContext> a
: ArrayPredictionContext({ a->parent }, { a->returnState }) {
}
ArrayPredictionContext::ArrayPredictionContext(const std::vector<std::weak_ptr<PredictionContext> > &parents,
ArrayPredictionContext::ArrayPredictionContext(const std::vector<std::weak_ptr<PredictionContext> > &parents_,
const std::vector<int> &returnStates)
: PredictionContext(calculateHashCode(parents, returnStates)), parents(parents), returnStates(returnStates) {
: PredictionContext(calculateHashCode(parents_, returnStates)), parents(makeRef(parents_)), returnStates(returnStates) {
assert(parents.size() > 0);
assert(returnStates.size() > 0);
}
@ -74,31 +74,40 @@ bool ArrayPredictionContext::operator == (const PredictionContext &o) const {
return false; // can't be same if hash is different
}
return antlrcpp::Arrays::equals(returnStates, other->returnStates) && antlrcpp::Arrays::equals(parents, other->parents);
return antlrcpp::Arrays::equals(returnStates, other->returnStates) &&
antlrcpp::Arrays::equals(parents, other->parents);
}
std::wstring ArrayPredictionContext::toString() {
std::string ArrayPredictionContext::toString() {
if (isEmpty()) {
return L"[]";
return "[]";
}
std::wstringstream ss;
ss << L"[";
std::stringstream ss;
ss << "[";
for (size_t i = 0; i < returnStates.size(); i++) {
if (i > 0) {
ss << L", ";
ss << ", ";
}
if (returnStates[i] == EMPTY_RETURN_STATE) {
ss << L"$";
ss << "$";
continue;
}
ss << returnStates[i];
if (!parents[i].expired()) {
ss << L" " << parents[i].lock()->toString();
if (parents[i] != nullptr) {
ss << " " << parents[i]->toString();
} else {
ss << L"null";
ss << "nul";
}
}
ss << L"]";
ss << "]";
return ss.str();
}
std::vector<Ref<PredictionContext>> ArrayPredictionContext::makeRef(const std::vector<std::weak_ptr<PredictionContext> > &input) {
std::vector<Ref<PredictionContext>> result;
for (auto element : input) {
result.push_back(element.lock());
}
return result;
}

View File

@ -47,13 +47,15 @@ namespace atn {
/// Parent can be empty only if full ctx mode and we make an array
/// from EMPTY and non-empty. We merge EMPTY by using null parent and
/// returnState == EMPTY_RETURN_STATE.
const std::vector<std::weak_ptr<PredictionContext>> parents;
// Also here: we use a strong reference to our parents to avoid having them freed prematurely.
// See also SinglePredictionContext.
const std::vector<Ref<PredictionContext>> parents;
/// Sorted for merge, no duplicates; if present, EMPTY_RETURN_STATE is always last.
const std::vector<int> returnStates;
ArrayPredictionContext(Ref<SingletonPredictionContext> a);
ArrayPredictionContext(const std::vector<std::weak_ptr<PredictionContext>> &parents,
ArrayPredictionContext(const std::vector<std::weak_ptr<PredictionContext>> &parents_,
const std::vector<int> &returnStates);
virtual ~ArrayPredictionContext() {};
@ -63,7 +65,9 @@ namespace atn {
virtual int getReturnState(size_t index) const override;
bool operator == (const PredictionContext &o) const override;
virtual std::wstring toString();
virtual std::string toString();
private:
std::vector<Ref<PredictionContext>> makeRef(const std::vector<std::weak_ptr<PredictionContext> > &input);
};
} // namespace atn

View File

@ -37,7 +37,7 @@
using namespace org::antlr::v4::runtime::misc;
using namespace org::antlr::v4::runtime::atn;
AtomTransition::AtomTransition(ATNState *target, int label) : Transition(target), _label(label) {
AtomTransition::AtomTransition(ATNState *target, size_t label) : Transition(target), _label(label) {
}
int AtomTransition::getSerializationType() const {
@ -45,13 +45,13 @@ int AtomTransition::getSerializationType() const {
}
IntervalSet AtomTransition::label() const {
return IntervalSet::of(_label);
return IntervalSet::of((int)_label);
}
bool AtomTransition::matches(int symbol, int /*minVocabSymbol*/, int /*maxVocabSymbol*/) const {
bool AtomTransition::matches(size_t symbol, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const {
return _label == symbol;
}
std::wstring AtomTransition::toString() const {
return L"ATOM " + Transition::toString() + L" { label: " + std::to_wstring(_label) + L" }";
std::string AtomTransition::toString() const {
return "ATOM " + Transition::toString() + " { label: " + std::to_string(_label) + " }";
}

View File

@ -39,22 +39,20 @@ namespace v4 {
namespace runtime {
namespace atn {
/// <summary>
/// TO_DO: make all transitions sets? no, should remove set edges </summary>
/// TO_DO: make all transitions sets? no, should remove set edges.
class ANTLR4CPP_PUBLIC AtomTransition final : public Transition {
/// <summary>
/// The token type or character value; or, signifies special label. </summary>
public:
const int _label;
/// The token type or character value; or, signifies special label.
const size_t _label;
AtomTransition(ATNState *target, int label);
AtomTransition(ATNState *target, size_t label);
virtual int getSerializationType() const override;
virtual misc::IntervalSet label() const override;
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const override;
virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override;
virtual std::wstring toString() const override;
virtual std::string toString() const override;
};
} // namespace atn

View File

@ -39,13 +39,13 @@ using namespace org::antlr::v4::runtime::atn;
DecisionInfo::DecisionInfo(size_t decision) : decision(decision) {
}
std::wstring DecisionInfo::toString() const {
std::wstringstream ss;
std::string DecisionInfo::toString() const {
std::stringstream ss;
ss << L"{decision=" << decision << L", contextSensitivities=" << contextSensitivities.size() << L", errors=";
ss << errors.size() << L", ambiguities=" << ambiguities.size() << L", SLL_lookahead=" << SLL_TotalLook;
ss << L", SLL_ATNTransitions=" << SLL_ATNTransitions << L", SLL_DFATransitions=" << SLL_DFATransitions;
ss << L", LL_Fallback=" << LL_Fallback << L", LL_lookahead=" << LL_TotalLook << L", LL_ATNTransitions=" << LL_ATNTransitions << L'}';
ss << "{decision=" << decision << ", contextSensitivities=" << contextSensitivities.size() << ", errors=";
ss << errors.size() << ", ambiguities=" << ambiguities.size() << ", SLL_lookahead=" << SLL_TotalLook;
ss << ", SLL_ATNTransitions=" << SLL_ATNTransitions << ", SLL_DFATransitions=" << SLL_DFATransitions;
ss << ", LL_Fallback=" << LL_Fallback << ", LL_lookahead=" << LL_TotalLook << ", LL_ATNTransitions=" << LL_ATNTransitions << '}';
return ss.str();
}

View File

@ -249,7 +249,7 @@ namespace atn {
/// <param name="decision"> The decision number </param>
DecisionInfo(size_t decision);
std::wstring toString() const;
std::string toString() const;
};
} // namespace atn

View File

@ -38,6 +38,6 @@ void DecisionState::InitializeInstanceFields() {
nonGreedy = false;
}
std::wstring DecisionState::toString() const {
return L"DECISION " + ATNState::toString();
std::string DecisionState::toString() const {
return "DECISION " + ATNState::toString();
}

View File

@ -52,7 +52,7 @@ namespace atn {
InitializeInstanceFields();
}
virtual std::wstring toString() const override;
virtual std::string toString() const override;
};
} // namespace atn

View File

@ -56,6 +56,6 @@ bool EmptyPredictionContext::operator == (const PredictionContext &o) const {
return this == &o;
}
std::wstring EmptyPredictionContext::toString() const {
return L"$";
std::string EmptyPredictionContext::toString() const {
return "$";
}

View File

@ -47,7 +47,7 @@ namespace atn {
virtual size_t size() const override;
virtual std::weak_ptr<PredictionContext> getParent(size_t index) const override;
virtual int getReturnState(size_t index) const override;
virtual std::wstring toString() const override;
virtual std::string toString() const override;
virtual bool operator == (const PredictionContext &o) const override;
};

View File

@ -52,10 +52,10 @@ bool EpsilonTransition::isEpsilon() const {
return true;
}
bool EpsilonTransition::matches(int /*symbol*/, int /*minVocabSymbol*/, int /*maxVocabSymbol*/) const {
bool EpsilonTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const {
return false;
}
std::wstring EpsilonTransition::toString() const {
return L"EPSILON " + Transition::toString() + L" {}";
std::string EpsilonTransition::toString() const {
return "EPSILON " + Transition::toString() + " {}";
}

View File

@ -56,9 +56,9 @@ namespace atn {
virtual int getSerializationType() const override;
virtual bool isEpsilon() const override;
virtual bool matches(int symbol, int minVocabSymbol, int maxVocabSymbol) const override;
virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override;
virtual std::wstring toString() const override;
virtual std::string toString() const override;
private:
const int _outermostPrecedenceReturn;

View File

@ -129,7 +129,7 @@ int LexerATNSimulator::matchATN(CharStream *input) {
ATNState *startState = (ATNState *)atn.modeToStartState[_mode];
if (debug) {
std::wcout << L"matchATN mode" << _mode << L" start: " << startState << std::endl;
std::cout << "matchATN mode" << _mode << " start: " << startState << std::endl;
}
size_t old_mode = _mode;
@ -146,7 +146,7 @@ int LexerATNSimulator::matchATN(CharStream *input) {
int predict = execATN(input, next);
if (debug) {
std::wcout << L"DFA after matchATN: " << _decisionToDFA[old_mode].toLexerString() << std::endl;
std::cout << "DFA after matchATN: " << _decisionToDFA[old_mode].toLexerString() << std::endl;
}
return predict;
@ -155,7 +155,7 @@ int LexerATNSimulator::matchATN(CharStream *input) {
int LexerATNSimulator::execATN(CharStream *input, dfa::DFAState *ds0) {
//System.out.println("enter exec index "+input.index()+" from "+ds0.configs);
if (debug) {
std::wcout << L"start state closure=" << ds0->configs << std::endl;
std::cout << "start state closure=" << ds0->configs << std::endl;
}
if (ds0->isAcceptState) {
@ -169,7 +169,7 @@ int LexerATNSimulator::execATN(CharStream *input, dfa::DFAState *ds0) {
while (true) { // while more work
if (debug) {
std::wcout << L"execATN loop starting closure: " << s->configs << std::endl;
std::cout << "execATN loop starting closure: " << s->configs << std::endl;
}
// As we move src->trg, src->trg, we keep track of the previous trg to
@ -227,7 +227,7 @@ dfa::DFAState *LexerATNSimulator::getExistingTargetState(dfa::DFAState *s, ssize
dfa::DFAState *target = s->edges[(size_t)(t - MIN_DFA_EDGE)];
if (debug && target != nullptr) {
std::wcout << std::wstring(L"reuse state ") << s->stateNumber << std::wstring(L" edge to ") << target->stateNumber << std::endl;
std::cout << std::string("reuse state ") << s->stateNumber << std::string(" edge to ") << target->stateNumber << std::endl;
}
return target;
@ -283,7 +283,7 @@ void LexerATNSimulator::getReachableConfigSet(CharStream *input, Ref<ATNConfigSe
}
if (debug) {
std::wcout << L"testing " << getTokenName((int)t) << " at " << c->toString(true) << std::endl;
std::cout << "testing " << getTokenName((int)t) << " at " << c->toString(true) << std::endl;
}
size_t n = c->state->getNumberOfTransitions();
@ -314,8 +314,8 @@ void LexerATNSimulator::getReachableConfigSet(CharStream *input, Ref<ATNConfigSe
void LexerATNSimulator::accept(CharStream *input, Ref<LexerActionExecutor> lexerActionExecutor, int /*startIndex*/,
size_t index, size_t line, size_t charPos) {
if (debug) {
std::wcout << L"ACTION ";
std::wcout << toString(lexerActionExecutor) << std::endl;
std::cout << "ACTION ";
std::cout << toString(lexerActionExecutor) << std::endl;
}
// seek to after last char in token
@ -329,7 +329,7 @@ void LexerATNSimulator::accept(CharStream *input, Ref<LexerActionExecutor> lexer
}
atn::ATNState *LexerATNSimulator::getReachableTarget(Transition *trans, ssize_t t) {
if (trans->matches((int)t, WCHAR_MIN, WCHAR_MAX)) {
if (trans->matches((int)t, std::numeric_limits<char32_t>::min(), std::numeric_limits<char32_t>::max())) {
return trans->target;
}
@ -350,15 +350,15 @@ Ref<ATNConfigSet> LexerATNSimulator::computeStartState(CharStream *input, ATNSta
bool LexerATNSimulator::closure(CharStream *input, Ref<LexerATNConfig> config, Ref<ATNConfigSet> configs,
bool currentAltReachedAcceptState, bool speculative, bool treatEofAsEpsilon) {
if (debug) {
std::wcout << L"closure(" << config->toString(true) << L")" << std::endl;
std::cout << "closure(" << config->toString(true) << ")" << std::endl;
}
if (is<RuleStopState *>(config->state)) {
if (debug) {
if (_recog != nullptr) {
std::wcout << L"closure at " << _recog->getRuleNames()[(size_t)config->state->ruleIndex] << L" rule stop " << config << std::endl;
std::cout << "closure at " << _recog->getRuleNames()[(size_t)config->state->ruleIndex] << " rule stop " << config << std::endl;
} else {
std::wcout << L"closure at rule stop " << config << std::endl;
std::cout << "closure at rule stop " << config << std::endl;
}
}
@ -441,7 +441,7 @@ Ref<LexerATNConfig> LexerATNSimulator::getEpsilonTarget(CharStream *input, Ref<L
*/
PredicateTransition *pt = static_cast<PredicateTransition*>(t);
if (debug) {
std::wcout << L"EVAL rule " << pt->ruleIndex << L":" << pt->predIndex << std::endl;
std::cout << "EVAL rule " << pt->ruleIndex << ":" << pt->predIndex << std::endl;
}
configs->hasSemanticContext = true;
if (evaluatePredicate(input, pt->ruleIndex, pt->predIndex, speculative)) {
@ -560,7 +560,7 @@ void LexerATNSimulator::addDFAEdge(dfa::DFAState *p, ssize_t t, dfa::DFAState *q
}
if (debug) {
std::wcout << std::wstring(L"EDGE ") << p << std::wstring(L" -> ") << q << std::wstring(L" upon ") << (static_cast<wchar_t>(t)) << std::endl;
std::cerr << std::string("EDGE ") << p << std::string(" -> ") << q << std::string(" upon ") << (static_cast<char>(t)) << std::endl;
}
std::lock_guard<std::recursive_mutex> lck(mtx);
@ -617,7 +617,7 @@ dfa::DFA& LexerATNSimulator::getDFA(size_t mode) {
return _decisionToDFA[mode];
}
std::wstring LexerATNSimulator::getText(CharStream *input) {
std::string LexerATNSimulator::getText(CharStream *input) {
// index is first lookahead char, don't include.
return input->getText(misc::Interval((int)_startIndex, (int)input->index() - 1));
}
@ -640,7 +640,7 @@ void LexerATNSimulator::setCharPositionInLine(int charPositionInLine) {
void LexerATNSimulator::consume(CharStream *input) {
ssize_t curChar = input->LA(1);
if (curChar == L'\n') {
if (curChar == '\n') {
_line++;
_charPositionInLine = 0;
} else {
@ -649,12 +649,12 @@ void LexerATNSimulator::consume(CharStream *input) {
input->consume();
}
std::wstring LexerATNSimulator::getTokenName(int t) {
std::string LexerATNSimulator::getTokenName(int t) {
if (t == -1) {
return L"EOF";
return "EOF";
}
//if ( atn.g!=null ) return atn.g.getTokenDisplayName(t);
return std::wstring(L"'") + static_cast<wchar_t>(t) + std::wstring(L"'");
return std::string("'") + static_cast<char>(t) + std::string("'");
}
void LexerATNSimulator::InitializeInstanceFields() {

View File

@ -230,13 +230,13 @@ namespace atn {
dfa::DFA& getDFA(size_t mode);
/// Get the text matched so far for the current token.
virtual std::wstring getText(CharStream *input);
virtual std::string getText(CharStream *input);
virtual size_t getLine() const;
virtual void setLine(size_t line);
virtual int getCharPositionInLine();
virtual void setCharPositionInLine(int charPositionInLine);
virtual void consume(CharStream *input);
virtual std::wstring getTokenName(int t);
virtual std::string getTokenName(int t);
private:
void InitializeInstanceFields();

View File

@ -83,7 +83,7 @@ namespace atn {
virtual size_t hashCode() const = 0;
virtual bool operator == (const LexerAction &obj) const = 0;
virtual std::wstring toString() const = 0;
virtual std::string toString() const = 0;
};
} // namespace atn

Some files were not shown because too many files have changed in this diff Show More