forked from Orchid/orchid
Changes in api and upwards
- Removed out-of-stack error reporting - Revised module system to match previous Orchid system - Errors are now in a Vec everywhere - Implemented atoms and lexer - Started implementation of line parser - Tree is now ephemeral to avoid copying Atoms held inside - Moved numbers into std and the shared parser into base - Started implementation of Commands
This commit is contained in:
33
orchid-host/src/parse.rs
Normal file
33
orchid-host/src/parse.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use orchid_base::interner::Tok;
|
||||
|
||||
use crate::tree::{OwnedItem, OwnedModule, OwnedTok, OwnedTokTree};
|
||||
|
||||
pub struct ParseCtx<'a> {
|
||||
tokens: &'a [OwnedTokTree]
|
||||
}
|
||||
|
||||
pub fn split_br(ctx: ParseCtx) -> impl Iterator<Item = ParseCtx> {
|
||||
ctx.tokens.split(|t| matches!(t.tok, OwnedTok::BR)).map(|tokens| ParseCtx { tokens })
|
||||
}
|
||||
|
||||
pub fn strip_br(tt: &OwnedTokTree) -> Option<OwnedTokTree> {
|
||||
let tok = match &tt.tok {
|
||||
OwnedTok::BR => return None,
|
||||
OwnedTok::Lambda(arg) => OwnedTok::Lambda(arg.iter().filter_map(strip_br).collect()),
|
||||
OwnedTok::S(p, b) => OwnedTok::S(p.clone(), b.iter().filter_map(strip_br).collect()),
|
||||
t => t.clone(),
|
||||
};
|
||||
Some(OwnedTokTree { tok, range: tt.range.clone() })
|
||||
}
|
||||
|
||||
pub fn parse_items(ctx: ParseCtx) -> Vec<OwnedItem> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn parse_item(ctx: ParseCtx) -> OwnedItem {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn parse_module(ctx: ParseCtx) -> (Tok<String>, OwnedModule) {
|
||||
todo!()
|
||||
}
|
||||
Reference in New Issue
Block a user