diff options
| author | Freya Murphy <freya@freyacat.org> | 2025-11-23 14:50:31 -0500 |
|---|---|---|
| committer | Freya Murphy <freya@freyacat.org> | 2025-11-23 16:18:34 -0500 |
| commit | bb670049840e64e96b9bf0bf72897d6f3a928194 (patch) | |
| tree | 93adb7011a450b693e8be0c23707ad9813842a63 /audio/src/parse/mod.rs | |
| parent | audio: some changes (diff) | |
| download | DungeonCrawl-bb670049840e64e96b9bf0bf72897d6f3a928194.tar.gz DungeonCrawl-bb670049840e64e96b9bf0bf72897d6f3a928194.tar.bz2 DungeonCrawl-bb670049840e64e96b9bf0bf72897d6f3a928194.zip | |
audio: refactor everything
Diffstat (limited to 'audio/src/parse/mod.rs')
| -rw-r--r-- | audio/src/parse/mod.rs | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/audio/src/parse/mod.rs b/audio/src/parse/mod.rs index 726aaa2..895ddbd 100644 --- a/audio/src/parse/mod.rs +++ b/audio/src/parse/mod.rs @@ -1,13 +1,33 @@ use crate::program::Instruction; +use lexer::{Lexer, TokenKind}; use parser::Parser; +use pos::Span; -pub type Result<T> = std::result::Result<T, String>; - -mod lex; +mod lexer; mod macros; mod parser; +mod pos; +mod util; + +pub type Result<T> = std::result::Result<T, ParserError>; + +#[derive(Clone, Debug)] +pub struct ParserError { + pub span: Span, + pub msg: String, + pub file: Option<String>, +} -pub fn parse(raw_src: &str) -> Result<Vec<Instruction>> { - let src = macros::process(raw_src); - Parser::new(&src).parse() +pub fn parse(src: &str) -> Result<Vec<Instruction>> { + let mut tokens = vec![]; + let mut lexer = Lexer::new(src); + loop { + let token = lexer.next_token()?; + tokens.push(token); + if token.kind == TokenKind::Eof { + break; + } + } + tokens = macros::process(tokens)?; + Parser::new(tokens).parse() } |