当前位置: 首页>>代码示例>>Java>>正文


Java Parser.setBuildParseTree方法代码示例

本文整理汇总了Java中org.antlr.v4.runtime.Parser.setBuildParseTree方法的典型用法代码示例。如果您正苦于以下问题:Java Parser.setBuildParseTree方法的具体用法?Java Parser.setBuildParseTree怎么用?Java Parser.setBuildParseTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.antlr.v4.runtime.Parser的用法示例。


在下文中一共展示了Parser.setBuildParseTree方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: process

import org.antlr.v4.runtime.Parser; //导入方法依赖的package包/类
protected void process(Lexer lexer, Class<? extends Parser> parserClass, Parser parser, InputStream is, Reader r) throws IOException, IllegalAccessException, InvocationTargetException, PrintException {
	try {
		ANTLRInputStream input = new ANTLRInputStream(r);
		lexer.setInputStream(input);
		CommonTokenStream tokens = new CommonTokenStream(lexer);

		tokens.fill();

		if ( showTokens ) {
			for (Object tok : tokens.getTokens()) {
				System.out.println(tok);
			}
		}

		if ( startRuleName.equals(LEXER_START_RULE_NAME) ) return;

		if ( diagnostics ) {
			parser.addErrorListener(new DiagnosticErrorListener());
			parser.getInterpreter().setPredictionMode(PredictionMode.LL_EXACT_AMBIG_DETECTION);
		}

		if ( printTree || gui || psFile!=null ) {
			parser.setBuildParseTree(true);
		}

		if ( SLL ) { // overrides diagnostics
			parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
		}

		parser.setTokenStream(tokens);
		parser.setTrace(trace);

		try {
			Method startRule = parserClass.getMethod(startRuleName);
			ParserRuleContext tree = (ParserRuleContext)startRule.invoke(parser, (Object[])null);

			if ( printTree ) {
				System.out.println(tree.toStringTree(parser));
			}
			if ( gui ) {
				tree.inspect(parser);
			}
			if ( psFile!=null ) {
				tree.save(parser, psFile); // Generate postscript
			}
		}
		catch (NoSuchMethodException nsme) {
			System.err.println("No method for rule "+startRuleName+" or it has arguments");
		}
	}
	finally {
		if ( r!=null ) r.close();
		if ( is!=null ) is.close();
	}
}
 
开发者ID:MegaApuTurkUltra,项目名称:Scratch-ApuC,代码行数:56,代码来源:TestRig.java

示例2: process

import org.antlr.v4.runtime.Parser; //导入方法依赖的package包/类
protected void process(Lexer lexer, Class<? extends Parser> parserClass, Parser parser, InputStream is, Reader r) throws IOException, IllegalAccessException, InvocationTargetException, PrintException {
	try {
		ANTLRInputStream input = new ANTLRInputStream(r);
		lexer.setInputStream(input);
		CommonTokenStream tokens = new CommonTokenStream(lexer);

		tokens.fill();

		if ( showTokens ) {
			for (Object tok : tokens.getTokens()) {
				System.out.println(tok);
			}
		}

		if ( startRuleName.equals(LEXER_START_RULE_NAME) ) return;

		if ( diagnostics ) {
			parser.addErrorListener(new DiagnosticErrorListener());
			parser.getInterpreter().setPredictionMode(PredictionMode.LL_EXACT_AMBIG_DETECTION);
		}

		if ( printTree || gui || psFile!=null ) {
			parser.setBuildParseTree(true);
		}

		if ( SLL ) { // overrides diagnostics
			parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
		}

		parser.setTokenStream(tokens);
		parser.setTrace(trace);

		try {
			Method startRule = parserClass.getMethod(startRuleName);
			ParserRuleContext tree = (ParserRuleContext)startRule.invoke(parser, (Object[])null);

			if ( printTree ) {
				System.out.println(tree.toStringTree(parser));
			}
			if ( gui ) {
				Trees.inspect(tree, parser);
			}
			if ( psFile!=null ) {
				Trees.save(tree, parser, psFile); // Generate postscript
			}
		}
		catch (NoSuchMethodException nsme) {
			System.err.println("No method for rule "+startRuleName+" or it has arguments");
		}
	}
	finally {
		if ( r!=null ) r.close();
		if ( is!=null ) is.close();
	}
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:56,代码来源:TestRig.java

示例3: process

import org.antlr.v4.runtime.Parser; //导入方法依赖的package包/类
protected void process(Lexer lexer, Class<? extends Parser> parserClass, Parser parser,
        InputStream is, Reader r, String filename) throws IOException, IllegalAccessException,
        InvocationTargetException, PrintException, ParserConfigurationException, TransformerFactoryConfigurationError, TransformerException {
    try {
        ANTLRInputStream input = new ANTLRInputStream(r);
        lexer.setInputStream(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);

        tokens.fill();

        if (this.startRuleName.equals(App.LEXER_START_RULE_NAME)) {
            return;
        }

        parser.setBuildParseTree(true);
        parser.setTokenStream(tokens);
        if (this.startRuleName.equals("")){
            this.startRuleName = parser.getRuleNames()[0];
        }

        try {
            Method startRule = parserClass.getMethod(this.startRuleName);
            ParserRuleContext tree = (ParserRuleContext) startRule.invoke(parser,
                    (Object[]) null);

            ParseTreeWalker walker = new ParseTreeWalker();
            XMLListener proxy = new XMLListener(filename, lexer.getTokenTypeMap());

            walker.walk(proxy, tree);

            Transformer transformer = TransformerFactory.newInstance().newTransformer();
            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
            transformer.setOutputProperty(OutputKeys.METHOD, "xml");
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
            transformer.transform(new DOMSource(proxy.doc),
                    new StreamResult(new OutputStreamWriter(System.out, "UTF-8")));

        } catch (NoSuchMethodException nsme) {
            System.err.println("No method for rule " + this.startRuleName
                    + " or it has arguments");
        }
    } finally {
        if (r != null) {
            r.close();
        }
        if (is != null) {
            is.close();
        }
    }
}
 
开发者ID:cscorley,项目名称:srcmlolol,代码行数:52,代码来源:App.java

示例4: parse

import org.antlr.v4.runtime.Parser; //导入方法依赖的package包/类
protected SpecificationContext parse(Lexer lexer, Parser parser, InputStream is, Reader r) throws IOException, IllegalAccessException, PrintException {
  ANTLRInputStream input = new ANTLRInputStream(r);
  lexer.setInputStream(input);
  CommonTokenStream tokens = new CommonTokenStream(lexer);

  tokens.fill();

  if (options.showTokens) {
    for (Object tok : tokens.getTokens()) {
      System.out.println(tok);
    }
  }

  if (options.diagnostics) {
    parser.addErrorListener(new DiagnosticErrorListener());
    parser.getInterpreter().setPredictionMode(PredictionMode.LL_EXACT_AMBIG_DETECTION);
  }

  parser.setBuildParseTree(true);

  // SLL overrides diagnostics
  // %%% Not sure what it really is though.
  if (options.sll) {
    parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
  }

  parser.setTokenStream(tokens);
  parser.setTrace(options.trace);

  SpecificationContext tree = ((WebkitIDLParser)parser).specification();

  if (options.printTree) {
    System.out.println(tree.toStringTree(parser));
  }
  if (options.gui) {
    tree.inspect(parser);
  }
  if (options.psFile != null) {
    tree.save(parser, options.psFile); // Generate postscript
  }

  return tree;
}
 
开发者ID:blackoutjack,项目名称:jamweaver,代码行数:44,代码来源:WebkitGenerator.java

示例5: parse

import org.antlr.v4.runtime.Parser; //导入方法依赖的package包/类
protected SpecificationContext parse(Lexer lexer, Parser parser, InputStream is, Reader r) throws IOException, IllegalAccessException, PrintException {
  ANTLRInputStream input = new ANTLRInputStream(r);
  lexer.setInputStream(input);
  CommonTokenStream tokens = new CommonTokenStream(lexer);

  tokens.fill();

  if (options.showTokens) {
    for (Object tok : tokens.getTokens()) {
      System.out.println(tok);
    }
  }

  if (options.diagnostics) {
    parser.addErrorListener(new DiagnosticErrorListener());
    parser.getInterpreter().setPredictionMode(PredictionMode.LL_EXACT_AMBIG_DETECTION);
  }

  parser.setBuildParseTree(true);

  // SLL overrides diagnostics
  // %%% Not sure what it really is though.
  if (options.sll) {
    parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
  }

  parser.setTokenStream(tokens);
  parser.setTrace(options.trace);

  SpecificationContext tree = ((GeckoIDLParser)parser).specification();

  if (options.printTree) {
    System.out.println(tree.toStringTree(parser));
  }
  if (options.gui) {
    tree.inspect(parser);
  }
  if (options.psFile != null) {
    tree.save(parser, options.psFile); // Generate postscript
  }

  return tree;
}
 
开发者ID:blackoutjack,项目名称:jamweaver,代码行数:44,代码来源:GeckoGenerator.java

示例6: configureParser

import org.antlr.v4.runtime.Parser; //导入方法依赖的package包/类
protected void configureParser(@NonNull Parser parser, @NonNull ParserConfiguration configuration) {
    ParserATNSimulator interpreter = parser.getInterpreter();

    // common configuration
    interpreter.force_global_context = false;
    interpreter.always_try_local_context = true;
    interpreter.optimize_tail_calls = true;
    parser.setBuildParseTree(true);
    parser.removeErrorListeners();

    switch (configuration) {
    case FASTEST:
        interpreter.setPredictionMode(PredictionMode.SLL);
        interpreter.tail_call_preserves_sll = false;
        interpreter.treat_sllk1_conflict_as_ambiguity = true;
        parser.setErrorHandler(new BailErrorStrategy());
        break;

    case SLL:
        throw new UnsupportedOperationException("The tail_call_preserves_sll flag cannot change within a single ATN instance.");
        //interpreter.setPredictionMode(PredictionMode.SLL);
        //interpreter.tail_call_preserves_sll = true;
        //interpreter.treat_sllk1_conflict_as_ambiguity = true;
        //parser.setErrorHandler(new BailErrorStrategy<Token>());
        //break;

    case HYBRID:
        interpreter.setPredictionMode(PredictionMode.LL);
        interpreter.tail_call_preserves_sll = false;
        interpreter.treat_sllk1_conflict_as_ambiguity = true;
        parser.setErrorHandler(new BailErrorStrategy());
        break;

    case HYBRID_SLL:
        throw new UnsupportedOperationException("The tail_call_preserves_sll flag cannot change within a single ATN instance.");
        //interpreter.setPredictionMode(PredictionMode.LL);
        //interpreter.tail_call_preserves_sll = true;
        //interpreter.treat_sllk1_conflict_as_ambiguity = true;
        //parser.setErrorHandler(new BailErrorStrategy<Token>());
        //break;

    case PRECISE:
        interpreter.setPredictionMode(PredictionMode.LL);
        interpreter.tail_call_preserves_sll = false;
        interpreter.treat_sllk1_conflict_as_ambiguity = false;
        parser.setErrorHandler(new DefaultErrorStrategy());
        parser.addErrorListener(DescriptiveErrorListener.INSTANCE);
        break;

    default:
        throw new IllegalArgumentException("Invalid configuration.");
    }
}
 
开发者ID:tunnelvisionlabs,项目名称:goworks,代码行数:54,代码来源:GoParserFactory.java


注:本文中的org.antlr.v4.runtime.Parser.setBuildParseTree方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。