Parser
Include parse_from_src function
+use fm::FileID;
+
use super::{Precedence, Program, errors::ParserErrorKind};
-use crate::ast::{BlockStatement, Expression, Statement, Type, ArraySize, ExpressionKind};
+use crate::{ast::{BlockStatement, Expression, Statement, Type, ArraySize, ExpressionKind}};
use crate::lexer::Lexer;
use crate::token::{Keyword, Token, TokenKind, SpannedToken};
use super::errors::ParserError;
@@ -36,6 +38,9 @@ impl<'a> Parser<'a> {
errors: Vec::new(),
}
}
+ pub fn from_src(file_id : FileID, src : &'a str) -> Self {
+ Parser::new(Lexer::new(file_id.as_usize(), src))
+ }
/// Note that this function does not alert the user of an EOF
/// calling this function repeatedly will repeatedly give you
@@ -133,6 +138,7 @@ impl<'a> Parser<'a> {
// so we advance from that
self.advance_tokens();
}
+
if self.errors.len() > 0 {
return Err(&self.errors)
} else {
