Example #1
0
 public void AddComment(ITTEAction action)
 {
     if (action.Comment == null)
     {
         return;
     }
     if (action.Disabled)
     {
         Append("// ");
     }
     else
     {
         Append("# ");
     }
     Append(action.Comment);
     NewLine();
 }
Example #2
0
        bool Action(out ITTEAction action)
        {
            action = null;

            // Comment
            MatchString(out string comment);
            bool isDisabled = Match(Kw("disabled"));

            // Subroutine
            if (Match(Kw("Call Subroutine")))
            {
                Match("(");
                Identifier(out string name);
                Match(")");
                action = new CallSubroutine(name, Parse.CallParallel.NoParallel);
            }
            // Start Rule Subroutine
            else if (Match(Kw("Start Rule")))
            {
                Match("(");
                Identifier(out string name);
                Match(",");

                if (Match(Kw("Restart Rule")))
                {
                    Match(")");
                    action = new CallSubroutine(name, Parse.CallParallel.AlreadyRunning_RestartRule);
                }
                else if (Match(Kw("Do Nothing")))
                {
                    Match(")");
                    action = new CallSubroutine(name, Parse.CallParallel.AlreadyRunning_DoNothing);
                }
                else
                {
                    throw new Exception("Expected 'Restart Rule' or 'Do Nothing'.");
                }
            }
            // Set variable.
            else if (Expression(out ITTEExpression expr))
            {
                // Unfold the index if required.
                ITTEExpression index = null;
                if (expr is IndexerExpression indexer)
                {
                    index = indexer.Index;
                    expr  = indexer.Expression;
                }

                // Make sure the expression is a variable.
                if (expr is ITTEVariable == false)
                {
                    throw new Exception("Expression is not a variable.");
                }

                string   op        = null;
                string[] operators = new string[] { "=", "+=", "-=", "/=", "*=", "%=", "^=" };
                foreach (string it in operators)
                {
                    if (Match(it))
                    {
                        op = it;
                        break;
                    }
                }

                Expression(out ITTEExpression value);
                action = new SetVariableAction((ITTEVariable)expr, op, value, index);
            }
            // Function.
            else if (Function(true, out FunctionExpression func))
            {
                action = func;
            }
            // Unknown.
            else
            {
                return(false);
            }

            action.Disabled = isDisabled;
            action.Comment  = comment;
            Match(";");
            return(true);
        }
 public void AddComment(ITTEAction action) => AddComment(action.Comment, action.Disabled);