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

Fixed line number counter in parser for comments

parent 90e4a60f
No related branches found
No related tags found
No related merge requests found
...@@ -35,11 +35,14 @@ def parse_groups(css): ...@@ -35,11 +35,14 @@ def parse_groups(css):
for c in css: for c in css:
char = c char = c
if char == '\n':
lineno += 1
if comment: if comment:
# Comment end? # Comment end?
if c == '/' and prev_char == '*': if char == '/' and prev_char == '*':
comment = False comment = False
elif c == '{': elif char == '{':
# Block start # Block start
if selectors is not None: if selectors is not None:
# Block is nested, save group selector # Block is nested, save group selector
...@@ -50,7 +53,7 @@ def parse_groups(css): ...@@ -50,7 +53,7 @@ def parse_groups(css):
#print stack.strip(), '->', selectors #print stack.strip(), '->', selectors
stack = '' stack = ''
assert len(selectors) assert len(selectors)
elif c == '}': elif char == '}':
# Last property may not have been closed with a semicolon # Last property may not have been closed with a semicolon
parse_property() parse_property()
...@@ -62,21 +65,18 @@ def parse_groups(css): ...@@ -62,21 +65,18 @@ def parse_groups(css):
current_group.append((selectors, properties)) current_group.append((selectors, properties))
selectors = None selectors = None
properties = [] properties = []
elif c == ';': elif char == ';':
# Property definition # Property definition
parse_property() parse_property()
stack = '' stack = ''
elif c == '*' and prev_char == '/': elif char == '*' and prev_char == '/':
# Comment start # Comment start
comment = True comment = True
stack = stack[:-1] stack = stack[:-1]
else: else:
if c == '\n': stack += char
lineno += 1
stack += c
prev_char = c prev_char = char
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