fix: cyclic dependency between RuleContext.js, Trees.js and ParserRuleContext.js
check for RuleNode instead of RuleContext since that it the only implementation (RuleNode -> RuleContext -> ParserRuleContext)
This commit is contained in:
parent
a4c66dc863
commit
26715ec6df
|
@ -6,6 +6,7 @@
|
||||||
const {RuleNode} = require('./tree/Tree');
|
const {RuleNode} = require('./tree/Tree');
|
||||||
const {INVALID_INTERVAL} = require('./tree/Tree');
|
const {INVALID_INTERVAL} = require('./tree/Tree');
|
||||||
const INVALID_ALT_NUMBER = require('./atn/ATN').INVALID_ALT_NUMBER || 0; // TODO: solve cyclic dependency to avoid || 0
|
const INVALID_ALT_NUMBER = require('./atn/ATN').INVALID_ALT_NUMBER || 0; // TODO: solve cyclic dependency to avoid || 0
|
||||||
|
const Trees = require('./tree/Trees');
|
||||||
|
|
||||||
class RuleContext extends RuleNode {
|
class RuleContext extends RuleNode {
|
||||||
/** A rule context is a record of a single rule invocation. It knows
|
/** A rule context is a record of a single rule invocation. It knows
|
||||||
|
@ -154,7 +155,4 @@ class RuleContext extends RuleNode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//need to manage circular dependencies, so export now
|
|
||||||
module.exports = RuleContext;
|
module.exports = RuleContext;
|
||||||
|
|
||||||
const Trees = require('./tree/Trees');
|
|
||||||
|
|
|
@ -29,6 +29,10 @@ class RuleNode extends ParseTree {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getRuleContext(){
|
||||||
|
throw new Error("missing interface implementation")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TerminalNode extends ParseTree {
|
class TerminalNode extends ParseTree {
|
||||||
|
|
|
@ -5,9 +5,7 @@
|
||||||
|
|
||||||
const Utils = require('./../Utils');
|
const Utils = require('./../Utils');
|
||||||
const {Token} = require('./../Token');
|
const {Token} = require('./../Token');
|
||||||
const {ErrorNode, TerminalNode} = require('./Tree');
|
const {ErrorNode, TerminalNode, RuleNode} = require('./Tree');
|
||||||
const ParserRuleContext = require('./../ParserRuleContext');
|
|
||||||
const RuleContext = require('./../RuleContext');
|
|
||||||
const ATN = require('./../atn/ATN');
|
const ATN = require('./../atn/ATN');
|
||||||
|
|
||||||
/** A set of utility routines useful for all kinds of ANTLR trees. */
|
/** A set of utility routines useful for all kinds of ANTLR trees. */
|
||||||
|
@ -49,8 +47,9 @@ const Trees = {
|
||||||
ruleNames = recog.ruleNames;
|
ruleNames = recog.ruleNames;
|
||||||
}
|
}
|
||||||
if(ruleNames!==null) {
|
if(ruleNames!==null) {
|
||||||
if (t instanceof RuleContext) {
|
if (t instanceof RuleNode) {
|
||||||
const altNumber = t.getAltNumber();
|
const context = t.getRuleContext()
|
||||||
|
const altNumber = context.getAltNumber();
|
||||||
if ( altNumber != (ATN.INVALID_ALT_NUMBER || 0) ) { // TODO: solve cyclic dependency to avoid || 0
|
if ( altNumber != (ATN.INVALID_ALT_NUMBER || 0) ) { // TODO: solve cyclic dependency to avoid || 0
|
||||||
return ruleNames[t.ruleIndex]+":"+altNumber;
|
return ruleNames[t.ruleIndex]+":"+altNumber;
|
||||||
}
|
}
|
||||||
|
@ -116,7 +115,7 @@ const Trees = {
|
||||||
if(t.symbol.type===index) {
|
if(t.symbol.type===index) {
|
||||||
nodes.push(t);
|
nodes.push(t);
|
||||||
}
|
}
|
||||||
} else if(!findTokens && (t instanceof ParserRuleContext)) {
|
} else if(!findTokens && (t instanceof RuleNode)) {
|
||||||
if(t.ruleIndex===index) {
|
if(t.ruleIndex===index) {
|
||||||
nodes.push(t);
|
nodes.push(t);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue