separate typed and untyped ASTs
This commit is contained in:
parent
91148b1a20
commit
86d4f7fffb
14 changed files with 512 additions and 262 deletions
|
|
@ -6,13 +6,14 @@ use pest::iterators::Pair;
|
|||
use pest::pratt_parser::PrattParser;
|
||||
use pest::Parser;
|
||||
|
||||
use crate::ast::module::{Module, ModulePath};
|
||||
use crate::ast::*;
|
||||
use crate::ast::untyped::module::Module;
|
||||
use crate::ast::untyped::*;
|
||||
use crate::ast::{Import, ModulePath};
|
||||
use crate::typing::Type;
|
||||
|
||||
#[derive(pest_derive::Parser)]
|
||||
#[grammar = "parsing/backend/pest/grammar.pest"]
|
||||
struct KrParser;
|
||||
struct LilaParser;
|
||||
|
||||
use lazy_static;
|
||||
lazy_static::lazy_static! {
|
||||
|
|
@ -38,7 +39,7 @@ pub fn parse_file(path: &Path) -> Result<Module, Error<Rule>> {
|
|||
}
|
||||
|
||||
pub fn parse_as_module(source: &str, path: ModulePath) -> Result<Module, Error<Rule>> {
|
||||
let mut pairs = KrParser::parse(Rule::source_file, &source)?;
|
||||
let mut pairs = LilaParser::parse(Rule::source_file, &source)?;
|
||||
|
||||
assert!(pairs.len() == 1);
|
||||
let module = parse_module(pairs.next().unwrap().into_inner().next().unwrap(), path);
|
||||
|
|
@ -59,7 +60,7 @@ pub fn parse_module(pair: Pair<Rule>, path: ModulePath) -> Module {
|
|||
module.definitions.push(def);
|
||||
}
|
||||
Rule::use_statement => {
|
||||
let path = parse_import_path(pair.into_inner().next().unwrap());
|
||||
let path = parse_import(pair.into_inner().next().unwrap());
|
||||
module.imports.push(path);
|
||||
}
|
||||
_ => panic!("unexpected rule in source_file: {:?}", pair.as_rule()),
|
||||
|
|
@ -112,8 +113,8 @@ fn parse_statement(pair: Pair<Rule>) -> Statement {
|
|||
Statement::CallStatement(call)
|
||||
}
|
||||
Rule::use_statement => {
|
||||
let path = parse_import_path(pair.into_inner().next().unwrap());
|
||||
Statement::UseStatement(path)
|
||||
let import = parse_import(pair.into_inner().next().unwrap());
|
||||
Statement::UseStatement(import)
|
||||
}
|
||||
Rule::if_statement => {
|
||||
let mut pairs = pair.into_inner();
|
||||
|
|
@ -133,8 +134,8 @@ fn parse_statement(pair: Pair<Rule>) -> Statement {
|
|||
|
||||
type ImportPath = ModulePath;
|
||||
|
||||
fn parse_import_path(pair: Pair<Rule>) -> ImportPath {
|
||||
ModulePath::from(pair.as_str())
|
||||
fn parse_import(pair: Pair<Rule>) -> Import {
|
||||
Import(pair.as_str().to_string())
|
||||
}
|
||||
|
||||
fn parse_call(pair: Pair<Rule>) -> Call {
|
||||
|
|
@ -147,7 +148,10 @@ fn parse_call(pair: Pair<Rule>) -> Call {
|
|||
.into_inner()
|
||||
.map(parse_expression)
|
||||
.collect();
|
||||
Call { callee, args }
|
||||
Call {
|
||||
callee: Box::new(callee),
|
||||
args,
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_expression(pair: Pair<Rule>) -> Expr {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue