Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Parse Tokens With Spans Using chumsky In Rust

rust
```cargo
[dependencies]
chumsky = { version = "0.9.2" }
```

use chumsky::prelude::*;
use std::ops::Range;

#[derive(Debug)]
pub enum Token {
    LetterA,
    LetterB,
}

fn main() {
    let source = "abba";
    let result = letters().parse(source);
    dbg!(&result);
}

fn letters() -> impl Parser<char, Vec<(Token, Range<usize>)>, Error = Simple<char>> {
    letter1().or(letter2()).repeated()
}

fn letter1() -> impl Parser<char, (Token, Range<usize>), Error = Simple<char>> {
    just("a").map_with_span(|_, span| (Token::LetterA, span))
}

fn letter2() -> impl Parser<char, (Token, Range<usize>), Error = Simple<char>> {
    just("b").map_with_span(|_, span| (Token::LetterB, span))
}
results start

- This is a test I'm doing for the Neopolitan LSP

- Individual Token are created with their spans in [TODO: Code shorthand span ] and [TODO: Code shorthand span ] then assembled into a Vec in [TODO: Code shorthand span ]