cl-parser: break parser into inline module

This commit is contained in:
John 2024-02-29 20:43:40 -06:00
parent cc281fc6ab
commit ab17ebbadc

View File

@ -5,17 +5,11 @@
//! [1]: https://git.soft.fish/j/Conlang/src/branch/main/grammar.ebnf
#![feature(decl_macro)]
pub use parser::Parser;
use cl_structures::span::*;
use cl_token::*;
use crate::error::{
Error,
ErrorKind::{self, *},
PResult, Parsing,
};
use cl_ast::*;
use conlang::lexer::Lexer;
pub mod error {
use super::*;
@ -228,6 +222,15 @@ pub mod error {
}
}
pub mod parser {
use super::*;
use crate::error::{
Error,
ErrorKind::{self, *},
PResult, Parsing,
};
use cl_ast::*;
use conlang::lexer::Lexer;
/// Parses a sequence of [Tokens](Token) into an [AST](cl_ast)
pub struct Parser<'t> {
@ -1127,7 +1130,11 @@ impl<'t> Parser<'t> {
/// [Block] = `{` [Stmt]* `}`
pub fn block(&mut self) -> PResult<Block> {
const PARSING: Parsing = Parsing::Block;
Ok(Block { stmts: delim(rep(Self::stmt, CURLIES.1, PARSING), CURLIES, PARSING)(self)? })
Ok(
Block {
stmts: delim(rep(Self::stmt, CURLIES.1, PARSING), CURLIES, PARSING)(self)?,
},
)
}
}
/// ## Control flow subexpressions
@ -1273,3 +1280,4 @@ impl<'t> Parser<'t> {
Ok(())
}
}
}