Commit Graph

193 Commits

Author SHA1 Message Date
Ewan Mellor 64048caf12
Implement UnbufferedCharStream in the Swift runtime.
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.
2017-10-25 13:31:19 -07:00
Ewan Mellor 7dd4017f41
Tidy up the exception behavior around IntervalSet and ATNConfigSet.
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.
2017-10-25 13:30:40 -07:00
Ewan Mellor fbe8c0d2a6
Tidy up the exception handling around RecognitionException.
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.
2017-10-25 13:30:08 -07:00
Ewan Mellor 7e03b0857a
Remove Utils.RuntimeException.
This was doing nothing for us that we couldn't already get with fatalError,
so it was just cluttering things.
2017-10-25 13:28:40 -07:00
Ewan Mellor 6c11160b51
Remove tokenNames / getTokenNames from the Recognizer interface.
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).
2017-10-25 13:28:40 -07:00
Ewan Mellor 23f532ddbd
Minor tidyups in the Swift runtime.
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.
2017-10-25 13:28:40 -07:00
Ewan Mellor f41316f934
Remove some stub functions from ATNSimulator.
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.
2017-10-25 13:28:40 -07:00
Ewan Mellor 8c03ef3138
Remove unused Utils.{readFile2String,readFile2StringByPath,writeFile}. 2017-10-25 13:28:39 -07:00
Ewan Mellor 5a99f1f7a8
Remove unused generic type parameter on UnbufferedTokenStream. 2017-10-25 13:28:38 -07:00
Ewan Mellor 70db334a58
Improve MurmurHash in a number of ways:
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).
2017-10-21 15:23:27 -07:00
Hanzhou Shi 0dce38109c Update boot.py and swift-target.md to reflect Swift 4 migration changes. 2017-10-21 12:44:44 -07:00
Terence Parr c9c7561701 Merge pull request #2032 from ewanmellor/swift-4
Migrate the Swift runtime to Swift 4.
2017-10-21 12:26:29 -07:00
Ewan Mellor 7aa6b544d9
Redo Package.swift for Swift Package Manager 4.0. 2017-10-20 10:12:47 -07:00
Ewan Mellor 8a292c0f4f
Migrate the Swift runtime to Swift 4.
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.
2017-10-20 10:12:46 -07:00
Ewan Mellor 365d4f40bb
Refactor to avoid forced casts. 2017-10-20 10:12:46 -07:00
Ewan Mellor 4bafc74e6c
Remove unused functions from StringExtension.
Some of these are subject to change for Swift 4, but since they are unused
we should remove them anyway.
2017-10-20 10:12:46 -07:00
Ewan Mellor 8ba2c0ba4f
Add entries to .gitignore for the files that are generated by
Swift Package Manager.
2017-10-20 10:12:46 -07:00
Ewan Mellor 5df3b2bbdf
Remove ANTLRError.nullPointer from the Swift runtime.
This was copied from the API of the equivalent code in Java when
the runtime was ported to Swift.  It is meaningless in Swift, and
was unused.
2017-10-12 00:52:44 -07:00
Hanzhou Shi 22caddc12f Autopass for doc conversion. 2017-07-29 23:28:15 -07:00
Hanzhou Shi 82b2480fe5 Tweak HTML comments. 2017-07-29 22:53:44 -07:00
Hanzhou Shi 0137218930 Removing dead code, malformed documentations, etc. 2017-07-29 17:27:33 -07:00
Hanzhou Shi 4c0bbfd768 Marking Mutex.synchronized with rethrow. 2017-06-03 22:57:22 -07:00
Hanzhou Shi 53b83d7184 Refactored synchronization by using mutex. 2017-06-03 22:57:22 -07:00
Hanzhou Shi 13769268c9 fixing string issue. 2017-06-03 22:57:21 -07:00
Hanzhou Shi a64ec12e73 fixing tests, and some cleanups. 2017-06-03 22:57:21 -07:00
Hanzhou Shi a879297bb5 swift build & swift test support Linux platform 2017-06-03 22:57:21 -07:00
Hanzhou Shi d66f89db52 Removed xcworkspace. 2017-06-03 22:57:20 -07:00
Hanzhou Shi 67f683d0ac Adding generation of dyanmically linked lib. 2017-06-03 22:57:20 -07:00
Hanzhou Shi 834f1ede27 Find antlr4 runtime instead of hardcoding. 2017-05-09 21:31:32 -07:00
Hanzhou Shi c53bd27734 Get rid of xcodeproj file. 2017-05-08 22:37:21 -07:00
Hanzhou Shi 55f9c06509 Now can generate xcode project. 2017-05-08 22:36:29 -07:00
Hanzhou Shi 9f41e6fd9d Adding support for generating local ANTLR Swift repo. 2017-05-08 22:28:46 -07:00
Hanzhou Shi d5f37015ab Adding more commands and comments. 2017-05-07 22:48:36 -07:00
Hanzhou Shi c13964868c Renaming test.py to boot.py and make it more general. 2017-05-07 22:37:48 -07:00
Hanzhou Shi 07048fe787 Fixing unit tests. 2017-04-02 09:41:55 -07:00
Hanzhou Shi b5caa8e945 Migrating to Swift 3.1. 2017-04-01 22:47:45 -07:00
hanzhos e254f346a4 Fixing Xcode project setting. 2017-03-31 14:56:52 -07:00
Jonas Auer 531f9f85dc Merge remote-tracking branch 'upstream/master' 2017-03-30 23:32:07 +02:00
Jonas Auer 7212b5d445 Fix spelling of StringExtension.swift 2017-03-30 23:28:47 +02:00
Jonas Auer acad3365cf Remove public modifier from String extension 2017-03-30 23:16:51 +02:00
Jonas Auer 315c28af7c Remove unused String.contains(_:) extension 2017-03-30 23:16:35 +02:00
parrt b5648f405b tweak documentation about various targets 2017-03-30 10:44:28 -07:00
Jonas Auer 79eb3721e4 Obsolete String.contains(_:) of Swift runtime
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.
2017-03-28 11:52:32 +02:00
Hanzhou Shi e334b0df86 Adding visitor tests. 2017-03-23 22:51:21 -07:00
Hanzhou Shi 91ce56c7fd Tweak Run Script phase. 2017-03-23 22:51:21 -07:00
Hanzhou Shi c3dc1b0d68 Update grammar name to align with JAVA tests. 2017-03-23 22:51:21 -07:00
Hanzhou Shi 2dab85ce2b Fixed printing of RewriteOps, now tests are passing. 2017-03-23 22:51:21 -07:00
Hanzhou Shi cb396a5047 Fixes #550 by separate op for insertAfter. 2017-03-23 22:51:21 -07:00
Hanzhou Shi cefd2c6528 Adding TokenStreamRewriterTests. 2017-03-23 22:51:20 -07:00
Hanzhou Shi 6d2b5b6790 Added "run script" build phase that can generate parser files. 2017-03-23 22:51:20 -07:00
Hanzhou Shi 0c71574c8e Specify output folder so generated files can be ignored correctly. 2017-03-05 20:56:29 -08:00
Hanzhou Shi e1898324df Run "swift test" in test. 2017-03-05 20:49:02 -08:00
Hanzhou Shi b66ffe86f9 Remove generated parser files and added testRig.
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.
2017-03-05 20:44:22 -08:00
parrt e353fa0484 update comment @since tag to 4.7.1 2017-03-01 14:53:43 -08:00
Hanzhou Shi 38c3aaae8f Implements #1674 "augment TerminalNode with setParent()" for Swift target. 2017-02-25 09:17:37 -08:00
Hanzhou Shi 392c637565 Implements #1665 for Swift target. Slightly different because #899 was not addressed in Swift target. 2017-02-24 23:14:24 -08:00
parrt 6215f18ec3 rename 4.6.1 to 4.7 everywhere 2017-02-23 14:48:58 -08:00
Ben Hamilton fd4246cf3f Implement new extended Unicode escape \u{10ABCD}. Bump UUID. Add lots more tests. 2017-02-23 09:39:44 -08:00
Ben Hamilton b190b6eca6 MAX_CHAR_VALUE to 0x10FFFF 2017-02-16 09:46:09 -08:00
Ivan Kochurkin 7b8ba3550b channelNames support in LexerInterpreter (C#, C++, Java, Swift). 2017-01-31 00:34:10 +03:00
Ivan Kochurkin 8359a998b6 Updated generated files. 2017-01-31 00:34:10 +03:00
Ivan Kochurkin c3d96eb5d7 Added channelNames to all runtimes. 2017-01-31 00:32:21 +03:00
Hanzhou Shi 7c24680e3c Reset fetchedEOF in BufferedTokenStream after setTokenSource is called. Fixes #1584. 2017-01-16 00:39:01 -08:00
Hanzhou Shi 893ed8449b Tweak xcodeproj 2017-01-16 00:23:26 -08:00
Hanzhou Shi 8fd99fe8d9 Adding Package.swift for SPM integration 2017-01-16 00:23:26 -08:00
Hanzhou Shi 139225f76c convert documentation to Swift style 2017-01-16 00:23:26 -08:00
Hanzhou Shi ee82046201 Reorg Swift runtime file structure. 2017-01-16 00:23:25 -08:00
parrt 2629433830 bump version to 4.6.1 in all files. 2016-12-28 12:03:43 -08:00
Sam Harwell 24b20e236f Remove redundant isExpectedToken check
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.
2016-12-27 17:21:25 -06:00
Sam Harwell 8b21cc3dfb Fix DefaultErrorStrategy.sync handling of end of rule
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
2016-12-23 16:28:46 -06:00
Akos Kiss cbac45e6ed Fix documentation of getHiddenTokensToRight in BufferedTokenStream 2016-12-22 11:24:26 +01:00
Terence Parr dd2f0a964f Merge pull request #1509 from janyou/Fixes-1073
Fixes #1073 for Swift target
2016-12-14 13:25:46 -08:00
Terence Parr fd3bd91828 Merge pull request #1508 from janyou/Fixes-1298
Fixes #1298 for Swift target
2016-12-14 13:25:27 -08:00
Terence Parr 8b75e3fc5b Merge pull request #1505 from janyou/Fixes-1238-994
Swift target Fixes #1238, Fixes #994
2016-12-14 13:25:04 -08:00
janyou 0c835a248a Fixes #1298 2016-12-14 11:58:53 +08:00
janyou be1b070a1a Fixes #1073 2016-12-14 11:40:07 +08:00
janyou f964dd4af0 Fixes #1042 2016-12-14 11:14:02 +08:00
janyou c9508b74a4 Fixes #1238, Fixes #994 2016-12-14 09:09:40 +08:00
parrt 2c99f187a0 make it read "Copyright (c) 2012-2016 The ANTLR Project" 2016-12-08 11:43:06 -08:00
parrt 1b1a9862c4 contributors->authors 2016-12-08 11:43:06 -08:00
parrt 61e8eba4fc fix typo 2016-12-08 11:43:06 -08:00
parrt 03c2426e9c add/update copyrights on swift. @janyou, I removed your jlabs copyright notice, replacing with antlr project copyright per contributors.txt 2016-12-08 11:40:30 -08:00
Terence Parr 2c63e95359 Merge pull request #1438 from ewanmellor/swift-playground
Create a new Xcode playground for Swift.
2016-12-03 10:48:03 -08:00
Ewan Mellor b0c3824357 Create a new Xcode playground for Swift.
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.
2016-12-01 01:23:52 -08:00
Ewan Mellor ee0babaa8f Update the bundle identifiers.
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.
2016-12-01 00:55:15 -08:00
Ewan Mellor 20ef01c442 Update the Xcode project to match the recommended values in Xcode 8.1. 2016-12-01 00:55:15 -08:00
hanjoes e0b326677b Migrating the current Swift tests to the new testing framework. 2016-11-19 18:30:48 -08:00
janyou 281d624751 Update RuntimeMetaData.swift 2016-11-19 18:30:48 -08:00
janyou 033e5ed136 Update Trees.swift 2016-11-19 18:30:48 -08:00
janyou e3cc81bc32 Update RuleContext.swift 2016-11-19 18:30:48 -08:00
janyou 97c5ebd359 Update Parser.swift 2016-11-19 18:30:48 -08:00
Ewan Mellor 1c6f6c4aed Ignore .xcuserdata, and remove those that were here already. 2016-11-19 18:30:48 -08:00
Ewan Mellor 69d9cfe302 Added a Swift runtime.
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.
2016-11-19 18:30:48 -08:00