/** * Returns {@code true} if the set of expected follow-states includes an implicit or explicit semicolon. */ private static boolean followedBySemicolon(RecognizerSharedState state, Callback.RecoverySets recoverySets, int currentIndex) { int top = state._fsp; if (currentIndex != state.lastErrorIndex) { long[] array = state.following[top].toPackedArray(); if (array.length == 1 && array[0] == (1L << Token.EOR_TOKEN_TYPE)) { return false; } } for (int i = top; i >= 0; i--) { BitSet localFollowSet = state.following[i]; if (recoverySets.matches(localFollowSet)) { return true; } } return false; }
public Object applyOnce(Object t, fptr whichRule) { if ( t==null ) return null; try { // share TreeParser object but not parsing-related state state = new RecognizerSharedState(); input = new CommonTreeNodeStream(originalAdaptor, t); ((CommonTreeNodeStream)input).setTokenStream(originalTokenStream); setBacktrackingLevel(1); TreeRuleReturnScope r = (TreeRuleReturnScope)whichRule.rule(); setBacktrackingLevel(0); if ( failed() ) return t; if ( showTransformations && r!=null && !t.equals(r.getTree()) && r.getTree()!=null ) { reportTransformation(t, r.getTree()); } if ( r!=null && r.getTree()!=null ) return r.getTree(); else return t; } catch (RecognitionException e) { ; } return t; }
/** * <p> * Promotes EOL which may lead to an automatically inserted semicolon. This is probably the most important method * for automatic semicolon insertion, as it is only possible to insert a semicolon in case of line breaks (even if * they are hidden in a multi-line comment!). * </p> */ public static void promoteEOL(Callback callback) { RecognizerSharedState state = callback.getState(); TokenStream input = callback.getInput(); // Don't promote EOL if there was a syntax error at EOF if (state.lastErrorIndex == input.size()) { return; } // Get current token and its type (the possibly offending token). Token prev = input.LT(-1); Token next = input.LT(1); int la = next.getType(); // Promoting an EOL means switching it from off channel to on channel. // A ML_COMMENT gets promoted when it contains an EOL. for (int idx = prev == null ? 0 : prev.getTokenIndex() + 1, max = la == Token.EOF ? input.size() : next.getTokenIndex(); idx < max; idx++) { Token lt = input.get(idx); if (lt.getChannel() == Token.DEFAULT_CHANNEL) { // On channel token found: stop scanning (previously promoted) break; } else if (isSemicolonEquivalent(lt)) { // We found our EOL: promote the token to on channel, position the input on it and reset the rule // start. lt.setChannel(Token.DEFAULT_CHANNEL); input.seek(idx); break; } } }
public BaseInternalContentAssistParser(TokenStream input, RecognizerSharedState state) { super(input, state); this.grammarElements = new ArrayList<EObject>(); this.localTrace = new ArrayList<EObject>(); this.paramStack = new ArrayList<Integer>(); this.grammarElementsWithParams = new ArrayList<Integer>(); this.followElements = new LinkedHashSetWithoutNull<FollowElement>(); }
/** * Construct from a token stream and a shared state. * @param input the token stream * @param state the shared state * @param errorHandler handles error messages */ public CobolStructureParserImpl( final TokenStream input, final RecognizerSharedState state, final RecognizerErrorHandler errorHandler) { super(input, state); _errorHandler = errorHandler; }
/** * Construct from a character stream and a shared state. * @param input the character stream * @param state the shared state * @param errorHandler handles error messages */ public CobolStructureLexerImpl( final CharStream input, final RecognizerSharedState state, final RecognizerErrorHandler errorHandler) { super(input, state); _errorHandler = errorHandler; }
/** * Construct from a tree nodes stream and a shared state. * @param input the tree nodes stream * @param state the shared state * @param errorHandler handles error messages */ public CobolStructureEmitterImpl( final TreeNodeStream input, final RecognizerSharedState state, final RecognizerErrorHandler errorHandler) { super(input, state); _errorHandler = errorHandler; }
public void applyOnce(Object t, fptr whichRule) { if ( t==null ) return; try { // share TreeParser object but not parsing-related state state = new RecognizerSharedState(); input = new CommonTreeNodeStream(originalAdaptor, t); ((CommonTreeNodeStream)input).setTokenStream(originalTokenStream); setBacktrackingLevel(1); whichRule.rule(); setBacktrackingLevel(0); } catch (RecognitionException e) { ; } }
public EditorOpsParserDelegate(TokenStream input, RecognizerSharedState state, Set<EditorOpDescr> runtimeNativeOps, Set<EditorOpDescr> runtimeUserOps) { super(input, runtimeNativeOps,runtimeUserOps); this.state = state; this.allNativeOps = aggAllOperations(runtimeNativeOps, runtimeUserOps); this.needClosingOpsStack = new LinkedList<EditorOpDescr>(); }
public CqlLexer(CharStream input) { this(input, new RecognizerSharedState()); }
public CqlLexer(CharStream input, RecognizerSharedState state) { super(input,state); gLexer = new Cql_Lexer(input, state, this); }
public Cql_Parser(TokenStream input, CqlParser gCql) { this(input, new RecognizerSharedState(), gCql); }
public Cql_Parser(TokenStream input, RecognizerSharedState state, CqlParser gCql) { super(input, state); this.gCql = gCql; gParent = gCql; }
public CqlParser(TokenStream input) { this(input, new RecognizerSharedState()); }
public CqlParser(TokenStream input, RecognizerSharedState state) { super(input, state); gParser = new Cql_Parser(input, state, this); }
/** * Allows to access the protected state of the super type. */ public RecognizerSharedState getState() { return state; }
/** * Delegates to super constructor. */ protected AbstractInternalHighlightingAntlrParser(TokenStream input, RecognizerSharedState state) { super(input, state); }
@Override public RecognizerSharedState getState() { return state; }
/** * Recover from an error found on the input stream. This is for {@link NoViableAltException} and * {@link MismatchedTokenException}. If you enable single token insertion and deletion, this will usually not handle * mismatched symbol exceptions but there could be a mismatched token that the * {@link Parser#match(IntStream, int, BitSet) match} routine could not recover from. */ public static void recover(IntStream inputStream, RecognitionException re, Callback callback) { RecognizerSharedState state = callback.getState(); if (re instanceof MismatchedTokenException) { // We expected a specific token // if that is not a semicolon, ASI is pointless, perform normal recovery int expecting = ((MismatchedTokenException) re).expecting; if (expecting != InternalN4JSParser.Semicolon) { callback.discardError(); // delete ASI message, a previously added ASI may fix too much! cf. // IDEBUG-215 callback.recoverBase(inputStream, re); return; } } // System.out.println("Line: " + re.line + ":" + re.index); int unexpectedTokenType = re.token.getType(); if (!followedBySemicolon(state, callback.getRecoverySets(), re.index) || isOffendingToken(unexpectedTokenType)) { callback.recoverBase(inputStream, re); } else { int la = inputStream.LA(1); TokenStream casted = (TokenStream) inputStream; if (!isOffendingToken(la)) { // Start on the position before the current token and scan backwards off channel tokens until the // previous on channel token. for (int ix = re.token.getTokenIndex() - 1; ix > 0; ix--) { Token lt = casted.get(ix); if (lt.getChannel() == Token.DEFAULT_CHANNEL) { // On channel token found: stop scanning. callback.recoverBase(inputStream, re); return; } else if (lt.getType() == InternalN4JSParser.RULE_EOL) { // We found our EOL: everything's good, no need to do additional recovering // rule start. if (!callback.allowASI(re)) { callback.recoverBase(inputStream, re); return; } if (!findCommaBeforeEOL(casted, ix)) { callback.addASIMessage(); return; } } else if (lt.getType() == InternalN4JSParser.RULE_ML_COMMENT) { String tokenText = lt.getText(); if (!findCommaBeforeEOL(casted, ix) && (tokenText.indexOf('\n', 2) >= 2 || tokenText.indexOf('\r', 2) >= 2)) { callback.addASIMessage(); return; } } } callback.recoverBase(inputStream, re); } } }
AbstractJavaVMOptionParser(TokenStream input, RecognizerSharedState state) { super(input, state); }
public ExtCss3Parser(TokenStream input, int port, RecognizerSharedState state) { super(input, port, state); }
public QueryLexer(CharStream input) { this(input, new RecognizerSharedState()); }
public QueryLexer(CharStream input, RecognizerSharedState state) { super(input,state); }
public QueryParser(TokenStream input) { this(input, new RecognizerSharedState()); }
public QueryParser(TokenStream input, RecognizerSharedState state) { super(input, state); }
public ANTLRLexerWithErrorInterface(CharStream input, RecognizerSharedState state) { super(input, state); }
protected AbstractPythonTTree(TreeNodeStream input, RecognizerSharedState state) { super(input, state); }
protected AbstractCppTTree(TreeNodeStream input, RecognizerSharedState state) { super(input, state); }
protected AbstractSheetParser(TokenStream input, RecognizerSharedState state) { super(input, state); }
protected AbstractAuditParser(TokenStream input, RecognizerSharedState state) { super(input, state); }
protected AbstractStructuredConfigParser(TokenStream input, RecognizerSharedState state) { super(input, state); }
protected AbstractEntParser(TokenStream input, RecognizerSharedState state) { super(input, state); }
protected AbstractIndexDefParser(TokenStream input, RecognizerSharedState state) { super(input, state); }