当前位置: 首页>>代码示例>>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;未经允许,请勿转载。