alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (SourceParserTest.java)

This example Groovy source code file (SourceParserTest.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

exception, groovylexer, groovylexer, groovyrecognizer, groovytestcase, io, printwriter, reader, sourcebuffer, sourcebuffer, sourceparsertest, stringwriter, stringwriter, unicodeescapingreader, unicodeescapingreader

The Groovy SourceParserTest.java source code

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

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy SourceParserTest.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.