Examples of Reduction


Examples of com.creativewidgetworks.goldparser.engine.Reduction

    private final String functionName;
    private final List<String> parameters;
    private final Reduction statements;

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

        functionName = reduction.get(1).getData().toString();
        parameters = (List<String>)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
View Full Code Here

Examples of com.creativewidgetworks.goldparser.engine.Reduction

        String ruleName = currentReduction.getParent().toString();
        return createInstance(ruleName);
    }
   
    protected Reduction createInstance(String ruleName) throws ParserException {
        Reduction reduction = null;

        // Look up the handler for the rule and construct an instance of the class
        Class clazz = ruleHandlers.get(ruleName);
        if (clazz == null) {
            clazz = ruleHandlers.get(ruleName.replace("'", "")); // Try removing single quotes
View Full Code Here

Examples of com.creativewidgetworks.goldparser.engine.Reduction

        arguments.add(reduction);
        setValue(new Variable(arguments));
    }

    public Arguments(GOLDParser parser) throws ParserException {
        Reduction reduction = parser.getCurrentReduction();

        List<Reduction> arguments = new ArrayList<Reduction>();
        buildArgumentList(reduction, arguments);

        setValue(new Variable(arguments));
View Full Code Here

Examples of com.creativewidgetworks.goldparser.engine.Reduction

    private GOLDParser theParser;
    private Reduction valueToNegate;

    public Negation(GOLDParser parser) {
        theParser = parser;
        Reduction reduction = parser.getCurrentReduction();
        if (reduction != null) {
            if (reduction.size() == 2) {
                valueToNegate = reduction.get(1).asReduction();
            } else {
                parser.raiseParserException(Simple3.formatMessage("error.param_count", "2", String.valueOf(reduction.size())));
            }
        } else {
            parser.raiseParserException(Simple3.formatMessage("error.no_reduction"));
        }           
    }
View Full Code Here

Examples of com.creativewidgetworks.goldparser.engine.Reduction

    private Reduction conditional;
    private Reduction thenStatements;
    private Reduction elseStatements;

    public IfThenElse(GOLDParser parser) {
        Reduction reduction = parser.getCurrentReduction();
        if (reduction != null) {
            if (reduction.size() == 5) {
                // if x then y end
                conditional    = reduction.get(1).asReduction();
                thenStatements = reduction.get(3).asReduction();               
            } else if (reduction.size() == 7) {
                // if x then y else z end
                conditional    = reduction.get(1).asReduction();
                thenStatements = reduction.get(3).asReduction();
                elseStatements = reduction.get(5).asReduction();
            } else {
                if (reduction.size() < 5) {
                    // if x then y form
                    parser.raiseParserException(Simple3.formatMessage("error.param_count", "5", String.valueOf(reduction.size())));
                }
                // if x then y else z end form
                parser.raiseParserException(Simple3.formatMessage("error.param_count", "7", String.valueOf(reduction.size())));
            }
        } else {
            parser.raiseParserException(Simple3.formatMessage("error.no_reduction"));
        }       
     }
View Full Code Here

Examples of com.creativewidgetworks.goldparser.engine.Reduction

    private GOLDParser theParser;
    private String variableName;

    public Id(GOLDParser parser) {
        theParser = parser;
        Reduction reduction = parser.getCurrentReduction();
        if (reduction != null) {
            if (reduction.size() == 1) {
                variableName = reduction.get(0).asString();
            } else {
                parser.raiseParserException(Simple3.formatMessage("error.param_count", "1", String.valueOf(reduction.size())));
            }
        } else {
            parser.raiseParserException(Simple3.formatMessage("error.no_reduction"));
        }       
    }
View Full Code Here

Examples of com.creativewidgetworks.goldparser.engine.Reduction

public class Parenthesis extends Reduction {

    Reduction innerReduction;
   
    public Parenthesis(GOLDParser parser) {
        Reduction reduction = parser.getCurrentReduction();
        if (reduction != null) {
            if (reduction.size() == 3) {
                innerReduction = parser.getCurrentReduction().get(1).asReduction();
            } else {
                parser.raiseParserException(Simple3.formatMessage("error.param_count", "3", String.valueOf(reduction.size())));
            }
        } else {
            parser.raiseParserException(Simple3.formatMessage("error.no_reduction"));
        }          
    }
View Full Code Here

Examples of com.creativewidgetworks.goldparser.engine.Reduction

    private final String functionName;
    private final List<Reduction> arguments;

    public FunctionCall(GOLDParser parser) {
        theParser = parser;
        Reduction reduction = parser.getCurrentReduction();
        functionName = reduction.get(0).getData().toString();

        if (reduction.get(2).asReduction() instanceof Arguments) {
            arguments = (List<Reduction>)reduction.get(2).asReduction().getValue().asObject();
        } else {
            // This handles the single parameter case
            Arguments args = new Arguments(reduction.get(2).asReduction());
            arguments = (List<Reduction>)args.getValue().asObject();
        }
    }
View Full Code Here

Examples of com.creativewidgetworks.goldparser.engine.Reduction

                // in other scopes having the same name will not be visible to the function.
                for (int i = 0; i < parameters.size(); i++) {
                    theParser.setProgramVariable(parameters.get(i), arguments.get(i).getValue());
                }

                Reduction statements = fn.getStatements();
                if (statements != null) {
                    statements.execute();
                    var = statements.getValue();
                }

                // Simple3 doesn't allow a simple RETURN without a value hence this
                // path will never be executed.  The code remains to support other
                // syntaxes that allow an empty return statement.  These lines of
View Full Code Here

Examples of com.creativewidgetworks.goldparser.engine.Reduction

public class Statements extends Reduction {
    private Reduction statement1;
    private Reduction statement2;

    public Statements(GOLDParser parser) {
        Reduction reduction = parser.getCurrentReduction();
        if (reduction != null) {
            if (reduction.size() > 0 && reduction.size() < 3) {
                statement1 = reduction.get(0).asReduction();
                statement2 = (reduction.size() > 1) ? reduction.get(1).asReduction() : null;
            } else {
                parser.raiseParserException(Simple3.formatMessage("error.param_count_range", "1", "2", String.valueOf(reduction.size())));
            }
        } else {
            parser.raiseParserException(Simple3.formatMessage("error.no_reduction"));
        }        
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.