Do the python shuffle!

[insert dance noises here]
This commit is contained in:
zgrep 2023-12-30 23:09:02 -05:00
parent 4021a8e20e
commit fd628c8d17
1 changed files with 9 additions and 3 deletions

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python3
from lark import Lark, Transformer, ParseError, Tree
from random import shuffle
parser = Lark(r'''
DIGIT : /[0-9]/
@ -12,9 +13,9 @@ parser = Lark(r'''
| bracketliteral "-" bracketliteral
brackets : "[" range+ "]" -> either
char : /[^\\\[\]\{\}\(\)\|\^~\?!]/
?achar : /[^\\\[\]\{\}\(\)\|\^~\?!¿]/
| "\\" /\D/
| //
char : achar?
numrange : DIGITS
| DIGITS "-" DIGITS [ "*" DIGITS ] [ "+" DIGITS ]
@ -23,6 +24,7 @@ parser = Lark(r'''
?concat_func : unit
| concat_func "{" DIGITS "}" -> concat_repeat
| concat_func "?" -> zero_or_one
| concat_func "¿" -> random
| concat_func "~" -> reverse
| concat_func "~" NUMBER -> roll
| concat_func "~{" NUMBER ["," DIGITS] "}" -> roll
@ -44,7 +46,7 @@ parser = Lark(r'''
| choice ("|" choice_func)+ -> either
?parens : "(" choice ")"
''', start='choice', ambiguity='resolve__antiscore_sum')
''', start='choice', priority='invert')
class Expand(Transformer):
def __init__(self, amp=None):
@ -74,6 +76,10 @@ class Expand(Transformer):
def zero_or_one(self, args):
return self.either([[''], args[0]])
def random(self, args):
shuffle(args[0])
return args[0]
def either(self, args):
result = []
for x in args: