Show More
@@ -116,6 +116,7 b' elements = {' | |||||
116 | "!": (10, ("not", 10)), |
|
116 | "!": (10, ("not", 10)), | |
117 | "and": (5, None, ("and", 5)), |
|
117 | "and": (5, None, ("and", 5)), | |
118 | "&": (5, None, ("and", 5)), |
|
118 | "&": (5, None, ("and", 5)), | |
|
119 | "%": (5, None, ("only", 5), ("onlypost", 5)), | |||
119 | "or": (4, None, ("or", 4)), |
|
120 | "or": (4, None, ("or", 4)), | |
120 | "|": (4, None, ("or", 4)), |
|
121 | "|": (4, None, ("or", 4)), | |
121 | "+": (4, None, ("or", 4)), |
|
122 | "+": (4, None, ("or", 4)), | |
@@ -152,7 +153,7 b' def tokenize(program, lookup=None):' | |||||
152 | elif c == '#' and program[pos:pos + 2] == '##': # look ahead carefully |
|
153 | elif c == '#' and program[pos:pos + 2] == '##': # look ahead carefully | |
153 | yield ('##', None, pos) |
|
154 | yield ('##', None, pos) | |
154 | pos += 1 # skip ahead |
|
155 | pos += 1 # skip ahead | |
155 | elif c in "():,-|&+!~^": # handle simple operators |
|
156 | elif c in "():,-|&+!~^%": # handle simple operators | |
156 | yield (c, None, pos) |
|
157 | yield (c, None, pos) | |
157 | elif (c in '"\'' or c == 'r' and |
|
158 | elif (c in '"\'' or c == 'r' and | |
158 | program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings |
|
159 | program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings | |
@@ -1922,6 +1923,8 b' methods = {' | |||||
1922 | "ancestor": ancestorspec, |
|
1923 | "ancestor": ancestorspec, | |
1923 | "parent": parentspec, |
|
1924 | "parent": parentspec, | |
1924 | "parentpost": p1, |
|
1925 | "parentpost": p1, | |
|
1926 | "only": only, | |||
|
1927 | "onlypost": only, | |||
1925 | } |
|
1928 | } | |
1926 |
|
1929 | |||
1927 | def optimize(x, small): |
|
1930 | def optimize(x, small): | |
@@ -1935,6 +1938,9 b' def optimize(x, small):' | |||||
1935 | op = x[0] |
|
1938 | op = x[0] | |
1936 | if op == 'minus': |
|
1939 | if op == 'minus': | |
1937 | return optimize(('and', x[1], ('not', x[2])), small) |
|
1940 | return optimize(('and', x[1], ('not', x[2])), small) | |
|
1941 | elif op == 'only': | |||
|
1942 | return optimize(('func', ('symbol', 'only'), | |||
|
1943 | ('list', x[1], x[2])), small) | |||
1938 | elif op == 'dagrangepre': |
|
1944 | elif op == 'dagrangepre': | |
1939 | return optimize(('func', ('symbol', 'ancestors'), x[1]), small) |
|
1945 | return optimize(('func', ('symbol', 'ancestors'), x[1]), small) | |
1940 | elif op == 'dagrangepost': |
|
1946 | elif op == 'dagrangepost': |
@@ -438,6 +438,32 b' Test empty set input' | |||||
438 | 8 |
|
438 | 8 | |
439 | 9 |
|
439 | 9 | |
440 |
|
440 | |||
|
441 | Test '%' operator | |||
|
442 | ||||
|
443 | $ log '9%' | |||
|
444 | 8 | |||
|
445 | 9 | |||
|
446 | $ log '9%5' | |||
|
447 | 2 | |||
|
448 | 4 | |||
|
449 | 8 | |||
|
450 | 9 | |||
|
451 | $ log '(7 + 9)%(5 + 2)' | |||
|
452 | 4 | |||
|
453 | 6 | |||
|
454 | 7 | |||
|
455 | 8 | |||
|
456 | 9 | |||
|
457 | ||||
|
458 | Test the order of operations | |||
|
459 | ||||
|
460 | $ log '7 + 9%5 + 2' | |||
|
461 | 7 | |||
|
462 | 2 | |||
|
463 | 4 | |||
|
464 | 8 | |||
|
465 | 9 | |||
|
466 | ||||
441 | Test explicit numeric revision |
|
467 | Test explicit numeric revision | |
442 | $ log 'rev(-1)' |
|
468 | $ log 'rev(-1)' | |
443 | $ log 'rev(0)' |
|
469 | $ log 'rev(0)' |
General Comments 0
You need to be logged in to leave comments.
Login now