Skip to content

A Python parser combinator library similar to Nom for Rust

Notifications You must be signed in to change notification settings

Harry-Lees/Nompy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nompy

A Python parser combinator library similar to the Nom library in Rust.

Examples

Parse Name

Parse a name and apply a simple transformation.

from nompy.combinators import succeeded, tag, take_rest, take_until, tuple_
from nompy.modifiers import apply

to_parse = "john doe"

parser = tuple_(
    apply(succeeded(take_until(" "), tag(" ")), str.capitalize),
    apply(take_rest(), str.capitalize),
)
result, remaining = parser(to_parse)
firstname, lastname = result
print(firstname, lastname)  # John Doe

Parse Phone Number

Parse an MSISDN with preceeding +

from nompy.combinators import preceeded, tag, take_while

to_parse = "+1234567890"

parser = preceeded(take_while(str.isnumeric), tag("+"))
result, remaining = parser(to_parse)
print(result)

About

A Python parser combinator library similar to Nom for Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages