Exemplo n.º 1
0
        public static void ParseEnd(ToffeeGenerator generator, string[] args)
        {
            // Could we even be in an if block?
            if (generator.Stack.Count < 2)
            {
                throw new ToffeeGeneratorException("Encountered 'endif' command without being inside an if block.");
            }
            // Are we in an if block?
            if (generator.Stack.Peek().Name != "if")
            {
                throw new ToffeeGeneratorException("Encountered 'endif' command instead of 'endpattern'");
            }

            // Get the last stack handle (The If block)
            ToffeeGeneratorStackFrame handle = generator.Stack.Pop();

            // Get the If command
            IfCommand command = (IfCommand)handle.State;

            // Was this IfCommand created via an ElseIf?
            // Then, we need to end the Else that was before this If
            if (command.WasElseIf)
            {
                ParseEnd(generator, null);
            }

            generator.Log("Exit If Block (Condition: {0}, TrueSize: {1}, FalseSize: {2})",
                          command.Define, command.TrueCode.Count, command.FalseCode.Count);
        }
Exemplo n.º 2
0
        public static void ParseElse(ToffeeGenerator generator, string[] args)
        {
            // Could we even be in an if block?
            if (generator.Stack.Count < 2)
            {
                throw new ToffeeGeneratorException("Encountered 'else' command without being inside an if block.");
            }
            // Are we in an if block?
            if (generator.Stack.Peek().Name != "if")
            {
                throw new ToffeeGeneratorException("Encountered 'else' command instead of 'endpattern'");
            }

            // Get the last stack handle (The If block)
            ToffeeGeneratorStackFrame handle = generator.Stack.Pop();

            // Create an else handle (This will be the Else block)
            ToffeeGeneratorStackFrame elseHandle = new ToffeeGeneratorStackFrame("if");

            // Set the state of the Else handle to the same state as the If handle
            // (They are both part of the same IfCommand)
            elseHandle.State = handle.State;

            // Get the original If command, and set the ConditionFalse to the Else handle's commands
            ((IfCommand)elseHandle.State).FalseCode = elseHandle.Commands;

            // Push the else handle onto the stack
            generator.Stack.Push(elseHandle);

            generator.Log("Exit If, Enter Else Block (Condition: {0})", ((IfCommand)handle.State).Define);
        }
Exemplo n.º 3
0
        public static void ParseEnd(ToffeeGenerator generator, string[] args)
        {
            if (generator.Stack.Count < 2)
            {
                throw new ToffeeGeneratorException("Encountered 'endpattern' command without being inside a pattern.");
            }
            if (generator.Stack.Peek().Name == "if")
            {
                throw new ToffeeGeneratorException("Encountered 'endpattern' command instead of 'endif'");
            }
            ToffeeGeneratorStackFrame handle = generator.Stack.Pop();

            generator.Log("Exit Pattern Block (Name: {0})", handle.Name);
            generator.AddPattern(handle.Name, handle.Commands);
        }
Exemplo n.º 4
0
        public static void ParseNot(ToffeeGenerator generator, string[] args)
        {
            // Do we have the correct arguments?
            if (args.Length != 1)
            {
                throw new ToffeeGeneratorException("Invalid number of arguments for 'if' command.");
            }
            IfCommand command = new IfCommand(args[0], true);
            ToffeeGeneratorStackFrame handle = new ToffeeGeneratorStackFrame("if");

            handle.State     = command;
            command.TrueCode = handle.Commands;
            generator.AddCommand(command);
            generator.Stack.Push(handle);

            generator.Log("Enter If Block (Condition: {0})", args[0]);
        }
Exemplo n.º 5
0
        public static void ParseElseIf(ToffeeGenerator generator, string[] args)
        {
            // Do we have the correct arguments?
            if (args.Length != 1)
            {
                throw new ToffeeGeneratorException("Invalid number of arguments for 'elseif' command.");
            }
            // Could we even be in an if block?
            if (generator.Stack.Count < 2)
            {
                throw new ToffeeGeneratorException("Encountered 'elseif' command without being inside an if block.");
            }
            // Are we in an if block?
            if (generator.Stack.Peek().Name != "if")
            {
                throw new ToffeeGeneratorException("Encountered 'elseif' command instead of 'endpattern'");
            }

            // Get the last stack handle (The If block)
            ToffeeGeneratorStackFrame handle = generator.Stack.Pop();

            // Create an else handle (This will be the ElseIf block)
            ToffeeGeneratorStackFrame elseHandle = new ToffeeGeneratorStackFrame("if");

            // Set the state of the Else handle to the same state as the If handle
            // (They are both part of the same IfCommand)
            elseHandle.State = handle.State;

            // Get the original If command, and set the ConditionFalse to the Else handle's commands
            IfCommand command = (IfCommand)handle.State;

            command.FalseCode = elseHandle.Commands;

            // Push the else handle onto the stack
            generator.Stack.Push(elseHandle);

            generator.Log("Exit If, Enter Else Block (Condition: {0})", ((IfCommand)handle.State).Define);

            // Parse the "elseif" as if it was an "if"
            // The IfCommand will be placed into the Else block for this If, creating an Else If
            Parse(generator, args);

            // The IfCommand that was just added onto the stack has created via ElseIf
            ((IfCommand)generator.Stack.Peek().State).WasElseIf = true;
        }