3 releases (breaking)

new 0.3.0 Jan 28, 2025
0.2.0 Jan 21, 2025
0.1.0 Jan 20, 2025

#78 in Parser tooling

Download history 118/week @ 2025-01-15 125/week @ 2025-01-22

243 downloads per month
Used in udled-tokenizers

MIT license

45KB
1.5K SLoC

Udled

Udled is a lexer and parser for the rust programming language.

use udled::{Tokenizer, Input, Lex, Error, token::{Alphabetic, Ws, Punctuation, OneOrMany, Spanned}, Reader, Span};

struct Word;

impl Tokenizer for Word {
    type Token<'a> = Lex<'a>;

    fn to_token<'a>(&self, reader: &mut Reader<'_, 'a>) -> Result<Self::Token<'a>, Error> {
        let span = reader.parse(Spanned(OneOrMany(Alphabetic)))
        Ok(Lex::new(span.slice(reader.input()).unwrap(), span))
    }

    fn peek<'a>(&self, reader: &mut Reader<'_, '_>) -> Result<bool, Error> {
        reader.peek(Alphabetic)
    }
}

fn main() {

  let mut input = Input::new("Hello, World!");

  let (greeting ,_ ,_ , subject, _) = input.parse((Word, Punctuation, Ws, Word, Punctuation));

  assert_eq!(greeting.as_str(), "Hello");
  assert_eq!(subject.as_str(), "World);

}

Dependencies

~315–560KB