This is a port of the equivalent code in the Java runtime.
This required a change to the CharStream interface: getText was documented
as throwing exceptions, but it wasn't actually declared as such. The
UnbufferedCharStream.getText implementation throws exceptions (in order to
match the semantics of the Java implementation), so this declaration is now
needed, and callsites need to be adjusted appropriately.
These classes throw exceptions if the instance is read-only, and only in
that case. This means that there is no need for us to propagate exception
declarations in the cases where we have guaranteed by construction
that the instance is writable. In particular, this means that IntervalSet
and ATNConfigSet's constructors won't throw exceptions(!) The set options
that return a new set (e.g. complement) no longer throw either.
To help with this, this cset adds BitSet.firstSetBit(). This is equivalent
to BitSet.nextSetBit(0), but is guaranteed not to throw an exception.
As a consequence, ANTLRErrorListener / DiagnosticErrorListener no longer
throw exceptions through any of their functions (syntaxError and report*),
and DefaultErrorStrategy can no longer throw exceptions as part of its
internal operations (though of course it can still throw exceptions if
recovery fails and a real parsing error needs to be reported).
Also, LL1Analyzer no longer throws exceptions at all, and so ATN.nextTokens
doesn't throw either.
This removes the generic parameter on RecognitionException, to make it
easier to handle them. This means that we no longer need to store them as
AnyObject and cast them back again. To do this, we add RecognizerProtocol,
which is a non-generic equivalent of the Recognizer interface (at least, the
parts of it that we need for error handling).
Remove all paths where the RecognitionException subclasses were throwing
exceptions in their initializers. This is just insane.
This has been ported over from the Java code, but it was deprecated there.
There's no point having it in the Swift runtime because we don't have the
legacy code to support. Also, it wasn't implemented properly, so it
never worked.
Remove {DFA,IntervalSet}.toString(_:[String?]?)
and the inits in ParserInterpreter and DFASerializer for the same reason.
Switch the unit tests to use the alternate toString(_:Vocabulary).
This fixes some hangovers from the port from Java:
* unnecessary type annotations;
* failure to use "if let" for nil checks;
* comments with Java code in them;
* a couple of fields that should have been declared private;
* some whitespace issues.
No semantic change.
These were ported over from the Java runtime, but they were all deprecated
there, and were commented as such here. There is no point having them in
the Swift runtime because we don't have legacy code to support.
Use Swift's overflowing operators rather than multipliedReportingOverflow
etc.
Use UInt32 for the hash values. This matches how MurmurHash3 is generally
defined (e.g. on Wikipedia).
Add support for decoding Strings (UTF-8, then little-endian) and hashing
the resultant UInt32 values.
Add a test set, using test patterns from Ian Boyd (public domain).
Remove a number of generic type constraints, since these can now
be inferred by the compiler.
Match the syntax change when passing a tuple into a function (adding
an extra set of parens).
Change filterPrecedencePredicates to avoid a now-illegal cast.
Match the renames truncatingBitPattern -> truncatingIfNeeded,
multiplyWithOverflow -> multipliedReportingOverflow, etc. In
some cases the multiplyWithOverflow calls are replaced by
overflowing operators (e.g. &*) instead.
Starting with iOS 10, macOS 10.12, tvOS 10.0 and watchOS 3.0, Foundation contains
its own definition of String.contains(_:), which conflicts with the extension
provided by antlr.
Current version of swift package manager doesn't support shell command
or any mechanism that we can leverage to generate parser files. Adding
a python script to kick off the unit tests.
We know by the time this check was reached that neither EPSILON nor the LL(1)
symbol are in the lookahead set from the current state. Since EPSILON is not
included, the state cannot see to the end of the rule and thus nextTokens
contains the complete set of valid LL(1) symbols from the current state. It is
therefore impossible for the LL(1) symbol to be "expected" when considering
lookahead with full context.
This change updates the default sync() strategy to match the strategy used
for selecting an alternative when prediction leaves the decision rule prior
to reaching a syntax error.
Closes#1545
This takes the example from
https://github.com/janyou/Antlr-Swift-Runtime/tree/master/Test and packages
it into an Xcode playground. This allows the user to interact with the
grammar directly inside Xcode, and serves as a live demo of the Swift support.
Update the docs to match.
This changes PRODUCT_BUNDLE_IDENTIFIER to read org.antlr.v4.swift.macos or
org.antlr.v4.swift.ios. This is similar to the naming scheme used in the Java
code.
The previous identifier was jlabs.Antlr4. I don't know what that refers to.
This comes from https://github.com/janyou/Antlr-Swift-Runtime and is
marked Copyright (c) 2015 janyou on top of the BSD license and Copyrights
for Terence Parr and Sam Harwell derived from the original ANTLR source.