Esempio n. 1
0
        public static bool ParseSignature(TokenStream tokenStream, StructList <LambdaArgument> signature)
        {
            ExpressionParser parser = new ExpressionParser(tokenStream);
            bool             retn   = parser.ParseLambdaSignature(ref signature);

            parser.Release();
            if (!retn)
            {
                signature.Clear();
            }

            return(retn);
        }
Esempio n. 2
0
        private bool ParseLambdaExpression(ref ASTNode node)
        {
            if (tokenStream.Current != ExpressionTokenType.ParenOpen)
            {
                return(false);
            }

            int advance = tokenStream.FindMatchingIndex(ExpressionTokenType.ParenOpen, ExpressionTokenType.ParenClose);

            if (advance < 0)
            {
                return(false);
            }

            if (!tokenStream.HasTokenAt(advance + 1))
            {
                return(false);
            }

            if (tokenStream.Peek(advance + 1) != ExpressionTokenType.LambdaArrow)
            {
                return(false);
            }

            StructList <LambdaArgument> signatureList = StructList <LambdaArgument> .GetMinSize(4);

            if (advance != 1)
            {
                ExpressionParser subParser = CreateSubParser(advance);

                if (!subParser.ParseLambdaSignature(ref signatureList))
                {
                    return(false);
                }

                tokenStream.Advance(); // step over =>
            }
            else
            {
                tokenStream.Advance(3); // 1 = ( 2 = ) 3 = =>
            }

            ASTNode body = null;

            body = ParseLoop(); // todo -- not sure how dangerous this might be

            node = ASTNode.LambdaExpressionNode(signatureList, body);

            return(true);
        }