Merge branch 'master' of github.com:antlr/antlr4

This commit is contained in:
parrt 2017-11-05 08:49:04 -08:00
commit b4c34da1f0
16 changed files with 121 additions and 42 deletions

View File

@ -2,9 +2,13 @@ sudo: true
language: java
before_cache:
- rm -rf $HOME/.m2/repository/org/antlr
cache:
timeout: 600
directories:
- $HOME/.m2
- $HOME/Library/Caches/Antlr4
- $HOME/Library/Caches/Homebrew
stages:

View File

@ -2,6 +2,11 @@
set -euo pipefail
cache_dir="$HOME/Library/Caches/Antlr4"
dotnet_url='https://download.microsoft.com/download/B/9/F/B9F1AF57-C14A-4670-9973-CDF47209B5BF/dotnet-dev-osx-x64.1.0.4.pkg'
dotnet_file=$(basename "$dotnet_url")
dotnet_shasum='63b5d99028cd8b2454736076106c96ba7d05f0fc'
thisdir=$(dirname "$0")
# OpenSSL setup for dotnet core
@ -10,10 +15,23 @@ ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
# download dotnet core
curl https://download.microsoft.com/download/B/9/F/B9F1AF57-C14A-4670-9973-CDF47209B5BF/dotnet-dev-osx-x64.1.0.4.pkg -o /tmp/dotnet-dev-osx-x64.1.0.4.pkg
mkdir -p "$cache_dir"
(cd "$cache_dir"
if [ -f "$dotnet_file" ]
then
if ! shasum -s -c <<<"$dotnet_shasum $dotnet_file"
then
rm -f "$dotnet_file"
fi
fi
if ! [ -f "$dotnet_file" ]
then
curl "$dotnet_url" -o "$dotnet_file"
fi
)
# install dotnet core
sudo installer -pkg /tmp/dotnet-dev-osx-x64.1.0.4.pkg -target /
sudo installer -pkg "$cache_dir/$dotnet_file" -target /
# make the link
ln -s /usr/local/share/dotnet/dotnet /usr/local/bin/

View File

@ -1,5 +1,7 @@
#!/bin/bash
set -euo pipefail
# linux specific setup, those setup have to be
# here since environment variables doesn't pass
# across scripts
@ -13,10 +15,20 @@ if [ $TRAVIS_OS_NAME == "linux" ]; then
curl https://swift.org/builds/$SWIFT_VERSION-release/ubuntu1404/$SWIFT_VERSION-RELEASE/$SWIFT_VERSION-RELEASE-ubuntu14.04.tar.gz -s | tar xz -C swift &> /dev/null
fi
if [ -z "${JAVA_HOME-}" ]
then
export JAVA_HOME="$(dirname $(java -XshowSettings:properties -version 2>&1 |
grep 'java\.home' | awk '{ print $3 }'))"
fi
# check swift
swift --version
swift build --version
pushd ../runtime/Swift
./boot.py --test
popd
if [ $GROUP == "LEXER" ]; then
mvn -q -Dgroups="org.antlr.v4.test.runtime.category.LexerTests" -Dtest=swift.* test
elif [ $GROUP == "PARSER" ]; then

View File

@ -1,4 +1,7 @@
version: '4.7.1-SNAPSHOT+AppVeyor.{build}'
cache:
- '%USERPROFILE%\.m2'
- '%USERPROFILE%\.nuget\packages -> **\project.json'
build: off
build_script:
- mvn -DskipTests install --batch-mode

View File

@ -170,3 +170,4 @@ YYYY/MM/DD, github id, Full name, email
2017/10/27, Griffon26, Maurice van der Pot, griffon26@kfk4ever.com
2017/05/29, rlfnb, Ralf Neeb, rlfnb@rlfnb.de
2017/10/29, gendalph, Максим Прохоренко, Maxim\dotProhorenko@gm@il.com
2017/11/02, jasonmoo, Jason Mooberry, jason.mooberry@gmail.com

View File

@ -59,8 +59,7 @@ Now, make sure C# runtime is built and installed locally.
```bash
cd ~/antlr/code/antlr4/runtime/CSharp/runtime/CSharp
# kill previous ones manually as "xbuild /t:Clean" didn't seem to do it
rm Antlr4.Runtime/bin/net20/Release/Antlr4.Runtime.dll
rm Antlr4.Runtime/obj/net20/Release/Antlr4.Runtime.dll
find . -name '*.dll' -exec rm {} \;
# build
xbuild /p:Configuration=Release Antlr4.Runtime/Antlr4.Runtime.mono.csproj
```

View File

@ -19,6 +19,16 @@ except you need to specify the language target, for example:
```
$ antlr4 -Dlanguage=Swift MyGrammar.g4
```
If you integrate this as a build step inside Xcode, then you should use the
"gnu" message format to have any error messages parsed by Xcode. You may
also want to use the `-o` option to put the autogenerated files in a
separate subdirectory.
```
antlr4 -Dlanguage=Swift -message-format gnu -o Autogen MyGrammar.g4
```
For a full list of antlr4 tool options, please visit the
[tool documentation page](tool-options.md).

14
pom.xml
View File

@ -130,6 +130,20 @@
<directory>test</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<filesets>
<fileset>
<directory>runtime/Swift/.build</directory>
<directory>runtime/Swift/Tests/Antlr4Tests/gen</directory>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>

View File

@ -92,7 +92,7 @@ open class Lexer: Recognizer<LexerATNSimulator>, TokenSource {
self._tokenFactorySourcePair.tokenSource = self
}
public init(_ input: CharStream) {
public required init(_ input: CharStream) {
self._input = input
self._tokenFactorySourcePair = TokenSourceAndStream()
super.init()

View File

@ -18,19 +18,6 @@ public class LexerInterpreter: Lexer {
internal final var _decisionToDFA: [DFA]
internal final var _sharedContextCache = PredictionContextCache()
// public override init() {
// super.init()}
// public convenience init(_ input : CharStream) {
// self.init()
// self._input = input;
// self._tokenFactorySourcePair = (self, input);
// }
//@Deprecated
public convenience init(_ grammarFileName: String, _ tokenNames: Array<String?>?, _ ruleNames: Array<String>, _ channelNames: Array<String>, _ modeNames: Array<String>, _ atn: ATN, _ input: CharStream) throws {
try self.init(grammarFileName, Vocabulary.fromTokenNames(tokenNames), ruleNames, channelNames, modeNames, atn, input)
}
public init(_ grammarFileName: String, _ vocabulary: Vocabulary, _ ruleNames: Array<String>, _ channelNames: Array<String>, _ modeNames: Array<String>, _ atn: ATN, _ input: CharStream) throws {
self.grammarFileName = grammarFileName
@ -54,6 +41,10 @@ public class LexerInterpreter: Lexer {
}
}
public required init(_ input: CharStream) {
fatalError("Use the other initializer")
}
override
public func getATN() -> ATN {
return atn

View File

@ -19,6 +19,8 @@ import Foundation
* code points in the buffer as ints.
*/
open class UnbufferedCharStream: CharStream {
private let bufferSize: Int
/**
* A moving window buffer of the data being scanned. While there's a marker,
* we keep adding to buffer. Otherwise, {@link #consume consume()} resets so
@ -77,6 +79,7 @@ open class UnbufferedCharStream: CharStream {
public init(_ input: InputStream, _ bufferSize: Int = 256) {
self.input = input
self.bufferSize = bufferSize
self.data = [Int](repeating: 0, count: bufferSize)
let si = UInt8StreamIterator(input)
self.unicodeIterator = UnicodeScalarStreamIterator(si)
@ -159,13 +162,6 @@ open class UnbufferedCharStream: CharStream {
}
public func LA(_ i: Int) throws -> Int {
let result = try LA_(i)
print("LA(\(i)) -> \(result)")
return result
}
private func LA_(_ i: Int) throws -> Int {
if i == -1 {
return lastChar // special case
}
@ -212,11 +208,16 @@ open class UnbufferedCharStream: CharStream {
// Copy data[p]..data[n-1] to data[0]..data[(n-1)-p], reset ptrs
// p is last valid char; move nothing if p==n as we have no valid char
let dataCapacity = data.capacity
data = Array(data[p ..< n])
data += [Int](repeating: 0, count: dataCapacity - (n - p))
precondition(data.capacity == dataCapacity)
n = n - p
if p == n {
if data.count != bufferSize {
data = [Int](repeating: 0, count: bufferSize)
}
n = 0
}
else {
data = Array(data[p ..< n])
n -= p
}
p = 0
lastCharBufferStart = lastChar
}
@ -344,11 +345,14 @@ fileprivate struct UInt8StreamIterator: IteratorProtocol {
break
}
let count = stream.read(&buffer, maxLength: buffer.capacity)
if count <= 0 {
let count = stream.read(&buffer, maxLength: buffer.count)
if count < 0 {
hasErrorOccurred = true
return nil
}
else if count == 0 {
return nil
}
buffGen = buffer.prefix(count).makeIterator()
return buffGen.next()

View File

@ -964,7 +964,7 @@ open class <lexer.name>: <superClass; null="Lexer"> {
return <lexer.name>.VOCABULARY
}
public override init(_ input: CharStream) {
public required init(_ input: CharStream) {
RuntimeMetaData.checkVersion("<lexerFile.ANTLRVersion>", RuntimeMetaData.VERSION)
super.init(input)
_interp = LexerATNSimulator(self, <lexer.name>._ATN, <lexer.name>._decisionToDFA, <lexer.name>._sharedContextCache)

View File

@ -31,9 +31,9 @@ This file contains the actual layout of the messages emitted by ANTLR.
This file contains the format that mimicks GCC output.
*/
location(file, line, column) ::= "<file>:<line>:"
location(file, line, column) ::= "<file>:<line>:<column>:"
message(id, text) ::= "<text> (<id>)"
message(id, text) ::= "<text> [error <id>]"
report(location, message, type) ::= "<location> <type>: <message>"

View File

@ -193,8 +193,11 @@ public class Tool {
public Tool(String[] args) {
this.args = args;
errMgr = new ErrorManager(this);
errMgr.setFormat(msgFormat);
// We have to use the default message format until we have
// parsed the -message-format command line option.
errMgr.setFormat("antlr");
handleArgs();
errMgr.setFormat(msgFormat);
}
protected void handleArgs() {
@ -248,7 +251,7 @@ public class Tool {
haveOutputDir = true;
if (outDir.exists() && !outDir.isDirectory()) {
errMgr.toolError(ErrorType.OUTPUT_DIR_IS_FILE, outputDirectory);
libDirectory = ".";
outputDirectory = ".";
}
}
else {

View File

@ -49,8 +49,18 @@ public class GoTarget extends Target {
"make", "new", "panic", "print", "println", "real", "recover"
};
// interface definition of RuleContext from runtime/Go/antlr/rule_context.go
private static final String[] goRuleContextInterfaceMethods = {
"Accept", "GetAltNumber", "GetBaseRuleContext", "GetChild", "GetChildCount",
"GetChildren", "GetInvokingState", "GetParent", "GetPayload", "GetRuleContext",
"GetRuleIndex", "GetSourceInterval", "GetText", "IsEmpty", "SetAltNumber",
"SetInvokingState", "SetParent", "String"
};
/** Avoid grammar symbols in this set to prevent conflicts in gen'd code. */
private final Set<String> badWords = new HashSet<String>(goKeywords.length + goPredeclaredIdentifiers.length + 3);
private final Set<String> badWords = new HashSet<String>(
goKeywords.length + goPredeclaredIdentifiers.length + goRuleContextInterfaceMethods.length + 3
);
private static final boolean DO_GOFMT = !Boolean.parseBoolean(System.getenv("ANTLR_GO_DISABLE_GOFMT"))
&& !Boolean.parseBoolean(System.getProperty("antlr.go.disable-gofmt"));
@ -75,6 +85,7 @@ public class GoTarget extends Target {
protected void addBadWords() {
badWords.addAll(Arrays.asList(goKeywords));
badWords.addAll(Arrays.asList(goPredeclaredIdentifiers));
badWords.addAll(Arrays.asList(goRuleContextInterfaceMethods));
badWords.add("rule");
badWords.add("parserRule");
badWords.add("action");

View File

@ -60,11 +60,20 @@ public class ErrorManager {
locationValid = true;
}
if (msg.fileName != null) {
File f = new File(msg.fileName);
// Don't show path to file in messages; too long.
String displayFileName = msg.fileName;
if ( f.exists() ) {
displayFileName = f.getName();
if (format.equals("antlr")) {
// Don't show path to file in messages in ANTLR format;
// they're too long.
File f = new File(msg.fileName);
if ( f.exists() ) {
displayFileName = f.getName();
}
}
else {
// For other message formats, use the full filename in the
// message. This assumes that these formats are intended to
// be parsed by IDEs, and so they need the full path to
// resolve correctly.
}
locationST.add("file", displayFileName);
locationValid = true;