Skip to content

Commit

Permalink
refactor: simplify css variable table creation
Browse files Browse the repository at this point in the history
  • Loading branch information
zormit committed Jul 22, 2023
1 parent 2ab6ca3 commit 7770f8d
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/textual/css/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ def substitute_references(
break
if token.name == "variable_name":
variable_name = token.value[1:-1] # Trim the $ and the :, i.e. "$x:" -> "x"
variable_tokens = variables.setdefault(variable_name, [])
yield token

while True:
Expand All @@ -284,18 +285,15 @@ def substitute_references(
if not token:
break
elif token.name == "whitespace":
variables.setdefault(variable_name, []).append(token)
variable_tokens.append(token)
yield token
elif token.name == "variable_value_end":
# in case of an empty variable, avoid not referenced error
variables.setdefault(variable_name, [])
yield token
break
# For variables referring to other variables
elif token.name == "variable_ref":
ref_name = token.value[1:]
if ref_name in variables:
variable_tokens = variables.setdefault(variable_name, [])
reference_tokens = variables[ref_name]
variable_tokens.extend(reference_tokens)
ref_location = token.location
Expand All @@ -309,7 +307,7 @@ def substitute_references(
else:
_unresolved(ref_name, variables.keys(), token)
else:
variables.setdefault(variable_name, []).append(token)
variable_tokens.append(token)
yield token
token = next(iter_tokens, None)
elif token.name == "variable_ref":
Expand Down

0 comments on commit 7770f8d

Please sign in to comment.