Skip to main content

Text parser.

Project description

buildstatus coverage

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

  1. Fork the repository.

  2. Install prerequisites.

    pip install -r requirements.txt
  3. Implement the new feature or bug fix.

  4. Implement test case(s) to ensure that future changes do not break legacy.

  5. Run the tests.

    make test
  6. Create a pull request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

textparser-0.14.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

textparser-0.14.0-py2.py3-none-any.whl (8.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file textparser-0.14.0.tar.gz.

File metadata

  • Download URL: textparser-0.14.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.8.1 pkginfo/1.3.2 requests/2.18.3 setuptools/38.5.0 requests-toolbelt/0.7.0 clint/0.5.1 CPython/2.7.14 Linux/4.13.0-46-generic

File hashes

Hashes for textparser-0.14.0.tar.gz
Algorithm Hash digest
SHA256 152cdd7aa40f5a699e2ab86fdeacfa0cbeb6dbf47e8d903f03995b7c7b65d807
MD5 7e0778b5aa7b37944951071a33cedeea
BLAKE2b-256 3c884efc2f3407979de0803ca46c2cf3aeaee7b019447f126e819eca83cc81ee

See more details on using hashes here.

File details

Details for the file textparser-0.14.0-py2.py3-none-any.whl.

File metadata

  • Download URL: textparser-0.14.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.8.1 pkginfo/1.3.2 requests/2.18.3 setuptools/38.5.0 requests-toolbelt/0.7.0 clint/0.5.1 CPython/2.7.14 Linux/4.13.0-46-generic

File hashes

Hashes for textparser-0.14.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 29ea556cbb0228c3ad5e39da34786f255d499787d6281b8e562bfbc642c7ed8a
MD5 bc3021a89ac67a0113cc3ac7e5a19983
BLAKE2b-256 a13c2232de686c0cf00c2b3cad7be3a163ff376756831a2953556a5b820f8a52

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page