Decorate functions with text identifiers to create macros when parsing other text!
Project description
Aniamls.txt
Turtles are cool
Sloths are cool
Mosquitos are dumb
>>> p = tpfd.Parser()
>>> @p.on_recognize('{Animal} are cool')
def main(kwargs):
animal = kwargs.get('animal')
print('I like {0}.'.format(animal))
>>> p.parse_file('animals.txt')
'I like turtles.'
'I like sloths.'
>>> p.iter_parse(['Turtles are cool', 'Sloths are cool', 'Mosquitos are dumb'])
'I like turtles.'
'I like sloths.'
>>> p.parse_string('Sloths are cool')
'I like sloths.'
>>> p.parse_string('Mosquitos are dumb')
None
Tpfd is an easy way to parse strings and execute functions depending on their contents. Inspired by flask and using parse under the hood, this allows you to decorate functions with grammar rules and if a pattern that matches one of your grammar rules is found, the function will be run with a set of keyword arguments you’ve specified passed to it! Great for parsing logs and executing macros on what it finds!
Notes
Any format spec supported by parse is supported by this library since it’s all parse under the hood. Example: {[field name]:[format spec]}
Current Features
Support for parsing text files
Support for accepting generators that output text.
TODO
Support streams
various built in converters to translate numbers/day names/dates
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file tpfd-0.0.1.tar.gz
.
File metadata
- Download URL: tpfd-0.0.1.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5343bc70cb9aa21f7c2fbf2d2feda63cd4187abf4b418e708121ac4ce9417e51 |
|
MD5 | 0fe8cd57325ac303d1240196754086ba |
|
BLAKE2b-256 | 10d6d75ac6e5b553520d2ea17a894eb5c03dce7b171e7e8d5d89a230c2abb22f |