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 {INVALID_INTERVAL} = require('./tree/Tree');
|
||||
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 {
|
||||
/** 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;
|
||||
|
||||
const Trees = require('./tree/Trees');
|
||||
|
|
|
@ -29,6 +29,10 @@ class RuleNode extends ParseTree {
|
|||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
getRuleContext(){
|
||||
throw new Error("missing interface implementation")
|
||||
}
|
||||
}
|
||||
|
||||
class TerminalNode extends ParseTree {
|
||||
|
|
|
@ -5,9 +5,7 @@
|
|||
|
||||
const Utils = require('./../Utils');
|
||||
const {Token} = require('./../Token');
|
||||
const {ErrorNode, TerminalNode} = require('./Tree');
|
||||
const ParserRuleContext = require('./../ParserRuleContext');
|
||||
const RuleContext = require('./../RuleContext');
|
||||
const {ErrorNode, TerminalNode, RuleNode} = require('./Tree');
|
||||
const ATN = require('./../atn/ATN');
|
||||
|
||||
/** A set of utility routines useful for all kinds of ANTLR trees. */
|
||||
|
@ -49,8 +47,9 @@ const Trees = {
|
|||
ruleNames = recog.ruleNames;
|
||||
}
|
||||
if(ruleNames!==null) {
|
||||
if (t instanceof RuleContext) {
|
||||
const altNumber = t.getAltNumber();
|
||||
if (t instanceof RuleNode) {
|
||||
const context = t.getRuleContext()
|
||||
const altNumber = context.getAltNumber();
|
||||
if ( altNumber != (ATN.INVALID_ALT_NUMBER || 0) ) { // TODO: solve cyclic dependency to avoid || 0
|
||||
return ruleNames[t.ruleIndex]+":"+altNumber;
|
||||
}
|
||||
|
@ -116,7 +115,7 @@ const Trees = {
|
|||
if(t.symbol.type===index) {
|
||||
nodes.push(t);
|
||||
}
|
||||
} else if(!findTokens && (t instanceof ParserRuleContext)) {
|
||||
} else if(!findTokens && (t instanceof RuleNode)) {
|
||||
if(t.ruleIndex===index) {
|
||||
nodes.push(t);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue