예제 #1
0
 /// <summary>
 ///		Ejecuta el programa
 /// </summary>
 private void Execute(InstructionsBaseCollection instructions)
 {
     if (instructions != null)
     {
         foreach (InstructionBase instruction in instructions)
         {
             Execute(instruction);
         }
     }
 }
예제 #2
0
        /// <summary>
        ///		Obtiene el contenido de una serie de líneas
        /// </summary>
        private string GetContentChildSentences(Program program, InstructionsBaseCollection instructions, string tag, List <string> lineChilds)
        {
            string line = "";

            // Recorre las instrucciones
            foreach (InstructionBase instruction in instructions)
            {
                if (instruction is InstructionComment)
                {
                    line += GetComment(instruction.Token.Value) + Environment.NewLine;
                }
                else if (instruction is InstructionMixinCall)
                {
                    line += CallFunction(instruction as InstructionMixinCall, tag, lineChilds) + Environment.NewLine;
                }
                else if (instruction is InstructionIfDefined)
                {
                    line += CallCheckDefined(instruction as InstructionIfDefined, tag) + Environment.NewLine;
                }
                else if (instruction is InstructionLineCss)
                {
                    InstructionLineCss child = instruction as InstructionLineCss;

                    if (child != null)
                    {
                        if (child.Sentences != null && child.Sentences.Count > 0)
                        {
                            lineChilds.Add(GetLine(program, tag, child));
                        }
                        else
                        {
                            string tagChild = GetTagsCss(program, child).TrimIgnoreNull();

                            // Añade un punto y coma si es necesario
                            if (!tagChild.EndsWith(";"))
                            {
                                tagChild += ";";
                            }
                            // Añade las etiquetas de la línea
                            line += GetIndent(child.Token.Indent + 1) + tagChild + Environment.NewLine;
                        }
                    }
                }
            }
            // Devuelve la línea
            return(line);
        }
예제 #3
0
        /// <summary>
        ///		Obtiene un bloque de instrucciones
        /// </summary>
        private InstructionsBaseCollection GetBlock(int indentBase)
        {
            InstructionsBaseCollection instructions = new InstructionsBaseCollection();
            bool end = false;

            // Obtiene las instrucciones que estén en un nivel de indentación superior
            while (!IsEof && !end)
            {
                Token token = ActualToken;

                if (token != null && token.Indent > indentBase)
                {
                    instructions.Add(CreateInstruction());
                }
                else
                {
                    end = true;
                }
            }
            // Devuelve la colección de instrucciones
            return(instructions);
        }
예제 #4
0
        /// <summary>
        ///		Lee las instrucciones
        /// </summary>
        private Token ReadInstructions(InstructionsBaseCollection instructions)
        {
            Token nextToken = GetToken(true);
            int   firstIndent;
            bool  end = false;

            // Quita las instrucciones de fin y de inicio de comando
            while (nextToken.Type == Token.TokenType.EndSentenceBlock)
            {
                GetToken();
                nextToken = GetToken(true);
            }
            // Obtiene la indentación inicial
            firstIndent = nextToken.Indent;
            // Lee las instrucciones
            while (nextToken.Type != Token.TokenType.EOF && nextToken.Indent >= firstIndent && !end)
            {
                InstructionsBaseCollection innerInstructions = new InstructionsBaseCollection();

                // Obtiene el token real
                nextToken = GetToken();
                // Trata las instrucciones
                switch (nextToken.Type)
                {
                case Token.TokenType.StartComment:
                    innerInstructions.Add(ReadComment(nextToken));
                    break;

                case Token.TokenType.StartSentenceBlock:
                case Token.TokenType.EndSentenceBlock:
                    // ... no hace nada, simplemente se las salta
                    break;

                case Token.TokenType.TagHTML:
                    innerInstructions.Add(ReadHtml(nextToken));
                    break;

                case Token.TokenType.Sentence:
                    innerInstructions.Add(ReadSentence(nextToken));
                    break;

                default:
                    innerInstructions.Add(new InstructionBase(nextToken));
                    break;
                }
                // Trata las instrucciones
                if (innerInstructions.Count > 0)
                {
                    bool error = false;

                    // Si hay algún error lo añade
                    foreach (InstructionBase instruction in innerInstructions)
                    {
                        if (instruction.IsError)
                        {
                            Compiler.LocalErrors.Add(instruction.Token, instruction.Error);
                            error = true;
                        }
                    }
                    // Se recupera de los errores
                    if (error)
                    {
                        RecoverError();
                    }
                    // En cualquier caso, mete las instrucciones en el buffer
                    instructions.AddRange(innerInstructions);
                }
                // Obtiene el siguiente token
                nextToken = GetToken(true);
                // Termina si es una sentencia else
                if (IsElseCommand(nextToken))
                {
                    end = true;
                }
            }
            // Devuelve el último token leído
            return(nextToken);
        }