Procházet zdrojové kódy

Parser now recognizes properties at the end of a block without semicolon

Taddeus Kroes před 13 roky
rodič
revize
47a2e5f567
1 změnil soubory, kde provedl 15 přidání a 9 odebrání
  1. 15 9
      parse.py

+ 15 - 9
parse.py

@@ -21,6 +21,16 @@ def parse_groups(css):
     selectors = None
     comment = False
 
+    def parse_property():
+        assert selectors is not None
+
+        if stack.strip():
+            parts = stack.split(':', 1)
+            assert len(parts) == 2
+            name, value = map(str.strip, parts)
+            assert '\n' not in name
+            properties.append((name, value))
+
     try:
         for c in css:
             char = c
@@ -41,6 +51,9 @@ def parse_groups(css):
                 stack = ''
                 assert len(selectors)
             elif c == '}':
+                # Last property may not have been closed with a semicolon
+                parse_property()
+
                 if selectors is None:
                     # Closing group
                     current_group = root_group
@@ -51,15 +64,8 @@ def parse_groups(css):
                     properties = []
             elif c == ';':
                 # Property definition
-                assert selectors is not None
-
-                if stack.strip():
-                    parts = stack.split(':', 1)
-                    assert len(parts) == 2
-                    name, value = map(str.strip, parts)
-                    assert '\n' not in name
-                    properties.append((name, value))
-                    stack = ''
+                parse_property()
+                stack = ''
             elif c == '*' and prev_char == '/':
                 # Comment start
                 comment = True