List of usage examples for org.antlr.v4.runtime CharStream LA
int LA(int i);
From source file:com.antsdb.saltedfish.sql.mysql.ExprGenerator.java
License:Open Source License
private static byte[] getBytes(Literal_value_binaryContext rule) { Token token = rule.STRING_LITERAL().getSymbol(); byte[] bytes = new byte[token.getStopIndex() - token.getStartIndex() - 1]; CharStream cs = token.getInputStream(); int pos = cs.index(); cs.seek(token.getStartIndex() + 1);//from w w w. ja va2s. c o m int j = 0; for (int i = 0; i < bytes.length; i++) { int ch = cs.LA(i + 1); if (ch == '\\') { i++; ch = cs.LA(i + 1); if (ch == '0') { ch = 0; } else if (ch == 'n') { ch = '\n'; } else if (ch == 'r') { ch = '\r'; } else if (ch == 'Z') { ch = '\032'; } } bytes[j] = (byte) ch; j++; } cs.seek(pos); if (j != bytes.length) { // esacpe characters byte[] old = bytes; bytes = new byte[j]; System.arraycopy(old, 0, bytes, 0, j); } return bytes; }
From source file:com.antsdb.saltedfish.sql.mysql.MysqlParserFactory.java
License:Open Source License
/** * mysql executes statement in a specially formatted comment like * / *!40101 SET NAMES utf8 * /;/*from w ww.ja v a 2 s.c om*/ * @param cs * @return */ private static boolean isCommtedStatement(CharStream cs) { int idx = cs.index(); if (cs.LA(idx + 1) != '/') { return false; } if (cs.LA(idx + 2) != '*') { return false; } if (cs.LA(idx + 3) != '!') { return false; } if (cs.LA(idx + 4) != '4') { return false; } return true; }
From source file:net.certiv.json.test.base.AbstractBase.java
License:Open Source License
public List<String> getTokenTypes(LexerGrammar lg, ATN atn, CharStream input) { LexerATNSimulator interp = new LexerATNSimulator(atn, new DFA[] { new DFA(atn.modeToStartState.get(Lexer.DEFAULT_MODE)) }, null); List<String> tokenTypes = new ArrayList<String>(); int ttype;//from www.j a v a 2 s . c o m boolean hitEOF = false; do { if (hitEOF) { tokenTypes.add("EOF"); break; } int t = input.LA(1); ttype = interp.match(input, Lexer.DEFAULT_MODE); if (ttype == Token.EOF) { tokenTypes.add("EOF"); } else { tokenTypes.add(lg.typeToTokenList.get(ttype)); } if (t == IntStream.EOF) { hitEOF = true; } } while (ttype != Token.EOF); return tokenTypes; }