37 The parser has to be payload_specification specific because it needs to know
38 the types of the records to build a FieldSelection.
41 def make_selection(string, location, tokens):
42 variable, comparator, value = tokens
43 if payload_specification
and variable
not in payload_specification:
44 raise RuntimeError(
"%s is not a value in the folder payload "
46 elif not payload_specification:
47 return (variable, comparator, value)
48 typeid = payload_specification[variable].storageType().
id()
51 from PyCool
import cool
52 EQ = Literal(
"==").setParseAction(
lambda t: cool.FieldSelection.EQ)
53 NE = Literal(
"!=").setParseAction(
lambda t: cool.FieldSelection.NE)
54 GE = Literal(
">=").setParseAction(
lambda t: cool.FieldSelection.GE)
55 LE = Literal(
"<=").setParseAction(
lambda t: cool.FieldSelection.LE)
56 GT = Literal(
">") .setParseAction(
lambda t: cool.FieldSelection.GT)
57 LT = Literal(
"<") .setParseAction(
lambda t: cool.FieldSelection.LT)
58 comparator = EQ | NE | GE | LE | GT | LT
59 operand = (variable + comparator + value).setParseAction(make_selection)
61 orop = Literal(
"or").suppress()
62 andop = Literal(
"and").suppress()
64 def logic_builder(connective):
65 def thunk(string, location, tokens):
67 for token
in tokens[0]:
70 return cool.CompositeSelection(connective, vec)
73 expr = StringStart() + operatorPrecedence( operand,
74 [(andop, 2, opAssoc.LEFT, logic_builder(cool.CompositeSelection.AND)),
75 (orop, 2, opAssoc.LEFT, logic_builder(cool.CompositeSelection.OR)),]
79 return expr.parseString(selection)[0]