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

com.github.uscexp.blockformatpropertyfile.interpreter.PropertyFileInterpreter Maven / Gradle / Ivy

There is a newer version: 0.2.0-Beta
Show newest version
/*
 * Copyright (C) 2014 by haui - all rights reserved
 */
package com.github.uscexp.blockformatpropertyfile.interpreter;

import java.util.Date;
import java.util.UUID;

import com.github.fge.grappa.Grappa;
import com.github.uscexp.blockformatpropertyfile.PropertyFile;
import com.github.uscexp.blockformatpropertyfile.exception.PropertyFileException;
import com.github.uscexp.blockformatpropertyfile.parser.PropertyFileParser;
import com.github.uscexp.grappa.extension.exception.AstInterpreterException;
import com.github.uscexp.grappa.extension.interpreter.AstInterpreter;
import com.github.uscexp.grappa.extension.interpreter.ProcessStore;
import com.github.uscexp.grappa.extension.nodes.AstTreeNode;
import com.github.uscexp.grappa.extension.parser.Parser;

/**
 * @author haui
 */
public class PropertyFileInterpreter {

	public static final String PROPERTY_FILE = "propertyFile";

	private PropertyFileParser parser;

	private static PropertyFileInterpreter instance = new PropertyFileInterpreter();

	public static PropertyFileInterpreter getInstance() {
		return instance;
	}

	public PropertyFileInterpreter() {
		parser = Grappa.createParser(PropertyFileParser.class);
	}

	public void execute(String input, PropertyFile propertyFile)
			throws PropertyFileException {
		AstTreeNode rootNode = Parser.parseInput(PropertyFileParser.class, parser.properties(), input, true);

		AstInterpreter astInterpreter = new AstInterpreter<>();

		Long id = new Date().getTime() + UUID.randomUUID().hashCode();
		try {
			interpret(propertyFile, rootNode, astInterpreter, id);
		} catch (Exception e) {
			throw new PropertyFileException("PropertyFile interpretation error!", e);
		} finally {
			astInterpreter.cleanUp(id);
		}
	}

	private void interpret(PropertyFile propertyFile, AstTreeNode rootNode,
			AstInterpreter astInterpreter, Long id)
			throws AstInterpreterException {
		ProcessStore processStore = ProcessStore.getInstance(id);
		processStore.setNewVariable(PROPERTY_FILE, propertyFile);
		astInterpreter.interpretBackwardOrder(PropertyFileParser.class, rootNode, id);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy