當前位置: 首頁>>代碼示例>>Java>>正文


Java Lexer.removeErrorListeners方法代碼示例

本文整理匯總了Java中org.antlr.v4.runtime.Lexer.removeErrorListeners方法的典型用法代碼示例。如果您正苦於以下問題:Java Lexer.removeErrorListeners方法的具體用法?Java Lexer.removeErrorListeners怎麽用?Java Lexer.removeErrorListeners使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.antlr.v4.runtime.Lexer的用法示例。


在下文中一共展示了Lexer.removeErrorListeners方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: makeBasicParser

import org.antlr.v4.runtime.Lexer; //導入方法依賴的package包/類
private static <T extends Parser> T makeBasicParser(Class<T> parserClass,
        ANTLRInputStream stream, String parsedObjectName, List<AntlrError> errors) {
    Lexer lexer;
    Parser parser;
    if (parserClass.isAssignableFrom(SQLParser.class)) {
        lexer = new SQLLexer(stream);
        parser = new SQLParser(new CommonTokenStream(lexer));
    } else if (parserClass.isAssignableFrom(IgnoreListParser.class)) {
        lexer = new IgnoreListLexer(stream);
        parser = new IgnoreListParser(new CommonTokenStream(lexer));
    } else {
        throw new IllegalArgumentException("Unknown parser class: " + parserClass);
    }

    CustomAntlrErrorListener err = new CustomAntlrErrorListener(parsedObjectName, errors);
    lexer.removeErrorListeners();
    lexer.addErrorListener(err);
    parser.removeErrorListeners();
    parser.addErrorListener(err);

    return parserClass.cast(parser);
}
 
開發者ID:pgcodekeeper,項目名稱:pgcodekeeper,代碼行數:23,代碼來源:AntlrParser.java

示例2: parseFile

import org.antlr.v4.runtime.Lexer; //導入方法依賴的package包/類
/**
 * Parses the supplied input using the OTLDListener and returns it after walking it
 * @param reader input to parse
 * @return walked OTLDListener
 * @throws IOException
 */
public static OTLDListener parseFile(InputStream reader) throws IOException {
    OTLDErrorListener errorListener = new OTLDErrorListener();
    ANTLRInputStream stream = new ANTLRInputStream(reader);

    Lexer lexer = new otldLexer(stream);
    lexer.removeErrorListeners();
    lexer.addErrorListener(errorListener);
    TokenStream tokens = new CommonTokenStream(lexer);

    otldParser parser = new otldParser(tokens);
    parser.removeErrorListeners();
    parser.addErrorListener(errorListener);
    ParseTree tree = parser.program();

    OTLDListener railroad = new OTLDListener();

    if (errorListener.getErrors().isEmpty()) {
        ParseTreeWalker walker = new ParseTreeWalker();
        walker.walk(railroad, tree);
    } else {
        railroad.errors.addAll(errorListener.getErrors());
    }

    return railroad;
}
 
開發者ID:jjkester,項目名稱:transportlanguage,代碼行數:32,代碼來源:OTLDListener.java

示例3: parse

import org.antlr.v4.runtime.Lexer; //導入方法依賴的package包/類
@Override
public void parse(Snapshot snapshot, Task task, SourceModificationEvent event) throws ParseException {
    this.snapshot = snapshot;
    String text = snapshot.getText().toString();
    ANTLRInputStream input = new ANTLRInputStream(text);
    Lexer lexer = new EditorConfigLexer(input);
    lexer.removeErrorListeners();

    CommonTokenStream tokens = new CommonTokenStream(lexer);
    parser = new EditorConfigParser(tokens);
    parser.removeErrorListeners();
    syntaxErrors = new ArrayList<>();
    EditorConfigErrorListener errorListener = new EditorConfigErrorListener(syntaxErrors);
    parser.addErrorListener(errorListener);
    EditorConfigParser.FileContext root = parser.file();
    result = new ECParserResult(snapshot, parser, root);
}
 
開發者ID:junichi11,項目名稱:netbeans-editorconfig-editor,代碼行數:18,代碼來源:ECParser.java

示例4: parse

import org.antlr.v4.runtime.Lexer; //導入方法依賴的package包/類
@Override
public void parse(Snapshot snapshot, Task task, SourceModificationEvent event) throws ParseException {
  this.snapshot = snapshot;
  String text = snapshot.getText().toString();
  ANTLRInputStream input = new ANTLRInputStream(text);
  Lexer lexer = new EditorConfigLexer(input);
  lexer.removeErrorListeners();

  CommonTokenStream tokens = new CommonTokenStream(lexer);
  parser = new EditorConfigParser(tokens);
  parser.removeErrorListeners();
  syntaxErrors = new ArrayList<>();
  EditorConfigErrorListener errorListener = new EditorConfigErrorListener(syntaxErrors);
  parser.addErrorListener(errorListener);
  EditorConfigParser.FileContext root = parser.file();
  result = new ECParserResult(snapshot, parser, root);
}
 
開發者ID:welovecoding,項目名稱:editorconfig-netbeans,代碼行數:18,代碼來源:ECParser.java

示例5: parseAnnisQuery

import org.antlr.v4.runtime.Lexer; //導入方法依賴的package包/類
private ParserRuleContext parseAnnisQuery (String query) {
    Lexer lexer = new AqlLexer((CharStream) null);
    ParserRuleContext tree = null;
    Antlr4DescriptiveErrorListener errorListener = new Antlr4DescriptiveErrorListener(
            query);
    // Like p. 111
    try {
        // Tokenize input data
        ANTLRInputStream input = new ANTLRInputStream(query);
        lexer.setInputStream(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        parser = new AqlParser(tokens);
        // Don't throw out erroneous stuff
        parser.setErrorHandler(new BailErrorStrategy());
        lexer.removeErrorListeners();
        lexer.addErrorListener(errorListener);
        parser.removeErrorListeners();
        parser.addErrorListener(errorListener);
        // Get starting rule from parser
        Method startRule = AqlParser.class.getMethod("start");
        tree = (ParserRuleContext) startRule.invoke(parser,
                (Object[]) null);
    }
    // Some things went wrong ...
    catch (Exception e) {
        log.error("Could not parse query. "
                + "Please make sure it is well-formed.");
        log.error(errorListener.generateFullErrorMsg().toString());
        addError(errorListener.generateFullErrorMsg());
    }
    return tree;
}
 
開發者ID:KorAP,項目名稱:Koral,代碼行數:33,代碼來源:AnnisQueryProcessor.java

示例6: doAutocomplete

import org.antlr.v4.runtime.Lexer; //導入方法依賴的package包/類
public AutocompleteResult doAutocomplete(String txt, int cur, ClassLoader l, Imports imports) {
  registry = AutocompleteRegistryFactory.createRegistry(cps);
  GroovyClassUtils cu = createClassUtils(l);
  setup(cu, registry);
  AutocompleteRegistryFactory.addDefaultImports(cu, registry, imports.toListOfStrings(), cps);
  AutocompleteRegistryFactory.moreSetup(cu);
  moreSetup(registry);

  Lexer lexer = new GroovyLexer(new ANTLRInputStream(txt));
  lexer.removeErrorListeners();
  CommonTokenStream tokens = new CommonTokenStream(lexer);

  // Create a parser that reads from the scanner
  GroovyParser parser = new GroovyParser(tokens);
  parser.removeErrorListeners();

  // start parsing at the compilationUnit rule
  ParserRuleContext t = parser.compilationUnit();
  ParseTreeWalker walker = new ParseTreeWalker();
  List<AutocompleteCandidate> q = new ArrayList<>();

  GroovyImportDeclarationCompletion extractor = new GroovyImportDeclarationCompletion(txt, cur, registry, cps, cu);
  GroovyNameBuilder extractor2 = new GroovyNameBuilder(registry, cu);
  GroovyNodeCompletion extractor3 = new GroovyNodeCompletion(txt, cur, registry, cu);

  walker.walk(extractor, t);
  if (extractor.getQuery() != null)
    q.addAll(extractor.getQuery());
  walker.walk(extractor2, t);
  walker.walk(extractor3, t);
  if (extractor3.getQuery() != null)
    q.addAll(extractor3.getQuery());
  List<String> ret = registry.searchCandidates(q);

  if (!ret.isEmpty()) {
    return new AutocompleteResult(ret, getStartIndex(extractor, extractor2, extractor3));
  }
  return findAutocompleteResult(txt, cur, cu);
}
 
開發者ID:twosigma,項目名稱:beakerx,代碼行數:40,代碼來源:GroovyAutocomplete.java

示例7: doAutocomplete

import org.antlr.v4.runtime.Lexer; //導入方法依賴的package包/類
public AutocompleteResult doAutocomplete(String txt, int cur, ClassLoader l) {
  ClassUtils cu = createClassUtils(l);
  setup(cu, registry);
  registry.clearForType(GroovyCompletionTypes.CUSTOM_TYPE);
  registry.clearForType(GroovyCompletionTypes.FIELD);
  registry.clearForType(GroovyCompletionTypes.NAME);
  addDefaultImports(cu);
  moreSetup(cu);
  moreSetup(registry);

  Lexer lexer = new GroovyLexer(new ANTLRInputStream(txt));
  lexer.removeErrorListeners();

  CommonTokenStream tokens = new CommonTokenStream(lexer);

  // Create a parser that reads from the scanner
  GroovyParser parser = new GroovyParser(tokens);
  parser.removeErrorListeners();

  // start parsing at the compilationUnit rule
  ParserRuleContext t = parser.compilationUnit();
  ParseTreeWalker walker = new ParseTreeWalker();
  List<AutocompleteCandidate> q = new ArrayList<AutocompleteCandidate>();

  GroovyImportDeclarationCompletion extractor = new GroovyImportDeclarationCompletion(txt,cur,registry,cps,cu);
  GroovyNameBuilder extractor2 = new GroovyNameBuilder(registry,cu );
  GroovyNodeCompletion extractor3 = new GroovyNodeCompletion(txt,cur, registry, cu);
  walker.walk(extractor, t);
  if(extractor.getQuery()!=null)
    q.addAll(extractor.getQuery());
  walker.walk(extractor2, t);
  walker.walk(extractor3, t);
  if(extractor3.getQuery()!=null)
    q.addAll(extractor3.getQuery());
  List<String> ret = registry.searchCandidates(q);

  if(ret.isEmpty()) {
    q.clear();
    for (int i=cur-1; i>=0; i--) {
      if(i<txt.length() && Character.isWhitespace(txt.charAt(i))) {
        String tx = txt.substring(i+1, cur).trim();
        if(!txt.isEmpty()) {
          if(tx.contains(".")) {
            q.add(cu.expandExpression(tx, registry, cu.DO_ALL));
          } else {
            q.add(new AutocompleteCandidate(GroovyCompletionTypes.NAME, tx));
          }
          ret = registry.searchCandidates(q);
        }
        break;
      }
    }
  }

  if(txt.charAt(cur-1)=='.') {
    for(int i=0; i<ret.size(); i++) {
      String s = ret.get(i);
      if(s.startsWith("."))
        ret.set(i, s.substring(1));
    }
  }
  
  // this shows the GUI
  if(GroovyCompletionTypes.debug)
    t.inspect(parser);
  return new AutocompleteResult(ret, getStartIndex(extractor,extractor2,extractor3));
}
 
開發者ID:twosigma,項目名稱:beaker-notebook-archive,代碼行數:68,代碼來源:GroovyAutocomplete.java


注:本文中的org.antlr.v4.runtime.Lexer.removeErrorListeners方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。