Beispiel #1
0
def numbersTransform():
    print ("\n=== sample0: numbersTransform ===")
    numbersTransformGrammar = """\
numbersTransform
<toolset>
def toReal(node):
    node.value = float(node.value)
<definition>
SEP         : ' '                       : drop
DOT         : '.'
digit       : [0..9]
integer     : digit+                    : join
real        : integer DOT integer?      : join
number      : real / integer            : toReal
addedNum    : SEP number                : liftNode
numbers     : number (addedNum)*        : extract
"""
    makeParser(numbersTransformGrammar)
    from numbersTransformParser import numbersTransformParser
    numbersTransformParser.test("123 4. 5.67")
def numbersTransform():
    print("\n=== sample0: numbersTransform ===")
    numbersTransformGrammar = """\
numbersTransform
<toolset>
def toReal(node):
    node.value = float(node.value)
<definition>
SEP         : ' '                       : drop
DOT         : '.'
digit       : [0..9]
integer     : digit+                    : join
real        : integer DOT integer?      : join
number      : real / integer            : toReal
addedNum    : SEP number                : liftNode
numbers     : number (addedNum)*        : extract
"""
    makeParser(numbersTransformGrammar)
    from numbersTransformParser import numbersTransformParser
    numbersTransformParser.test("123 4. 5.67")