Commit Graph

6861 Commits

Author SHA1 Message Date
zqlu.cn c360a05919 update contributors.txt 2017-11-24 16:41:18 +08:00
zqlu.cn 88a7580b78 Fix interval usage
For JavaScript runtime, Interval class constructor assume start and stop
to be number.
2017-11-24 16:37:40 +08:00
Ewan Mellor ed52b5a053
Add an accessLevel parser option.
Add an accessLevel parser option.  Use this to specify the access level
(public, etc) used on the classes and protocols in the generated
parser / lexer / listeners.  This required adding the option to
tool.Grammar.parserOptions so that it was known as a valid option, and
to codegen.model.{Recognizer,ListenerFile,VisitorFile} so that it was
available to the template in all the necessary contexts.

The Swift template has been extended to recognize this option, and generate
classes and members using "open", "public" or "internal" as appropriate.

This is only fully implemented for Swift.  The option is generic, but
the language-specific templates will need to be updated for any language
that would like similar support.

Closes #1597.
2017-11-16 00:18:28 -08:00
Ewan Mellor 22337f35c0
[CSharp] Add a retry if we get SIGILL when running dotnet.
Issue #2078 is a crash (SIGILL) inside the dotnet runtime when running on
macOS on Travis.  This is intermittent, so a retry may help.  Retry this
specific exit status inside runProcess.
2017-11-14 13:33:01 -08:00
Ewan Mellor 84eca87da2
[CSharp] Switch Travis / macOS to .NET Core 1.1.4.
Switch to .NET Core SDK 1.1.4 for the Travis macOS tests.  This is
the LTS release at the moment.

Issue #2078 is starting to look like a crash (SIGILL) inside the dotnet
runtime, so this upgrade may help with that.
2017-11-14 01:47:33 -08:00
Ewan Mellor cbb10279ab
[CSharp] Add extra diagnostics to the C# runtime tests.
Log the command / stdout / stderr / exit status at three places
during the C# runtime tests.

At these places we are executing subprocesses, but if those fail we
weren't logging the info that we may need to diagnose the problem.
2017-11-14 01:40:54 -08:00
Ewan Mellor 0ba9808982
[CSharp] Assert that test compilation succeeded.
Assert that the dotnet restore / build commands succeeded.  If we
get a failure at this point, the test is obviously going to fail, and
we're masking the error by trying to push on with other commands.
2017-11-14 01:40:54 -08:00
Rostislav Listerenko 9ec6c665d5 #2021 nuget artifact in appveyor 2017-11-13 08:47:15 +03:00
Terence Parr e158824ca8 Merge branch 'mike-lischke-interpreter2' 2017-11-12 15:48:29 -08:00
Terence Parr 0e895afb04 don't generate interp data if there are errors (it needs to serialize ATN which can fail upon error). 2017-11-12 15:47:46 -08:00
Rostislav Listerenko 5b5f195b12 #2021 fixes nuget packaging options to avoid missing dll exceptions in transitive dependencies 2017-11-12 16:11:12 +03:00
Ewan Mellor 2e0ed500dc
[CSharp] Print the stack trace if compilation fails. 2017-11-11 22:24:16 -08:00
Ewan Mellor eb9124fff8
[Swift] Fix parse-cancellation in BailErrorStrategy.
BailErrorStrategy is supposed to throw an error that's different from
the ordinary recognition error, specifically so that it can be handled
differently by client code.  This was not ported over from Java correctly.

Fix this by moving parseCancellation from ANTLRError to ANTLRException,
adding its RecognitionException argument, and throwing it from the
two handlers in BailErrorStrategy.

Also remove ANTLRException.cannotInvokeStartRule, which is unused.
(The Java runtime uses it when ParseTreePatternMatcher throws a generic
exception, but we don't have that.)
2017-11-11 10:45:38 -08:00
Mike Lischke eaed562cb3 Merge branch 'master' into interpreter2 2017-11-11 11:06:53 +01:00
Ewan Mellor 7cf8ef7bc5
[Swift] Remove ArrayList.
This was only used in some commented-out debugging code.  Swift has
perfectly good array types, we don't need to implement our own.
2017-11-10 18:46:06 -08:00
Ewan Mellor 6cc35ad677
[Swift] Remove pointless do block from LexerATNSimulator.
Remove pointless do block from LexerATNSimulator.  This is a translation
from Java of a try/finally block, but we have the finally clause in a
defer block so we don't need the do block.
2017-11-10 18:12:19 -08:00
Ewan Mellor e2f4cdc68d
[Swift] Some minor tidyups.
Minor tidyups in the Swift runtime.  No semantic change.
2017-11-10 18:12:19 -08:00
Ewan Mellor e77d690e36
Report errors in ANTLRFileStream.
Change the initializer to ANTLRFileStream so that it throws any errors that
occur while reading the file.  Previously, it was just dropping any errors on
the floor (inside Utils.readFile).

Remove Utils.readFile, it's not used anywhere else.
2017-11-10 18:06:12 -08:00
Ewan Mellor 2b00ca06aa
[Swift] Fix initialization of {Lexer,Parser}Interpreter.decisionToDFA.
Fix initialization of {Lexer,Parser}Interpreter.decisionToDFA.  These
were always being created as empty arrays, which would never work.

I don't know if anyone's using this code; presumably not.
2017-11-10 17:52:50 -08:00
Ewan Mellor b2a55d1bec
[Swift] Remove unused ATN.modeNameToStartState.
Remove unused ATN.modeNameToStartState.  In the Java runtime this is
only used by LexerATNFactory (i.e. during lexer generation) and we don't
have the equivalent in the Swift runtime at all.
2017-11-10 16:50:43 -08:00
Ewan Mellor 167a3b8808
[Swift] Remove Recognizer.tokenTypeMapCache and .ruleIndexMapCache.
Remove Recognizer.tokenTypeMapCache and .ruleIndexMapCache.  These
were easily replaced in Swift with lazy vars.  The input to these
two caches are fixed fields on the Recognizer (the Vocabulary and
rule names respectively) so a lazy var suffices.

Note that these differed compared with the Java runtime -- they are
declared as static in Java and therefore the caches are shared across
all recognizer instances, but the Swift runtime had them as Recognizer
instance variables, which meant that at most we had a cache with one
entry which got destroyed along with the parser.  Regardless, using
lazy vars is still simpler.

This removes the only usage of ArrayWrapper in the Swift runtime, so
delete that too.
2017-11-10 16:45:24 -08:00
Ewan Mellor 19c0ecaedf
[Swift] Remove Triple.swift.
This is not in use.  It never has been, as far as I can see.
2017-11-10 15:02:05 -08:00
Ewan Mellor 4baedb5e7b
[Swift] Make ATNSimulator.sharedContextCache non-optional.
Make ATNSimulator.sharedContextCache declared as non-optional.  It
was used this way anyway, so it was just being pointlessly forced
at the use-sites.
2017-11-09 15:12:21 -08:00
Ewan Mellor b548999b16
[Swift] Make DFA.precedenceDfa be a "let" rather than a "var".
Make DFA.precedenceDfa be a "let" rather than a "var", and remove
setPrecedenceDfa.  This field never varies after construction.  The
code in setPrecedenceDfa was carried over from the Java runtime, but
it only threw an exception, and was deprecated.  There's no need for
that in the Swift runtime.
2017-11-09 14:56:39 -08:00
Ewan Mellor afdfb56b59
[Swift] Replace IntervalSet.setReadonly with makeReadonly.
Replace IntervalSet.setReadonly(Bool) with makeReadonly().  This
operation only ever works in one direction, and would throw an exception
if a caller attempted to make a read-only IntervalSet read-write again.
By changing the interface we remove the need to check this, and so we
don't need to declare the exception.  Unlike in the Java runtime, we
need to declare the possibility of the exception at the callsite, so this
was pointlessly cluttering.
2017-11-09 14:49:45 -08:00
Ewan Mellor 06300e82bc
[Swift] Make all the mutexes "let" rather than "var".
Make all the mutexes in the Swift runtime use "let" rather than "var".

They are never changed, and they wouldn't make good mutexes if they were.
2017-11-09 14:44:50 -08:00
Ewan Mellor 00753dd8c9
Simplify ParseTree and ParserRuleContext.
Make ParseTree, RuleNode, and TerminalNode be protocols rather than
classes.  These had no useful functionality (which is not surprising,
since they are interfaces in the Java implementation) so there is
no need for them to be classes.  This reduces the depth of the inheritance
tree.

Add a subscript getter to ParseTree (and corresponding implementations in
the concrete classes).  This has two advantages over Tree.getChild(_: Int):
it can be declared to return ParseTree rather than Tree, and it can fault
on index-out-of-range rather than returning nil.  Note that covariant
specialization of the return type is not supported through protocols in Swift
yet (https://bugs.swift.org/browse/SR-522).  This means that ParseTree
cannot specialize Tree.getChild()'s return type in the way that the Java
implementation does.

Remove the return value from addChild / addErrorNode / addAnyChild.
This kind of chaining where a function returns its parameter does not fit
well with Swift's generics / protocols model.
2017-11-07 17:16:10 -08:00
Ewan Mellor 8c2f80f1c7
Tidy-ups inside the Swift runtime.
Change ParserRuleContext.exception to be RecognitionException?
rather than AnyObject!.  I don't know why it was declared that
way because the Java code uses RecognitionException.

Remove ParserRuleContext.addChild(Token) and addErrorNode(Token).
These are deprecated in the Java code and there was no need to
bring them over to the Swift runtime.

Fix ParserRuleContext.toInfoString, which was mangled when it was
ported from Java.

Various other tidyups: removal of useless type annotations, use of
if let, etc.
2017-11-07 17:14:44 -08:00
Ewan Mellor 5dd835f0a1
Merge branch 'swift-fix-uuid-extension' into swift-fix-deprecated-string-methods 2017-11-07 17:06:20 -08:00
Ewan Mellor ba392be1af
Remove use of deprecated String functions in StringExtension.
Remove some functions that are no longer used, and update the
rest to Swift 4's String API.  lastIndexOf changes to lastIndex(of: ),
matching the standard library naming conventions, and returns a
String.Index? instead of an Int.

Add an implementation of Substring.hasPrefix for Linux; this
is in the Apple standard library but not the Linux one.
https://bugs.swift.org/browse/SR-5627

Add unit tests for StringExtension.

Bump the Swift download for the Travis Linux tests from 4.0
to 4.0.2.  There is a bug in Substring.range(of:) in 4.0.0
(https://bugs.swift.org/browse/SR-5663) that we need to avoid.
2017-11-07 17:06:15 -08:00
Ewan Mellor 15a7b3be24
Rewrite ParseTreePatternMatcher to use standard library
String functions and avoid our custom String extensions.
2017-11-07 17:06:15 -08:00
Ewan Mellor 73d90ec18b
Tidy up some uses of String.characters and integer indexing into Strings.
In Swift 4, Strings have a set of sequence operations that we can use, so
that we don't need our String extensions.  Tidy up a bunch of places where
the code has been converted from Java through Swift 3 and Swift 4, and
become a mess.
2017-11-07 17:06:15 -08:00
Ewan Mellor 775040e186
Remove the toString implementations.
In Swift, we use description for the same thing.  All these just stubbed-over
or replicated the description implementation, except for PredicateTransition
which now implements CustomStringConvertible.
2017-11-07 17:06:15 -08:00
Ewan Mellor 7cfdd9d124
Change TokenStreamRewriter to use an inout String as the execute(buf:)
parameter rather than StringBuilder.

Tidy up the rest of the class on the way through.

This is the last use of StringBuilder, so we can remove that class entirely.
2017-11-07 17:06:15 -08:00
Ewan Mellor 7933999fa6
Remove uses of StringBuilder.
Remove the uses of StringBuilder where it is simply accumulating a String
for us.  In Swift we can use a var String for this; there is no need for
a StringBuilder class like in Java.
2017-11-07 17:06:14 -08:00
Ewan Mellor e2b94c783a
Rewrite RuntimeMetaData.getMajorMinorVersion to use standard library
String functions and avoid our custom String extensions.
2017-11-07 17:06:14 -08:00
Ewan Mellor 08ba9379d8
Added tests for RuntimeMetaData.getMajorMinorVersion. 2017-11-07 17:06:14 -08:00
Ewan Mellor fd8fd175a6
Fix ParseTreePatternMatcher.split in the Swift runtime.
Fix the parsing inside ParseTreePatternMatcher.split.  It was trivially
broken in a number of ways, with bugs that aren't in the Java version
that it was ported from, so it's obviously never been run before.

This adds unit tests for ParseTreePatternMatcher.split, and makes Chunk
implement Equatable, so that it we can compare Chunk instances in the
tests.

Tidy up the description implementations at the same time.
2017-11-07 17:05:22 -08:00
Ewan Mellor 4edb37d136
Open the error strategies to subclasses.
Mark every method in BailErrorStrategy and DefaultErrorStrategy as "open",
so that they can be extended by subclasses in user code.
2017-11-07 17:02:46 -08:00
gendalph e1e6ce5c03 The correction for cmake depends on the demo,
the minimal rebuilding by the generated part.

Only if the grammar files (*.g4) have been changed
2017-11-06 17:53:18 +03:00
Ajay Panyala 154585cffd Update contributors.txt 2017-11-05 13:56:57 -08:00
Ajay Panyala e8a2fbe524 Support building ANTLR Cpp Runtime with Intel compilers 2017-11-05 13:53:56 -08:00
parrt b4c34da1f0 Merge branch 'master' of github.com:antlr/antlr4 2017-11-05 08:49:04 -08:00
Ewan Mellor fd58a8c4fd
Tidy ATNDeserializer.
Remove lots of unnecessary type annotations, replace unnecessarily
complicated static initializers, and use "if let" and "guard let" to remove
lots of casting.

Bring together a couple of hundred lines of copy-paste code between
the deserialize and deserializeFromJson paths.

Fix some obvious bugs in the deserialize path.  This code is entirely unused;
we use deserializeFromJson in the autogenerated parsers.  I'm inclined to
remove deserialize since it was so broken, but I'm leaving it for now, in
case someone needs compatibility with ATNs from different language targets
and wants to fix it.
2017-11-04 12:53:17 -07:00
Ewan Mellor f36a1558ca
Implement UUID.init(mostSigBits, leastSigBits).
The implementation here before just tried to make a UUID from the empty
string.

Remove the unused UUID.toUUID.  It was broken too.

Rename the file that this was in, since NSUUID and Foundation.UUID are not
the same thing.
2017-11-04 12:49:29 -07:00
Terence Parr 676e6f4810
Merge pull request #2099 from ewanmellor/travis-swift-runtime-tests
Run the Swift runtime unit tests during the Travis run.
2017-11-04 12:17:44 -07:00
Terence Parr c1b7bf94f6
Merge pull request #2098 from jasonmoo/rule_context_methods_fix
Add RuleContext interface methods to reserved words
2017-11-04 12:17:13 -07:00
Ewan Mellor 376f7384c3
Run the Swift runtime unit tests during the Travis run.
These are the unit tests that are written in Swift, not the more
in-depth runtime-testsuite tests (we were always running those).

I don't know why JAVA_HOME isn't set during run-tests-swift.sh, but it
isn't.  Set it, since runtime/Swift/boot.py expects it as part of the
parser generation.
2017-11-04 11:41:20 -07:00
Terence Parr 0fd2098b6c
Merge pull request #2096 from ewanmellor/mvn-clean-swift
Include the Swift runtime in "mvn clean".
2017-11-04 10:51:42 -07:00
Terence Parr 58ddf07905
Merge pull request #2093 from ewanmellor/swift-lexer-init-required
Make CharStream.init(CharStream) required (in the Swift runtime).
2017-11-04 10:50:51 -07:00