Java 类org.antlr.runtime.RecognizerSharedState 实例源码

项目:n4js    文件:SemicolonInjectionHelper.java   
/**
 * 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;
}
项目:jtcc    文件:TreeRewriter.java   
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;
}
项目:VectorAttackScanner    文件:TreeRewriter.java   
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;
}
项目:n4js    文件:SemicolonInjectionHelper.java   
/**
 * <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;
        }
    }
}
项目:xtext-core    文件:BaseInternalContentAssistParser.java   
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>();
}
项目:legstar-cob2xsd    文件:CobolStructureParserImpl.java   
/**
 * 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;
}
项目:legstar-cob2xsd    文件:CobolStructureLexerImpl.java   
/**
 * 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;

}
项目:legstar-cob2xsd    文件:CobolStructureEmitterImpl.java   
/**
 * 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;
}
项目:jtcc    文件:TreeFilter.java   
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) { ; }
}
项目:VectorAttackScanner    文件:TreeFilter.java   
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) { ; }
}
项目:legstar-core2    文件:CobolStructureParserImpl.java   
/**
 * 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;
}
项目:legstar-core2    文件:CobolStructureLexerImpl.java   
/**
 * 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;

}
项目:legstar-core2    文件:CobolStructureEmitterImpl.java   
/**
 * 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;
}
项目:pm    文件:EditorOpsParserDelegate.java   
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>();
}
项目:sstable-adaptor    文件:CqlLexer.java   
public CqlLexer(CharStream input) {
    this(input, new RecognizerSharedState());
}
项目:sstable-adaptor    文件:CqlLexer.java   
public CqlLexer(CharStream input, RecognizerSharedState state) {
    super(input,state);
    gLexer = new Cql_Lexer(input, state, this);
}
项目:sstable-adaptor    文件:Cql_Parser.java   
public Cql_Parser(TokenStream input, CqlParser gCql) {
    this(input, new RecognizerSharedState(), gCql);
}
项目:sstable-adaptor    文件:Cql_Parser.java   
public Cql_Parser(TokenStream input, RecognizerSharedState state, CqlParser gCql) {
    super(input, state);
    this.gCql = gCql;
    gParent = gCql;
}
项目:sstable-adaptor    文件:CqlParser.java   
public CqlParser(TokenStream input) {
    this(input, new RecognizerSharedState());
}
项目:sstable-adaptor    文件:CqlParser.java   
public CqlParser(TokenStream input, RecognizerSharedState state) {
    super(input, state);
    gParser = new Cql_Parser(input, state, this);
}
项目:n4js    文件:CustomN4JSParser.java   
/**
 * Allows to access the protected state of the super type.
 */
public RecognizerSharedState getState() {
    return state;
}
项目:n4js    文件:AbstractInternalHighlightingAntlrParser.java   
/**
 * Delegates to super constructor.
 */
protected AbstractInternalHighlightingAntlrParser(TokenStream input, RecognizerSharedState state) {
    super(input, state);
}
项目:n4js    文件:InternalHighlightingParser.java   
@Override
public RecognizerSharedState getState() {
    return state;
}
项目:n4js    文件:InternalSemicolonInjectingParser.java   
@Override
public RecognizerSharedState getState() {
    return state;
}
项目:n4js    文件:SemicolonInjectionHelper.java   
/**
 * 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);
        }
    }
}
项目:incubator-netbeans    文件:AbstractJavaVMOptionParser.java   
AbstractJavaVMOptionParser(TokenStream input, RecognizerSharedState state) {
    super(input, state);
}
项目:incubator-netbeans    文件:ExtCss3Parser.java   
public ExtCss3Parser(TokenStream input, int port, RecognizerSharedState state) {
    super(input, port, state);
}
项目:rview    文件:QueryLexer.java   
public QueryLexer(CharStream input) {
    this(input, new RecognizerSharedState());
}
项目:rview    文件:QueryLexer.java   
public QueryLexer(CharStream input, RecognizerSharedState state) {
    super(input,state);
}
项目:rview    文件:QueryParser.java   
public QueryParser(TokenStream input) {
    this(input, new RecognizerSharedState());
}
项目:rview    文件:QueryParser.java   
public QueryParser(TokenStream input, RecognizerSharedState state) {
    super(input, state);
}
项目:zjdroid    文件:LexerErrorInterface.java   
public ANTLRLexerWithErrorInterface(CharStream input, RecognizerSharedState state) {
    super(input, state);
}
项目:DalvikSSA    文件:LexerErrorInterface.java   
public ANTLRLexerWithErrorInterface(CharStream input, RecognizerSharedState state) {
    super(input, state);
}
项目:Rapture    文件:AbstractPythonTTree.java   
protected AbstractPythonTTree(TreeNodeStream input, RecognizerSharedState state) {
    super(input, state);
}
项目:Rapture    文件:AbstractCppTTree.java   
protected AbstractCppTTree(TreeNodeStream input, RecognizerSharedState state) {
    super(input, state);
}
项目:Rapture    文件:AbstractSheetParser.java   
protected AbstractSheetParser(TokenStream input, RecognizerSharedState state) {
    super(input, state);
}
项目:Rapture    文件:AbstractAuditParser.java   
protected AbstractAuditParser(TokenStream input, RecognizerSharedState state) {
    super(input, state);
}
项目:Rapture    文件:AbstractStructuredConfigParser.java   
protected AbstractStructuredConfigParser(TokenStream input, RecognizerSharedState state) {
    super(input, state);
}
项目:Rapture    文件:AbstractEntParser.java   
protected AbstractEntParser(TokenStream input, RecognizerSharedState state) {
    super(input, state);
}
项目:Rapture    文件:AbstractIndexDefParser.java   
protected AbstractIndexDefParser(TokenStream input, RecognizerSharedState state) {
    super(input, state);
}