private static TerminalNode getStartNode(ParseTree tree) { if (tree instanceof TerminalNode) { return (TerminalNode) tree; } Deque<ParseTree> workList = new ArrayDeque<ParseTree>(); IntegerStack workIndexStack = new IntegerStack(); workList.push(tree); workIndexStack.push(0); while (!workList.isEmpty()) { ParseTree currentTree = workList.peek(); int currentIndex = workIndexStack.peek(); if (currentIndex == currentTree.getChildCount()) { workList.pop(); workIndexStack.pop(); continue; } // move work list to next child workIndexStack.push(workIndexStack.pop() + 1); // process the current child ParseTree child = currentTree.getChild(currentIndex); if (child instanceof TerminalNode) { return (TerminalNode) child; } workList.push(child); workIndexStack.push(0); } return null; }
private SimpleLexerState(int mode, @NullAllowed IntegerStack modeStack) { this.mode = mode; if (modeStack == null || modeStack.isEmpty()) { this.modeStack = EMPTY_MODE_STACK; } else { this.modeStack = new IntegerStack(modeStack); } }
private static SimpleLexerState create(int mode, @NullAllowed IntegerStack modeStack) { if (mode == Lexer.DEFAULT_MODE && (modeStack == null || modeStack.isEmpty())) { return INITIAL; } return new SimpleLexerState(mode, modeStack); }
public LexerState(int mode, IntegerStack stack) { Mode = mode; Stack = new IntegerStack(stack); }
public IntegerStack getModeStack() { return modeStack; }
public ANTLRv4LexerState(int mode, IntegerStack modeStack, int currentRuleType) { super(mode, modeStack); this.currentRuleType = currentRuleType; }
/** * @effects Makes this be a new AntlrLexerState s with s.mode = mode and * s.modeStack = modeStack if modeStack != null, else * s.modeStack = nil */ public AntlrLexerState(int mode, IntegerStack modeStack) { this.mode = mode; this.modeStack = modeStack != null ? modeStack.toArray() : null; }
/** * Constructs a new instance of {@link ANTLRLexerState} * containing the mode and mode stack information for an ANTLR * lexer. * * @param mode The current lexer mode, {@link Lexer#_mode}. * @param modeStack The lexer mode stack, {@link Lexer#_modeStack}, or {@code null} . */ public ANTLRLexerState(int mode, @Nullable IntegerStack modeStack) { this.mode = mode; this.modeStack = modeStack != null ? modeStack.toArray() : null; }
/** * Constructs a new instance of {@link ANTLRLexerState} containing the mode and mode stack information for an ANTLR * lexer. * * @param mode The current lexer mode, {@link Lexer#_mode}. * @param modeStack The lexer mode stack, {@link Lexer#_modeStack}, or {@code null} . */ public ANTLRLexerState(int mode, @Nullable IntegerStack modeStack) { this.mode = mode; this.modeStack = modeStack != null ? modeStack.toArray() : null; }