Exemple #1
0
 public If(IParseExpression expression, IParseStatement statement, List <ElseIf> elseIfs, Else els)
 {
     Expression = expression;
     Statement  = statement;
     ElseIfs    = elseIfs;
     Else       = els;
 }
        /// <summary>
        /// Adds a child element to the block.
        /// </summary>
        /// <param name="child">The child statement to add.</param>
        /// <exception cref="System.ArgumentNullException">If child is null.</exception>
        public void AddItem(IParseStatement child)
        {
            if (child == null)
                throw new ArgumentNullException("child");

            this.children.Add(child);
        }
Exemple #3
0
 public Foreach(IParseType type, Token identifier, IParseExpression expression, IParseStatement statement)
 {
     Type       = type;
     Identifier = identifier;
     Expression = expression;
     Statement  = statement;
 }
Exemple #4
0
 public For(IParseStatement initializer, IParseExpression condition, IParseStatement iterator, IParseStatement block, Token initializerSemicolon)
 {
     Initializer          = initializer;
     Condition            = condition;
     Iterator             = iterator;
     Block                = block;
     InitializerSemicolon = initializerSemicolon;
 }
        private IStatement StatementFromContext(Scope scope, IParseStatement statementContext)
        {
            switch (statementContext)
            {
            case VariableDeclaration declare: {
                var newVar = new ScopedVariable(true, scope, new DefineContextHandler(this, declare)).GetVar();
                return(new DefineAction(newVar));
            }

            case Assignment assignment: return(new SetVariableAction(this, scope, assignment));

            case Increment increment: return(new IncrementAction(this, scope, increment));

            case If @if: return(new IfAction(this, scope, @if));

            case While @while: return(new WhileAction(this, scope, @while));

            case For @for: return(new ForAction(this, scope, @for));

            case Foreach @foreach: return(new ForeachAction(this, scope, @foreach));

            case Return @return: return(new ReturnAction(this, scope, @return));

            case Delete delete: return(new DeleteAction(this, scope, delete));

            case Continue @continue: return(new ContinueAction(this, @continue.Range));

            case Break @break: return(new BreakAction(this, @break.Range));

            case Switch @switch: return(new SwitchAction(this, scope, @switch));

            case Block @block: return(new BlockAction(this, scope, @block));

            case FunctionExpression func: return(new CallMethodAction(this, scope, func, false, scope));

            // Expression statements (functions)
            case ExpressionStatement exprStatement:

                // Parse the expression
                var expr = GetExpression(scope, exprStatement.Expression, false);

                if (!expr.IsStatement())
                {
                    Script.Diagnostics.Error("Expressions can't be used as statements.", statementContext.Range);
                    return(new MissingElementAction(TranslateInfo));
                }
                if (expr is IStatement == false)
                {
                    return(new MissingElementAction(TranslateInfo));
                }
                return((IStatement)expr);

            // New
            case NewExpression newExpression: return(new CreateObjectAction(this, scope, newExpression));

            default: return(new MissingElementAction(TranslateInfo));
            }
        }
Exemple #6
0
        /// <summary>
        /// Adds a child element to the block.
        /// </summary>
        /// <param name="child">The child statement to add.</param>
        /// <exception cref="System.ArgumentNullException">If child is null.</exception>
        public void AddItem(IParseStatement child)
        {
            if (child == null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            this.children.Add(child);
        }
Exemple #7
0
 public RuleContext(Token ruleToken, Token name, Token disabled, NumberExpression order, List <RuleSetting> settings, List <IfCondition> conditions, IParseStatement statement)
 {
     RuleToken  = ruleToken;
     NameToken  = name;
     Disabled   = disabled;
     Order      = order;
     Settings   = settings;
     Conditions = conditions;
     Statement  = statement;
 }
        /// <summary>Gets an IStatement from a StatementContext.</summary>
        /// <param name="scope">The scope the statement was created in.</param>
        /// <param name="statementContext">The context of the statement.</param>
        public IStatement GetStatement(Scope scope, IParseStatement statementContext)
        {
            IStatement statement = StatementFromContext(scope, statementContext);

            // Apply related output comment.
            if (statementContext.Comment != null)
            {
                statement.OutputComment(Script.Diagnostics, statementContext.Comment.Range, statementContext.Comment.GetContents());
            }

            return(statement);
        }
        /// <summary>Gets an IStatement from a StatementContext.</summary>
        /// <param name="scope">The scope the statement was created in.</param>
        /// <param name="statementContext">The context of the statement.</param>
        public IStatement GetStatement(Scope scope, IParseStatement statementContext)
        {
            IStatement statement = StatementFromContext(scope, statementContext);

            // Apply related output comment.
            if (statementContext is ICommentableStatement comment && comment.ActionComment != null)
            {
                string   text  = comment.ActionComment.Text.Substring(1).Trim();
                DocRange range = comment.ActionComment.Range;
                statement.OutputComment(Script.Diagnostics, range, text);
            }

            return(statement);
        }
Exemple #10
0
 public Else(IParseStatement statement)
 {
     Statement = statement;
 }
Exemple #11
0
 public ElseIf(IParseExpression expression, IParseStatement statement)
 {
     Expression = expression;
     Statement  = statement;
 }
Exemple #12
0
 public LambdaExpression(List <LambdaParameter> parameters, Token arrow, IParseStatement statement)
 {
     Parameters = parameters;
     Arrow      = arrow;
     Statement  = statement;
 }
Exemple #13
0
 public While(IParseExpression condition, IParseStatement statement)
 {
     Condition = condition;
     Statement = statement;
 }