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

com.creativewidgetworks.goldparser.simple3.rulehandlers.Parameters Maven / Gradle / Ivy

package com.creativewidgetworks.goldparser.simple3.rulehandlers;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

import com.creativewidgetworks.goldparser.engine.Reduction;
import com.creativewidgetworks.goldparser.parser.ProcessRule;
import com.creativewidgetworks.goldparser.parser.Variable;
import com.creativewidgetworks.goldparser.parser.GOLDParser;

@ProcessRule(rule={
    " ::= Id , ",
    " ::= Id",
    " ::= ",
    " ::= "
})

/**
 * Rule handler for the function parameters rule.
 *
 * @author Ralph Iden (http://www.creativewidgetworks.com)
 * @version 5.0.0 
 */
public class Parameters extends Reduction {

    public static final String KEY_PARAMETERS = "[ParameterStack]";

    public Parameters(GOLDParser parser) {
        Reduction reduction = parser.getCurrentReduction();

        List parameters = new ArrayList();

        if (reduction.size() > 0) {
            Stack stack;

            Variable var = parser.getProgramVariable(KEY_PARAMETERS);
            if (var == null) {
                stack = new Stack();
                parser.setProgramVariable(KEY_PARAMETERS, new Variable(stack));
            } else {
                stack = (Stack)var.asObject();
            }

            stack.push(reduction.get(0).getData());

            // Copy the values of the current stack to the value object leaving
            // all the values on the stack
            int paramCount = stack.size();
            for (int i = paramCount - 1; i >= 0; i--) {
                parameters.add(stack.get(i).toString());
            }
        }

        setValue(new Variable(parameters));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy