initial parser signature
This commit is contained in:
parent
cc423a0bec
commit
b2e56594b0
3 changed files with 26 additions and 5 deletions
|
|
@ -1,9 +1,10 @@
|
|||
use std::{env, fmt, fs};
|
||||
use std::fmt;
|
||||
|
||||
use ariadne::{sources, Color, Label, Report, ReportKind};
|
||||
use chumsky::prelude::*;
|
||||
|
||||
pub type Span = SimpleSpan<usize>;
|
||||
pub type Output<'a> = Vec<(Token<'a>, Span)>;
|
||||
pub type Error<'a> = extra::Err<Rich<'a, char, Span>>;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum Token<'src> {
|
||||
|
|
@ -76,7 +77,7 @@ impl<'src> fmt::Display for Token<'src> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn lexer<'src>() -> impl Parser<'src, &'src str, Vec<(Token<'src>, Span)>, extra::Err<Rich<'src, char, Span>>> {
|
||||
pub fn lexer<'src>() -> impl Parser<'src, &'src str, Output<'src>, Error<'src>> {
|
||||
// A parser for numbers
|
||||
let digits = text::digits(10).slice();
|
||||
|
||||
|
|
@ -173,8 +174,6 @@ mod tests {
|
|||
#[test]
|
||||
fn simple_test() {
|
||||
use Token::*;
|
||||
type Output<'a> = Vec<(Token<'a>, Span)>;
|
||||
type MyErr<'a> = extra::Err<Rich<'a, char, Span>>;
|
||||
let cases = [
|
||||
("true", vec![(Bool(true), Span::new(0, 4))]),
|
||||
("false", vec![(Bool(false), Span::new(0, 5))]),
|
||||
|
|
|
|||
|
|
@ -1 +1,18 @@
|
|||
use std::{env, fmt, fs};
|
||||
|
||||
use ariadne::{sources, Color, Label, Report, ReportKind};
|
||||
use chumsky::{input::SpannedInput, prelude::*};
|
||||
|
||||
use crate::lexer::{lexer, Span, Token};
|
||||
|
||||
pub type Spanned<T> = (T, Span);
|
||||
|
||||
// The type of the input that our parser operates on. The input is the `&[(Token, Span)]` token buffer generated by the
|
||||
// lexer, wrapped in a `SpannedInput` which 'splits' it apart into its constituent parts, tokens and spans, for chumsky
|
||||
// to understand.
|
||||
type ParserInput<'tokens, 'src> = SpannedInput<Token<'src>, Span, &'tokens [(Token<'src>, Span)]>;
|
||||
|
||||
pub fn parser<'tokens, 'src: 'tokens>(
|
||||
) -> impl Parser<'tokens, ParserInput<'tokens, 'src>, Spanned<Expr<'src>>, extra::Err<Rich<'tokens, Token<'src>, Span>>>
|
||||
+ Clone {
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue