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

下面列出了怎么用org.antlr.runtime.RecognizerSharedState的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: kogito-runtimes   文件: DrlExprParser.java
/** Parse an expression from text */
public ConstraintConnectiveDescr parse( final String text ) {
    ConstraintConnectiveDescr constraint = null;
    try {
        DRLLexer lexer = DRLFactory.getDRLLexer(new ANTLRStringStream(text), languageLevel);
        CommonTokenStream input = new CommonTokenStream( lexer );
        RecognizerSharedState state = new RecognizerSharedState();
        helper = new ParserHelper( input, state, languageLevel );
        DRLExpressions parser = DRLFactory.getDRLExpressions(input, state, helper, languageLevel);
        parser.setBuildDescr( true );
        parser.setLeftMostExpr( null ); // setting initial value just in case
        BaseDescr expr = parser.conditionalOrExpression();
        if ( expr != null && !parser.hasErrors() ) {
            constraint = ConstraintConnectiveDescr.newAnd();
            constraint.addOrMerge( expr );
        }
    } catch ( RecognitionException e ) {
        helper.reportError( e );
    }
    return constraint;
}
 
源代码2 项目: 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;
}
 
源代码3 项目: kogito-runtimes   文件: ParserHelper.java
public ParserHelper(TokenStream input,
                    RecognizerSharedState state,
                    LanguageLevelOption languageLevel) {
    this.errorMessageFactory = new DroolsParserExceptionFactory( paraphrases, languageLevel );
    this.input = input;
    this.state = state;
    this.languageLevel = languageLevel;
}
 
源代码4 项目: kogito-runtimes   文件: DRLFactory.java
public static DRLExpressions getDRLExpressions(TokenStream input, RecognizerSharedState state, ParserHelper helper, LanguageLevelOption languageLevel ) {
    switch (languageLevel) {
        case DRL5:
            return new DRL5Expressions(input, state, helper);
        case DRL6:
        case DRL6_STRICT:
            return new DRL6Expressions(input, state, helper);
    }
    throw new RuntimeException("Unknown language level");
}
 
源代码5 项目: 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();
	if (la == InternalN4JSParser.Semicolon) {
		return;
	}

	// 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>();
}
 
源代码7 项目: 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;
}
 
源代码8 项目: 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;

}
 
源代码9 项目: 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;
}
 
public FastSimpleGenericEdifactDirectXMLLexer( CharStream input ) {
  this( input, new RecognizerSharedState() );
}
 
public FastSimpleGenericEdifactDirectXMLLexer( CharStream input, RecognizerSharedState state ) {
  super( input, state );
}
 
public FastSimpleGenericEdifactDirectXMLParser( TokenStream input ) {
  this( input, new RecognizerSharedState() );
}
 
public FastSimpleGenericEdifactDirectXMLParser( TokenStream input, RecognizerSharedState state ) {
  super( input, state );
}
 
源代码14 项目: kogito-runtimes   文件: JavaLexer.java
public JavaLexer(CharStream input) {
	this(input, new RecognizerSharedState());
}
 
源代码15 项目: kogito-runtimes   文件: JavaLexer.java
public JavaLexer(CharStream input, RecognizerSharedState state) {
	super(input,state);
}
 
源代码16 项目: kogito-runtimes   文件: DSLMapParser.java
public DSLMapParser(TokenStream input) {
	this(input, new RecognizerSharedState());
}
 
源代码17 项目: kogito-runtimes   文件: DSLMapParser.java
public DSLMapParser(TokenStream input, RecognizerSharedState state) {
	super(input, state);
}
 
源代码18 项目: kogito-runtimes   文件: DSLMapLexer.java
public DSLMapLexer(CharStream input) {
	this(input, new RecognizerSharedState());
}
 
源代码19 项目: kogito-runtimes   文件: DSLMapLexer.java
public DSLMapLexer(CharStream input, RecognizerSharedState state) {
	super(input,state);
}
 
源代码20 项目: kogito-runtimes   文件: DSLMapWalker.java
public DSLMapWalker(TreeNodeStream input) {
	this(input, new RecognizerSharedState());
}
 
源代码21 项目: kogito-runtimes   文件: DSLMapWalker.java
public DSLMapWalker(TreeNodeStream input, RecognizerSharedState state) {
	super(input, state);
}
 
源代码22 项目: kogito-runtimes   文件: AbstractDRLParser.java
public AbstractDRLParser(TokenStream input) {
    this.input = input;
    this.state = new RecognizerSharedState();
    this.helper = new ParserHelper( input, state, getLanguageLevel() );
}
 
源代码23 项目: kogito-runtimes   文件: AbstractDRLLexer.java
public AbstractDRLLexer(CharStream input, RecognizerSharedState state) {
    super(input, state);
}
 
源代码24 项目: kogito-runtimes   文件: DRLExpressions.java
public DRLExpressions(TokenStream input, RecognizerSharedState state) {
    super(input, state);
}
 
public FastSimpleGenericEdifactDirectXMLParser( TokenStream input ) {
  this( input, new RecognizerSharedState() );
}
 
/**
 * Delegates to super constructor.
 */
protected AbstractInternalHighlightingAntlrParser(TokenStream input, RecognizerSharedState state) {
	super(input, state);
}
 
源代码27 项目: n4js   文件: InternalHighlightingParser.java
@Override
public RecognizerSharedState getState() {
	return state;
}
 
源代码28 项目: n4js   文件: CustomN4JSParser.java
/**
 * Allows to access the protected state of the super type.
 */
public RecognizerSharedState getState() {
	return state;
}
 
源代码29 项目: n4js   文件: InternalSemicolonInjectingParser.java
@Override
public RecognizerSharedState getState() {
	return state;
}
 
源代码30 项目: 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);
		}
	}
}