All Downloads are FREE. Search and download functionalities are using the official Maven repository.

yajco.generator.parsergen.beaver.templates.LALRParserClassTemplate.vm Maven / Gradle / Ivy

Go to download

YAJCo - Yet Another Java Compiler Compiler - object oriented language specification - beaver parser generator

The newest version!
##
## Input - parserClassName
## Input - parserPackageName
## Input - packageClassPackageName
## Input - mainElementClassName
## Input - scannerClassName
## Input - referenceResolverClassName
package $parserClassPackageName;

import ${parserPackageName}.$scannerClassName;

public class $parserClassName {
	private static ${parserPackageName}.$parserClassName parser;

	public $mainElementClassName parse(String input) throws ParseException {
		$scannerClassName scanner = new ${scannerClassName}(input);
		if (parser == null) {
			parser = new ${parserPackageName}.${parserClassName}();
		}

		try {
			${referenceResolverClassName} referenceResolver = ${referenceResolverClassName}.createInstance();
			$mainElementClassName root = ((${parserPackageName}.SymbolWrapper<${mainElementClassName}>) parser.parse(scanner)).getWrappedObject();
			referenceResolver.resolveReferences();
			return root;
		} catch (java.io.IOException e) {
			throw new ParseException("Problem parsing source code ", e);
		} catch (${parserPackageName}.${parserClassName}.Exception e) {
			throw new ParseException("Problem parsing source code ", e);
		}
	}

	public $mainElementClassName parse(java.io.Reader reader) throws ParseException {
		try {
			return parse(readAsString(reader));
		} catch(java.io.IOException e) {
			throw new ParseException("Problem reading input file", e);
		}
	}

	private String readAsString(java.io.Reader r) throws java.io.IOException {
		StringBuilder sb = new StringBuilder();
		java.io.BufferedReader br = new java.io.BufferedReader(r);
		String line;
		while ((line = br.readLine()) != null) {
			sb.append(line + "\n");
		}
		return sb.toString();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy