org.antlr.runtime.BitSet Java Examples

The following examples show how to use org.antlr.runtime.BitSet. 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: SemicolonInjectionHelper.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
boolean matches(BitSet bitSet) {
	long[] array = bitSet.toPackedArray();
	int len = array.length;
	if (len < 3 || array[0] != 0L) {
		return false;
	}
	long leftBits = array[1];
	long rightBits = array[2];
	if (rightBits == semicolonRecoverySetRight
			&& (leftBits == semicolonRecoverySetLeft || leftBits == semicolonRecoverySetWithComma)) {
		for (int i = 3; i < len; i++) {
			if (array[i] != 0L) {
				return false;
			}
		}
		return true;
	}
	return false;
}
 
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: ExtCss3Parser.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Consume tokens until one matches the given token set */
    @Override
    public void consumeUntil(IntStream i, BitSet set) {
//        System.out.println("consumeUntil(" + set.toString(getTokenNames()) + ")");
        Token ttype;
        List<Token> skipped = new ArrayList<>();
        beginResync();
        try {
            while ((ttype = input.LT(1)) != null && ttype.getType() != Token.EOF && !set.member(ttype.getType())) {
//            System.out.println("consume during recover LA(1)=" + getTokenNames()[input.LA(1)]);
                input.consume();
                skipped.add(ttype);
            }
        } finally {
            endResync();
        }
        ((NbParseTreeBuilder) dbg).consumeSkippedTokens(skipped);
    }
 
Example #4
Source File: DroolsParserExceptionFactory.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
private String expectedTokensAsString( BitSet set ) {
    StringBuilder buf = new StringBuilder();
    buf.append( "{ " );
    int i = 0;
    for ( int token : set.toArray() ) {
        if ( i > 0 ) buf.append( ", " );
        buf.append( getBetterToken( token ) );
        i++;
    }
    buf.append( " }" );
    return buf.toString();
}
 
Example #5
Source File: InternalSemicolonInjectingParser.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** Added for debugging purposes only. */
@SuppressWarnings("unused")
private String bitsetName(BitSet bitset) {
	Optional<Field> findField = Stream.of(InternalN4JSParser.class.getDeclaredFields())
			.filter(f -> Modifier.isStatic(f.getModifiers())).filter(f -> {
				try {
					return bitset == f.get(null);
				} catch (Exception ex) {
					//
				}
				return false;
			}).findFirst();
	return findField.map(Field::getName).orElse("NN");
}
 
Example #6
Source File: BaseInternalContentAssistParser.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Object recoverFromMismatchedToken(IntStream input, int ttype, BitSet follow) throws RecognitionException {
	try {
		mismatch = true;
		return super.recoverFromMismatchedToken(input, ttype, follow);
	} finally {
		mismatch = false;
	}
}
 
Example #7
Source File: SemicolonInjectionHelper.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Computes the ASI recovery sets.
 */
default RecoverySets computeRecoverySets() {
	BitSet followSet = getSemicolonFollowSet();
	long[] array = followSet.toPackedArray();
	if (array.length != 3 || array[0] != 0L) {
		throw new RuntimeException("Internal token types changed. Need to rework ASI.");
	}
	int commaBit = getCommaBit() - Long.SIZE;
	if (commaBit < 0 || commaBit > Long.SIZE) {
		throw new RuntimeException("Internal token types changed. Need to rework ASI.");
	}
	RecoverySets result = new RecoverySets(array, commaBit);

	return result;
}
 
Example #8
Source File: Bug326509Test.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testBug326509() {
	for(int i = 0; i <= 200; i++) {
		testMe.pushFollow(new BitSet());
	}
	BitSet[] following = testMe.getFollowing();
	for(int i = 0; i < following.length && i <= 200; i++) {
		assertNotNull(Integer.toString(i), following[i]);
	}
}
 
Example #9
Source File: Bug326509Test.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testBug326509() {
	for(int i = 0; i <= 200; i++) {
		testMe.pushFollow(new BitSet());
	}
	BitSet[] following = testMe.getFollowing();
	for(int i = 0; i < following.length && i <= 200; i++) {
		assertNotNull(Integer.toString(i), following[i]);
	}
}
 
Example #10
Source File: FastSimpleGenericEdifactDirectXMLParser.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public Object recoverFromMismatchedSet( IntStream input, RecognitionException e, BitSet follow ) throws RecognitionException {
  throw e;
}
 
Example #11
Source File: FastSimpleGenericEdifactDirectXMLParser.java    From hop with Apache License 2.0 4 votes vote down vote up
protected void mismatch( IntStream input, int ttype, BitSet follow ) throws RecognitionException {
  throw new MismatchedTokenException( ttype, input );
}
 
Example #12
Source File: FastSimpleGenericEdifactDirectXMLParser.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
protected void mismatch( IntStream input, int ttype, BitSet follow ) throws RecognitionException {
  throw new MismatchedTokenException( ttype, input );
}
 
Example #13
Source File: BaseInternalContentAssistParser.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean mismatchIsMissingToken(IntStream input, BitSet follow) {
	return false;
}
 
Example #14
Source File: Bug326509Test.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void pushFollow(BitSet bitSet) {
	super.pushFollow(bitSet);
}
 
Example #15
Source File: Bug326509Test.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public BitSet[] getFollowing() {
	return state.following;
}
 
Example #16
Source File: Bug326509Test.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void pushFollow(BitSet bitSet) {
	super.pushFollow(bitSet);
}
 
Example #17
Source File: Bug326509Test.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public BitSet[] getFollowing() {
	return state.following;
}
 
Example #18
Source File: ExtCss3Parser.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
protected Object recoverFromMismatchedToken(IntStream input, int ttype, BitSet follow) throws RecognitionException {
    //disable the default token auto-insertion/deletion recovery
    throw new MismatchedTokenException(ttype, input);
}
 
Example #19
Source File: InternalSemicolonInjectingParser.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public BitSet getSemicolonFollowSet() {
	return FOLLOW_ruleExpression_in_ruleExpressionStatement;
}
 
Example #20
Source File: InternalHighlightingParser.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public BitSet getSemicolonFollowSet() {
	return FOLLOW_ruleExpression_in_ruleExpressionStatement;
}
 
Example #21
Source File: FastSimpleGenericEdifactDirectXMLParser.java    From hop with Apache License 2.0 4 votes vote down vote up
public Object recoverFromMismatchedSet( IntStream input, RecognitionException e, BitSet follow ) throws RecognitionException {
  throw e;
}
 
Example #22
Source File: SemicolonInjectionHelper.java    From n4js with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Obtain the follow set that is relevant for the ASI.
 */
BitSet getSemicolonFollowSet();