Exemple #1
0
 protected static bool IsPropertyName(ScssParserContext context)
 {
     var tokens = context.Tokens.Moment();
     if (tokens.Empty) return false;
     var prev = tokens.Read();
     var prevNoWhite = TokenType.Whitespace;
     while (!tokens.Empty) {
         var token = tokens.Read();
         switch (token.Type) {
             case TokenType.SingleLineComment:
             case TokenType.MultiLineComment:
             case TokenType.Whitespace:
                 break;
             case TokenType.Colon:
                 if (prev.Type == TokenType.Colon) return false;
                 break;
             case TokenType.OpenCurlyBracket:
                 if (prevNoWhite == TokenType.Colon) return true;
                 return false;
             case TokenType.Semicolon:
                 return true;
         }
         if (token.Type != TokenType.Whitespace && token.Type != TokenType.SingleLineComment &&
             token.Type != TokenType.MultiLineComment) {
             prevNoWhite = token.Type;
         }
         prev = token;
     }
     return false;
 }
Exemple #2
0
        protected static void ParseBlock(ScssParserContext context, RuleSetNode node)
        {
            context.Tokens.SkipWhiteAndComments();
            context.Tokens.Read(TokenType.OpenCurlyBracket);
            var stop = false;

            while (!context.Tokens.Empty && !stop) {
                context.Tokens.SkipWhiteAndComments();
                var preview = context.Tokens.Peek();
                switch (preview.Type) {
                    case TokenType.Semicolon:
                    case TokenType.Whitespace:
                        context.Tokens.Read();
                        break;
                    case TokenType.CloseCurlyBracket:
                        stop = true;
                        break;
                    default:
                        if (IsPropertyName(context)) {
                            var rule = ScssDeclarationNode.Parse(context);
                            node.Rules.Nodes.Add(rule);
                        } else {
                            var ruleSet = Parse(context);
                            node.RuleSets.Nodes.Add(ruleSet);
                        }
                        break;
                }
            }
            context.Tokens.Read(TokenType.CloseCurlyBracket);
        }
 public void ParseSubRuleTest()
 {
     const string css = "div { p {color: red;} }";
     var tokens = new Tokenizer().Read(css);
     var context = new ScssParserContext(new TokensQueue(tokens));
     var node = RuleSetNode.Parse(context);
     AssertExt.AreEqual(new RuleSetNode {
         RawSelector = new TypeSelector("div"),
         RuleSets = {
             Nodes = {
                 new RuleSetNode {
                     RawSelector = new TypeSelector("p"),
                     Rules = {
                         Nodes = {
                             new ScssDeclarationNode {
                                 Property = "color",
                                 Value = new ValuesNode { Value = Expression.Parse("red")}
                             }
                         }
                     }
                 }
             }
         }
     }, node);
 }
 public static ScssDocumentNode Parse(ScssParserContext context)
 {
     var res = new ScssDocumentNode();
     while (!context.Tokens.Empty) {
         var node = RuleSetNode.Parse(context);
         res.Nodes.Add(node);
     }
     return res;
 }
Exemple #5
0
 public static RuleSetNode Parse(ScssParserContext context)
 {
     var raw = SelectorExpression.Parse(context.Tokens, context.Selector);
     context.PushSelector(raw);
     var res = new RuleSetNode {
         RawSelector = raw,
         Selector = context.Selector
     };
     ParseBlock(context, res);
     context.PopSelector();
     return res;
 }
Exemple #6
0
 public static ValuesNode Parse(ScssParserContext context)
 {
     var res = new ValuesNode { Value = Expression.Parse(context.Tokens) };
     context.Tokens.SkipWhiteAndComments();
     var preview = context.Tokens.Peek();
     if (preview.Type == TokenType.ExclamationPoint) {
         context.Tokens.Read();
         var important = context.Tokens.Read(TokenType.Literal);
         if (important.StringValue != "important") throw new TokenException("!important expected", important);
         res.Important = true;
     }
     return res;
 }
 public static ScssDeclarationNode Parse(ScssParserContext context)
 {
     var res = new ScssDeclarationNode();
     context.Tokens.SkipWhiteAndComments();
     res.Property = context.Tokens.Read(TokenType.Literal).StringValue;
     context.Tokens.SkipWhiteAndComments();
     context.Tokens.Read(TokenType.Colon);
     context.Tokens.SkipWhiteAndComments();
     var preview = context.Tokens.Peek();
     if (preview.Type == TokenType.OpenCurlyBracket) {
         res.Value = NestedValueNode.Parse(context);
     } else {
         res.Value = ValuesNode.Parse(context);
     }
     return res;
 }
Exemple #8
0
 protected BaseNode ParseSelf(ScssParserContext context)
 {
     var stop = false;
     while (!context.Tokens.Empty && !stop) {
         var preview = context.Tokens.Peek();
         switch (preview.Type) {
             case TokenType.SingleLineComment:
             case TokenType.MultiLineComment:
                 context.Tokens.Read();
                 Comments.Add(new CommentNode(preview));
                 break;
             default:
                 stop = !AcceptToken(ref preview);
                 break;
         }
     }
     return this;
 }
 public static NestedValueNode Parse(ScssParserContext context)
 {
     var res = new NestedValueNode();
     context.Tokens.SkipWhiteAndComments();
     context.Tokens.Read(TokenType.OpenCurlyBracket);
     while (!context.Tokens.Empty) {
         context.Tokens.SkipWhiteAndComments();
         var preview = context.Tokens.Peek();
         if (preview.Type == TokenType.CloseCurlyBracket) break;
         if (preview.Type == TokenType.Semicolon) {
             context.Tokens.Read();
             continue;
         }
         var rule = ScssDeclarationNode.Parse(context);
         res.Rules.Add(rule);
     }
     context.Tokens.Read(TokenType.CloseCurlyBracket);
     return res;
 }