Crate mpc [] [src]

This crate provides simple bindings for orangeduck's mpc library. This is still a work in progress and contains a modified version of mpc and some temporary glue code

Modules

colors

Contains consts for ANSI color escape sequences

glue

Contains the rust-side of glue code. The main purpose of the code is to avoid having to interface with a C union in Rust. The main offender is mpc_result_t

macros

Contains some nice macros to help with needed FFI and parser creation The str_c! and c_str! macros exist because ownership issues

Macros

c_str

Convert a rustic string (whether &str or String) to C's const char*

dfs

Dereference pointer and convert struct member mem to String

dfu

Dereference pointer and convert struct member mem to usize

g_string

simulate C's compile time string literal concatenation to allow copy-pasta of mpc grammars written in C without any hassle # Usage g_string![ "So many strings\n" "So many options\n" "So much things\n" ]

parser

Create a mpc_parser_t using mpca_lang grammars # Usage There are four possible ways to use this macro. Each does a slightly different thing: 1. To make a parser and immediately run on provided input in the form of something stringy: parser! { grammar:{g_string![ "word : /[a-zA-Z0-9]+/; \n" "punct: '.' | '!' | ',' | ';' | '?' | '-' | ':';\n" "sentence: <word>+ <punct>; \n" "paragraph: <sentence>+; \n" ]} filename: {"myfilename.txt"} input: { "A big brown piece of DOG jumped over something.".to_string() + "Bananas are awesome. What do you mean, potato?""} main: paragraph parsers: word punct sentence } 2. To do the same, but automatically read the file: parser! { grammar:{g_string![ "word : /[a-zA-Z0-9]+/; \n" "punct: '.' | '!' | ',' | ';' | '?' | '-' | ':';\n" "sentence: <word>+ <punct>; \n" "paragraph: <sentence>+; \n" ]} filename: {"myfilename.txt"} main: paragraph parsers: word punct sentence } 3. Parse input without a filename: parser! { grammar:{g_string![ "word : /[a-zA-Z0-9]+/; \n" "punct: '.' | '!' | ',' | ';' | '?' | '-' | ':';\n" "sentence: <word>+ <punct>; \n" "paragraph: <sentence>+; \n" ]} input: { "A big brown piece of DOG jumped over something.".to_string() + "Bananas are awesome. What do you mean, potato?""} main: paragraph parsers: word punct sentence } 4. Prepare parsers for later use: parser! { grammar:{g_string![ "word : /[a-zA-Z0-9]+/; \n" "punct: '.' | '!' | ',' | ';' | '?' | '-' | ':';\n" "sentence: <word>+ <punct>; \n" "paragraph: <sentence>+; \n" ]} main: paragraph parsers: word punct sentence } For cases 1-3 parser! returns Result<*mut mpc_ast_t, *mut mpc_err_t> In case 4 parser! returns a vector containing prepared parsers. The vector is not to be touched by a programmer. Its sole purpose is to be passed to run_parser!

run_parser

Runs a parser prepared with parser!

str_c

Convert a C's const char* to a rustic String

trace

print! for lazy people - no format, args are thrown in delimited with spaces

traceln

println! for lazy people - no format, args are thrown in delimited with spaces also throw in a newline