Text parser.
Project description
About
A text parser written in the Python language.
The parser is pretty fast, but not as user friendly as PyParsing and Lark.
Project homepage: https://github.com/eerimoq/textparser
Documentation: http://textparser.readthedocs.org/en/latest
Credits
Thanks PyParsing for a user friendly interface. Many of textparser’s class names are taken from this project.
Installation
pip install textparser
Example usage
The Hello World example parses the string Hello, World! and outputs its parse tree ['Hello', ',', 'World', '!'].
The script:
from pprint import pprint
import textparser
from textparser import Sequence
class Parser(textparser.Parser):
def token_specs(self):
return [
('SKIP', r'[ \r\n\t]+'),
('WORD', r'\w+'),
('EMARK', '!', r'!'),
('COMMA', ',', r','),
('MISMATCH', r'.')
]
def grammar(self):
return Sequence('WORD', ',', 'WORD', '!')
tree = Parser().parse('Hello, World!')
token_tree = Parser().parse('Hello, World!', token_tree=True)
print('Tree:', tree)
print()
print('Token tree:')
pprint(token_tree)
Script execution:
$ env PYTHONPATH=. python3 examples/hello_world.py
Tree: ['Hello', ',', 'World', '!']
Token tree:
[Token(kind='WORD', value='Hello', offset=0),
Token(kind=',', value=',', offset=5),
Token(kind='WORD', value='World', offset=7),
Token(kind='!', value='!', offset=12)]
Contributing
Fork the repository.
Install prerequisites.
pip install -r requirements.txt
Implement the new feature or bug fix.
Implement test case(s) to ensure that future changes do not break legacy.
Run the tests.
make test
Create a pull request.
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
Built Distribution
Hashes for textparser-0.13.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82de72245d585afaf0155955ca8b8668dacf20d98451b7ce2f44583c076d74e8 |
|
MD5 | 14f2c10dc40ad23eba32f30efdfb327a |
|
BLAKE2b-256 | b4e7460990e8a7b20aa77abaa543ed0224828e21abe4008b2f13d7db4d126721 |