Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A text parser.

License

NotificationsYou must be signed in to change notification settings

eerimoq/textparser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

A text parser written in the Python language.

The project has one goal, speed! See the benchmark below more details.

Project homepage:https://github.com/eerimoq/textparser

Documentation:http://textparser.readthedocs.org/en/latest

Credits

  • ThanksPyParsing for a user friendly interface. Many oftextparser's class names are taken from this project.

Installation

pipinstalltextparser

Example usage

TheHello World example parses the stringHello, World! andoutputs its parse tree['Hello', ',', 'World', '!'].

The script:

importtextparserfromtextparserimportSequenceclassParser(textparser.Parser):deftoken_specs(self):return [            ('SKIP',r'[ \r\n\t]+'),            ('WORD',r'\w+'),            ('EMARK','!',r'!'),            ('COMMA',',',r','),            ('MISMATCH',r'.')        ]defgrammar(self):returnSequence('WORD',',','WORD','!')tree=Parser().parse('Hello, World!')print('Tree:',tree)

Script execution:

$ env PYTHONPATH=. python3 examples/hello_world.pyTree: ['Hello', ',', 'World', '!']

Benchmark

Abenchmark comparing the speed of 10 JSON parsers, parsing a276kb file.

$ env PYTHONPATH=. python3 examples/benchmarks/json/speed.pyParsed 'examples/benchmarks/json/data.json' 1 time(s) in:PACKAGE         SECONDS   RATIO  VERSIONtextparser         0.10    100%  0.21.1parsimonious       0.17    169%  unknownlark (LALR)        0.27    267%  0.7.0funcparserlib      0.34    340%  unknowntextx              0.54    546%  1.8.0pyparsing          0.68    684%  2.4.0pyleri             0.88    886%  1.2.2parsy              0.92    925%  1.2.0parsita            2.28   2286%  unknownlark (Earley)      2.34   2348%  0.7.0

NOTE 1: The parsers are not necessarily optimized forspeed. Optimizing them will likely affect the measurements.

NOTE 2: The structure of the resulting parse trees varies andadditional processing may be required to make them fit the userapplication.

NOTE 3: Only JSON parsers are compared. Parsing other languages maygive vastly different results.

Contributing

  1. Fork the repository.

  2. Implement the new feature or bug fix.

  3. Implement test case(s) to ensure that future changes do not breaklegacy.

  4. Run the tests.

    python3 -m unittest
  5. Create a pull request.

Sponsor this project

 

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp