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

com.creativewidgetworks.goldparser.simple2.rulehandlers.Assign Maven / Gradle / Ivy

package com.creativewidgetworks.goldparser.simple2.rulehandlers;

import com.creativewidgetworks.goldparser.engine.ParserException;
import com.creativewidgetworks.goldparser.engine.Reduction;
import com.creativewidgetworks.goldparser.parser.GOLDParser;
import com.creativewidgetworks.goldparser.parser.ProcessRule;
import com.creativewidgetworks.goldparser.simple2.Simple2;


@ProcessRule(rule={
    " ::= assign Id '=' "    
 })

/**
 * Rule handler for the assignment rule.
 *
 * @author Ralph Iden (http://www.creativewidgetworks.com)
 * @version 5.0.0 
 */
public class Assign extends Reduction {
    private GOLDParser theParser;
    private String variableName;
    private Reduction variableValue;

    public Assign(GOLDParser parser) {
        theParser = parser;
        Reduction reduction = parser.getCurrentReduction();
        if (reduction != null) {
            if (reduction.size() == 4) {
                variableName = reduction.get(1).asString();
                variableValue = reduction.get(3).asReduction();
            } else {
                parser.raiseParserException(Simple2.formatMessage("error.param_count", "4", String.valueOf(reduction.size())));
            }
        } else {
            parser.raiseParserException(Simple2.formatMessage("error.no_reduction"));
        }
    }

    @Override
    public void execute() throws ParserException {
        theParser.setProgramVariable(variableName, variableValue.getValue());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy