[svn r45] inherit value and escaped chars+unicode trunk
authordglazman
Tue, 16 Mar 2010 05:21:03 -0500
branchtrunk
changeset 41 070b030fd454
parent 40 b4f62e185074
child 42 67149c16b5af
[svn r45] inherit value and escaped chars+unicode
cssParser.js
demo.xhtml
--- a/cssParser.js	Tue Mar 16 04:15:42 2010 -0500
+++ b/cssParser.js	Tue Mar 16 05:21:03 2010 -0500
@@ -100,6 +100,11 @@
      SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI, SI
   ],
 
+  kHexValues: {
+    "0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9,
+    "a": 10, "b": 11, "c": 12, "d": 13, "e": 14, "f": 15
+  },
+
   mString : "",
   mPos : 0,
   mPreservedPos : [],
@@ -182,11 +187,49 @@
     return new jscsspToken(jscsspToken.HEX_TYPE, s);
   },
 
+  gatherEscape: function() {
+    var c = this.peek();
+    if (c == -1)
+      return "";
+    if (this.isHexDigit(c)) {
+      var code = 0;
+      for (var i = 0; i < 6; i++) {
+        c = this.read();
+        if (this.isHexDigit(c))
+          code = code * 16 + this.kHexValues[c.toLowerCase()];
+        else if (!this.isHexDigit(c) && !this.isWhiteSpace(c)) {
+          this.pushback();
+          break;
+        }
+        else
+          break;
+      }
+      if (i == 6) {
+        c = this.peek();
+        if (this.isWhiteSpace(c))
+          this.read();
+      }
+      return String.fromCharCode(code);
+    }
+    c = this.read();
+    if (c != "\n")
+      return c;
+    return "";
+  },
+
   gatherIdent: function(c) {
-    var s = c;
+    var s = "";
+    if (c == CSS_ESCAPE)
+      s += this.gatherEscape();
+    else
+      s += c;
     c = this.read();
-    while (c != -1 && this.isIdent(c)) {
-      s += c;
+    while (c != -1
+           && (this.isIdent(c) || c == CSS_ESCAPE)) {
+      if (c == CSS_ESCAPE)
+	      s += this.gatherEscape();
+	    else
+        s += c;
       c = this.read();
     }
     if (c != -1)
@@ -1002,13 +1045,13 @@
       }
   
       if (token.isIdent(this.kINHERIT)) {
-        token = this.getToken(true, true);
         if (value) {
           value = "";
 	        break;
         }
         else {
-          value += token.value;
+          value += this.kINHERIT;
+          token = this.getToken(true, true);
           break;
         }
       }
@@ -1888,9 +1931,9 @@
         if (!token.isNotNull())
           return "";
         if (token.isWhiteSpace()) {
-          token = this.lookAhead(true, true);
+          nextToken = this.lookAhead(true, true);
           // if next token is not a closing parenthesis, that's an error
-          if (!token.isSymbol(")")) {
+          if (!nextToken.isSymbol(")")) {
             token = this.currentToken;
             break;
           }
@@ -2228,6 +2271,10 @@
         s += " { ";
         var token = this.getToken(true, false);
         while (true) {
+          if (!token.isNotNull()) {
+            valid = true;
+            break;
+          }
           if (token.isSymbol("}")) {
             s += "}";
             valid = true;
--- a/demo.xhtml	Tue Mar 16 04:15:42 2010 -0500
+++ b/demo.xhtml	Tue Mar 16 05:21:03 2010 -0500
@@ -8,11 +8,11 @@
 /* comment between two declarations */<a ></a>border: 2px silver solid; padding: 1em; -moz-border-radius: 11px;
 -webkit-border-radius:11px}
 body { font-family: sans-serif; margin: 1em }
-.foo { border-style: inherit }
 /* comment between two style rules */
 h1 { background-color: silver }
 h2 { background-color: lightgrey }
-h1, h2 { margin: 0px; padding: 4px }}</style>
+h1, h2 { margin: 0px; padding: 4px }}
+.foo { p\^roperty: value; bor\0000C4de: inherit }</style>
   <script type="application/x-javascript"  src="cssParser.js"></script>
   <script type="application/x-javascript">
     function onLoad() {