All Projects → drhagen → parsita

drhagen / parsita

Licence: MIT License
The easiest way to parse text in Python

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to parsita

jasentaa
A parser combinator library for Clojure and ClojureScript
Stars: ✭ 53 (-27.4%)
Mutual labels:  parser-combinators
FLexer
Simple Lexer and Parser in F#
Stars: ✭ 22 (-69.86%)
Mutual labels:  parser-combinators
leftry
Leftry - A left-recursion enabled recursive-descent parser combinator library for Lua.
Stars: ✭ 32 (-56.16%)
Mutual labels:  parser-combinators
metal
A Java library for parsing binary data formats, using declarative descriptions.
Stars: ✭ 13 (-82.19%)
Mutual labels:  parser-combinators
CombinedParsers.jl
Compiled parser combinators and regular expressions in pure julia
Stars: ✭ 76 (+4.11%)
Mutual labels:  parser-combinators
maxpc
Max’s Parser Combinators: a simple and pragmatic library for writing parsers and lexers based on combinatory parsing.
Stars: ✭ 42 (-42.47%)
Mutual labels:  parser-combinators
Kt2Dart
🔦 [Deprecated] Transpile Kotlin codes into Dart, Make Flutter Great Again
Stars: ✭ 84 (+15.07%)
Mutual labels:  parser-combinators
parser-combinators
Lightweight package providing commonly useful parser combinators
Stars: ✭ 41 (-43.84%)
Mutual labels:  parser-combinators
parsekt
Parser Combinator library for Kotlin
Stars: ✭ 27 (-63.01%)
Mutual labels:  parser-combinators
loquat
Monadic parser combinators for JavaScript / TypeScript
Stars: ✭ 47 (-35.62%)
Mutual labels:  parser-combinators
ParsecSharp
The faster monadic parser combinator library for C#
Stars: ✭ 23 (-68.49%)
Mutual labels:  parser-combinators
parser-lang
A parser combinator library with declarative superpowers
Stars: ✭ 25 (-65.75%)
Mutual labels:  parser-combinators
Parsey
Swift Parser Combinators
Stars: ✭ 56 (-23.29%)
Mutual labels:  parser-combinators
SuperCombinators
[Deprecated] A Swift parser combinator framework
Stars: ✭ 19 (-73.97%)
Mutual labels:  parser-combinators
ppc
A parser combinator library for PHP
Stars: ✭ 34 (-53.42%)
Mutual labels:  parser-combinators
mecha
A parser combinator library for Zig
Stars: ✭ 220 (+201.37%)
Mutual labels:  parser-combinators
parserz
A purely-functional library for creating both parsers, pretty-printers, and grammar definitions from a single, type-safe specification of a grammar
Stars: ✭ 68 (-6.85%)
Mutual labels:  parser-combinators
galileo
Scala Math - Numerical (Matlab-like) and Symbolic (Mathematica-like) tool
Stars: ✭ 62 (-15.07%)
Mutual labels:  parser-combinators
PigletC
A toy C-like language compiler for PigletVM
Stars: ✭ 51 (-30.14%)
Mutual labels:  parser-combinators
ex spirit
No description or website provided.
Stars: ✭ 26 (-64.38%)
Mutual labels:  parser-combinators

Parsita

Build status Code coverage Latest PyPI version Supported Python versions

The executable grammar of parsers combinators made available in the executable pseudocode of Python.

Parsita is a parser combinator library written in Python. Parser combinators provide an easy way to define a grammar using code so that the grammar itself effectively parses the source. They are not the fastest at parsing, but they are the easiest to write.

Like all good parser combinator libraries, Parsita abuses operators to provide a clean grammar-like syntax. The __or__ method is defined so that | tests between two alternatives. The __and__ method is defined so that & tests two parsers in sequence. Other operators are used as well.

In a technique that I think is new to Python, Parsita uses metaclass magic to allow for forward declarations of values. This is important for parser combinators because grammars are often recursive or mutually recursive, meaning that some components must be used in the definition of others before they themselves are defined.

See the Documentation for the full user guide.

Installation

The recommended means of installation is with pip from PyPI.

pip install parsita

Hello world

The following is a very basic parser for extracting the name from a Hello, {name}! string.

from parsita import *

class HelloWorldParsers(TextParsers, whitespace=r'[ ]*'):
    hello_world = lit('Hello') >> ',' >> reg(r'[A-Z][a-z]*') << '!'

# A successful parse produces the parsed value
name = HelloWorldParsers.hello_world.parse('Hello, David!').or_die()
assert name == 'David'

# A parsing failure produces a useful error message
name = HelloWorldParsers.hello_world.parse('Hello David!').or_die()
# parsita.state.ParseError: Expected ',' but found 'David'
# Line 1, character 7
#
# Hello David!
#       ^
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].