Exemplo n.º 1
0
        /// <summary>
        ///		Crea una instrucción Media
        /// </summary>
        private InstructionBase CreateInstructionMedia()
        {
            InstructionMedia instruction = new InstructionMedia(GetToken());
            TokenSmallCss    token       = GetToken();

            // Rellena los parámetros
            while (!IsEof && token.Row == instruction.Token.Row)
            {
                // Añade el valor
                instruction.Parameters += $"{token.Value} ";
                // Obtiene el siguiente token
                token = GetToken();
            }
            // Si el siguiente contenido es de una línea CSS, lo guarda
            if (token.TypeCss == TokenSmallCss.TokenCssType.Literal)
            {
                instruction.Line = CreateInstructionLiteral(token);
            }
            else
            {
                instruction.Error = ParseError("No se encuentra el contenido de la línea @media");
            }
            // Dvuelve la instrucción
            return(instruction);
        }
Exemplo n.º 2
0
        /// <summary>
        ///		Obtiene una instrucción de asignación de variables
        /// </summary>
        private InstructionBase CreateInstructionVariable()
        {
            InstructionVariableIdentifier instruction = new InstructionVariableIdentifier(GetToken());
            TokenSmallCss tokenValue = GetToken();

            if (tokenValue.Row == instruction.Token.Row &&
                tokenValue.TypeCss == TokenSmallCss.TokenCssType.Literal)
            {
                if (tokenValue.Value.TrimIgnoreNull() == ":")
                {
                    tokenValue = GetToken();
                    if (tokenValue.Row == instruction.Token.Row &&
                        tokenValue.TypeCss == TokenSmallCss.TokenCssType.Literal)
                    {
                        instruction.Value.Add(new ExpressionBase(tokenValue));
                    }
                    else
                    {
                        instruction.Error = ParseError("No se reconoce el valor asignado a la variable");
                    }
                }
                else
                {
                    instruction.Value.Add(new ExpressionBase(tokenValue));
                }
            }
            else
            {
                instruction.Error = ParseError("No se reconoce el valor asignado a la variable");
            }
            // Devuelve la instrucción
            return(instruction);
        }
Exemplo n.º 3
0
        /// <summary>
        ///		Crea una instrucción IfDefined
        /// </summary>
        private InstructionBase CreateInstructionIfDefined()
        {
            InstructionIfDefined instruction = new InstructionIfDefined(GetToken());
            TokenSmallCss        token       = GetToken();

            // Obtiene la variable
            if (token.Row == instruction.Token.Row &&
                (token.TypeCss == TokenSmallCss.TokenCssType.Literal ||
                 token.TypeCss == TokenSmallCss.TokenCssType.Variable))
            {
                // Asigna el nombre de la variable
                instruction.Identifier = token.Value;
                // Obtiene las instrucciones
                if (CheckIsBlock(instruction.Token))
                {
                    instruction.SentencesIf.AddRange(GetBlock(instruction.Token.Indent));
                }
                else
                {
                    instruction.Error = ParseError("No se han definido las instrucciones de la función");
                }
            }
            else
            {
                instruction.Error = ParseError("No se encuentra la definición de variable");
            }
            // Devuelve la instrucción
            return(instruction);
        }
Exemplo n.º 4
0
        /// <summary>
        ///		Obtiene un token de error
        /// </summary>
        private TokenSmallCss GetTokenError()
        {
            TokenSmallCss token = new TokenSmallCss(GetToken());

            // Indica que es un token erróneo
            token.TypeCss = TokenSmallCss.TokenCssType.Error;
            // Devuelve el token
            return(token);
        }
Exemplo n.º 5
0
        /// <summary>
        ///		Obtiene el token actual incrementando
        /// </summary>
        private TokenSmallCss GetToken()
        {
            TokenSmallCss token = ActualToken;

            // Incrementa el índice
            IndexActual++;
            // Devuelve el token
            return(token);
        }
Exemplo n.º 6
0
        /// <summary>
        ///		Crea la instrucción de llamada a un Mixin
        /// </summary>
        private InstructionBase CreateInstructionMininCall()
        {
            InstructionMixinCall instruction = new InstructionMixinCall(GetToken());
            TokenSmallCss        token       = GetToken();

            // Obtiene los datos
            if (token.Row == instruction.Token.Row && token.TypeCss == TokenSmallCss.TokenCssType.Literal)
            {
                // Asigna el nombre de la función
                instruction.Name = token.Value;
                // Obtiene los argumentos
                if (ActualToken != null && ActualToken.Row == instruction.Token.Row)
                {
                    bool end = false;

                    while (!end && !IsEof)
                    {
                        // Comprueba si es un parámetro o un comentario
                        if (ActualToken.Row == instruction.Token.Row)
                        {
                            if (ActualToken.TypeCss == TokenSmallCss.TokenCssType.Literal ||
                                ActualToken.TypeCss == TokenSmallCss.TokenCssType.Variable)
                            {
                                instruction.Parameters.Add(GetToken());
                            }
                            else if (ActualToken.TypeCss == TokenSmallCss.TokenCssType.Comment)
                            {
                                instruction.Sentences.Add(CreateInstructionComment());
                            }
                            else
                            {
                                instruction.Error = ParseError($"No se reconoce el token entre los parámetros de llamada a la función '{instruction.Name}'");
                            }
                        }
                        else
                        {
                            end = true;
                        }
                    }
                }
            }
            else
            {
                instruction.Error = ParseError("No se encuentra el nombre del mixin al que se está llamando");
            }
            // Devuelve la instrucción
            return(instruction);
        }
Exemplo n.º 7
0
        /// <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);
        }
Exemplo n.º 8
0
        /// <summary>
        ///		Crea la instrucción de crear archivo
        /// </summary>
        private InstructionIncludeFile CreateInstructionIncludeFile()
        {
            InstructionIncludeFile instruction = new InstructionIncludeFile(GetToken());
            TokenSmallCss          token       = GetToken();

            // Captura el nombre de archivo
            if (token.Row == instruction.Token.Row && token.TypeCss == TokenSmallCss.TokenCssType.Literal)
            {
                instruction.FileName = token.Value;
            }
            else if (token.Row == instruction.Token.Row && token.TypeCss == TokenSmallCss.TokenCssType.Comment)
            {
                instruction.FileName = "_" + token.Value;
            }
            else
            {
                instruction.Error = ParseError("No se reconoce el nombre de archivo a incluir");
            }
            // Devuelve la instrucción
            return(instruction);
        }
Exemplo n.º 9
0
 /// <summary>
 ///		Obtiene el valor de una variable
 /// </summary>
 private string GetVariableValue(Program program, TokenSmallCss token)
 {
     return(GetVariableValue(program, token.Value));
 }
Exemplo n.º 10
0
        /// <summary>
        ///		Crea la instrucción de definición de un Mixin
        /// </summary>
        private InstructionBase CreateInstructionMixinDefinition()
        {
            InstructionFunction instruction = new InstructionFunction(GetToken());
            TokenSmallCss       token       = GetToken();

            // Obtiene la función
            if (token.Row == instruction.Token.Row && token.TypeCss == TokenSmallCss.TokenCssType.Literal)
            {
                // Asigna el nombre de la función
                instruction.Name = token.Value;
                // Obtiene los argumentos
                if (ActualToken.Row == instruction.Token.Row)
                {
                    bool end = false;

                    while (!end && !IsEof)
                    {
                        // Comprueba si es un argumento
                        if (ActualToken.Row == instruction.Token.Row)
                        {
                            if (ActualToken.TypeCss == TokenSmallCss.TokenCssType.Literal ||
                                ActualToken.TypeCss == TokenSmallCss.TokenCssType.Variable)
                            {
                                string argument = ActualToken.Value;

                                // Normaliza el argumento
                                if (!argument.StartsWith("$"))
                                {
                                    argument = "$" + argument;
                                }
                                // Añade el nombre del argumento
                                instruction.Arguments.Add(argument);
                                // Obtiene el siguiente token
                                GetToken();
                            }
                            else if (ActualToken.TypeCss == TokenSmallCss.TokenCssType.Comment)
                            {
                                instruction.Sentences.Add(CreateInstructionComment());
                            }
                            else
                            {
                                instruction.Error = ParseError($"No se reconoce el token entre los argumentos de la función '{instruction.Name}'");
                            }
                        }
                        else
                        {
                            end = true;
                        }
                    }
                }
                if (!instruction.IsError)
                {
                    if (CheckIsBlock(instruction.Token))
                    {
                        instruction.Sentences.AddRange(GetBlock(instruction.Token.Indent));
                    }
                    else
                    {
                        instruction.Error = ParseError("No se han definido las instrucciones de la función");
                    }
                }
            }
            else
            {
                instruction.Error = ParseError("No se encuentra el nombre de la función");
            }
            // Devuelve la instrucción
            return(instruction);
        }