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"
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 print "STACK=", stack assert i.eof() symbols = {} def do_eval(stack): global symbols op = stack.pop() print "~_~_:", op, stack if op == '+': arg2 = do_eval(stack) arg1 = do_eval(stack) print arg1, '+', arg2
#!/usr/bin/python from nehebkau.stringiter import stringiter from nehebkau.parser import attr_t def moveit(i): i.inc() def dontmoveit(i): c = i.clone() i.inc() i <<= c s = '0123456789' it = stringiter(s) it2 = stringiter(s) moveit(it) assert it != it2 it = stringiter(s) it2 = stringiter(s) dontmoveit(it) assert it == it2 it.inc() assert it == it2 + 1