nescparserfactory.java

来自「plugin for eclipse」· Java 代码 · 共 58 行

JAVA
58
字号
/*
 * Created on Apr 29, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package isis.anp.nesc.common;

import isis.anp.common.TNode;
import isis.anp.nesc.NesCLexer;
import isis.anp.nesc.NesCLexerTokenTypes;
import isis.anp.nesc.NesCParser;
import isis.anp.preprocessor.PreprocessorException;

import java.io.DataInputStream;

import antlr.TokenStreamHiddenTokenFilter;

/**
 * Creates a new nesC parser.
 * @author sallai
 */
public class NesCParserFactory {
	/**
	 * Constructor is private to allow no instantiation.
	 * @author sallai
	 */
	private NesCParserFactory() {}
	
	/**
	 * Returns a parser initialized with the given input file and parser context.
	 * @param inputFileName name of input file
	 * @param ctx parser context
	 * @return
	 * @throws PreprocessorException
	 */
	public static NesCParser create(String inputFileName, NesCParserContext ctx) throws PreprocessorException {
        DataInputStream preprocessedStream = null;
        
		preprocessedStream = new DataInputStream(ctx.getPreprocessor().preprocess(inputFileName));
            
        // create a nesC lexer on the preprocessed stream
        NesCLexer lexer = new NesCLexer(preprocessedStream);
		lexer.setTokenObjectClass(isis.anp.common.CToken.class.getName());
        lexer.initialize(inputFileName);  

        // create a filter to hide TinyDoc comments
        TokenStreamHiddenTokenFilter filter = new TokenStreamHiddenTokenFilter(lexer);
        filter.hide(NesCLexerTokenTypes.TinyDoc);
        
		NesCParser parser = new NesCParser(filter, ctx);
        parser.setASTNodeClass(TNode.class.getName());
        TNode.setTokenVocabulary(isis.anp.nesc.NesCLexerTokenTypes.class.getName());
      
		return parser;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?