A SLY lexer and parser for Liquid filtered expressions.
Filtered expressions are those found in Liquid output statements, echo
tags and assign
tags.
The result of FilteredExpressionParser().parse()
is an AST built from existing Python Liquid Expression
objects, rooted at a FilteredExpression
.
This is intended to be an example of how one might use SLY to parse an expression for a custom tag in Python Liquid. The tags built-in to Python Liquid do not use SLY (or PLY or any other general purpose parsing package), instead we chose to write our own lexers and recursive descent parsers, one for each of the common Liquid expression types. This decision was made on performance grounds. Benchmarks show Python Liquid's parser to be roughly three times faster for filtered expressions than this SLY implementation.
The following grammar defines the "standard" Liquid filtered expression,