Permalink
Browse files

add support for regular css multi-line comments. Closes #12

  • Loading branch information...
1 parent 3d9d9b8 commit 36daf50fada3f236f9c822e204b15923a82e424c @tj tj committed Jun 2, 2013
Showing with 57 additions and 6 deletions.
  1. +11 −1 examples/nesting.css
  2. +10 −0 lib/compiler.js
  3. +17 −0 lib/lexer.js
  4. +1 −0 lib/parser.js
  5. +11 −4 test/cases/comments.css
  6. +7 −1 test/cases/comments.out.css
View
@@ -1,8 +1,18 @@
+/*
+
+regular multi-line comment
+
+*/
+
+/* regular comment */
+
body
background: #888
color: #eee
+// stripped comment
+
ul
margin: 0
li
@@ -16,4 +26,4 @@ ul
ul
width: 50px
li
- list-style: disc
+ list-style: disc
View
@@ -47,6 +47,8 @@ module.exports = function(node){
return ret;
case 'prop':
return prop(node);
+ case 'comment':
+ return comment(node);
default:
throw new Error('invalid node "' + node[0] + '"');
}
@@ -68,6 +70,14 @@ module.exports = function(node){
}
/**
+ * Visit comment.
+ */
+
+ function comment(node) {
+ return indent() + '/*' + node[1] + '*/\n';
+ }
+
+ /**
* Visit prop.
*/
View
@@ -93,6 +93,7 @@ module.exports = function(str) {
function next() {
return stashed()
|| comment()
+ || csscomment()
|| indentation()
|| prop()
|| rule();
@@ -117,6 +118,22 @@ module.exports = function(str) {
return next();
}
+ /**
+ * Multiline comment.
+ */
+
+ function csscomment() {
+ if ('/' != str[0] || '*' != str[1]) return;
+ str = str.slice(2);
+
+ var i = 0;
+ while ('*' != str[i] && '/' != str[i + 1]) ++i;
+
+ var buf = str.slice(0, i);
+ str = str.slice(buf.length + 2);
+
+ return ['comment', buf];
+ }
/**
* INDENT
View
@@ -78,6 +78,7 @@ module.exports = function(str) {
function stmt() {
if (is('rule')) return rule();
if (is('prop')) return prop();
+ return next();
}
/**
View
@@ -1,11 +1,18 @@
+/*
+
+this is a button
+
+*/
+
// foo
button
// bar
color: #eee
// bar
-
-
-
+
+
+
// baz
- background: blue
+ /* css style */
+ background: blue
@@ -1,4 +1,10 @@
+/*
+this is a button
+*/
+
+
button {
color: #eee;
+ /* css style */
background: blue;
-}
+}

0 comments on commit 36daf50

Please sign in to comment.