org.antlr.runtime.RecognizerSharedState Java Examples

The following examples show how to use org.antlr.runtime.RecognizerSharedState. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DrlExprParser.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
/** 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;
}
 
Example #2
Source File: SemicolonInjectionHelper.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: BaseInternalContentAssistParser.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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>();
}
 
Example #4
Source File: DRLFactory.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
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");
}
 
Example #5
Source File: CobolStructureEmitterImpl.java    From legstar-core2 with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #6
Source File: CobolStructureLexerImpl.java    From legstar-core2 with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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;

}
 
Example #7
Source File: CobolStructureParserImpl.java    From legstar-core2 with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #8
Source File: ParserHelper.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public ParserHelper(TokenStream input,
                    RecognizerSharedState state,
                    LanguageLevelOption languageLevel) {
    this.errorMessageFactory = new DroolsParserExceptionFactory( paraphrases, languageLevel );
    this.input = input;
    this.state = state;
    this.languageLevel = languageLevel;
}
 
Example #9
Source File: SemicolonInjectionHelper.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <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;
		}
	}
}
 
Example #10
Source File: QueryFilterParser.java    From usergrid with Apache License 2.0 4 votes vote down vote up
public QueryFilterParser( TokenStream input ) {
    this( input, new RecognizerSharedState() );
}
 
Example #11
Source File: FilterParser.java    From binnavi with Apache License 2.0 4 votes vote down vote up
public FilterParser(final TokenStream input) {
  this(input, new RecognizerSharedState());
}
 
Example #12
Source File: InternalTaxonomyParser.java    From slr-toolkit with Eclipse Public License 1.0 4 votes vote down vote up
public InternalTaxonomyParser(TokenStream input) {
    this(input, new RecognizerSharedState());
}
 
Example #13
Source File: QueryFilterLexer.java    From usergrid with Apache License 2.0 4 votes vote down vote up
public QueryFilterLexer( CharStream input ) {
    this( input, new RecognizerSharedState() );
}
 
Example #14
Source File: QueryFilterParser.java    From usergrid with Apache License 2.0 4 votes vote down vote up
public QueryFilterParser( TokenStream input, RecognizerSharedState state ) {
    super( input, state );
}
 
Example #15
Source File: CTFLexer.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
public CTFLexer(CharStream input, RecognizerSharedState state) {
	super(input,state);
}
 
Example #16
Source File: FastSimpleGenericEdifactDirectXMLLexer.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public FastSimpleGenericEdifactDirectXMLLexer( CharStream input ) {
  this( input, new RecognizerSharedState() );
}
 
Example #17
Source File: CobolStructureEmitterImpl.java    From legstar-core2 with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Construct from a tree nodes stream.
 * @param input the tree nodes stream
 * @param errorHandler handles error messages
 */
public CobolStructureEmitterImpl(
        final TreeNodeStream input,
        final RecognizerErrorHandler errorHandler) {
    this(input, new RecognizerSharedState(), errorHandler);
}
 
Example #18
Source File: CobolStructureLexerImpl.java    From legstar-core2 with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Construct from a character stream.
 * @param input the character stream
 * @param errorHandler handles error messages
 */
public CobolStructureLexerImpl(
        final CharStream input,
        final RecognizerErrorHandler errorHandler) {
    this(input, new RecognizerSharedState(), errorHandler);
}
 
Example #19
Source File: CFMLLexer.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
public CFMLLexer(CharStream input) {
    this(input, new RecognizerSharedState());
}
 
Example #20
Source File: LexerErrorInterface.java    From HeyGirl with Apache License 2.0 4 votes vote down vote up
public ANTLRLexerWithErrorInterface(CharStream input, RecognizerSharedState state) {
    super(input, state);
}
 
Example #21
Source File: QueryFilterLexer.java    From usergrid with Apache License 2.0 4 votes vote down vote up
public QueryFilterLexer( CharStream input, RecognizerSharedState state ) {
    super( input, state );
}
 
Example #22
Source File: ConditionParser.java    From binnavi with Apache License 2.0 4 votes vote down vote up
public ConditionParser(final TokenStream input) {
  this(input, new RecognizerSharedState());
}
 
Example #23
Source File: ConditionLexer.java    From binnavi with Apache License 2.0 4 votes vote down vote up
public ConditionLexer(final CharStream input) {
  this(input, new RecognizerSharedState());
}
 
Example #24
Source File: MemoryExpressionLexer.java    From binnavi with Apache License 2.0 4 votes vote down vote up
public MemoryExpressionLexer(final CharStream input) {
  this(input, new RecognizerSharedState());
}
 
Example #25
Source File: MemoryExpressionParser.java    From binnavi with Apache License 2.0 4 votes vote down vote up
public MemoryExpressionParser(final TokenStream input) {
  this(input, new RecognizerSharedState());
}
 
Example #26
Source File: EofListener.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected RecognizerSharedState getParserState() {
	return parserState;
}
 
Example #27
Source File: Lexer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected Lexer(CharStream input, RecognizerSharedState state) {
	super(input, state);
}
 
Example #28
Source File: FastSimpleGenericEdifactDirectXMLLexer.java    From hop with Apache License 2.0 4 votes vote down vote up
public FastSimpleGenericEdifactDirectXMLLexer( CharStream input ) {
  this( input, new RecognizerSharedState() );
}
 
Example #29
Source File: Lexer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Lexer(CharStream input, RecognizerSharedState state) {
    super(input,state);
}
 
Example #30
Source File: AbstractInternalAntlrParser.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected AbstractInternalAntlrParser(TokenStream input, RecognizerSharedState state) {
	super(input, state);
}