예제 #1
0
def assignUsing(s):
    def assignPA(tokens):
        if s in tokens:
            tokens[tokens[s]] = tokens[0]
            del tokens[s]

    return assignPA


GROUP = (
    MARK
    + Group(
        ZeroOrMore(
            (item + Optional(ATTRIBUTE)("attr")).setParseAction(assignUsing("attr"))
        )
    )
    + (WORD("name") | UNMARK)
).setParseAction(assignUsing("name"))
item <<= FLOAT | NUMBER | STRING | BLOB | GROUP

item.runTests(
    """\
    [ '10:1234567890' @name 25 @age +0.45 @percentage person:zed
    [ [ "hello" 1 child root
    [ "child" [ 200 '4:like' "I" "hello" things root
    [ [ "data" [ 2 1 ] @numbers child root
    [ [ 1 2 3 ] @test 4 5 6 root
    """
)
예제 #2
0
    a:b\c
    a:b\-c*
    a:b\+c*
    [ a\- TO a\+ ]
    [a\ TO a*]
    a\\\+b
    a\+b
    c:\temp\~foo.txt
    XY\
    a\u0062c
    a:b\c~2.0
    XY\u005a
    XY\u005A
    item:\ item:ABCD\
    \
    a\ or b    
    a\:b\-c
    a\:b\+c
    a\:b\-c\*
    a\:b\+c\*
    a\:b\-c\~
    a\:b\+c\~
    a:b\c~
    [ a\ TO a* ]
    """

success1, _ = expression.runTests(tests)
success2, _ = expression.runTests(failtests, failureTests=True)

print(("FAIL", "OK")[success1 and success2])
예제 #3
0
    a:b\c
    a:b\-c*
    a:b\+c*
    [ a\- TO a\+ ]
    [a\ TO a*]
    a\\\+b
    a\+b
    c:\temp\~foo.txt
    XY\
    a\u0062c
    a:b\c~2.0
    XY\u005a
    XY\u005A
    item:\ item:ABCD\
    \
    a\ or b    
    a\:b\-c
    a\:b\+c
    a\:b\-c\*
    a\:b\+c\*
    a\:b\-c\~
    a\:b\+c\~
    a:b\c~
    [ a\ TO a* ]
    """

success1, _ = expression.runTests(tests)
success2, _ = expression.runTests(failtests, failureTests=True)
    
print(("FAIL", "OK")[success1 and success2])