private void ReadScopeContent(ScopeNode currentScope) { var buffer = new StringBuilder(); var interpolations = new List<ValueList>(); //States var inCommentStart = false; var paranthesesLevel = 0; var inDoubleQuotes = false; while (!EndOfStream) { var c = (char) Read(); if (inDoubleQuotes) { buffer.Append(c); if (c == '"') { inDoubleQuotes = false; } } else { switch (c) { case ' ': //Ignore starting white space if (buffer.Length == 0) break; goto default; case '@': if (buffer.Length != 0) throw new Exception("Must be first character"); ReadAt(currentScope); break; case '$': var name = ReadUntil(':'); var vn = new VariableNode(name); vn.Expression = new Expression(ReadValueList(';')); Expect(';'); currentScope.Add(vn); break; case '/': if (inCommentStart) { ReadInlineComment(); inCommentStart = false; //Remove the first slash from the buffer buffer.Length--; } else { buffer.Append(c); inCommentStart = true; } break; case '*': if (inCommentStart) { var node = ReadComment(); currentScope.Add(node); inCommentStart = false; //Remove the first slash from the buffer buffer.Length--; break; } goto default; case ';': { throw new ScssReaderException("Unexpected ;", File.Path, _lineNumber); } case ':': var pc = (char) Peek(); if (char.IsLetter(pc)) //hover etc. { buffer.Append(c); } else if (pc == ':') { buffer.Append(c); buffer.Append(pc); Read(); } else { var pn = new PropertyNode(); pn.Name = new ScssString(buffer.ToString().Trim(), interpolations); pn.Expression = new Expression(ReadValueList(';', '{')); buffer.Clear(); var pc2 = (char) Read(); if (pc2 == ';') { currentScope.Add(pn); } else if (pc2 == '{') { var result = new NamespaceNode(pn); ReadScopeContent(result); currentScope.Add(result); } else { throw new ScssReaderException("Expected { or ;", File.Path, _lineNumber); } } break; case '"': inDoubleQuotes = true; goto default; case '(': paranthesesLevel++; goto default; case ')': paranthesesLevel--; goto default; case '{': { var node = new SelectorNode(); node.Selector = new ScssString(buffer.ToString().Trim(), interpolations); ReadScopeContent(node); currentScope.Add(node); buffer.Clear(); } break; case '}': return; case '#': if (Peek() == '{') { inCommentStart = false; var value = ReadInterpolation(); buffer.Append("{" + interpolations.Count + "}"); interpolations.Add(value); break; } else { goto default; } case '\n': inCommentStart = false; break; default: inCommentStart = false; buffer.Append(c); break; } } } }
private void ReadMixin(ScopeNode currentScope) { var name = ReadName(); VariableNode[] args = new VariableNode[0]; SkipWhitespace(); if (Peek() == '(') args = ReadArgumentDefinition().ToArray(); var node = new MixinNode(name, args); Expect('{'); ReadScopeContent(node); currentScope.Add(node); }
private void ReadReturn(ScopeNode currentScope) { ExpressionNode value = ReadValueList(';'); Expect(';'); var result = new ReturnNode(new Expression(value)); currentScope.Add(result); }
private void ReadInclude(ScopeNode currentScope) { var name = ReadName(); ValueList args = new ValueList(); SkipWhitespace(); if (Peek() == '(') args = ReadArgumentCall(); SkipWhitespace(); var result = new IncludeNode(name, args); currentScope.Add(result); if (Peek() == '{') { Expect('{'); ReadScopeContent(result); } else Optional(';'); }
private void ReadMedia(ScopeNode currentScope) { var def = ReadUntil('{'); MediaNode node = new MediaNode() { Definition = def.TrimEnd() }; ReadScopeContent(node); currentScope.Add(node); }
private void ReadIf(ScopeNode currentScope) { var val = ReadValueList('{'); Expect('{'); var ifNode = new IfNode(val); currentScope.Add(ifNode); ReadScopeContent(ifNode); }
private void ReadImport(ScopeNode currentScope) { var path = ReadUntil(';'); currentScope.Add(new ImportNode(path)); }
private void ReadFunction(ScopeNode currentScope) { var name = ReadName(); var args = ReadArgumentDefinition(); var node = new FunctionNode(name, args.ToArray()); Expect('{'); ReadScopeContent(node); currentScope.Add(node); }
private void ReadFor(ScopeNode currentScope) { Expect('$'); var varName = ReadName(); Expect("from"); SkipWhitespace(); var from = ReadValueList('t'); Expect("through"); SkipWhitespace(); var through = ReadValueList('{'); Expect('{'); var node = new ForNode(new VariableNode(varName), new Expression(from), new Expression(through)); currentScope.Add(node); ReadScopeContent(node); }
private void ReadExtend(ScopeNode currentScope) { string selector = ReadUntil(';'); currentScope.Add(new ExtendNode(selector)); }
private void ReadEach(ScopeNode currentScope) { var varNames = ReadValueList('i'); Expect("in"); var val = ReadValueList('{'); Expect('{'); var node = new EachNode(varNames, val); currentScope.Add(node); ReadScopeContent(node); }
private void ReadContent(ScopeNode currentScope) { currentScope.Add(new ContentNode()); Optional(';'); }