Skip to content
Snippets Groups Projects
Commit efb00ab5 authored by Taddeüs Kroes's avatar Taddeüs Kroes
Browse files

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
No related branches found
No related tags found
No related merge requests found
...@@ -19,20 +19,16 @@ def parse_groups(css): ...@@ -19,20 +19,16 @@ def parse_groups(css):
current_group = root_group = [] current_group = root_group = []
groups = [(None, root_group)] groups = [(None, root_group)]
selectors = None selectors = None
multiline_comment = inline_comment = False comment = False
try: try:
for c in css: for c in css:
char = c char = c
if multiline_comment: if comment:
# Multiline comment end? # Comment end?
if c == '/' and prev_char == '*': if c == '/' and prev_char == '*':
multiline_comment = False comment = False
elif inline_comment:
# Inline comment end?
if c == '\n':
inline_comment = False
elif c == '{': elif c == '{':
# Block start # Block start
if selectors is not None: if selectors is not None:
...@@ -56,22 +52,25 @@ def parse_groups(css): ...@@ -56,22 +52,25 @@ def parse_groups(css):
elif c == ';': elif c == ';':
# Property definition # Property definition
assert selectors is not None assert selectors is not None
name, value = map(str.strip, stack.split(':', 1))
assert '\n' not in name if stack.strip():
properties.append((name, value)) parts = stack.split(':', 1)
stack = '' 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 == '/': elif c == '*' and prev_char == '/':
# Multiline comment start # Comment start
multiline_comment = True comment = True
elif c == '/' and prev_char == '/': stack = stack[:-1]
# Inline comment start
inline_comment = True
else: else:
if c == '\n': if c == '\n':
lineno += 1 lineno += 1
stack += c stack += c
prev_char = c
prev_char = c
except AssertionError: except AssertionError:
raise Exception('unexpected \'%c\' on line %d' % (char, lineno)) raise Exception('unexpected \'%c\' on line %d' % (char, lineno))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment