refactor: lexer types, start parser

This commit is contained in:
Artemy Egorov 2024-08-11 19:02:18 +03:00
parent ccc9773030
commit 9c41541712
7 changed files with 45 additions and 14 deletions

View file

@ -1,5 +1,6 @@
use super::{
lexer::types::{Spanned, Token},
lexer::types::Token,
types::Spanned,
utils::{prepend_indent, set_indent},
};

View file

@ -1,7 +1,10 @@
use chumsky::prelude::*;
use types::{Span, Spanned, Token};
pub mod types;
use chumsky::prelude::*;
use types::*;
use super::types::{Span, Spanned};
pub fn lexer<'src>(
) -> impl Parser<'src, &'src str, Vec<Spanned<Token<'src>>>, extra::Err<Rich<'src, char, Span>>> {
let token = choice((symbol(), tag(), argument(), textual()));

View file

@ -1,8 +1,3 @@
use chumsky::prelude::*;
pub type Span = SimpleSpan<usize>;
pub type Spanned<T> = (T, Span);
#[derive(Clone, Debug, PartialEq)]
pub enum Token<'src> {
// Symbols
@ -69,9 +64,3 @@ pub enum Token<'src> {
Pre,
Meta,
}
impl<'src> From<Spanned<Token<'src>>> for Token<'src> {
fn from(value: Spanned<Token<'src>>) -> Self {
value.0
}
}

View file

@ -1,3 +1,5 @@
pub mod format;
pub mod lexer;
pub mod parser;
pub mod types;
pub mod utils;

24
src/daleth/parser/mod.rs Normal file
View file

@ -0,0 +1,24 @@
pub mod types;
use super::{
lexer::types::Token,
types::{Span, Spanned},
};
use crate::typed::{Page, Tag::*};
use chumsky::prelude::*;
use types::*;
pub fn parser<'tokens, 'src: 'tokens>() -> impl Parser<
'tokens,
ParserInput<'tokens, 'src>,
Spanned<Page>,
extra::Err<Rich<'tokens, Token<'src>, Span>>,
> {
let br = just(Token::Br).to(Br);
let tag = br;
tag.repeated()
.collect()
.map_with(|t, e| (Page { data: t }, e.span()))
}

View file

@ -0,0 +1,8 @@
use crate::daleth::{
lexer::types::*,
types::{Span, Spanned},
};
use chumsky::input::SpannedInput;
pub type ParserInput<'tokens, 'src> =
SpannedInput<Token<'src>, Span, &'tokens [Spanned<Token<'src>>]>;

4
src/daleth/types.rs Normal file
View file

@ -0,0 +1,4 @@
use chumsky::span::SimpleSpan;
pub type Span = SimpleSpan<usize>;
pub type Spanned<T> = (T, Span);