Package org.codehaus.groovy.antlr

Source Code of org.codehaus.groovy.antlr.SourceParserTest

package org.codehaus.groovy.antlr;

import groovy.util.GroovyTestCase;

import java.io.PrintWriter;
import java.io.Reader;
import java.io.StringWriter;

import org.codehaus.groovy.antlr.parser.GroovyLexer;
import org.codehaus.groovy.antlr.parser.GroovyRecognizer;

public abstract class SourceParserTest extends GroovyTestCase {
    protected void parse(String name, Reader reader) {
        SourceBuffer sourceBuffer = new SourceBuffer();
        UnicodeEscapingReader unicodeReader = new UnicodeEscapingReader(reader, sourceBuffer);
        GroovyLexer lexer = new GroovyLexer(unicodeReader);
        unicodeReader.setLexer(lexer);
        GroovyRecognizer parser = GroovyRecognizer.make(lexer);
        parser.setSourceBuffer(sourceBuffer);
        parser.setFilename(name);

        // start parsing at the compilationUnit rule
        try {
            parser.compilationUnit();
        }
        catch (Exception ex) {
            StringWriter out = new StringWriter();
            out.write(ex.getMessage());
            out.write("\n");
            ex.printStackTrace(new PrintWriter(out));
            fail(out.toString());
        }
    }
}
TOP

Related Classes of org.codehaus.groovy.antlr.SourceParserTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.