runtime no longer depends on tool module

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 8787]
This commit is contained in:
parrt 2011-06-28 11:51:21 -08:00
parent 87c727e91f
commit 1510686b02
12 changed files with 25 additions and 46 deletions

View File

@ -1,15 +1,11 @@
package org.antlr.v4.runtime.atn;
import org.antlr.v4.tool.*;
public class ActionTransition extends Transition {
public int ruleIndex;
public int actionIndex = -1;
public GrammarAST actionAST;
public ActionTransition(GrammarAST actionAST, ATNState target) {
public ActionTransition(ATNState target) {
super(target);
this.actionAST = actionAST;
}
public ActionTransition(ATNState target, int ruleIndex, int actionIndex) {
@ -23,11 +19,6 @@ public class ActionTransition extends Transition {
}
public String toString() {
if ( actionAST!=null ) return "{"+actionAST.getText()+"}";
return "action_"+ruleIndex+":"+actionIndex;
}
public String toString(Grammar g) {
return toString();
}
}

View File

@ -1,7 +1,5 @@
package org.antlr.v4.runtime.atn;
import org.antlr.v4.tool.*;
/** TODO: this is old comment:
* A tree of semantic predicates from the grammar AST if label==SEMPRED.
* In the ATN, labels will always be exactly one predicate, but the DFA
@ -11,11 +9,9 @@ import org.antlr.v4.tool.*;
public class PredicateTransition extends Transition {
public int ruleIndex;
public int predIndex;
public GrammarAST predAST;
public PredicateTransition(GrammarAST predicateASTNode, ATNState target) {
public PredicateTransition(ATNState target) {
super(target);
this.predAST = predicateASTNode;
}
public PredicateTransition(ATNState target, int ruleIndex, int predIndex) {
@ -27,11 +23,7 @@ public class PredicateTransition extends Transition {
public boolean isEpsilon() { return true; }
public String toString() {
if ( predAST!=null ) return predAST.getText();
return "pred-"+ruleIndex+":"+predIndex;
}
public String toString(Grammar g) {
return toString();
}
}

View File

@ -1,6 +1,5 @@
package org.antlr.v4.runtime.atn;
import org.antlr.v4.misc.CharSupport;
import org.antlr.v4.runtime.misc.IntervalSet;
public class RangeTransition extends Transition {
@ -20,7 +19,6 @@ public class RangeTransition extends Transition {
@Override
public String toString() {
return CharSupport.getANTLRCharLiteralForChar(from)+".."+
CharSupport.getANTLRCharLiteralForChar(to);
return "'"+(char)from+"'..'"+(char)to+"'";
}
}

View File

@ -27,11 +27,11 @@
*/
package org.antlr.v4.runtime.tree;
import org.antlr.runtime.misc.IntArray;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.misc.LookaheadStream;
import java.util.Stack;
public class CommonTreeNodeStream extends LookaheadStream<Object> implements TreeNodeStream {
public static final int DEFAULT_INITIAL_BUFFER_SIZE = 100;
public static final int INITIAL_CALL_STACK_SIZE = 10;
@ -49,7 +49,7 @@ public class CommonTreeNodeStream extends LookaheadStream<Object> implements Tre
protected TreeIterator it;
/** Stack of indexes used for push/pop calls */
protected IntArray calls;
protected Stack<Integer> calls;
/** Tree (nil A B C) trees like flat A B C streams */
protected boolean hasNilRoot = false;
@ -122,7 +122,7 @@ public class CommonTreeNodeStream extends LookaheadStream<Object> implements Tre
*/
public void push(int index) {
if ( calls==null ) {
calls = new IntArray();
calls = new Stack<Integer>();
}
calls.push(p); // save current index
seek(index);

View File

@ -27,8 +27,8 @@
*/
package org.antlr.v4.runtime.tree;
import org.antlr.runtime.Token;
import org.antlr.runtime.misc.FastQueue;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.FastQueue;
import java.util.Iterator;

View File

@ -1,7 +1,6 @@
package org.antlr.v4.runtime.tree.gui;
import org.antlr.runtime.tree.CommonTreeAdaptor;
import org.antlr.runtime.tree.TreeAdaptor;
import org.antlr.v4.runtime.tree.*;
/** */
public class ASTViewer {
@ -17,12 +16,12 @@ public class ASTViewer {
this.adaptor = new CommonTreeAdaptor();
this.root = root;
}
public void open() {
ASTViewFrame m = new ASTViewFrame();
m.tree.setModel(new JTreeASTModel(adaptor, root));
m.pack();
m.setSize(800,600);
m.setVisible(true);
m.setVisible(true);
}
}

View File

@ -1,11 +1,9 @@
package org.antlr.v4.runtime.tree.gui;
import org.antlr.runtime.tree.CommonTreeAdaptor;
import org.antlr.runtime.tree.TreeAdaptor;
import org.antlr.v4.runtime.tree.*;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
import javax.swing.tree.*;
public class JTreeASTModel implements TreeModel {
TreeAdaptor adaptor;

View File

@ -48,7 +48,7 @@ public class ATNPrinter {
}
else if ( t instanceof ActionTransition ) {
ActionTransition a = (ActionTransition)t;
buf.append("-"+a.actionAST.getText()+"->"+ getStateString(t.target)+'\n');
buf.append("-"+a.toString()+"->"+ getStateString(t.target)+'\n');
}
else if ( t instanceof AtomTransition ) {
AtomTransition a = (AtomTransition)t;

View File

@ -174,7 +174,7 @@ public class ParserATNFactory implements ATNFactory {
//System.out.println("sempred: "+ pred);
ATNState left = newState(pred);
ATNState right = newState(pred);
PredicateTransition p = new PredicateTransition(pred, right);
PredicateTransition p = new PredicateTransition(right);
p.ruleIndex = currentRule.index;
p.predIndex = g.sempreds.get(pred);
left.transition = p;
@ -185,7 +185,7 @@ public class ParserATNFactory implements ATNFactory {
public Handle gated_sempred(GrammarAST pred) {
ATNState left = newState(pred);
ATNState right = newState(pred);
left.transition = new PredicateTransition(pred, right);
left.transition = new PredicateTransition(right);
pred.atnState = left;
return new Handle(left, right);
}
@ -198,7 +198,7 @@ public class ParserATNFactory implements ATNFactory {
//System.out.println("action: "+action);
ATNState left = newState(action);
ATNState right = newState(action);
ActionTransition a = new ActionTransition(action, right);
ActionTransition a = new ActionTransition(right);
a.ruleIndex = currentRule.index;
if ( action.getType()==ANTLRParser.FORCED_ACTION ) {
a.actionIndex = g.actions.get(action);

View File

@ -110,7 +110,8 @@ public class Grammar implements AttributeResolver {
*/
public LinkedHashMap<ActionAST, Integer> actions = new LinkedHashMap<ActionAST, Integer>();
/** All sempreds found in grammar; maps tree node to sempred index */
/** All sempreds found in grammar; maps tree node to sempred index;
* sempred index is 0..n-1 */
public LinkedHashMap<PredAST, Integer> sempreds = new LinkedHashMap<PredAST, Integer>();
public Map<String, AttributeDict> scopes = new LinkedHashMap<String, AttributeDict>();

View File

@ -101,7 +101,7 @@ public class Rule implements AttributeResolver {
public void definePredicateInAlt(int currentAlt, PredAST predAST) {
alt[currentAlt].actions.add(predAST);
g.sempreds.put(predAST, g.sempreds.size() + 1);
g.sempreds.put(predAST, g.sempreds.size());
}
public Attribute resolveRetvalOrProperty(String y) {

View File

@ -48,7 +48,7 @@ public class TestATNConstruction extends BaseTest {
"s3->BlockEnd_9\n" +
"s5->s6\n" +
"BlockEnd_9->RuleStop_a_1\n" +
"s6-{;}->s7\n" +
"s6-action_0:-1->s7\n" + // actionIndex -1 since not forced action
"RuleStop_a_1-EOF->s10\n" +
"s7->BlockEnd_9\n";
checkRule(g, "a", expecting);
@ -363,8 +363,8 @@ public class TestATNConstruction extends BaseTest {
"RuleStart_a_0->BlockStart_10\n" +
"BlockStart_10->s2\n" +
"BlockStart_10->s6\n" +
"s2-{p1}?->s3\n" +
"s6-{p2}?->s7\n" +
"s2-pred-0:0->s3\n" +
"s6-pred-0:1->s7\n" +
"s3->s4\n" +
"s7->s8\n" +
"s4-A->s5\n" +