Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Big update to the listener events #12

Merged
merged 62 commits into from
Feb 15, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
a5a4035
oops; forgot to update the templates when I renamed the ATN simulator
parrt Feb 6, 2012
59e4a54
alter tests for new parser atn name
parrt Feb 7, 2012
5c79fc6
["\\] didn't work in lexer
parrt Feb 7, 2012
66d82fa
Merge remote-tracking branch 'parrt/master'
sharwell Feb 8, 2012
a6524d8
Add pom.xml to support maven builds
sharwell Feb 8, 2012
18a6414
Use ATNConfigSet for parameter instead of OrderedHashSet<ATNConfig>
sharwell Feb 8, 2012
326cb25
Construct Parser with TokenStream (restriction from IntStream)
sharwell Feb 8, 2012
5225604
Use for each instead of indexed for; use isEmpty() instead of size()==0
sharwell Feb 8, 2012
1df7092
Use ATNConfigSet instead of OrderedHashSet<ATNConfig>
sharwell Feb 8, 2012
2249135
Specify generic type parameters
sharwell Feb 8, 2012
71e0c66
Rename NUM_EDGES to MAX_DFA_EDGE, reduce max value to 127
sharwell Feb 8, 2012
64210f4
Add @NotNull annotations, make ATNConfig.semanticContext field final
sharwell Feb 8, 2012
dcdfac4
Improved implementation of equals() and hashCode() for ATNConfig
sharwell Feb 9, 2012
773e9e1
Add generic type argument
sharwell Feb 9, 2012
6420331
Improved SemanticContext.hashCode(), add @Override annotations
sharwell Feb 9, 2012
21a855e
Specify generic type parameters in generated code
sharwell Feb 9, 2012
d181b23
Specify generic type parameter
sharwell Feb 9, 2012
a9e44f3
Use isEmpty() instead of size()==0, use StringBuilder instead of Stri…
sharwell Feb 9, 2012
a34fd63
Use isEmpty() instead of size()==0
sharwell Feb 9, 2012
f43f9f2
Override CommonTokenStream.reset() to make sure the stream is left on…
sharwell Feb 9, 2012
3b4ae2a
Use trivial implementation of mark/release for BufferedTokenStream
sharwell Feb 9, 2012
5279b25
Use isEmpty() instead of size()==0, use StringBuilder instead of Stri…
sharwell Feb 9, 2012
4f3e40f
Use List instead of Vector
sharwell Feb 9, 2012
33c8f9b
Suppress "cast" warnings in generated code
sharwell Feb 9, 2012
851069d
Hard tabs in generated code
sharwell Feb 9, 2012
32aefbc
Fix start/stop indexes for contexts created by LR rules
sharwell Feb 9, 2012
05a199e
Compile grammars with debug info for tests
sharwell Feb 9, 2012
e5aa949
More informative parameter names
sharwell Feb 9, 2012
0ec084d
Simplified exec code in BaseTest
sharwell Feb 9, 2012
460e449
Merge pull request #1 from sharwell/master
parrt Feb 9, 2012
f5f3861
Fix unit test
sharwell Feb 9, 2012
40a8759
Add LexerATNSimulator.getTraceStream
sharwell Feb 9, 2012
9c554a0
Add LexerATNSimulator.copyState (allows copying state information fro…
sharwell Feb 9, 2012
46094f5
Merge pull request #7 from sharwell/9c554a002b8fd9f72a0005c90cb83ac75…
parrt Feb 10, 2012
f278d3b
add unit test for left-recur grammars
parrt Feb 11, 2012
6e4cba1
Allow var args in ctor of IntervalSet
parrt Feb 11, 2012
b80b22e
rm remnants of tree parser
parrt Feb 12, 2012
808d23e
add some useful classes
parrt Feb 12, 2012
dee579a
oops; need to alter this when removing up/down stuff
parrt Feb 12, 2012
62146c1
Remove redundant null check
sharwell Feb 13, 2012
9600a70
Fix NPE in CommonToken when TokenSource is not available
sharwell Feb 13, 2012
f8285bc
another useful tuple
parrt Feb 13, 2012
3dbf4cd
mid-job push so i can pull from work to continue. working on updating…
parrt Feb 13, 2012
8af1e23
adding tests
parrt Feb 13, 2012
40b3bc0
Merge pull request #9 from sharwell/9600a70724
parrt Feb 13, 2012
43daec6
Merge branch 'master', remote-tracking branch 'origin' into enhance-ctx
parrt Feb 13, 2012
d06b83f
Merge pull request #8 from sharwell/62146c1651620445e96303e5522eddc21…
parrt Feb 13, 2012
ebb8b3a
Merge branch 'master' of github.com:parrt/antlr4 into enhance-ctx
parrt Feb 13, 2012
97ab2c4
mode wasn't working as lexer command
parrt Feb 13, 2012
b68ce1f
almost got ctx stuff working
parrt Feb 13, 2012
146a9b0
Fix unit test placing output files like "null.java" in the project di…
sharwell Feb 13, 2012
7b672c3
Merge pull request #11 from sharwell/clean-tests
parrt Feb 13, 2012
2091f2d
change enterRule to enter in listener interface
parrt Feb 14, 2012
0031075
Merge branch 'master' into enhance-ctx
parrt Feb 14, 2012
203ad46
fixed 8 unit tests; only 9 fail now.
parrt Feb 14, 2012
6c2beb5
see A.g4 for getter syntax; use e() not gete(). adding ContextGetterD…
parrt Feb 14, 2012
a678674
got it generating getters, labels correctly. now to impl getters
parrt Feb 14, 2012
b8f50d4
update playground
parrt Feb 14, 2012
cdb420f
got implementation of getters in! Fixes #8
parrt Feb 14, 2012
e30627c
updated command line options.
parrt Feb 14, 2012
fa3a664
got some good examples working that play around with the getter methods.
parrt Feb 15, 2012
3d56d40
update playground
parrt Feb 15, 2012
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/tool/target/
/runtime/Java/target/
/gunit/target/
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
ANTLR v4 Honey Badger early access

Feb 14, 2012

* Fixed https://github.com/antlr/antlr4/issues/8 and lots of other little things.

Jan 30, 2012

* Moving to github.
Expand Down
80 changes: 80 additions & 0 deletions gunit/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.antlr</groupId>
<artifactId>antlr4-gunit</artifactId>
<version>4.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>antlr4-gunit</name>
<url>http://www.antlr.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr-runtime</artifactId>
<version>3.4.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>ST4</artifactId>
<version>4.0.4</version>
</dependency>
</dependencies>

<build>

<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>resources</directory>
</resource>
</resources>

<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr3-maven-plugin</artifactId>
<version>3.4</version>
<configuration>
<sourceDirectory>src</sourceDirectory>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<goals>
<goal>antlr</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>

</project>
50 changes: 50 additions & 0 deletions runtime/Java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>antlr4-runtime</name>
<url>http://www.antlr.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>ST4</artifactId>
<version>4.0.4-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.abego</groupId>
<artifactId>treelayout.core</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/org.abego.treelayout.core.jar</systemPath>
</dependency>
</dependencies>

<build>

<sourceDirectory>src</sourceDirectory>

<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>

</project>
9 changes: 5 additions & 4 deletions runtime/Java/src/org/antlr/v4/runtime/ANTLRErrorStrategy.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.antlr.v4.runtime;

import org.antlr.v4.runtime.atn.ATNConfig;
import org.antlr.v4.runtime.atn.ATNConfigSet;
import org.antlr.v4.runtime.atn.DecisionState;
import org.antlr.v4.runtime.atn.SemanticContext;
import org.antlr.v4.runtime.dfa.DFA;
Expand Down Expand Up @@ -125,12 +126,12 @@ void reportError(@NotNull Parser recognizer,
*/
void reportAmbiguity(@NotNull Parser recognizer,
DFA dfa, int startIndex, int stopIndex, @NotNull IntervalSet ambigAlts,
@NotNull OrderedHashSet<ATNConfig> configs);
@NotNull ATNConfigSet configs);

void reportAttemptingFullContext(@NotNull Parser recognizer,
@NotNull DFA dfa,
int startIndex, int stopIndex,
@NotNull OrderedHashSet<ATNConfig> configs);
@NotNull ATNConfigSet configs);

/** Called by the parser when it find a conflict that is resolved by retrying the parse
* with full context. This is not a warning; it simply notifies you that your grammar
Expand All @@ -140,7 +141,7 @@ void reportAttemptingFullContext(@NotNull Parser recognizer,
void reportContextSensitivity(@NotNull Parser recognizer,
@NotNull DFA dfa,
int startIndex, int stopIndex,
@NotNull OrderedHashSet<ATNConfig> configs);
@NotNull ATNConfigSet configs);

/** Called by the parser when it finds less than n-1 predicates for n ambiguous alternatives.
* If there are n-1, we assume that the missing predicate is !(the "or" of the other predicates).
Expand All @@ -152,5 +153,5 @@ void reportInsufficientPredicates(@NotNull Parser recognizer,
int startIndex, int stopIndex, @NotNull IntervalSet ambigAlts,
DecisionState decState,
@NotNull SemanticContext[] altToPred,
@NotNull OrderedHashSet<ATNConfig> configs, boolean fullContextParse);
@NotNull ATNConfigSet configs, boolean fullContextParse);
}
12 changes: 1 addition & 11 deletions runtime/Java/src/org/antlr/v4/runtime/BufferedTokenStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,14 @@ public BufferedTokenStream(TokenSource tokenSource) {

@Override
public int mark() {
if ( p == -1 ) setup();
lastMarker = index();
return lastMarker;
return 0;
}

@Override
public void release(int marker) {
// no resources to release
}

public void rewind(int marker) {
seek(marker);
}

public void rewind() {
seek(lastMarker);
}

public void reset() {
p = 0;
lastMarker = 0;
Expand Down
8 changes: 5 additions & 3 deletions runtime/Java/src/org/antlr/v4/runtime/CommonToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ public CommonToken(TokenSource source, int type, int channel, int start, int sto
this.channel = channel;
this.start = start;
this.stop = stop;
this.line = source.getLine();
this.charPositionInLine = source.getCharPositionInLine();
if (source != null) {
this.line = source.getLine();
this.charPositionInLine = source.getCharPositionInLine();
}
}

public CommonToken(int type, String text) {
Expand Down Expand Up @@ -190,7 +192,7 @@ public TokenSource getTokenSource() {
}

public CharStream getInputStream() {
return source.getInputStream();
return source != null ? source.getInputStream() : null;
}

public String toString() {
Expand Down
6 changes: 6 additions & 0 deletions runtime/Java/src/org/antlr/v4/runtime/CommonTokenStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ public void seek(int index) {
}
}

@Override
public void reset() {
super.reset();
p = skipOffTokenChannels(p);
}

@Override
protected CommonToken LB(int k) {
if ( k==0 || (p-k)<0 ) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,21 +554,21 @@ public void consumeUntil(Parser recognizer, IntervalSet set) {
@Override
public void reportAmbiguity(@NotNull Parser recognizer,
DFA dfa, int startIndex, int stopIndex, @NotNull IntervalSet ambigAlts,
@NotNull OrderedHashSet<ATNConfig> configs)
@NotNull ATNConfigSet configs)
{
}

@Override
public void reportAttemptingFullContext(@NotNull Parser recognizer,
@NotNull DFA dfa,
int startIndex, int stopIndex,
@NotNull OrderedHashSet<ATNConfig> configs)
@NotNull ATNConfigSet configs)
{
}

@Override
public void reportContextSensitivity(@NotNull Parser recognizer, @NotNull DFA dfa,
int startIndex, int stopIndex, @NotNull OrderedHashSet<ATNConfig> configs)
int startIndex, int stopIndex, @NotNull ATNConfigSet configs)
{
}

Expand All @@ -579,7 +579,7 @@ public void reportInsufficientPredicates(@NotNull Parser recognizer,
@NotNull IntervalSet ambigAlts,
DecisionState decState,
@NotNull SemanticContext[] altToPred,
@NotNull OrderedHashSet<ATNConfig> configs, boolean fullContextParse)
@NotNull ATNConfigSet configs, boolean fullContextParse)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
package org.antlr.v4.runtime;

import org.antlr.v4.runtime.atn.ATNConfig;
import org.antlr.v4.runtime.atn.ATNConfigSet;
import org.antlr.v4.runtime.atn.DecisionState;
import org.antlr.v4.runtime.atn.SemanticContext;
import org.antlr.v4.runtime.dfa.DFA;
Expand All @@ -43,7 +44,7 @@ public class DiagnosticErrorStrategy extends DefaultErrorStrategy {
@Override
public void reportAmbiguity(@NotNull Parser recognizer,
DFA dfa, int startIndex, int stopIndex, @NotNull IntervalSet ambigAlts,
@NotNull OrderedHashSet<ATNConfig> configs)
@NotNull ATNConfigSet configs)
{
recognizer.notifyErrorListeners("reportAmbiguity d=" + dfa.decision + ": ambigAlts=" + ambigAlts + ":" + configs + ", input='" +
recognizer.getInputString(startIndex, stopIndex) + "'");
Expand All @@ -53,15 +54,15 @@ public void reportAmbiguity(@NotNull Parser recognizer,
public void reportAttemptingFullContext(@NotNull Parser recognizer,
@NotNull DFA dfa,
int startIndex, int stopIndex,
@NotNull OrderedHashSet<ATNConfig> configs)
@NotNull ATNConfigSet configs)
{
recognizer.notifyErrorListeners("reportAttemptingFullContext d=" + dfa.decision + ": " + configs + ", input='" +
recognizer.getInputString(startIndex, stopIndex) + "'");
}

@Override
public void reportContextSensitivity(@NotNull Parser recognizer, @NotNull DFA dfa,
int startIndex, int stopIndex, @NotNull OrderedHashSet<ATNConfig> configs)
int startIndex, int stopIndex, @NotNull ATNConfigSet configs)
{
recognizer.notifyErrorListeners("reportContextSensitivity d=" + dfa.decision + ": " + configs + ", input='" +
recognizer.getInputString(startIndex, stopIndex) + "'");
Expand All @@ -74,7 +75,7 @@ public void reportInsufficientPredicates(@NotNull Parser recognizer,
@NotNull IntervalSet ambigAlts,
DecisionState decState,
@NotNull SemanticContext[] altToPred,
@NotNull OrderedHashSet<ATNConfig> configs, boolean fullContextParse)
@NotNull ATNConfigSet configs, boolean fullContextParse)
{
recognizer.notifyErrorListeners("reportInsufficientPredicates d=" + dfa.decision + ", decState=" + decState +
", ambigAlts=" + ambigAlts + ":" + Arrays.toString(altToPred) +
Expand Down
9 changes: 3 additions & 6 deletions runtime/Java/src/org/antlr/v4/runtime/Lexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public abstract class Lexer extends Recognizer<Integer, LexerATNSimulator>
/** The token type for the current token */
public int _type;

public ArrayDeque<Integer> _modeStack;
public ArrayDeque<Integer> _modeStack = new ArrayDeque<Integer>();
public int _mode = Lexer.DEFAULT_MODE;

/** You can set the text for the current token to override what is in
Expand All @@ -115,9 +115,7 @@ public void reset() {

_hitEOF = false;
_mode = Lexer.DEFAULT_MODE;
if (_modeStack != null) {
_modeStack.clear();
}
_modeStack.clear();

getInterpreter().reset();
}
Expand Down Expand Up @@ -184,14 +182,13 @@ public void mode(int m) {

public void pushMode(int m) {
if ( LexerATNSimulator.debug ) System.out.println("pushMode "+m);
if ( _modeStack ==null ) _modeStack = new ArrayDeque<Integer>();
getInterpreter().tracePushMode(m);
_modeStack.push(_mode);
mode(m);
}

public int popMode() {
if ( _modeStack ==null ) throw new EmptyStackException();
if ( _modeStack.isEmpty() ) throw new EmptyStackException();
if ( LexerATNSimulator.debug ) System.out.println("popMode back to "+ _modeStack.peek());
getInterpreter().tracePopMode();
mode( _modeStack.pop() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,19 @@ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT

package org.antlr.v4.runtime;

import org.antlr.v4.runtime.atn.ATNConfig;
import org.antlr.v4.runtime.misc.OrderedHashSet;
import org.antlr.v4.runtime.atn.ATNConfigSet;

public class LexerNoViableAltException extends RecognitionException {
/** Matching attempted at what input index? */
public int startIndex;

/** Which configurations did we try at input.index() that couldn't match input.LA(1)? */
public OrderedHashSet<ATNConfig> deadEndConfigs;
public ATNConfigSet deadEndConfigs;

public LexerNoViableAltException(Lexer lexer,
CharStream input,
int startIndex,
OrderedHashSet<ATNConfig> deadEndConfigs) {
ATNConfigSet deadEndConfigs) {
super(lexer, input, null);
this.startIndex = startIndex;
this.deadEndConfigs = deadEndConfigs;
Expand Down
Loading