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

com.github.uscexp.blockformatpropertyfile.parser.AstBlockDefinitionTreeNode 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.parser;

import com.github.uscexp.blockformatpropertyfile.PropertyStruct;
import com.github.uscexp.grappa.extension.util.IStack;

/**
 * Command implementation for the PropertyFileParser rule: blockDefinition.
 */
public class AstBlockDefinitionTreeNode extends AstBaseCommandTreeNode {

	private PropertyStruct propertyStruct;

	public AstBlockDefinitionTreeNode(String rule, String value) {
		super(rule, value);
	}

	@Override
	protected void interpretAfterChilds(Long id)
		throws Exception {
		super.interpretAfterChilds(id);
		IStack stack = processStore.getStack();
		Object key = stack.pop();
		
		if(key instanceof PropertyStruct) {
			PropertyStruct struct = (PropertyStruct) key;
			propertyStruct = getBlockPropertyStruct();
			propertyStruct.put(struct.getName(), struct);
		} else {
			Object val = null;
			if(!stack.isEmpty())
				val = stack.pop();
			
			propertyStruct = getBlockPropertyStruct();
			propertyStruct.put((String) key, val);
		}
	}

}