mirror of
https://github.com/TxtDot/dalet-rs.git
synced 2024-11-21 16:26:21 +03:00
refactor: lexer types, start parser
This commit is contained in:
parent
ccc9773030
commit
9c41541712
7 changed files with 45 additions and 14 deletions
|
@ -1,5 +1,6 @@
|
||||||
use super::{
|
use super::{
|
||||||
lexer::types::{Spanned, Token},
|
lexer::types::Token,
|
||||||
|
types::Spanned,
|
||||||
utils::{prepend_indent, set_indent},
|
utils::{prepend_indent, set_indent},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
use chumsky::prelude::*;
|
|
||||||
use types::{Span, Spanned, Token};
|
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
|
use chumsky::prelude::*;
|
||||||
|
use types::*;
|
||||||
|
|
||||||
|
use super::types::{Span, Spanned};
|
||||||
|
|
||||||
pub fn lexer<'src>(
|
pub fn lexer<'src>(
|
||||||
) -> impl Parser<'src, &'src str, Vec<Spanned<Token<'src>>>, extra::Err<Rich<'src, char, Span>>> {
|
) -> impl Parser<'src, &'src str, Vec<Spanned<Token<'src>>>, extra::Err<Rich<'src, char, Span>>> {
|
||||||
let token = choice((symbol(), tag(), argument(), textual()));
|
let token = choice((symbol(), tag(), argument(), textual()));
|
||||||
|
|
|
@ -1,8 +1,3 @@
|
||||||
use chumsky::prelude::*;
|
|
||||||
|
|
||||||
pub type Span = SimpleSpan<usize>;
|
|
||||||
pub type Spanned<T> = (T, Span);
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum Token<'src> {
|
pub enum Token<'src> {
|
||||||
// Symbols
|
// Symbols
|
||||||
|
@ -69,9 +64,3 @@ pub enum Token<'src> {
|
||||||
Pre,
|
Pre,
|
||||||
Meta,
|
Meta,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'src> From<Spanned<Token<'src>>> for Token<'src> {
|
|
||||||
fn from(value: Spanned<Token<'src>>) -> Self {
|
|
||||||
value.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
pub mod format;
|
pub mod format;
|
||||||
pub mod lexer;
|
pub mod lexer;
|
||||||
|
pub mod parser;
|
||||||
|
pub mod types;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
|
24
src/daleth/parser/mod.rs
Normal file
24
src/daleth/parser/mod.rs
Normal 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()))
|
||||||
|
}
|
8
src/daleth/parser/types.rs
Normal file
8
src/daleth/parser/types.rs
Normal 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
4
src/daleth/types.rs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
use chumsky::span::SimpleSpan;
|
||||||
|
|
||||||
|
pub type Span = SimpleSpan<usize>;
|
||||||
|
pub type Spanned<T> = (T, Span);
|
Loading…
Add table
Reference in a new issue