sssooonnnggg /
rslua
Yet another Lua lexer and Lua parser for Lua 5.3 written in pure Rust.
67/100 healthLoading repository data…
jsdw / repository
Yet Another Parser library for Rust. A lightweight, dependency free, parser combinator inspired set of utility methods to help with parsing strings and slices.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
This small, zero-dependency crate helps you to parse input strings and slices by building on the Iterator
interface.
The aim of this crate is to provide the sorts of functions you'd come to expect from a parser combinator library, but without immersing you into a world of parser combinators and forcing you to use a novel return type, library-provided errors or parser-combinator based control flow. we sacrifice some conciseness in exchange for simplicity.
Some specific features/goals:
Tokens/Iterator._err
variants incase you need error information when they don't otherwise hand back errors for simplicity.Tokens::offset and Tokens::location().Tokens::location),
and implement any of the provided functions using these primitives.Have a look at the Tokens trait for all of the parsing methods made available, and examples for each.
Have a look in the examples folder for more in depth examples.
use yap::{
// This trait has all of the parsing methods on it:
Tokens,
// Allows you to use `.into_tokens()` on strings and slices,
// to get an instance of the above:
IntoTokens
};
// Step 1: convert our input into something implementing `Tokens`
// ================================================================
let mut tokens = "10 + 2 x 12-4,foobar".into_tokens();
// Step 2: Parse some things from our tokens
// =========================================
#[derive(PartialEq,Debug)]
enum Op { Plus, Minus, Multiply }
#[derive(PartialEq,Debug)]
enum OpOrDigit { Op(Op), Digit(u32) }
// The `Tokens` trait builds on `Iterator`, so we get a `next` method.
fn parse_op(t: &mut impl Tokens<Item=char>) -> Option<Op> {
match t.next()? {
'-' => Some(Op::Minus),
'+' => Some(Op::Plus),
'x' => Some(Op::Multiply),
_ => None
}
}
// We also get other useful functions..
fn parse_digits(t: &mut impl Tokens<Item=char>) -> Option<u32> {
t.take_while(|c| c.is_digit(10))
.parse::<u32, String>()
.ok()
}
// As well as combinator functions like `sep_by_all` and `surrounded_by`..
let op_or_digit = tokens.sep_by_all(
|t| t.surrounded_by(
|t| parse_digits(t).map(OpOrDigit::Digit),
|t| { t.skip_while(|c| c.is_ascii_whitespace()); }
),
|t| parse_op(t).map(OpOrDigit::Op)
);
// Now we've parsed our input into OpOrDigits, let's calculate the result..
let mut current_op = Op::Plus;
let mut current_digit = 0;
for d in op_or_digit.into_iter() {
match d {
OpOrDigit::Op(op) => {
current_op = op
},
OpOrDigit::Digit(n) => {
match current_op {
Op::Plus => { current_digit += n },
Op::Minus => { current_digit -= n },
Op::Multiply => { current_digit *= n },
}
},
}
}
assert_eq!(current_digit, 140);
// Step 3: do whatever you like with the rest of the input!
// ========================================================
// This is available on the concrete type that strings
// are converted into (rather than on the `Tokens` trait):
let remaining = tokens.remaining();
assert_eq!(remaining, ",foobar");
Selected from shared topics, language and repository description—not editorial ratings.
sssooonnnggg /
Yet another Lua lexer and Lua parser for Lua 5.3 written in pure Rust.
67/100 healthMalien /
Just an attempt to write yet another LUA interpreter / JIT compiler. Kinda want to look into compiler design and dynamic language / VM optimizations
50/100 healthyou06 /
Yet another SQL parser in rust.
41/100 healthhargoniX /
Yet Another NMEA Parser
39/100 healthtimsueberkrueb /
Yet Another LR parser generator
30/100 healthHJfod /
Yet Another Parser written in Rust
27/100 health