Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/erinxocon/tpfd
Text Parsing Function Dispatcher - tpfd
https://github.com/erinxocon/tpfd
Last synced: 15 days ago
JSON representation
Text Parsing Function Dispatcher - tpfd
- Host: GitHub
- URL: https://github.com/erinxocon/tpfd
- Owner: erinxocon
- License: mit
- Created: 2016-02-04T13:07:12.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2021-04-20T17:06:03.000Z (over 3 years ago)
- Last Synced: 2024-09-22T01:39:00.275Z (about 2 months ago)
- Language: Python
- Homepage:
- Size: 58.6 KB
- Stars: 104
- Watchers: 4
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
TPFD - Text Parsing Function Dispatcher
=======================================
.. image:: https://travis-ci.org/erinxocon/tpfd.svg?branch=master
:target: https://travis-ci.org/erinxocon/tpfd
.. image:: https://img.shields.io/pypi/v/tpfd.svg?maxAge=2592000
:target: https://pypi.python.org/pypi/tpfd/
.. image:: https://img.shields.io/pypi/l/tpfd.svg?maxAge=2592000
:target: https://opensource.org/licenses/MIT**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!
Examples
--------
.. code-block:: pythonAniamls.txt
Turtles are cool
Sloths are cool
Mosquitos are dumb>>> p = tpfd.Parser()
>>> @p.on_parse('{Animal} are cool')
def main(animal):
print('I like {0}.'.format(animal))
>>> p.parse_file('animals.txt')
'I like turtles.'
'I like sloths.'>>> p.parse(['Turtles are cool', 'Sloths are cool', 'Mosquitos are dumb'])
'I like turtles.'
'I like sloths.'
>>> p.parse('Sloths are cool')
'I like sloths.'
>>> p.parse('Mosquitos are dumb')
None
>>> @p.on_find('>{}<')
def find_example(words):
print (words)
>>> p.find('the bold text
')
'the bold text'To Install
----------::
$ pip install tpfd
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 or ints
* Support for parsing unicode strings
* Supports parsing strings, ints and interator/generator's automagically with new ``parse`` method.TODO
----
* Expose custom types functionality that `Parse `_ already offers