本文整理汇总了Java中org.antlr.runtime.ANTLRReaderStream类的典型用法代码示例。如果您正苦于以下问题:Java ANTLRReaderStream类的具体用法?Java ANTLRReaderStream怎么用?Java ANTLRReaderStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ANTLRReaderStream类属于org.antlr.runtime包,在下文中一共展示了ANTLRReaderStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseTree
import org.antlr.runtime.ANTLRReaderStream; //导入依赖的package包/类
static Tree parseTree(CharSource input)
throws IOException
{
try (Reader reader = input.openStream()) {
ThriftLexer lexer = new ThriftLexer(new ANTLRReaderStream(reader));
ThriftParser parser = new ThriftParser(new CommonTokenStream(lexer));
try {
Tree tree = (Tree) parser.document().getTree();
if (parser.getNumberOfSyntaxErrors() > 0) {
throw new IllegalArgumentException("syntax error");
}
return tree;
}
catch (RecognitionException e) {
throw new IllegalArgumentException(e);
}
}
}
示例2: getKoopaAST
import org.antlr.runtime.ANTLRReaderStream; //导入依赖的package包/类
private static CommonTree getKoopaAST(String filename)
throws FileNotFoundException, IOException, RecognitionException {
System.out.println("Reading " + filename);
Reader reader = new FileReader(filename);
KGLexer lexer = new KGLexer(new ANTLRReaderStream(reader));
CommonTokenStream tokens = new CommonTokenStream(lexer);
KGParser parser = new KGParser(tokens);
KGParser.koopa_return koopa = parser.koopa();
CommonTree ast = (CommonTree) koopa.getTree();
if (SHOW_AST) {
new ASTFrame("KG", ast).setVisible(true);
}
return ast;
}
示例3: doParse
import org.antlr.runtime.ANTLRReaderStream; //导入依赖的package包/类
@Override
public IParseResult doParse(Reader reader) {
try {
return parse(getDefaultRuleName(), new ANTLRReaderStream(reader));
} catch (IOException e) {
throw new WrappedException(e);
}
}
示例4: parse
import org.antlr.runtime.ANTLRReaderStream; //导入依赖的package包/类
@Override
public IParseResult parse(ParserRule rule, Reader reader) {
try {
IParseResult parseResult = parse(rule.getName(), new ANTLRReaderStream(reader));
return parseResult;
} catch (IOException e) {
throw new WrappedException(e);
}
}
示例5: getCharStream
import org.antlr.runtime.ANTLRReaderStream; //导入依赖的package包/类
protected CharStream getCharStream(final Reader reader) {
try {
return new ANTLRReaderStream(reader);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
示例6: process
import org.antlr.runtime.ANTLRReaderStream; //导入依赖的package包/类
/**
* The only method that should be called to initiate the process
* @param is The input stream from where to get the data
* @param os The output stream to write the processed fragment/document to
* @param htmlFilter An interface called during the processing of the document. Can be used to modify elements
* @param convertIntoValidXML Converts the output into valid XML for XSL processing for example
*/
public static void process( Reader reader, Writer writer, IHTMLFilter htmlFilter, boolean convertIntoValidXML ) throws HandlingException {
try {
// Open a char stream input for the document
ANTLRStringStream input = new ANTLRReaderStream( reader );
// Start lexing the input
htmlLexerLexer lex = new htmlLexerLexer(input);
// Tokenstream for the parser.
CommonTokenStream tokens = new CommonTokenStream(lex);
htmlParserParser parser = new htmlParserParser(tokens);
htmlParserParser.document_return root = parser.document();
// Set up the tree parser
CommonTreeNodeStream nodes = new CommonTreeNodeStream((Tree)root.getTree());
htmlTreeParser walker = new htmlTreeParser(nodes);
// Initialize data structures
topNode = new ThreadLocal();
currentNode = new ThreadLocal();
attrNode = new ThreadLocal();
// Walk in the entire document using the tree parser.
walker.document();
// Get the top node
TagNode top = (TagNode)topNode.get();
// Write the clean document out.
top.writeAll( writer, htmlFilter, convertIntoValidXML, false );
} catch ( IOException ioe ) {
throw new HandlingException( "Could not parse document" );
} catch ( RecognitionException re ) {
throw new HandlingException( "Could not parse document" );
}
}
示例7: getAntlrStream
import org.antlr.runtime.ANTLRReaderStream; //导入依赖的package包/类
private static ANTLRReaderStream getAntlrStream(String code) {
try {
return new ANTLRReaderStream(new StringReader(code));
} catch (IOException e) {
// Will never happen, since it's a StringReader...
return null;
}
}
示例8: stringStream
import org.antlr.runtime.ANTLRReaderStream; //导入依赖的package包/类
public static CSSInputStream stringStream(String source) throws IOException {
CSSInputStream stream = new CSSInputStream();
stream.rawData = source;
stream.encoding = Charset.defaultCharset().name();
BufferedReader br = new BufferedReader(
new InputStreamReader(new ByteArrayInputStream(source.getBytes()), stream.encoding));
stream.input = new ANTLRReaderStream(br);
return stream;
}
示例9: tokenStartPositions
import org.antlr.runtime.ANTLRReaderStream; //导入依赖的package包/类
private List<Integer> tokenStartPositions() throws IOException {
List<Integer> res = new ArrayList<Integer>();
ANTLRReaderStream input = new ANTLRInputStream(new FileInputStream(masterFile));
v4Lexer lexer = new v4Lexer(input);
Token t = lexer.nextToken();
while (t.getType() != Token.EOF) {
if (t.getChannel() != Token.HIDDEN_CHANNEL) {
res.add(lexer.getCharIndex());
}
t = lexer.nextToken();
}
return res;
}
示例10: newParser
import org.antlr.runtime.ANTLRReaderStream; //导入依赖的package包/类
public static ObjCppParser newParser(String s) throws IOException {
Result result = new Result(new JNAeratorConfig(), null, null);
ObjCppParser parser = new ObjCppParser(new CommonTokenStream(new ObjCppLexer(
new ANTLRReaderStream(new StringReader(s)))) // , new DummyDebugEventListener()
);
parser.objCParserHelper = result.typeConverter;
return parser;
}
示例11: newObjCDemangler
import org.antlr.runtime.ANTLRReaderStream; //导入依赖的package包/类
static ObjCDemanglingParser newObjCDemangler(String s, final boolean verbose) throws IOException {
return new ObjCDemanglingParser(
new CommonTokenStream(
new ObjCDemanglingLexer(
new ANTLRReaderStream(new StringReader(s)))) // , new DummyDebugEventListener()
) {
@Override
public void reportError(RecognitionException arg0) {
if (verbose) {
// System.err.println(arg0 + " (next = '" + next() + "')");
super.reportError(arg0);
}
}
};
}
示例12: newObjCppParser
import org.antlr.runtime.ANTLRReaderStream; //导入依赖的package包/类
protected ObjCppParser newObjCppParser(TypeConversion typeConverter, String s, final boolean verbose, final PrintStream errorOut) throws IOException {
ObjCppParser parser = new ObjCppParser(
new CommonTokenStream(
new ObjCppLexer(
new ANTLRReaderStream(new StringReader(s)))) // , new DummyDebugEventListener()
) {
@Override
public void emitErrorMessage(String msg) {
if (errorOut == null) {
// if (verbose)
// super.emitErrorMessage(msg);
} else {
errorOut.println(msg);
}
}
@Override
public void reportError(RecognitionException arg0) {
if (verbose) {
super.reportError(arg0);
}
}
};
parser.setupScopes();
parser.objCParserHelper = typeConverter;
return parser;
}
示例13: newParser
import org.antlr.runtime.ANTLRReaderStream; //导入依赖的package包/类
public static ObjCppParser newParser(String s) throws IOException {
Result result = new Result(new JNAeratorConfig(), null, null);
ObjCppParser parser = new ObjCppParser(new CommonTokenStream(new ObjCppLexer(
new ANTLRReaderStream(new StringReader(s))))
// , new DummyDebugEventListener()
);
parser.objCParserHelper = result.typeConverter;
return parser;
}
示例14: extractTagsFromString
import org.antlr.runtime.ANTLRReaderStream; //导入依赖的package包/类
private List<String> extractTagsFromString(String in) throws IOException {
try (Reader stringToInputStream = new StringReader(in)) {
TagLexer tagsLexer = new TagLexer(new ANTLRReaderStream(stringToInputStream));
CommonTokenStream tokens = new CommonTokenStream(tagsLexer);
TagParser pa = new TagParser(tokens);
return pa.getParsedTags();
}
}
示例15: getTokenStream
import org.antlr.runtime.ANTLRReaderStream; //导入依赖的package包/类
public static CommonTokenStream getTokenStream(java.io.Reader reader)
throws java.io.IOException
{
SExpressionLexer lexer
= new SExpressionLexer(new ANTLRReaderStream(reader));
return new CommonTokenStream(lexer);
}