com.creativewidgetworks.goldparser.simple3.rulehandlers.Function Maven / Gradle / Ivy
package com.creativewidgetworks.goldparser.simple3.rulehandlers;
import java.util.List;
import com.creativewidgetworks.goldparser.engine.Reduction;
import com.creativewidgetworks.goldparser.parser.GOLDParser;
import com.creativewidgetworks.goldparser.parser.ProcessRule;
import com.creativewidgetworks.goldparser.parser.Variable;
@ProcessRule(rule=" ::= function Id ( ) begin end")
/**
* Rule handler for the function declaration rule.
*
* function ID ( parameters;
private final Reduction statements;
public Function(GOLDParser parser) {
Reduction reduction = parser.getCurrentReduction();
functionName = reduction.get(1).getData().toString();
parameters = (List)reduction.get(3).asReduction().getValue().asObject();
statements = reduction.get(6).asReduction();
// Clean up the parameter call stack
parser.clearProgramVariable(Parameters.KEY_PARAMETERS);
// Make the function available to be called
parser.setProgramVariable(FUNCTION_PREFIX + functionName, new Variable(this));
}
public List getParameters() {
return parameters;
}
public Reduction getStatements() {
return statements;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy