From ba8fb86e3fa5d5343bba66304b92f9903dd2157e Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sat, 13 Nov 2021 14:22:34 -0800 Subject: [PATCH] Create new Parser wrapper type --- schala-lang/language/src/parsing/new.rs | 29 ++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/schala-lang/language/src/parsing/new.rs b/schala-lang/language/src/parsing/new.rs index 8f516ae..c830b72 100644 --- a/schala-lang/language/src/parsing/new.rs +++ b/schala-lang/language/src/parsing/new.rs @@ -1,11 +1,38 @@ use std::rc::Rc; -use crate::ast::*; +//TODO make use of the format_parse_error function +//use crate::error::{SchalaError, format_parse_error}; +use crate::parsing::ParseError; +use crate::{ast::*, identifier::IdStore, schala::SourceReference}; fn rc_string(s: &str) -> Rc { Rc::new(s.to_string()) } +pub struct Parser { + id_store: IdStore, +} + +impl Parser { + pub(crate) fn new() -> Self { + Self { id_store: IdStore::new() } + } + + pub(crate) fn parse(input: &str, _source_reference: &SourceReference) -> Result { + schala_parser::program(input).map_err(|err: peg::error::ParseError<_>| { + let msg = err.to_string(); + ParseError { + production_name: Some("some-production".to_string()), + msg, + token: crate::tokenizing::Token { + kind: crate::tokenizing::TokenKind::Semicolon, + location: Default::default(), + }, + } + }) + } +} + enum ExtendedPart<'a> { Index(Vec), Accessor(&'a str),