aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2023-07-01 13:55:17 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2023-07-01 13:55:17 +0200
commit666086944880f4b04fece7e4f7e53d4a3317251c (patch)
treed33fc5c40fe0d0ef63004758abf9ff1ffc57d5ee
parentAdd rule to update ctags file. (diff)
downloadmuppet-strings-666086944880f4b04fece7e4f7e53d4a3317251c.tar.gz
muppet-strings-666086944880f4b04fece7e4f7e53d4a3317251c.tar.xz
Tag all operators as operators.
-rw-r--r--muppet/format.py61
1 files changed, 33 insertions, 28 deletions
diff --git a/muppet/format.py b/muppet/format.py
index 870dfd3..8c52eb4 100644
--- a/muppet/format.py
+++ b/muppet/format.py
@@ -58,6 +58,11 @@ def keyword(x: str) -> Tag:
return tag(x, 'keyword', x)
+def operator(op: str) -> Tag:
+ """Tag string as an operator."""
+ return tag(op, 'operator')
+
+
def print_hash(hash: list[HashEntry],
indent: int,
context: Context) -> Tag:
@@ -271,7 +276,7 @@ def parse(form: Any, indent: int, context: list[str]) -> Tag:
decls += [declare_var(name)]
if 'value' in data:
decls += [
- ' ', '=', ' ',
+ ' ', operator('='), ' ',
# TODO this is a declaration
parse(data.get('value'), indent+1, context),
]
@@ -711,7 +716,7 @@ def parse(form: Any, indent: int, context: list[str]) -> Tag:
ind(indent+1),
tag(key, 'parameter'),
' '*pad,
- ' ', '=>', ' ',
+ ' ', operator('=>'), ' ',
parse(value, indent+3, context),
',', '\n',
]
@@ -722,7 +727,7 @@ def parse(form: Any, indent: int, context: list[str]) -> Tag:
ind(indent+1),
tag('*', 'parameter', 'splat'),
' '*pad,
- ' ', '=>', ' ',
+ ' ', operator('=>'), ' ',
parse(value, indent+2, context),
',', '\n',
]
@@ -751,7 +756,7 @@ def parse(form: Any, indent: int, context: list[str]) -> Tag:
ind(indent+1),
tag(key, 'parameter'),
' '*pad,
- ' ', '=>', ' ',
+ ' ', operator('=>'), ' ',
parse(value, indent+3, context),
',', '\n',
]
@@ -762,7 +767,7 @@ def parse(form: Any, indent: int, context: list[str]) -> Tag:
ind(indent+1),
tag(key, 'parameter'),
' '*pad,
- ' ', '+>', ' ',
+ ' ', operator('+>'), ' ',
parse(value, indent+2, context),
',', '\n',
]
@@ -773,7 +778,7 @@ def parse(form: Any, indent: int, context: list[str]) -> Tag:
ind(indent+1),
tag('*', 'parameter', 'splat'),
' '*pad,
- ' ', '=>', ' ',
+ ' ', operator('=>'), ' ',
parse(value, indent+2, context),
',', '\n',
]
@@ -830,90 +835,90 @@ def parse(form: Any, indent: int, context: list[str]) -> Tag:
case ['!', x]:
return tag([
- '!', ' ',
+ operator('!'), ' ',
parse(x, indent, context),
])
case ['!=', a, b]:
return tag([
parse(a, indent, context),
- ' ', '!=', ' ',
+ ' ', operator('!='), ' ',
parse(b, indent, context),
])
case ['+', a, b]:
return tag([
parse(a, indent, context),
- ' ', '+', ' ',
+ ' ', operator('+'), ' ',
parse(b, indent, context),
])
case ['-', a, b]:
return tag([
parse(a, indent, context),
- ' ', '-', ' ',
+ ' ', operator('-'), ' ',
parse(b, indent, context),
])
case ['-', a]:
return tag([
- '-', ' ',
+ operator('-'), ' ',
parse(a, indent, context),
])
case ['*', a, b]:
return tag([
parse(a, indent, context),
- ' ', '*', ' ',
+ ' ', operator('*'), ' ',
parse(b, indent, context),
])
case ['%', a, b]:
return tag([
parse(a, indent, context),
- ' ', '%', ' ',
+ ' ', operator('%'), ' ',
parse(b, indent, context),
])
case ['<<', a, b]:
return tag([
parse(a, indent, context),
- ' ', '<<', ' ',
+ ' ', operator('<<'), ' ',
parse(b, indent, context),
])
case ['>>', a, b]:
return tag([
parse(a, indent, context),
- ' ', '>>', ' ',
+ ' ', operator('>>'), ' ',
parse(b, indent, context),
])
case ['>=', a, b]:
return tag([
parse(a, indent, context),
- ' ', '>=', ' ',
+ ' ', operator('>='), ' ',
parse(b, indent, context),
])
case ['<=', a, b]:
return tag([
parse(a, indent, context),
- ' ', '<=', ' ',
+ ' ', operator('<='), ' ',
parse(b, indent, context),
])
case ['>', a, b]:
return tag([
parse(a, indent, context),
- ' ', '>', ' ',
+ ' ', operator('>'), ' ',
parse(b, indent, context),
])
case ['<', a, b]:
return tag([
parse(a, indent, context),
- ' ', '<', ' ',
+ ' ', operator('<'), ' ',
parse(b, indent, context),
])
@@ -922,7 +927,7 @@ def parse(form: Any, indent: int, context: list[str]) -> Tag:
parse(left, indent, context),
'\n',
ind(indent),
- '~>', ' ',
+ operator('~>'), ' ',
parse(right, indent, context)
])
@@ -931,7 +936,7 @@ def parse(form: Any, indent: int, context: list[str]) -> Tag:
parse(left, indent, context),
'\n',
ind(indent),
- '->', ' ',
+ operator('->'), ' ',
parse(right, indent, context),
])
@@ -940,49 +945,49 @@ def parse(form: Any, indent: int, context: list[str]) -> Tag:
parse(left, indent, context),
'\n',
ind(indent),
- '.',
+ operator('.'),
parse(right, indent+1, context),
])
case ['/', a, b]:
return tag([
parse(a, indent, context),
- ' ', '/', ' ',
+ ' ', operator('/'), ' ',
parse(b, indent, context),
])
case ['=', field, value]:
return tag([
parse(field, indent, ['declaration'] + context),
- ' ', '=', ' ',
+ ' ', operator('='), ' ',
parse(value, indent, context),
], 'declaration')
case ['==', a, b]:
return tag([
parse(a, indent, context),
- ' ', '==', ' ',
+ ' ', operator('=='), ' ',
parse(b, indent, context),
])
case ['=~', a, b]:
return tag([
parse(a, indent, context),
- ' ', '=~', ' ',
+ ' ', operator('=~'), ' ',
parse(b, indent, context),
])
case ['!~', a, b]:
return tag([
parse(a, indent, context),
- ' ', '!~', ' ',
+ ' ', operator('!~'), ' ',
parse(b, indent, context),
])
case ['?', condition, cases]:
return tag([
parse(condition, indent, context),
- ' ', '?', ' ', '{', '\n',
+ ' ', operator('?'), ' ', '{', '\n',
print_hash(cases, indent+1, context),
ind(indent),
'}',