public static Token nextRealToken(CommonTokenStream tokens, int i) { int n = tokens.size(); i++; // search after current i token if ( i>=n || i<0 ) return null; Token t = tokens.get(i); while ( t.getChannel()==Token.HIDDEN_CHANNEL ) { if ( t.getType()==Token.EOF ) { TokenSource tokenSource = tokens.getTokenSource(); if ( tokenSource==null ) { return new CommonToken(Token.EOF, "EOF"); } TokenFactory<?> tokenFactory = tokenSource.getTokenFactory(); if ( tokenFactory==null ) { return new CommonToken(Token.EOF, "EOF"); } return tokenFactory.create(Token.EOF, "EOF"); } i++; if ( i>=n ) return null; // just in case no EOF t = tokens.get(i); } return t; }
public StashingTokenFactory(TokenFactory<T> delegate) { this.delegate = delegate; }
@Override public void setTokenFactory(TokenFactory<?> factory) { source().setTokenFactory(factory); }
@Override public TokenFactory<?> getTokenFactory() { return source().getTokenFactory(); }
@Override public void setTokenFactory(TokenFactory<?> tokenFactory) { this.tokenFactory = tokenFactory; }
@Override public TokenFactory<?> getTokenFactory() { return tokenFactory; }
@Override public TokenFactory<?> getTokenFactory() { return tokenSource.getTokenFactory(); }
@Override public void setTokenFactory(TokenFactory<?> tokenFactory) { tokenSource.setTokenFactory(tokenFactory); }
@Override public TokenFactory<?> getTokenFactory() { return CommonTokenFactory.DEFAULT; }
@Override public void setTokenFactory(TokenFactory<?> factory) { }
@Override public TokenFactory getTokenFactory() { return grammarLexer.getTokenFactory(); }
@Override public void setTokenFactory(TokenFactory tokenFactory) { grammarLexer.setTokenFactory(tokenFactory); }
@Override public TokenFactory getTokenFactory() { return groupLexer.getTokenFactory(); }
@Override public void setTokenFactory(TokenFactory tokenFactory) { groupLexer.setTokenFactory(tokenFactory); }
@Override public TokenFactory getTokenFactory() { return lexer.getTokenFactory(); }
@Override public void setTokenFactory(TokenFactory tokenFactory) { lexer.setTokenFactory(tokenFactory); }
@Override public TokenFactory getTokenFactory() { return tokenFactory; }
@Override public void setTokenFactory(TokenFactory tokenFactory) { source.setTokenFactory(tokenFactory); this.tokenFactory = tokenFactory != null ? tokenFactory : CommonTokenFactory.DEFAULT; }
@Override public void setTokenFactory(TokenFactory tokenFactory) { Parameters.notNull("tokenFactory", tokenFactory); this.tokenFactory = tokenFactory; }
@Override public void setTokenFactory(TokenFactory<?> factory) { this.factory = factory; }
@Override public TokenFactory<?> getTokenFactory() { return factory; }