forgot about "?"

This commit is contained in:
zgrep 2018-07-11 23:34:39 -04:00
parent f152c25877
commit c24ab434fc
1 changed files with 5 additions and 1 deletions

6
xed.py
View File

@ -13,7 +13,7 @@ parser = Lark(r'''
| bracketliteral "-" bracketliteral
brackets : "[" range+ "]" -> either
char : /[^\\\[\]\{\}\(\)\|\^~]/
char : /[^\\\[\]\{\}\(\)\|\^~\?]/
| "\\" /\D/
| //
@ -23,6 +23,7 @@ parser = Lark(r'''
?unit : parens | brackets | char
?concat_func : unit
| concat_func "{" DIGITS "}" -> concat_repeat
| concat_func "?" -> zero_or_one
| concat_func "~" -> reverse
| concat_func "~" NUMBER -> roll
| concat_func "~{" NUMBER ["," DIGITS] "}" -> roll
@ -67,6 +68,9 @@ class Expand(Transformer):
result.append(chr(a))
return result
def zero_or_one(self, args):
return self.either([[''], args[0]])
def either(self, args):
result = []
for x in args: