interpolate(text,
filepath=None,
lineno=-1,
offset=0,
lookup=' strict ' )
|
|
Parse the given string and extract expressions.
This function is a generator that yields TEXT events for literal strings,
and EXPR events for expressions, depending on the results of parsing the
string.
>>> for kind, data, pos in interpolate("hey ${foo}bar"):
... print('%s %r' % (kind, data))
TEXT 'hey '
EXPR Expression('foo')
TEXT 'bar'
- Parameters:
text - the text to parse
filepath - absolute path to the file in which the text was found
(optional)
lineno - the line number at which the text was found (optional)
offset - the column number at which the text starts in the source
(optional)
lookup - the variable lookup mechanism; either "lenient" (the
default), "strict", or a custom lookup class
- Returns:
- a list of TEXT and EXPR events
- Raises:
|