diff --git a/lib/src/parse/parser.dart b/lib/src/parse/parser.dart index ca81da5f..8e36be49 100644 --- a/lib/src/parse/parser.dart +++ b/lib/src/parse/parser.dart @@ -17,8 +17,6 @@ abstract class Parser { // ## Tokens - String commentText() => rawText(ignoreComments); - bool scanWhitespace() { var start = scanner.position; ignoreComments(); diff --git a/lib/src/parse/scss.dart b/lib/src/parse/scss.dart index 1de39451..90755050 100644 --- a/lib/src/parse/scss.dart +++ b/lib/src/parse/scss.dart @@ -155,15 +155,15 @@ class ScssParser extends Parser { first == $dot || (first == $hash && scanner.peekChar(1) != $lbrace)) { nameBuffer.writeCharCode(scanner.readChar()); - nameBuffer.write(commentText()); + nameBuffer.write(rawText(ignoreComments)); } if (!_lookingAtInterpolatedIdentifier()) return nameBuffer; nameBuffer.addInterpolation(_interpolatedIdentifier()); - nameBuffer.write(rawText(_tryComment)); + if (scanner.matches("/*")) nameBuffer.write(rawText(loudComment)); var midBuffer = new StringBuffer(); - midBuffer.write(commentText()); + midBuffer.write(rawText(ignoreComments)); if (!scanner.scanChar($colon)) return nameBuffer; midBuffer.writeCharCode($colon); @@ -184,7 +184,7 @@ class ScssParser extends Parser { ..writeCharCode($colon); } - var postColonWhitespace = commentText(); + var postColonWhitespace = rawText(ignoreComments); if (scanner.peekChar() == $lbrace) { return new Declaration(name, scanner.spanFrom(start), children: _children(_declarationChild)); @@ -254,31 +254,6 @@ class ScssParser extends Parser { return _declaration(); } - /// Consumes whitespace if available and returns any comments it contained. - List _comments() { - var nodes = []; - while (true) { - whitespace(); - - var comment = _tryComment(); - if (comment == null) return nodes; - - nodes.add(comment); - } - } - - Comment _tryComment() { - if (scanner.peekChar() != $slash) return null; - switch (scanner.peekChar(1)) { - case $slash: - return _silentComment(); - case $asterisk: - return _loudComment(); - default: - return null; - } - } - Comment _silentComment() { var start = scanner.state; scanner.expect("//"); @@ -1544,20 +1519,36 @@ class ScssParser extends Parser { List _children(Statement child()) { scanner.expectChar($lbrace); + whitespace(); var children = []; while (true) { - children.addAll(_comments()); switch (scanner.peekChar()) { case $dollar: children.add(_variableDeclaration()); break; + case $slash: + switch (scanner.peekChar(1)) { + case $slash: + children.add(_silentComment()); + break; + case $asterisk: + children.add(_loudComment()); + break; + default: + children.add(child()); + break; + } + break; + case $semicolon: scanner.readChar(); + whitespace(); break; case $rbrace: scanner.expectChar($rbrace); + whitespace(); return children; default: @@ -1568,22 +1559,37 @@ class ScssParser extends Parser { } List _statements(Statement statement()) { - var statements = []..addAll(_comments()); + var statements = []; + whitespace(); while (!scanner.isDone) { switch (scanner.peekChar()) { case $dollar: statements.add(_variableDeclaration()); break; + case $slash: + switch (scanner.peekChar(1)) { + case $slash: + statements.add(_silentComment()); + break; + case $asterisk: + statements.add(_loudComment()); + break; + default: + statements.add(statement()); + break; + } + break; + case $semicolon: scanner.readChar(); + whitespace(); break; default: statements.add(statement()); break; } - statements.addAll(_comments()); } return statements; }