From 939f47dfdef56b21042aa986e5143918703551f4 Mon Sep 17 00:00:00 2001 From: portnov Date: Sat, 21 Jun 2008 16:45:35 +0600 Subject: [PATCH] More universal read(). --- texts.bnf | 1 + unibnfgen.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/texts.bnf b/texts.bnf index 6428b40..226765d 100644 --- a/texts.bnf +++ b/texts.bnf @@ -1,3 +1,4 @@ +Text = Period | Period " " Text; Period = Statement | Question; Question = GeneralQuestion | Doesnt | SpecialQuestion ; SpecialQuestion = QWord Helper Subject Predicate Adjective "?"; diff --git a/unibnfgen.py b/unibnfgen.py index 54a5587..58fb460 100755 --- a/unibnfgen.py +++ b/unibnfgen.py @@ -56,13 +56,18 @@ def interpret(s): s = s.replace(r'\n','\n') return s -def read(): +def read_one(): s = raw_input() + s = re.sub('#.*','',s) s = s.strip() if not s: - return s + return read_one() + return s + +def read(): + s = read_one() while s[-1] != ';': - s += raw_input() + s += read_one() return s yacc.yacc() @@ -78,7 +83,6 @@ while True: s = read() except EOFError: break - s = re.sub('#.*','',s) if s == '' : continue value = yacc.parse(s) # print ">> Parsed: ",value -- 1.7.2.3