Undebt: Using pyparsing¶
While Undebt’s parsing utilities are very helpful and provide much of the necessary functionality for writing a grammar
, all of the objects are pyparsing objects, and thus it is often necessary and/or useful to use pyparsing
utilities.
While the official pyparsing documentation is a great resource, most of the more advanced utilities there will usually not be necessary. This documentation is an overview of those that are most likely to be useful.
Operators¶
+ (And)
Adding two grammar elements produces a new grammar element that matches the first one, then the second one, with optional intervening whitespace.
| (Or)
Oring two grammar elements produces a new grammar element that attempts to match the first one, then if that fails, attempts to match the second one.
~ (Negative Lookahead)
Inverting a grammar element produces a new grammar element that produces no tokens and matches only if the inverted grammar doesn’t match. Using a negative lookahead also doesn’t advance the current parsing position.
^ (Match Longest)
Similar to |
, but matches the longest of the grammar elements that match, instead of the first grammar element that matches.
Functions¶
Literal(str)
Creates a grammar element that matches str
exactly.
Keyword(str)
Creates a grammar element that matches str
only if it is surrounded by non-letters.
Optional(...)
Creates a grammar element that matches zero or one of the contained grammar element.
ZeroOrMore(...)
Creates a grammar element that matches zero or more of the contained grammar element.
OneOrMore(...)
Creates a grammar element that matches one or more of the contained grammar element.
originalTextFor(...)
Modifies a grammar element to produce only a single token that is the original text that was matched by that grammar element.
Word(charset)
Creates a grammar element that matches a word made of characters in charset
.
SkipTo(...)
Skips parsing position to the next match for the contained objects.
Combine(...)
Forces any grammar elements added together inside of Combine
to not match intervening whitespace and produce only a single token.
Regex(str)
Creates a grammar element that matches str
as a regular expression.