I need to parse expressions based on following rules:
- An expression can contain a filter object represented as
name:value
- An expression can contain a string expression
- An expression can contain Booleans OR,AND
- Everything inside can be quoted
So a typical expression looks like
filter1:45 hello world filter:5454
filter1:45 'hello world' filter:5454
hello world
'hello world' OR filter:43
Here's what I've tried so far:
class BooleanLiteral(Keyword):
grammar = Enum(K("OR"), K("AND"))
class LineFilter(Namespace):
grammar = flag('inverted', "-"), name(), ":", attr('value', word)
class LineExpression(List):
grammar = csl(LineFilter, separator=blank)
With this grammar, I can parse strings like
filter2:32 filter1:3243
From what I understood I can provide csl
function with a list of objects, and the grammar needs to be in that order. However what if I want to parse an object like
filter34:43 hello filter32:3232
OR
filter34:43 OR filter32:3232
How can I say that there are multiple types of objects (filters, expressions, booleans) in an expression? Is that possible with peg?