From: <ka...@us...> - 2009-07-30 05:36:45
|
Revision: 2297 http://paintown.svn.sourceforge.net/paintown/?rev=2297&view=rev Author: kazzmir Date: 2009-07-30 05:36:39 +0000 (Thu, 30 Jul 2009) Log Message: ----------- add ensure pattern Modified Paths: -------------- trunk/src/mugen/parser/peg.py Modified: trunk/src/mugen/parser/peg.py =================================================================== --- trunk/src/mugen/parser/peg.py 2009-07-30 02:17:05 UTC (rev 2296) +++ trunk/src/mugen/parser/peg.py 2009-07-30 05:36:39 UTC (rev 2297) @@ -320,6 +320,33 @@ else: return str +class PatternEnsure(Pattern): + def __init__(self, next): + Pattern.__init__(self) + self.next = next + + def ensureRules(self, find): + self.next.ensureRules(find) + + def generate_bnf(self): + return "&" + self.next.generate_bnf() + + def generate_python(self, result, stream, failure): + my_result = newResult() + data = """ +%s = Result(%s.getPosition()) +%s +""" % (my_result, result, self.next.generate_python(my_result, stream, failure).strip()) + return data + + def generate_cpp(self, peg, result, stream, failure): + my_result = newResult() + data = """ +Result %s(%s.getPosition()); +%s +""" % (my_result, result, self.next.generate_cpp(peg, my_result, stream, failure).strip()) + return data + class PatternNot(Pattern): def __init__(self, next): Pattern.__init__(self) @@ -345,7 +372,6 @@ return data - def generate_cpp(self, peg, result, stream, failure): not_label = "not_%s" % nextVar() my_result = newResult() @@ -1208,6 +1234,7 @@ ]), Rule("item", [ PatternAction(PatternSequence([ + PatternBind("ensure", PatternMaybe(PatternVerbatim("&"))), PatternBind("pnot", PatternMaybe(PatternVerbatim("!"))), PatternBind("pattern", PatternOr([ @@ -1221,6 +1248,8 @@ pattern = modifier(pattern) if pnot != None: pattern = peg.PatternNot(pattern) +if ensure != None: + pattern = peg.PatternEnsure(pattern) value = pattern """), ]), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |