mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
moved all crates into seperate folder + related path fixes
This commit is contained in:
parent
12ef03bb86
commit
eee85fa45d
1063 changed files with 92 additions and 93 deletions
2
crates/ast/src/parse/mod.rs
Normal file
2
crates/ast/src/parse/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
pub mod parse_ast;
|
||||
pub mod parse_header;
|
54
crates/ast/src/parse/parse_ast.rs
Normal file
54
crates/ast/src/parse/parse_ast.rs
Normal file
|
@ -0,0 +1,54 @@
|
|||
use bumpalo::Bump;
|
||||
use roc_module::symbol::Interns;
|
||||
use roc_region::all::Region;
|
||||
|
||||
use crate::{
|
||||
ast_error::ASTResult,
|
||||
lang::{
|
||||
core::{
|
||||
ast::AST,
|
||||
def::{def2::DefId, def_to_def2::str_to_def2},
|
||||
expr::expr2::Expr2,
|
||||
},
|
||||
env::Env,
|
||||
scope::Scope,
|
||||
},
|
||||
};
|
||||
|
||||
use super::parse_header;
|
||||
|
||||
pub fn parse_from_string<'a>(
|
||||
code_str: &'a str,
|
||||
env: &mut Env<'a>,
|
||||
ast_arena: &'a Bump,
|
||||
interns: &mut Interns,
|
||||
) -> ASTResult<AST> {
|
||||
let blank_line_indx = code_str
|
||||
.find("\n\n")
|
||||
.expect("I was expecting two newline chars to split header and rest of code.");
|
||||
|
||||
let header_str = &code_str[0..blank_line_indx];
|
||||
let tail_str = &code_str[blank_line_indx..];
|
||||
|
||||
let mut scope = Scope::new(env.home, env.pool, env.var_store);
|
||||
scope.fill_scope(env, &mut interns.all_ident_ids)?;
|
||||
|
||||
let region = Region::zero();
|
||||
|
||||
let mut def_ids = Vec::<DefId>::new();
|
||||
|
||||
let def2_vec = str_to_def2(ast_arena, tail_str, env, &mut scope, region)?;
|
||||
|
||||
for def2 in def2_vec {
|
||||
let def_id = env.pool.add(def2);
|
||||
|
||||
def_ids.push(def_id);
|
||||
}
|
||||
|
||||
let ast_node_id = env.pool.add(Expr2::Blank);
|
||||
|
||||
Ok(AST {
|
||||
header: parse_header::parse_from_string(header_str, ast_node_id),
|
||||
def_ids,
|
||||
})
|
||||
}
|
12
crates/ast/src/parse/parse_header.rs
Normal file
12
crates/ast/src/parse/parse_header.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::lang::core::{expr::expr2::ExprId, header::AppHeader};
|
||||
|
||||
// TODO don't use mock struct and actually parse string
|
||||
pub fn parse_from_string(_header_str: &str, ast_node_id: ExprId) -> AppHeader {
|
||||
AppHeader {
|
||||
app_name: "\"untitled-app\"".to_owned(),
|
||||
packages_base: "\"c-platform/main.roc\"".to_owned(),
|
||||
imports: vec![],
|
||||
provides: vec!["main".to_owned()],
|
||||
ast_node_id,
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue