Example #1
0
        private LambdaNode ParseCore(out List <Error> errors, out List <int> lineMap, CharCursor chars, int[] perm, DataViewType[] types)
        {
            Contracts.AssertValue(chars);
            Contracts.AssertNonEmpty(types);
            Contracts.Assert(Utils.Size(perm) == types.Length);

            _errors  = null;
            _lineMap = new List <int>();
            _curs    = new TokenCursor(_lex.LexSource(chars));
            _types   = types;
            _perm    = perm;

            // Skip over initial comments, new lines, lexing errors, etc.
            SkipJunk();

            LambdaNode node = ParseLambda(TokCur);

            if (TidCur != TokKind.Eof)
            {
                PostError(TokCur, "Expected end of input");
            }

            errors  = _errors;
            lineMap = _lineMap;

            _errors  = null;
            _lineMap = null;
            _curs    = null;

            return(node);
        }
 public override void Visit(LambdaNode node)
 {
     Contracts.AssertValue(node);
     if (node.Vars.Length == 1)
     {
         node.Vars[0].Accept(this);
     }
     else
     {
         _wrt.Write('(');
         var pre = "";
         foreach (var v in node.Vars)
         {
             _wrt.Write(pre);
             v.Accept(this);
             pre = "";
         }
         _wrt.Write(")");
     }
     _wrt.Write(" => ");
     node.Expr.Accept(this);
 }
            public ColumnInfo(IExceptionContext ectx, string[] inputColumnNames, DataViewType[] inputTypes, string expression, string outputColumnName, int vectorInputColumn, LambdaNode node, int[] perm)
            {
                ectx.AssertNonEmpty(inputTypes);
                ectx.Assert(Utils.Size(inputTypes) == Utils.Size(inputColumnNames));
                ectx.AssertNonWhiteSpace(expression);
                ectx.AssertNonWhiteSpace(outputColumnName);
                ectx.AssertValue(node);

                InputColumnNames     = inputColumnNames;
                OutputColumnName     = outputColumnName;
                OutputColumnItemType = node.ResultType as PrimitiveDataViewType;
                ectx.AssertValue(OutputColumnItemType);
                VectorInputColumn = vectorInputColumn;
                Perm       = perm;
                Expression = expression;

                InputKinds = new InternalDataKind[inputTypes.Length];
                for (int i = 0; i < inputTypes.Length; i++)
                {
                    InputKinds[i] = inputTypes[i].GetRawKind();
                }

                Del = LambdaCompiler.Compile(out var errors, node);
                if (Utils.Size(errors) > 0)
                {
                    throw ectx.Except($"generating code failed: {errors[0].GetMessage()}");
                }
            }
Example #4
0
 public override void PostVisit(LambdaNode node)
 {
     Contracts.Assert(false);
 }
Example #5
0
 // PreVisit and PostVisit methods for non-leaf node types.
 public override bool PreVisit(LambdaNode node)
 {
     Visit(node); return(false);
 }
Example #6
0
 // Visit methods for non-leaf node types.
 public abstract void Visit(LambdaNode node);
Example #7
0
 // Visit methods for non-leaf node types.
 // If PreVisit returns true, the children are visited and PostVisit is called.
 public virtual bool PreVisit(LambdaNode node)
 {
     return(true);
 }