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:

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!')

print('Tree:', tree)

Script execution:

$ python3 examples/hello_world.py
Tree: ['Hello', ',', 'World', '!']
$

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.11.0.tar.gz (7.7 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.11.0-py2.py3-none-any.whl (6.4 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: textparser-0.11.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for textparser-0.11.0.tar.gz
Algorithm Hash digest
SHA256 9e69d6fa52881ab4808599cf268e140523a1e0ccae3da19018fe5df8cd13cd7d
MD5 e1f6bc32499e56cbd60cf972a83b5de7
BLAKE2b-256 8e289748a6e667a8924828e3f3ad75e03021a102c87950fe29e00725969bc233

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for textparser-0.11.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cdb34552bdb0611a3d772a2d96c5b25ceb204be404dc744b81ada2e75e89bd0e
MD5 9a2717b3abe6cfeb91f13f0f5158ca5d
BLAKE2b-256 962cd1a0d08481f217501e415d3102a903248cb7eeb5d4284471dcc603617413

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