Search in sources :

Example 1 with StrictParameterizedKeyValueStringContext

use of org.apache.sysml.parser.pydml.PydmlParser.StrictParameterizedKeyValueStringContext in project incubator-systemml by apache.

the class PydmlSyntacticValidator method exitExternalFunctionDefExpression.

@Override
public void exitExternalFunctionDefExpression(ExternalFunctionDefExpressionContext ctx) {
    ExternalFunctionStatement functionStmt = new ExternalFunctionStatement();
    ArrayList<DataIdentifier> functionInputs = getFunctionParameters(ctx.inputParams);
    functionStmt.setInputParams(functionInputs);
    // set function outputs
    ArrayList<DataIdentifier> functionOutputs = getFunctionParameters(ctx.outputParams);
    functionStmt.setOutputParams(functionOutputs);
    // set function name
    functionStmt.setName(ctx.name.getText());
    // set other parameters
    HashMap<String, String> otherParams = new HashMap<String, String>();
    boolean atleastOneClassName = false;
    for (StrictParameterizedKeyValueStringContext otherParamCtx : ctx.otherParams) {
        String paramName = otherParamCtx.paramName.getText();
        String val = "";
        String text = otherParamCtx.paramVal.getText();
        // First unquote the string
        if ((text.startsWith("\"") && text.endsWith("\"")) || (text.startsWith("\'") && text.endsWith("\'"))) {
            if (text.length() > 2) {
                val = text.substring(1, text.length() - 1);
            }
        // Empty value allowed
        } else {
            notifyErrorListeners("the value of user parameter for external function should be of type str", ctx.start);
            return;
        }
        otherParams.put(paramName, val);
        if (paramName.equals("classname")) {
            atleastOneClassName = true;
        }
    }
    functionStmt.setOtherParams(otherParams);
    if (!atleastOneClassName) {
        notifyErrorListeners("the parameter \'className\' needs to be passed for defExternal", ctx.start);
        return;
    }
    ctx.info.stmt = functionStmt;
    setFileLineColumn(ctx.info.stmt, ctx);
    ctx.info.functionName = ctx.name.getText();
}
Also used : StrictParameterizedKeyValueStringContext(org.apache.sysml.parser.pydml.PydmlParser.StrictParameterizedKeyValueStringContext) DataIdentifier(org.apache.sysml.parser.DataIdentifier) HashMap(java.util.HashMap) ExternalFunctionStatement(org.apache.sysml.parser.ExternalFunctionStatement)

Aggregations

HashMap (java.util.HashMap)1 DataIdentifier (org.apache.sysml.parser.DataIdentifier)1 ExternalFunctionStatement (org.apache.sysml.parser.ExternalFunctionStatement)1 StrictParameterizedKeyValueStringContext (org.apache.sysml.parser.pydml.PydmlParser.StrictParameterizedKeyValueStringContext)1