Esempio n. 1
0
        public virtual bool compileMethod(BehavioralObject methodClass, Functor1 <bool, MethodDeclarationNode> compileMethodFromMethodDeclarationNode)
        {
            ParseTreeNode rootParseNode = parser.methodParseTree();

            if (parser.ErrorCount > 0)
            {
                return(false);
            }
            switch (rootParseNode.ParseNodeType)
            {
            case ParseNodeType.MethodDeclaration:
            case ParseNodeType.PrimitiveMethodDeclaration:
                abstractSyntaxTreeGenerator = newASTGenerator();
                var methodDeclarationNode = abstractSyntaxTreeGenerator.applyTo(rootParseNode) as MethodDeclarationNode;
                if (methodDeclarationNode == null)
                {
                    return(false);
                }
                if (ErrorCount < 1 && !methodDeclarationNode.IsCompilable)
                {
                    return(false);
                }
                return(compileMethodFromMethodDeclarationNode(methodDeclarationNode));

            default:
                return(false);
            }
        }
Esempio n. 2
0
        public virtual bool compile(ScriptType rootParseNodeType, Object selfValue, List <ParameterExpression> rootParameters, out BlockLiteralNode blockLiteralNode)
        {
            ParseTreeNode rootParseNode;
            List <String> parameterNames = null;

            if (rootParameters != null)
            {
                parameterNames = new List <String>();
                foreach (var parameter in rootParameters)
                {
                    parameterNames.Add(parameter.Name);
                }
            }
            switch (rootParseNodeType)
            {
            default:
            case ScriptType.BlockDeclaration:
                rootParseNode = parser.parseTree();
                break;

            case ScriptType.SelfExpression:
                rootParseNode = parser.selfExpressionParseTree(parameterNames);
                break;
            }

            if (parser.ErrorCount > 0 || !rootParseNode.IsBlockLiteral)
            {
                blockLiteralNode = null;
                return(false);
            }

            abstractSyntaxTreeGenerator = newASTGenerator(selfValue, rootParameters);
            blockLiteralNode            = abstractSyntaxTreeGenerator.applyTo(rootParseNode) as BlockLiteralNode;
            if (blockLiteralNode == null)
            {
                return(false);
            }
            if (ErrorCount > 0)
            {
                return(false);
            }
            return(blockLiteralNode.IsCompilable);
        }