Exemple #1
0
        public override void Exit()
        {
            StatementSyntax statement;

            if (_hookName == null)
            {
                statement = SF.Block();
            }
            else
            {
                statement = BlockContext.MakeWriteStatement(MethodCallContext.CreateMethodCall(_hookName, true));
            }
            ExpressionSyntax condition;

            if (_valueExpression == null)
            {
                condition = _testExpression;
            }
            else
            {
                condition = SF.BinaryExpression(SyntaxKind.EqualsExpression, _testExpression, _valueExpression);
            }
            var whenStatement = SF.IfStatement(condition, statement);

            _exitHandler(whenStatement);
        }
Exemple #2
0
        public override void NameTag(string nameTag)
        {
            var hooks = this.Context.ResolveNameTag(nameTag);

            if (hooks == null)
            {
                foreach (var hook in hooks)
                {
                    Add(_defaultOperator, MethodCallContext.CreateMethodCall(hook, true));
                }
            }
            else
            {
                Text($"!ERROR: ?{nameTag} was not defined!");
            }
        }
Exemple #3
0
        public override void Exit()
        {
            StatementSyntax statement;

            if (_hookName == null)
            {
                statement = SF.Block();
            }
            else
            {
                statement = BlockContext.MakeWriteStatement(MethodCallContext.CreateMethodCall(_hookName, true));
            }
            var ifStatement = SF.IfStatement(_condition, statement, _elseClause);

            _exitHandler(ifStatement);
        }
Exemple #4
0
        public override void NameTag(string nameTag)
        {
            var hooks = this.Context.ResolveNameTag(nameTag);

            if (hooks == null)
            {
                Text($"!ERROR: ?{nameTag} was not defined.");
            }
            else
            {
                foreach (var hook in hooks)
                {
                    WriteStatement(
                        MethodCallContext.CreateMethodCall(hook, true)
                        );
                }
            }
        }
Exemple #5
0
            public ExpressionSyntax ToExpression()
            {
                if (this.Expression != null)
                {
                    return(this.Expression);
                }
                switch (this.Operator.OperatorType)
                {
                case OperatorTypes.Parenthesis:
                    return(SF.ParenthesizedExpression(Right.ToExpression()));

                case OperatorTypes.Power:
                    return(MethodCallContext.CreateMethodCall("Pow", false, new ArgumentSyntax[] { SF.Argument(Left.ToExpression()), SF.Argument(Right.ToExpression()) }));

                case OperatorTypes.IsIn:
                    return(MethodCallContext.CreateMethodCall("IsIn", false, new ArgumentSyntax[] { SF.Argument(Left.ToExpression()), SF.Argument(Right.ToExpression()) }));

                case OperatorTypes.Contains:
                    return(MethodCallContext.CreateMethodCall("Contains", false, new ArgumentSyntax[] { SF.Argument(Left.ToExpression()), SF.Argument(Right.ToExpression()) }));

                case OperatorTypes.Index:
                    return(MethodCallContext.CreateMethodCall("Index", false, new ArgumentSyntax[] { SF.Argument(Left.ToExpression()), SF.Argument(Right.ToExpression()) }));

                case OperatorTypes.IndexOf:
                    return(MethodCallContext.CreateMethodCall("Index", false, new ArgumentSyntax[] { SF.Argument(Right.ToExpression()), SF.Argument(Left.ToExpression()) }));

                case OperatorTypes.LastIndex:
                    return(MethodCallContext.CreateMethodCall("IndexFromLast", false, new ArgumentSyntax[] { SF.Argument(Left.ToExpression()), SF.Argument(Right.ToExpression()) }));

                case OperatorTypes.LastIndexOf:
                    return(MethodCallContext.CreateMethodCall("IndexFromLast", false, new ArgumentSyntax[] { SF.Argument(Right.ToExpression()), SF.Argument(Left.ToExpression()) }));

                case OperatorTypes.Noop:
                    return(Right.ToExpression());

                default:
                    return(SF.BinaryExpression(this.Operator.SyntaxKind, Left.ToExpression(), Right.ToExpression()));
                }
            }
Exemple #6
0
        public override void Exit()
        {
            List <StatementSyntax> loopStatements = new List <StatementSyntax>();

            //loopStatements.Add(StateHelper.MakeStatePushStatement());
            loopStatements.Add(SF.ExpressionStatement(
                                   SF.AssignmentExpression(
                                       SyntaxKind.SimpleAssignmentExpression,
                                       VariableHelper.MakeStateVariableExpression(_asVariableName),
                                       SF.IdentifierName(_iteratorVariableName)
                                       )
                                   )
                               );
            if (_hookName != null)
            {
                loopStatements.Add(BlockContext.MakeWriteStatement(MethodCallContext.CreateMethodCall(_hookName, true)));
            }
            //loopStatements.Add(StateHelper.MakeStatePopWriteStatement());
            var forEachStatement = SF.ForEachStatement(SF.ParseTypeName("var"), _iteratorVariableName, _expression, SF.Block(loopStatements));

            _exitHandler(forEachStatement);
        }
Exemple #7
0
        public override ICodeContext CreateContext(CodeContextTypes contextType, string name = null, Bag <string> attributes = null)
        {
            switch (contextType)
            {
            case CodeContextTypes.Argument:
                return(new ExpressionContext((expression) =>
                {
                    if (expression == null)
                    {
                        _condition = SF.LiteralExpression(SyntaxKind.FalseKeyword);
                    }
                    else
                    {
                        _condition = expression.ToExpression();
                    }
                }));

            case CodeContextTypes.ElseIf:
                return(new IfContext(name, (ifStatement) =>
                {
                    _elseClause = SF.ElseClause(ifStatement);
                }));

            case CodeContextTypes.Else:
                string elseHookName = name;
                return(new BlockContext((block) =>
                {
                    if (elseHookName == null)
                    {
                        _elseClause = SF.ElseClause(block);
                    }
                    else
                    {
                        _elseClause = SF.ElseClause(BlockContext.MakeWriteStatement(MethodCallContext.CreateMethodCall(elseHookName, true)));
                    }
                }));
            }
            return(base.CreateContext(contextType, name, attributes));
        }
Exemple #8
0
        public override ICodeContext CreateContext(CodeContextTypes contextType, string name = null, Bag <string> attributes = null)
        {
            switch (contextType)
            {
            case CodeContextTypes.Argument:
                return(new ExpressionContext((expression) =>
                {
                    if (expression == null)
                    {
                        _valueExpression = SF.LiteralExpression(SyntaxKind.TrueKeyword);
                    }
                    else
                    {
                        _valueExpression = expression.ToExpression();
                    }
                }));

            case CodeContextTypes.When:
                return(new WhenContext(name, _valueExpression, (whenStatement) =>
                {
                    _whenClauses.Add(whenStatement);
                }));

            case CodeContextTypes.Otherwise:
                string elseHookName = name;
                return(new BlockContext((block) =>
                {
                    if (elseHookName == null)
                    {
                        _otherwiseClause = SF.ElseClause(block);
                    }
                    else
                    {
                        _otherwiseClause = SF.ElseClause(BlockContext.MakeWriteStatement(MethodCallContext.CreateMethodCall(elseHookName, true)));
                    }
                }));
            }
            return(base.CreateContext(contextType, name, attributes));
        }