Esempio n. 1
0
def test_parse(s, parser, matched_str, attrval):
    print '**********', s, '************'
    i = stringiter(s)
    c = i.clone()
    attr = attr_t()
    m = parser.parse(i, None, None, attr)
    if matched_str:
        assert m
        print "yeah hit"
        assert m == matched_str, "%s != %s" % (m, matched_str)
        print "match is correct"
        assert i == c + len(matched_str)
        print "iterator incremented correct amount"
        assert attr.value == attrval, 'got attr.value "%s" expected "%s"' % (attr.value, attrval)
    else:
        assert i == c
        print "verified iterator not changed"
Esempio n. 2
0


assignment <<= (tok_p('IDENTIFIER') >> tok_p('ASSIGN') >> expr)[pushval(0), pushop('s')]

float_p <<= (tok_p('PLUS') | tok_p('MINUS')).opt >> tok_p('FLOAT')

expr <<= term >> ((tok_p('PLUS') | tok_p('MINUS')) >> term).star[pushzero]

term <<= factor >> ((tok_p('TIMES') | tok_p('DIVIDE'))>> factor).star[pushzero]

factor <<= number | tok_p('IDENTIFIER')[push, pushop('l')] | (tok_p('LPAREN') >> expr >> tok_p('RPAREN'))

number <<= (tok_p('NUMBER') | float_p)[push]

attr = attr_t()

toks = tokenize('''baz = bar * 0 + 3
bar = 1 * 4 + foo
foo = 2 + 5
''')
#1
#2
#''')

print "TOKS:"
pprint(toks)
i = stringiter(toks)

print program.parse(i, None, None, attr)
print attr
Esempio n. 3
0
def parse(s, prsr):
    i = stringiter(s)
    attr = attr_t()
    m = prsr.parse(i, None, None, attr)
    print "afterwards attr is", attr.value
    return m