Tabnine Logo
CommonTokenStream.seek
Code IndexAdd Tabnine to your IDE (free)

How to use
seek
method
in
org.antlr.v4.runtime.CommonTokenStream

Best Java code snippets using org.antlr.v4.runtime.CommonTokenStream.seek (Showing top 6 results out of 315)

origin: confluentinc/ksql

private ParserRuleContext getParseTree(final String sql) {
 final SqlBaseLexer sqlBaseLexer = new SqlBaseLexer(
   new CaseInsensitiveStream(CharStreams.fromString(sql)));
 final CommonTokenStream tokenStream = new CommonTokenStream(sqlBaseLexer);
 final SqlBaseParser sqlBaseParser = new SqlBaseParser(tokenStream);
 sqlBaseLexer.removeErrorListeners();
 sqlBaseLexer.addErrorListener(ERROR_LISTENER);
 sqlBaseParser.removeErrorListeners();
 sqlBaseParser.addErrorListener(ERROR_LISTENER);
 final Function<SqlBaseParser, ParserRuleContext> parseFunction = SqlBaseParser::statements;
 try {
  // first, try parsing with potentially faster SLL mode
  sqlBaseParser.getInterpreter().setPredictionMode(PredictionMode.SLL);
  return parseFunction.apply(sqlBaseParser);
 } catch (final ParseCancellationException ex) {
  // if we fail, parse with LL mode
  tokenStream.seek(0); // rewind input stream
  sqlBaseParser.reset();
  sqlBaseParser.getInterpreter().setPredictionMode(PredictionMode.LL);
  return parseFunction.apply(sqlBaseParser);
 }
}
origin: org.bitbucket.goalhub.krTools.krLanguages/swiprolog

public void switchToFullLL() {
  // First rewind the token stream
  this.tokens.seek(0);
  // Use full (custom) error reporting now
  this.parser.setErrorHandler(new ErrorStrategy4());
  this.parser.addErrorListener(this);
  // Now try full LL(*)
  this.parser.getInterpreter().setPredictionMode(PredictionMode.LL);
}
origin: stanford-futuredata/macrobase

private Node invokeParser(String name, String sql,
  Function<SqlBaseParser, ParserRuleContext> parseFunction) {
  try {
    SqlBaseLexer lexer = new SqlBaseLexer(
      new CaseInsensitiveStream(new ANTLRInputStream(sql)));
    CommonTokenStream tokenStream = new CommonTokenStream(lexer);
    SqlBaseParser parser = new SqlBaseParser(tokenStream);
    parser.addParseListener(new PostProcessor(Arrays.asList(parser.getRuleNames())));
    lexer.removeErrorListeners();
    lexer.addErrorListener(ERROR_LISTENER);
    parser.removeErrorListeners();
    parser.addErrorListener(ERROR_LISTENER);
    ParserRuleContext tree;
    try {
      // first, try parsing with potentially faster SLL mode
      parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
      tree = parseFunction.apply(parser);
    } catch (ParseCancellationException ex) {
      // if we fail, parse with LL mode
      tokenStream.seek(0); // rewind input stream
      parser.reset();
      parser.getInterpreter().setPredictionMode(PredictionMode.LL);
      tree = parseFunction.apply(parser);
    }
    return new AstBuilder().visit(tree);
  } catch (StackOverflowError e) {
    throw new ParsingException(name + " is too large (stack overflow while parsing)");
  }
}
origin: harbby/sylph

tokenStream.seek(0); // rewind input stream
parser.reset();
origin: bkiers/Liqp

private ParseTree parse(LiquidLexer lexer) {
  lexer.removeErrorListeners();
  lexer.addErrorListener(new BaseErrorListener(){
    @Override
    public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
      throw new RuntimeException(String.format("lexer error on line %s, index %s", line, charPositionInLine), e);
    }
  });
  CommonTokenStream tokens = new CommonTokenStream(lexer);
  LiquidParser parser = new LiquidParser(tokens);
  parser.removeErrorListeners();
  parser.addErrorListener(new BaseErrorListener(){
    @Override
    public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
      throw new RuntimeException(String.format("parser error on line %s, index %s", line, charPositionInLine), e);
    }
  });
  
  parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
  try {
    return parser.parse();
  } catch (Exception e) {
    tokens.seek(0);
    parser.reset();
    parser.getInterpreter().setPredictionMode(PredictionMode.LL);
    return parser.parse();
  }
}
origin: org.bitbucket.goalhub.grammar/languageTools

this.tokens.seek(0);
org.antlr.v4.runtimeCommonTokenStreamseek

Popular methods of CommonTokenStream

  • <init>
    Constructs a new CommonTokenStream using the specified token source and filtering tokens to the spec
  • getTokens
  • fill
  • get
  • getHiddenTokensToLeft
  • size
  • LA
  • getHiddenTokensToRight
  • reset
  • LB
  • getText
  • getTokenSource
  • getText,
  • getTokenSource,
  • lazyInit,
  • nextTokenOnChannel,
  • previousTokenOnChannel,
  • sync,
  • LT,
  • consume,
  • index

Popular in Java

  • Finding current android device location
  • requestLocationUpdates (LocationManager)
  • setScale (BigDecimal)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • InputStreamReader (java.io)
    A class for turning a byte stream into a character stream. Data read from the source input stream is
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • XPath (javax.xml.xpath)
    XPath provides access to the XPath evaluation environment and expressions. Evaluation of XPath Expr
  • Logger (org.slf4j)
    The org.slf4j.Logger interface is the main user entry point of SLF4J API. It is expected that loggin
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now