Skip to content

Rusty Parsec is a parser combinator library in Rust, modeled after the F# library, FParsec.

Notifications You must be signed in to change notification settings

jakewitcher/rusty_parsec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rusty Parsec

Rusty Parsec is a parser combinator library in Rust based on the F# library FParsec.

Below is an example using the library to parse the phrases "hello, world" or "goodbye, world."

let p_hello = p_string(String::from("hello"));
let p_goodbye = p_string(String::from("goodbye"));
let p_world = p_string(String::from("world"));
let p_comma = p_char(',');

let parser = p_hello
    .or(p_goodbye)
    .take_prev(p_comma)
    .take_prev(ws())
    .and(p_world);

parser.run(String::from("hello, world")); 
    // => ("hello", "world")

parser.run(String::from("goodbye, world")); 
    // => ("goodbye", "world")
    
parser.run(String::from("hello, nerds")); 
    // => "expected 'world' but found 'nerds' at line 1, column 8"

About

Rusty Parsec is a parser combinator library in Rust, modeled after the F# library, FParsec.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages