Java 类org.antlr.runtime.ANTLRReaderStream 实例源码

项目:thrift-java-compiler    文件:ThriftIdlParser.java   
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);
        }
    }
}
项目:Koopa    文件:KGToANTLR.java   
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;
}
项目:Koopa    文件:KGToDTD.java   
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;
}
项目:xtext-core    文件:AbstractAntlrParser.java   
@Override
public IParseResult doParse(Reader reader) {
    try {
        return parse(getDefaultRuleName(), new ANTLRReaderStream(reader));
    } catch (IOException e) {
        throw new WrappedException(e);
    }
}
项目:xtext-core    文件:AbstractAntlrParser.java   
@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);
    }
}
项目:xtext-core    文件:AbstractAntlrParser.java   
@Override
public IParseResult parse(RuleCall ruleCall, Reader reader, int initialLookAhead) {
    try {
        NodeModelBuilder builder = nodeModelBuilder.get();
        builder.setForcedFirstGrammarElement(ruleCall);
        IParseResult parseResult = doParse(ruleCall.getRule().getName(), new ANTLRReaderStream(reader), builder, initialLookAhead);
        return parseResult;
    } catch (IOException e) {
        throw new WrappedException(e);
    }
}
项目:xtext-core    文件:AbstractTokenSourceProvider.java   
protected CharStream getCharStream(final Reader reader) {
  try {
    return new ANTLRReaderStream(reader);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xssprotect    文件:HTMLParser.java   
/**
 * 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" );
    }
}
项目:mclab-core    文件:TokenUtil.java   
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;
  }
}
项目:swingbox-javahelp-viewer    文件:CSSInputStream.java   
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;
}
项目:form-follows-function    文件:VSGC1117Test.java   
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;
}
项目:JNAerator    文件:JNAerator.java   
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;
}
项目:JNAerator    文件:BridgeSupportParser.java   
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);
                }
            }
        };
    }
项目:JNAerator    文件:JNAeratorParser.java   
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;
    }
项目:JNAerator    文件:ObjCppParsingTest.java   
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;
}
项目:ws.tagit    文件:TagTemplate.java   
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();
    }
}
项目:jsignalml    文件:Processor.java   
public static CommonTokenStream getTokenStream(java.io.Reader reader)
    throws java.io.IOException
{
    SExpressionLexer lexer
        = new SExpressionLexer(new ANTLRReaderStream(reader));
    return new CommonTokenStream(lexer);
}
项目:jsignalml    文件:Processor.java   
public static CommonTokenStream getTokenStream(java.io.Reader reader)
    throws java.io.IOException
{
    SExpressionLexer lexer
        = new SExpressionLexer(new ANTLRReaderStream(reader));
    return new CommonTokenStream(lexer);
}
项目:cordovastudio    文件:CSSInputStream.java   
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;
}
项目:protostuff    文件:ProtoUtil.java   
/**
 * Loads the proto from an {@link ANTLRReaderStream}.
 */
public static void loadFrom(ANTLRReaderStream input, Proto target) throws Exception
{
    // Create an ExprLexer that feeds from that stream
    ProtoLexer lexer = new ProtoLexer(input);
    // Create a stream of tokens fed by the lexer
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    // Create a parser that feeds off the token stream
    ProtoParser parser = new ProtoParser(tokens);
    // Begin parsing at rule parse
    parser.parse(target);
}
项目:asup    文件:CLParserWrapper.java   
@Override
public CLObject parse(Reader in) throws CLScriptException {

    try {
        return invokeParser(new ANTLRReaderStream(in));
    } catch (IOException ex) {
           throw new CLScriptException(ex);
       }
}
项目:asup    文件:CLCommandParserWrapper.java   
@Override
public CLCommand parse(Reader in) throws CLScriptException {

    try {
        return invokeParser(new ANTLRReaderStream(in));
    } catch (IOException ex) {
           throw new CLScriptException(ex);
       }
}
项目:asup    文件:CLParameterParserWrapper.java   
@Override
public CLParmAbstractComponent parse(Reader in) throws CLScriptException {

    try {
        return invokeParser(new ANTLRReaderStream(in));
    } catch (IOException ex) {
           throw new CLScriptException(ex);
       }
}
项目:asup    文件:CLExpressionParserWrapper.java   
@Override
public QExpression parse(Reader in) throws CLScriptException {

    try {
        return invokeParser(new ANTLRReaderStream(in));
    } catch (IOException ex) {
           throw new CLScriptException(ex);
       }
}
项目:mclab-core    文件:ScannerTestBase.java   
static MatlabLexer getLexer(String filename) throws IOException {
    BufferedReader in = new BufferedReader(new FileReader(filename));
    MatlabLexer lexer = new MatlabLexer(new ANTLRReaderStream(in));
    return lexer;
}
项目:jtcc    文件:TCCTokenizer.java   
public TCCTokenizer(Reader reader) throws IOException {
    initialize(new ANTLRReaderStream(reader));
}
项目:protostuff    文件:ProtoUtil.java   
/**
 * Loads the proto from a {@link Reader}.
 */
public static void loadFrom(Reader reader, Proto target) throws Exception
{
    loadFrom(new ANTLRReaderStream(reader), target);
}
项目:Koopa    文件:GrammarView.java   
private void colorize(StyledDocument document, String pathToGrammarResource) {
    try {
        final InputStream resourceStream = GrammarView.class
                .getResourceAsStream(pathToGrammarResource);

        final InputStreamReader reader = new InputStreamReader(
                resourceStream);

        KGLexer lexer = new KGLexer(new ANTLRReaderStream(reader));

        boolean justSawDef = false;
        while (true) {
            CommonToken token = (CommonToken) lexer.nextToken();

            if (token.getType() == Token.EOF)
                break;

            Style style = null;
            if (token.getType() == KGLexer.COMMENT) {
                style = getCommentStyle(document);
                justSawDef = false;

            } else if ("def".equals(token.getText())) {
                style = getKeywordStyle(document);
                justSawDef = true;

            } else if ("def".equals(token.getText())) {
                style = getKeywordStyle(document);
                justSawDef = false;

            } else if (token.getType() == KGLexer.IDENTIFIER) {
                if (!token.getText().toUpperCase().equals(token.getText()))
                    style = getIdentifierStyle(document);

                if (justSawDef)
                    ruleNameOffsets.put(token.getText(),
                            token.getStartIndex());

                justSawDef = false;

            } else if (token.getType() == KGLexer.NATIVE_CODE) {
                style = getNativeStyle(document);
                justSawDef = false;

            } else if (token.getType() == KGLexer.WHITESPACE) {
                // Nop.

            } else {
                justSawDef = false;
            }

            if (style != null) {
                final int start = token.getStartIndex();
                final int stop = token.getStopIndex();
                final int len = stop - start + 1;

                document.setCharacterAttributes(start, len, style, false);
            }
        }

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
项目:Koopa    文件:KGG.java   
public static String generate(String name, String pack, String path)
        throws IOException, RecognitionException {

    if (!path.endsWith("/"))
        path += "/";

    Reader reader = new FileReader(path + name + ".kg");

    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);
    }

    // The following is for testing purposes.
    // CommonTreeNodeStream nodes = new CommonTreeNodeStream(ast);
    // KGTreeParser treeParser = new KGTreeParser(nodes);
    // treeParser.koopa();

    Reader templatesIn = new InputStreamReader(
            KGG.class
                    .getResourceAsStream("/koopa/grammars/generator/koopa.stg"));
    StringTemplateGroup templates = new StringTemplateGroup(templatesIn,
            DefaultTemplateLexer.class);

    // templates.emitDebugStartStopStrings(true);

    CommonTreeNodeStream nodes = new CommonTreeNodeStream(ast);
    KGGenerator walker = new KGGenerator(nodes);
    walker.setTemplateLib(templates);

    String formatted = walker.koopa(name, pack,
            contents(path + name + ".kg-imports"),
            contents(path + name + ".kg-usercode")).toString();

    // System.out.println(formatted);

    return formatted;
}
项目:mclab    文件:ScannerTestBase.java   
static MatlabLexer getLexer(String filename) throws IOException {
    BufferedReader in = new BufferedReader(new FileReader(filename));
    MatlabLexer lexer = new MatlabLexer(new ANTLRReaderStream(in));
    return lexer;
}