Java Code Examples for org.antlr.runtime.CharStream#EOF
The following examples show how to use
org.antlr.runtime.CharStream#EOF .
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: QueryParserStreamUtil.java From spork with Apache License 2.0 | 6 votes |
/** * Refer to ANTLRStringStream class for definitions of n, p, and data. * @param i look ahead number */ public static int LA(int i, int n, int p, char[] data) { if( i == 0 ) { return 0; // undefined } if ( i < 0 ) { i++; // e.g., translate LA(-1) to use offset 0 } if( p + i - 1 >= n ) { return CharStream.EOF; } return Character.toUpperCase( data[ p + i - 1 ] ); }
Example 2
Source File: Lexer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public Token nextToken() { while (true) { state.token = null; state.channel = Token.DEFAULT_CHANNEL; state.tokenStartCharIndex = input.index(); state.tokenStartCharPositionInLine = input.getCharPositionInLine(); state.tokenStartLine = input.getLine(); state.text = null; if ( input.LA(1)==CharStream.EOF ) { return Token.EOF_TOKEN; } try { mTokens(); if ( state.token==null ) { emit(); } else if ( state.token==Token.SKIP_TOKEN ) { continue; } return state.token; } /* * Avoid infinite loop (editor freeze) on {@link FailedPredicateException} */ catch (NoViableAltException | FailedPredicateException e) { reportError(e); recover(e); // throw out current char and try again } catch (RecognitionException re) { reportError(re); // match() routine has already called recover() } } }
Example 3
Source File: SQLParser.java From phoenix with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public int LA(int i) { if (i == 0) { return 0; // undefined } if (i < 0) { i++; // e.g., translate LA(-1) to use offset 0 } if ((p + i - 1) >= n) { return CharStream.EOF; } return Character.toLowerCase(data[p + i - 1]); }
Example 4
Source File: SQLParser.java From phoenix with Apache License 2.0 | 5 votes |
@Override public int LA(int i) { if (i == 0) { return 0; // undefined } if (i < 0) { i++; // e.g., translate LA(-1) to use offset 0 } if ((p + i - 1) >= n) { return CharStream.EOF; } return Character.toLowerCase(data[p + i - 1]); }
Example 5
Source File: CliCompiler.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public int LA(int i) { int returnChar = super.LA(i); if (returnChar == CharStream.EOF) { return returnChar; } else if (returnChar == 0) { return returnChar; } return Character.toUpperCase((char)returnChar); }
Example 6
Source File: CFMLLexer.java From openbd-core with GNU General Public License v3.0 | 5 votes |
public Token nextToken() { if ( state.token != null && state.token.getType() == SCRIPTCLOSE ){ return Token.EOF_TOKEN; } while (true) { state.token = null; state.channel = Token.DEFAULT_CHANNEL; state.tokenStartCharIndex = input.index(); state.tokenStartCharPositionInLine = input.getCharPositionInLine(); state.tokenStartLine = input.getLine(); state.text = null; if ( input.LA(1)==CharStream.EOF ) { return Token.EOF_TOKEN; } try { mTokens(); if ( state.token==null ) { emit(); } else if ( state.token==Token.SKIP_TOKEN ) { continue; } return state.token; } catch (RecognitionException re) { //reportError(re); return Token.EOF_TOKEN; //throw new RuntimeException("Bailing out!"); // or throw Error } } }
Example 7
Source File: ANTLRNoCaseReaderStream.java From openbd-core with GNU General Public License v3.0 | 5 votes |
@Override public int LA( int i ) { if ( i==0 ) { return 0; // undefined } if ( i<0 ) { i++; // e.g., translate LA(-1) to use offset 0 } if ( (p+i-1) >= n ) { return CharStream.EOF; } return Character.toUpperCase(data[p+i-1]); }
Example 8
Source File: ANTLRNoCaseStringStream.java From openbd-core with GNU General Public License v3.0 | 5 votes |
@Override public int LA( int i ) { if ( i==0 ) { return 0; // undefined } if ( i<0 ) { i++; // e.g., translate LA(-1) to use offset 0 } if ( (p+i-1) >= n ) { return CharStream.EOF; } return Character.toUpperCase(data[p+i-1]); }
Example 9
Source File: SQLParser.java From phoenix with Apache License 2.0 | 5 votes |
@Override public int LA(int i) { if (i == 0) { return 0; // undefined } if (i < 0) { i++; // e.g., translate LA(-1) to use offset 0 } if ((p + i - 1) >= n) { return CharStream.EOF; } return Character.toLowerCase(data[p + i - 1]); }
Example 10
Source File: Lexer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public Token nextToken() { while (true) { this.state.token = null; this.state.channel = Token.DEFAULT_CHANNEL; this.state.tokenStartCharIndex = input.index(); this.state.tokenStartCharPositionInLine = input.getCharPositionInLine(); this.state.tokenStartLine = input.getLine(); this.state.text = null; if (input.LA(1) == CharStream.EOF) { return Token.EOF_TOKEN; } try { mTokens(); if (this.state.token == null) { emit(); } else if (this.state.token == Token.SKIP_TOKEN) { continue; } return this.state.token; } catch (RecognitionException re) { reportError(re); if (re instanceof NoViableAltException || re instanceof FailedPredicateException) { recover(re); } // create token that holds mismatched char Token t = new CommonToken(input, Token.INVALID_TOKEN_TYPE, Token.HIDDEN_CHANNEL, this.state.tokenStartCharIndex, getCharIndex() - 1); t.setLine(this.state.tokenStartLine); t.setCharPositionInLine(this.state.tokenStartCharPositionInLine); tokenErrorMap.put(t, getErrorMessage(re, this.getTokenNames())); emit(t); return this.state.token; } } }
Example 11
Source File: AntlrNoCaseStringStream.java From cuba with Apache License 2.0 | 5 votes |
@Override public int LA(int i) { if (i == 0) { return 0; // undefined } if (i < 0) { i++; // e.g., translate LA(-1) to use offset 0 } if ((p + i - 1) >= n) { return CharStream.EOF; } return Character.toUpperCase(data[p + i - 1]); }
Example 12
Source File: Lexer.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override public Token nextToken() { while (true) { this.state.token = null; this.state.channel = Token.DEFAULT_CHANNEL; this.state.tokenStartCharIndex = input.index(); this.state.tokenStartCharPositionInLine = input .getCharPositionInLine(); this.state.tokenStartLine = input.getLine(); this.state.text = null; if (input.LA(1) == CharStream.EOF) { return Token.EOF_TOKEN; } try { mTokens(); if (this.state.token == null) { emit(); } else if (this.state.token == Token.SKIP_TOKEN) { continue; } return this.state.token; } catch (RecognitionException re) { reportError(re); if (re instanceof NoViableAltException || re instanceof FailedPredicateException) { recover(re); } // create token that holds mismatched char Token t = new CommonToken(input, Token.INVALID_TOKEN_TYPE, Token.HIDDEN_CHANNEL, this.state.tokenStartCharIndex, getCharIndex() - 1); t.setLine(this.state.tokenStartLine); t.setCharPositionInLine( this.state.tokenStartCharPositionInLine); tokenErrorMap.put(t, getErrorMessage(re, this.getTokenNames())); emit(t); return this.state.token; } } }
Example 13
Source File: Lexer.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public Token nextToken() { while (true) { state.token = null; state.channel = Token.DEFAULT_CHANNEL; state.tokenStartCharIndex = input.index(); state.tokenStartCharPositionInLine = input.getCharPositionInLine(); state.tokenStartLine = input.getLine(); state.text = null; if ( input.LA(1)==CharStream.EOF ) { return Token.EOF_TOKEN; } try { mTokens(); if ( state.token==null ) { emit(); } else if ( state.token==Token.SKIP_TOKEN ) { continue; } return state.token; } /* * Avoid infinite loop (editor freeze) on {@link FailedPredicateException} */ catch (NoViableAltException | FailedPredicateException e) { reportError(e); recover(e); // throw out current char and try again } catch (RecognitionException re) { reportError(re); // match() routine has already called recover() } } }
Example 14
Source File: AntlrCharStream.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
private int read() { int result = input.read(); if (result == LexerInput.EOF) { result = CharStream.EOF; } return result; }
Example 15
Source File: CaseInsensitiveStream.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public int LA(int i) { int result = stream.LT(i); switch (result) { case 0: case CharStream.EOF: return result; default: return Character.toUpperCase(result); } }
Example 16
Source File: NbLexerCharStream.java From netbeans with Apache License 2.0 | 5 votes |
private int read() { int result = li.read(); if (result == LexerInput.EOF) { result = CharStream.EOF; } return result; }
Example 17
Source File: LazyTokenStream.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** * Fills the buffer but stops on a div or div-equals token. */ @SuppressWarnings("unchecked") @Override protected void fillBuffer() { int oldP = p; int index = tokens.size(); Token t = tokenSource.nextToken(); while (t != null && t.getType() != CharStream.EOF) { // stop on div, div-equal and right curly brace tokens. int type = t.getType(); if (type == InternalN4JSLexer.Solidus || type == InternalN4JSLexer.SolidusEqualsSign || type == InternalN4JSLexer.RightCurlyBracket) { t.setTokenIndex(index); tokens.add(t); index++; break; } boolean discard = false; // is there a channel override for token type? if (channelOverrideMap != null) { Integer channelI = (Integer) channelOverrideMap.get(Integer.valueOf(type)); if (channelI != null) { t.setChannel(channelI.intValue()); } } if (discardSet != null && discardSet.contains(Integer.valueOf(type))) { discard = true; } else if (discardOffChannelTokens && t.getChannel() != this.channel) { discard = true; } if (!discard) { t.setTokenIndex(index); tokens.add(t); index++; } t = tokenSource.nextToken(); } // leave p pointing at first token on channel p = oldP == -1 ? 0 : oldP; p = skipOffTokenChannels(p); }