Commit efb00ab5 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Fixed some parser features:

- Inline comments are no longer supported.
- Multiline comment detection now actually works.
- Emtpy property definitions do not yield errors anymore.
parent 3c2f770e
......@@ -19,20 +19,16 @@ def parse_groups(css):
current_group = root_group = []
groups = [(None, root_group)]
selectors = None
multiline_comment = inline_comment = False
comment = False
try:
for c in css:
char = c
if multiline_comment:
# Multiline comment end?
if comment:
# Comment end?
if c == '/' and prev_char == '*':
multiline_comment = False
elif inline_comment:
# Inline comment end?
if c == '\n':
inline_comment = False
comment = False
elif c == '{':
# Block start
if selectors is not None:
......@@ -56,22 +52,25 @@ def parse_groups(css):
elif c == ';':
# Property definition
assert selectors is not None
name, value = map(str.strip, stack.split(':', 1))
assert '\n' not in name
properties.append((name, value))
stack = ''
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 = ''
elif c == '*' and prev_char == '/':
# Multiline comment start
multiline_comment = True
elif c == '/' and prev_char == '/':
# Inline comment start
inline_comment = True
# Comment start
comment = True
stack = stack[:-1]
else:
if c == '\n':
lineno += 1
stack += c
prev_char = c
prev_char = c
except AssertionError:
raise Exception('unexpected \'%c\' on line %d' % (char, lineno))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment