コード例 #1
0
        /// <summary>
        ///		Obtiene las etiquetas Css de una línea
        /// </summary>
        private string GetTagsCss(Program program, InstructionLineCss line)
        {
            string tag = "";

            // Recoge las etiquetas
            foreach (TokenSmallCss token in line.Tokens)
            {
                if (token.TypeCss == TokenSmallCss.TokenCssType.Comment)
                {
                    tag += GetComment(token.Value);
                }
                else if (token.TypeCss == TokenSmallCss.TokenCssType.Literal)
                {
                    if (token.Value.IsEmpty())                             // ... por el problema de los tokens con "" que aparecen vacíos
                    {
                        tag += "\"\"";
                    }
                    else
                    {
                        tag += token.Value + " ";
                    }
                }
                else if (token.TypeCss == TokenSmallCss.TokenCssType.Variable)
                {
                    tag += GetVariableValue(program, token) + " ";
                }
            }
            // Devuelve la cadena
            return(tag);
        }
コード例 #2
0
        /// <summary>
        ///		Escribe las líneas CSS
        /// </summary>
        private string GetLine(Program program, string tagParent, InstructionLineCss lineCss)
        {
            string        tag        = CombineTags(tagParent, GetTagsCss(program, lineCss));
            string        line       = "";
            List <string> lineChilds = new List <string>();

            // Recorre las líneas hija
            line = GetContentChildSentences(program, lineCss.Sentences, tag, lineChilds);
            // Devuelve la línea compactada
            return(CompactCss(lineCss.Token.Indent, tag, line, lineChilds));
        }
コード例 #3
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);
        }
コード例 #4
0
ファイル: Parser.cs プロジェクト: jbautistam/Compilers
        /// <summary>
        ///		Crea una instrucción de literal
        /// </summary>
        private InstructionLineCss CreateInstructionLiteral(TokenSmallCss token = null)
        {
            InstructionLineCss instruction;
            bool end = false;

            // Crea la instrucción
            if (token != null)
            {
                instruction = new InstructionLineCss(token);
            }
            else
            {
                instruction = new InstructionLineCss(GetToken());
            }
            // Recorre los tokens
            while (!IsEof && !end)
            {
                // Si cambiamos de línea a una de mayor indentación, obtenemos el bloque
                if (CheckIsBlock(instruction.Token) || CheckIsEndLine(instruction.Token))
                {
                    end = true;
                }
                else if (ActualToken.Row == instruction.Token.Row)                         // ... si seguimos en la misma línea
                {
                    if (ActualToken.TypeCss == TokenSmallCss.TokenCssType.Literal ||
                        ActualToken.TypeCss == TokenSmallCss.TokenCssType.Variable)
                    {
                        instruction.Tokens.Add(GetToken());
                    }
                    else if (ActualToken.TypeCss == TokenSmallCss.TokenCssType.Comment)
                    {
                        instruction.Sentences.Add(CreateInstructionComment());
                    }
                    else
                    {
                        instruction.Tokens.Add(GetTokenError());
                    }
                }
            }
            // Si lo siguiente es un bloque
            if (CheckIsBlock(instruction.Token))
            {
                instruction.Sentences.AddRange(GetBlock(instruction.Token.Indent));
            }
            // Devuelve la instrucción
            return(instruction);
        }
コード例 #5
0
 /// <summary>
 ///		Escribe la línea
 /// </summary>
 private void WriteLine(Program program, InstructionLineCss line)
 {
     _generator.AppendLine(GetIndent(line.Token.Indent) + GetTagsCss(program, line));
 }