Exemplo n.º 1
0
        public void Build(TokenList tokens)
        {
            instructionListToken = tokens.Current;
            if (isStandardSection)
            {
                tokens.Advance();                 // only advance past the section token if
            }
            // if the current token is the name of the instruction list, store it
            if (tokens.Current != null)
            {
                if (tokens.Current.TokenType == TokenType.QuotedString)
                {
                    name = tokens.Current.Value;
                    tokens.Advance();
                }
            }

            // read each instruction, one by one until the end of the instruction list is reached
            while (tokens.Current != null)
            {
                // if we've reached a token indicating the end of this instruction block, advance past the ending token and return
                if ((!isLoopBlock && Token.IsEnd(tokens.Current)) ||
                    (isLoopBlock && Token.IsLoop(tokens.Current)) ||
                    (acceptELSEInPlaceOfEND && (Token.IsElse(tokens.Current) || Token.IsElseIf(tokens.Current))))
                {
                    // record the type of terminating token then advance past it
                    switch (tokens.Current.Value)
                    {
                    case "else": terminator = TerminatorType.Else; break;

                    case "elseif": terminator = TerminatorType.ElseIf; break;

                    case "loop": terminator = TerminatorType.Loop; break;
                    }
                    tokens.Advance();
                    return;
                }
                list.Add(TokenParser.BuildInstruction(tokens));
            }
        }
Exemplo n.º 2
0
        public SprocketScript(string source, string descriptiveName, string scriptIdentificationString)
        {
            this.source     = source;
            this.identifier = new ExecutionState.ScriptRecursionIdentifier(descriptiveName, scriptIdentificationString);

            TokenList tokens;

            try
            {
                tokens = Tokeniser.Extract(source);
            }
            catch (TokeniserException ex)
            {
                Token falseToken = new Token(source.Substring(ex.Position, 1), TokenType.FreeText, ex.Position);
                Token token      = new Token(GetErrorHTML(ex.Message, falseToken, null), TokenType.FreeText, 0);
                tokens      = new TokenList(new List <Token>(new Token[] { token }));
                instruction = new ShowInstruction();
                instruction.Build(tokens);
                hasError  = true;
                exception = ex;
                return;
            }

            try
            {
                instruction = TokenParser.BuildInstruction(tokens);
            }
            catch (TokenParserException ex)
            {
                Token token = new Token(GetErrorHTML(ex.Message, ex.Token, null), TokenType.FreeText, 0);
                tokens      = new TokenList(new List <Token>(new Token[] { token }));
                instruction = new ShowInstruction();
                instruction.Build(tokens);
                hasError = true;
            }
        }