コード例 #1
0
 public virtual LessNode VisitSingleValuedExpression(LessParser.SingleValuedExpressionContext context)
 {
     throw new System.NotImplementedException();
 }
コード例 #2
0
        private Expression GetSingleValuedExpression(LessParser.SingleValuedExpressionContext context)
        {
            Expression GetMathOperation()
            {
                var mathOperation = context.op;

                if (mathOperation == null)
                {
                    return(null);
                }

                var lhs = GetSingleValuedExpression(context.singleValuedExpression(0));
                var rhs = GetSingleValuedExpression(context.singleValuedExpression(1));

                return(new MathOperation(lhs, mathOperation.Text, rhs, keepSpaces: HasLeadingWhitespace(mathOperation) && HasTrailingWhitespace(mathOperation)));
            }

            Expression GetColor()
            {
                var color = context.color();

                if (color == null)
                {
                    return(null);
                }

                var hexColor = color.HexColor();

                if (hexColor != null)
                {
                    return(Color.FromHexString(hexColor.GetText()));
                }

                return(Color.FromKeyword(color.KnownColor().GetText()));
            }

            Expression GetStringLiteral()
            {
                return((LessString)context.@string()?.Accept(this));
            }

            Expression GetBoolean()
            {
                var boolean = context.booleanValue();

                if (boolean == null)
                {
                    return(null);
                }

                return(new BooleanValue(string.Equals("true", boolean.GetText())));
            }

            if (context == null)
            {
                return(null);
            }

            LessNode result = context.variableName()?.Accept(this)
                              ?? GetColor()
                              ?? context.measurement()?.Accept(this)
                              ?? GetStringLiteral()
                              ?? context.escapeSequence()?.Accept(this)
                              ?? context.function()?.Accept(this)
                              ?? context.unicodeRange()?.Accept(this)
                              ?? context.identifier()?.Accept(this)
                              ?? context.parenthesizedExpression()?.Accept(this)
                              ?? GetMathOperation()
                              ?? context.url()?.Accept(this)
                              ?? context.quotedExpression()?.Accept(this)
                              ?? context.selector()?.Accept(this)
                              ?? GetBoolean()
                              ?? throw new ParserException($"Unexpected expression {context.GetText()}");

            return((Expression)result);
        }