From 93761df5ed6532365599c180147fa1f7fd4752ca Mon Sep 17 00:00:00 2001 From: kad Date: Wed, 10 Aug 2011 11:16:07 -0600 Subject: [PATCH] Allow spaces after ; for separated rolls --- modules/Dice.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/Dice.py b/modules/Dice.py index 1431faa..78d3f8e 100644 --- a/modules/Dice.py +++ b/modules/Dice.py @@ -31,14 +31,15 @@ class Dice(Module): """Roll simple or complex dice strings.""" - tokens = ['NUMBER', 'TEXT'] - literals = ['#', '/', '+', '-', 'd', ';'] + tokens = ['NUMBER', 'TEXT', 'ROLLSEP'] + literals = ['#', '/', '+', '-', 'd'] def build(self): lex.lex(module=self) yacc.yacc(module=self) t_TEXT = r'\s+[^;]+' + t_ROLLSEP = r';\s*' def t_NUMBER(self, t): r'\d+' @@ -49,7 +50,7 @@ class Dice(Module): t.lexer.skip(1) precedence = ( - ('left', ';'), + ('left', 'ROLLSEP'), ('left', '+', '-'), ('right', 'd'), ('left', '#'), @@ -141,7 +142,7 @@ class Dice(Module): # have a comment that describes the roll # Multiple roll strings can be chained with semicolon - 'roll : roll ";" roll' + 'roll : roll ROLLSEP roll' global output p[0] = p[1] + "; " + p[3] output = p[0]