summaryrefslogtreecommitdiff
path: root/audio/src/parse/mod.rs
blob: 895ddbd20274be9cb0d523638516ca073db00905 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use crate::program::Instruction;
use lexer::{Lexer, TokenKind};
use parser::Parser;
use pos::Span;

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(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()
}