internal static LambdaNode ParseAndBindLambda(IHostEnvironment env, string expression, int ivec, DataViewType[] inputTypes, out int[] perm)
        {
            perm = Utils.GetIdentityPermutation(inputTypes.Length);
            if (ivec >= 0)
            {
                if (ivec > 0)
                {
                    perm[0] = ivec;
                    for (int i = 1; i <= ivec; i++)
                    {
                        perm[i] = i - 1;
                    }
                }
            }
            CharCursor chars = new CharCursor(expression);

            var node = LambdaParser.Parse(out List <Error> errors, out List <int> lineMap, chars, perm, inputTypes);

            if (Utils.Size(errors) > 0)
            {
                throw env.ExceptParam(nameof(expression), $"parsing failed: {errors[0].GetMessage()}");
            }

            using (var ch = env.Start("LabmdaBinder.Run"))
                LambdaBinder.Run(env, ref errors, node, msg => ch.Error(msg));

            if (Utils.Size(errors) > 0)
            {
                throw env.ExceptParam(nameof(expression), $"binding failed: {errors[0].GetMessage()}");
            }
            return(node);
        }
Beispiel #2
0
#pragma warning restore 414

            public LexerImpl(Lexer lex, CharCursor cursor)
            {
                _lex        = lex;
                _cursor     = cursor;
                _sb         = new StringBuilder();
                _queue      = new Queue <Token>(4);
                _fLineStart = true;
            }
Beispiel #3
0
        public IEnumerable <Token> LexSource(CharCursor cursor)
        {
            Contracts.AssertValue(cursor);

            LexerImpl impl = new LexerImpl(this, cursor);
            Token     tok;

            while ((tok = impl.GetNextToken()) != null)
            {
                yield return(tok);
            }
            yield return(impl.GetEof());
        }
Beispiel #4
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);
        }
Beispiel #5
0
        public static LambdaNode Parse(out List <Error> errors, out List <int> lineMap, CharCursor chars, int[] perm, params DataViewType[] types)
        {
            Contracts.AssertValue(chars);
            Contracts.AssertNonEmpty(types);
            Contracts.Assert(types.Length <= LambdaCompiler.MaxParams);
            Contracts.Assert(Utils.Size(perm) == types.Length);

            LambdaParser psr = new LambdaParser();

            return(psr.ParseCore(out errors, out lineMap, chars, perm, types));
        }