mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
fmt
This commit is contained in:
parent
810c7dce80
commit
4828c9ba62
19 changed files with 177 additions and 143 deletions
|
@ -1,4 +1,4 @@
|
||||||
use roc_module::symbol::{IdentId};
|
use roc_module::symbol::IdentId;
|
||||||
use snafu::{Backtrace, Snafu};
|
use snafu::{Backtrace, Snafu};
|
||||||
|
|
||||||
use crate::lang::core::ast::ASTNodeId;
|
use crate::lang::core::ast::ASTNodeId;
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
use roc_module::symbol::IdentId;
|
use roc_module::symbol::IdentId;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
lang::core::{
|
lang::core::expr::{expr2::Expr2, expr2_to_string::expr2_to_string},
|
||||||
expr::{expr2::Expr2, expr2_to_string::expr2_to_string},
|
|
||||||
},
|
|
||||||
mem_pool::pool::{NodeId, Pool},
|
mem_pool::pool::{NodeId, Pool},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
use bumpalo::collections::Vec as BumpVec;
|
use bumpalo::collections::Vec as BumpVec;
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use roc_module::ident::{Ident, IdentStr};
|
use roc_module::ident::{Ident, IdentStr};
|
||||||
use roc_parse::{parser::SyntaxError};
|
use roc_parse::parser::SyntaxError;
|
||||||
use roc_region::all::Region;
|
use roc_region::all::Region;
|
||||||
|
|
||||||
use crate::lang::{
|
use crate::lang::{core::expr::expr_to_expr2::loc_expr_to_expr2, env::Env, scope::Scope};
|
||||||
core::{expr::expr_to_expr2::loc_expr_to_expr2},
|
|
||||||
env::Env,
|
|
||||||
scope::Scope,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::def2::Def2;
|
use super::def2::Def2;
|
||||||
|
|
||||||
|
|
|
@ -108,11 +108,11 @@ pub enum Expr2 {
|
||||||
},
|
},
|
||||||
Closure {
|
Closure {
|
||||||
args: PoolVec<(Variable, NodeId<Pattern2>)>, // 8B
|
args: PoolVec<(Variable, NodeId<Pattern2>)>, // 8B
|
||||||
uniq_symbol: Symbol, // 8B This is a globally uniqe symbol for the function, not the name of the function
|
uniq_symbol: Symbol, // 8B This is a globally uniqe symbol for the function, not the name of the function
|
||||||
body_id: ExprId, // 4B
|
body_id: ExprId, // 4B
|
||||||
function_type: Variable, // 4B
|
function_type: Variable, // 4B
|
||||||
recursive: Recursive, // 1B
|
recursive: Recursive, // 1B
|
||||||
extra: NodeId<ClosureExtra>, // 4B
|
extra: NodeId<ClosureExtra>, // 4B
|
||||||
},
|
},
|
||||||
// Product Types
|
// Product Types
|
||||||
Record {
|
Record {
|
||||||
|
|
|
@ -18,13 +18,13 @@ pub enum FunctionDef {
|
||||||
arguments: PoolVec<(PatternId, Type2)>, // 8B
|
arguments: PoolVec<(PatternId, Type2)>, // 8B
|
||||||
rigids: NodeId<Rigids>, // 4B
|
rigids: NodeId<Rigids>, // 4B
|
||||||
return_type: TypeId, // 4B
|
return_type: TypeId, // 4B
|
||||||
body_id: ExprId, // 4B
|
body_id: ExprId, // 4B
|
||||||
},
|
},
|
||||||
NoAnnotation {
|
NoAnnotation {
|
||||||
name: Symbol, // 8B
|
name: Symbol, // 8B
|
||||||
arguments: PoolVec<(PatternId, Variable)>, // 8B
|
arguments: PoolVec<(PatternId, Variable)>, // 8B
|
||||||
return_var: Variable, // 4B
|
return_var: Variable, // 4B
|
||||||
body_id: ExprId, // 4B
|
body_id: ExprId, // 4B
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -170,15 +170,14 @@ impl<'a> Env<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_name_for_ident_id(&self, ident_id: IdentId) -> ASTResult<&str> {
|
pub fn get_name_for_ident_id(&self, ident_id: IdentId) -> ASTResult<&str> {
|
||||||
Ok(
|
Ok(self
|
||||||
self.ident_ids.get_name(ident_id).with_context(||
|
.ident_ids
|
||||||
IdentIdNotFound {
|
.get_name(ident_id)
|
||||||
ident_id,
|
.with_context(|| IdentIdNotFound {
|
||||||
env_ident_ids_str: format!("{:?}", self.ident_ids),
|
ident_id,
|
||||||
}
|
env_ident_ids_str: format!("{:?}", self.ident_ids),
|
||||||
)?
|
})?
|
||||||
.as_inline_str()
|
.as_inline_str()
|
||||||
.as_str()
|
.as_str())
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,11 @@ pub fn new_colon_mn(expr_id: ExprId, parent_id_opt: Option<MarkNodeId>) -> Marku
|
||||||
new_operator_mn(nodes::COLON.to_owned(), expr_id, parent_id_opt)
|
new_operator_mn(nodes::COLON.to_owned(), expr_id, parent_id_opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_operator_mn(content: String, expr_id: ExprId, parent_id_opt: Option<MarkNodeId>) -> MarkupNode {
|
pub fn new_operator_mn(
|
||||||
|
content: String,
|
||||||
|
expr_id: ExprId,
|
||||||
|
parent_id_opt: Option<MarkNodeId>,
|
||||||
|
) -> MarkupNode {
|
||||||
MarkupNode::Text {
|
MarkupNode::Text {
|
||||||
content: content,
|
content: content,
|
||||||
ast_node_id: ASTNodeId::AExprId(expr_id),
|
ast_node_id: ASTNodeId::AExprId(expr_id),
|
||||||
|
|
|
@ -1,9 +1,17 @@
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use roc_ast::{ast_error::ASTResult, lang::{core::ast::AST, env::Env}};
|
use roc_ast::{
|
||||||
|
ast_error::ASTResult,
|
||||||
|
lang::{core::ast::AST, env::Env},
|
||||||
|
};
|
||||||
use roc_module::symbol::Interns;
|
use roc_module::symbol::Interns;
|
||||||
|
|
||||||
use crate::{markup::{convert::{from_def2::def2_to_markup, from_header::header_to_markup}, nodes::set_parent_for_all}, slow_pool::{MarkNodeId, SlowPool}};
|
use crate::{
|
||||||
|
markup::{
|
||||||
|
convert::{from_def2::def2_to_markup, from_header::header_to_markup},
|
||||||
|
nodes::set_parent_for_all,
|
||||||
|
},
|
||||||
|
slow_pool::{MarkNodeId, SlowPool},
|
||||||
|
};
|
||||||
|
|
||||||
pub fn ast_to_mark_nodes<'a, 'b>(
|
pub fn ast_to_mark_nodes<'a, 'b>(
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
|
@ -25,4 +33,4 @@ pub fn ast_to_mark_nodes<'a, 'b>(
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(all_mark_node_ids)
|
Ok(all_mark_node_ids)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
use crate::{markup::{common_nodes::new_blank_mn_w_nls, top_level_def::tld_mark_node}, slow_pool::{MarkNodeId, SlowPool}};
|
use crate::{
|
||||||
|
markup::{common_nodes::new_blank_mn_w_nls, top_level_def::tld_mark_node},
|
||||||
|
slow_pool::{MarkNodeId, SlowPool},
|
||||||
|
};
|
||||||
|
|
||||||
use super::{from_expr2::expr2_to_markup};
|
use super::from_expr2::expr2_to_markup;
|
||||||
|
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use roc_ast::{
|
use roc_ast::{
|
||||||
ast_error::ASTResult,
|
ast_error::ASTResult,
|
||||||
lang::{
|
lang::{
|
||||||
core::{
|
core::{
|
||||||
ast::{ASTNodeId},
|
ast::ASTNodeId,
|
||||||
def::def2::{Def2, DefId},
|
def::def2::{Def2, DefId},
|
||||||
},
|
},
|
||||||
env::Env,
|
env::Env,
|
||||||
|
@ -37,16 +40,11 @@ pub fn def2_to_markup<'a, 'b>(
|
||||||
*expr_id,
|
*expr_id,
|
||||||
mark_node_pool,
|
mark_node_pool,
|
||||||
interns,
|
interns,
|
||||||
0
|
0,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let tld_mn = tld_mark_node(
|
let tld_mn =
|
||||||
*identifier_id,
|
tld_mark_node(*identifier_id, expr_mn_id, ast_node_id, mark_node_pool, env)?;
|
||||||
expr_mn_id,
|
|
||||||
ast_node_id,
|
|
||||||
mark_node_pool,
|
|
||||||
env
|
|
||||||
)?;
|
|
||||||
|
|
||||||
mark_node_pool.add(tld_mn)
|
mark_node_pool.add(tld_mn)
|
||||||
}
|
}
|
||||||
|
@ -54,4 +52,4 @@ pub fn def2_to_markup<'a, 'b>(
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(mark_node_id)
|
Ok(mark_node_id)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,34 @@
|
||||||
|
use crate::{
|
||||||
use crate::{markup::{attribute::Attributes, common_nodes::{new_arg_name_mn, new_arrow_mn, new_blank_mn, new_colon_mn, new_comma_mn, new_equals_mn, new_left_accolade_mn, new_left_square_mn, new_operator_mn, new_right_accolade_mn, new_right_square_mn}, nodes::{MarkupNode, get_string, new_markup_node}}, slow_pool::{MarkNodeId, SlowPool}, syntax_highlight::HighlightStyle};
|
markup::{
|
||||||
|
attribute::Attributes,
|
||||||
|
common_nodes::{
|
||||||
|
new_arg_name_mn, new_arrow_mn, new_blank_mn, new_colon_mn, new_comma_mn, new_equals_mn,
|
||||||
|
new_left_accolade_mn, new_left_square_mn, new_operator_mn, new_right_accolade_mn,
|
||||||
|
new_right_square_mn,
|
||||||
|
},
|
||||||
|
nodes::{get_string, new_markup_node, MarkupNode},
|
||||||
|
},
|
||||||
|
slow_pool::{MarkNodeId, SlowPool},
|
||||||
|
syntax_highlight::HighlightStyle,
|
||||||
|
};
|
||||||
|
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use roc_ast::{ast_error::{ASTResult, IdentIdNotFound}, lang::{core::{ast::ASTNodeId, expr::{
|
use roc_ast::{
|
||||||
|
ast_error::{ASTResult, IdentIdNotFound},
|
||||||
|
lang::{
|
||||||
|
core::{
|
||||||
|
ast::ASTNodeId,
|
||||||
|
expr::{
|
||||||
expr2::{Expr2, ExprId},
|
expr2::{Expr2, ExprId},
|
||||||
record_field::RecordField,
|
record_field::RecordField,
|
||||||
}, pattern::{Pattern2, get_identifier_string}, val_def::ValueDef}, env::Env}};
|
},
|
||||||
|
pattern::{get_identifier_string, Pattern2},
|
||||||
|
val_def::ValueDef,
|
||||||
|
},
|
||||||
|
env::Env,
|
||||||
|
},
|
||||||
|
};
|
||||||
use roc_module::{ident::Ident, symbol::Interns};
|
use roc_module::{ident::Ident, symbol::Interns};
|
||||||
use snafu::OptionExt;
|
use snafu::OptionExt;
|
||||||
|
|
||||||
|
@ -20,7 +42,6 @@ pub fn expr2_to_markup<'a, 'b>(
|
||||||
interns: &Interns,
|
interns: &Interns,
|
||||||
indent_level: usize,
|
indent_level: usize,
|
||||||
) -> ASTResult<MarkNodeId> {
|
) -> ASTResult<MarkNodeId> {
|
||||||
|
|
||||||
let ast_node_id = ASTNodeId::AExprId(expr2_node_id);
|
let ast_node_id = ASTNodeId::AExprId(expr2_node_id);
|
||||||
|
|
||||||
println!("EXPR2 {:?}", expr2);
|
println!("EXPR2 {:?}", expr2);
|
||||||
|
@ -50,7 +71,7 @@ pub fn expr2_to_markup<'a, 'b>(
|
||||||
mark_node_pool,
|
mark_node_pool,
|
||||||
indent_level,
|
indent_level,
|
||||||
)
|
)
|
||||||
},
|
}
|
||||||
Expr2::GlobalTag { name, .. } => new_markup_node(
|
Expr2::GlobalTag { name, .. } => new_markup_node(
|
||||||
with_indent(indent_level, &get_string(env, name)),
|
with_indent(indent_level, &get_string(env, name)),
|
||||||
ast_node_id,
|
ast_node_id,
|
||||||
|
@ -60,7 +81,15 @@ pub fn expr2_to_markup<'a, 'b>(
|
||||||
),
|
),
|
||||||
Expr2::Call { expr: expr_id, .. } => {
|
Expr2::Call { expr: expr_id, .. } => {
|
||||||
let expr = env.pool.get(*expr_id);
|
let expr = env.pool.get(*expr_id);
|
||||||
expr2_to_markup(arena, env, expr, *expr_id, mark_node_pool, interns, indent_level)?
|
expr2_to_markup(
|
||||||
|
arena,
|
||||||
|
env,
|
||||||
|
expr,
|
||||||
|
*expr_id,
|
||||||
|
mark_node_pool,
|
||||||
|
interns,
|
||||||
|
indent_level,
|
||||||
|
)?
|
||||||
}
|
}
|
||||||
Expr2::Var(symbol) => {
|
Expr2::Var(symbol) => {
|
||||||
let text = env.get_name_for_ident_id(symbol.ident_id())?;
|
let text = env.get_name_for_ident_id(symbol.ident_id())?;
|
||||||
|
@ -90,7 +119,7 @@ pub fn expr2_to_markup<'a, 'b>(
|
||||||
*node_id,
|
*node_id,
|
||||||
mark_node_pool,
|
mark_node_pool,
|
||||||
interns,
|
interns,
|
||||||
indent_level
|
indent_level,
|
||||||
)?);
|
)?);
|
||||||
|
|
||||||
if idx + 1 < elems.len() {
|
if idx + 1 < elems.len() {
|
||||||
|
@ -154,7 +183,7 @@ pub fn expr2_to_markup<'a, 'b>(
|
||||||
*sub_expr2_node_id,
|
*sub_expr2_node_id,
|
||||||
mark_node_pool,
|
mark_node_pool,
|
||||||
interns,
|
interns,
|
||||||
indent_level
|
indent_level,
|
||||||
)?);
|
)?);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -215,7 +244,7 @@ pub fn expr2_to_markup<'a, 'b>(
|
||||||
*expr_id,
|
*expr_id,
|
||||||
mark_node_pool,
|
mark_node_pool,
|
||||||
interns,
|
interns,
|
||||||
indent_level
|
indent_level,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let body_mn = mark_node_pool.get_mut(body_mn_id);
|
let body_mn = mark_node_pool.get_mut(body_mn_id);
|
||||||
|
@ -238,79 +267,67 @@ pub fn expr2_to_markup<'a, 'b>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expr2::Closure{
|
Expr2::Closure {
|
||||||
function_type:_,
|
function_type: _,
|
||||||
uniq_symbol:_,
|
uniq_symbol: _,
|
||||||
recursive:_,
|
recursive: _,
|
||||||
args,
|
args,
|
||||||
body_id,
|
body_id,
|
||||||
extra:_
|
extra: _,
|
||||||
} => {
|
} => {
|
||||||
let backslash_mn = new_operator_mn("\\".to_string(), expr2_node_id, None);
|
let backslash_mn = new_operator_mn("\\".to_string(), expr2_node_id, None);
|
||||||
let backslash_mn_id = mark_node_pool.add(backslash_mn);
|
let backslash_mn_id = mark_node_pool.add(backslash_mn);
|
||||||
|
|
||||||
let arg_idents: Vec<&Ident> =
|
let arg_idents: Vec<&Ident> =
|
||||||
args.iter(env.pool).map(
|
args.iter(env.pool)
|
||||||
| (_, arg_node_id) | {
|
.map(|(_, arg_node_id)| {
|
||||||
let arg_pattern2 = env.pool.get(*arg_node_id);
|
let arg_pattern2 = env.pool.get(*arg_node_id);
|
||||||
|
|
||||||
match arg_pattern2 {
|
match arg_pattern2 {
|
||||||
Pattern2::Identifier(id_symbol) => {
|
Pattern2::Identifier(id_symbol) => {
|
||||||
let ident_id = id_symbol.ident_id();
|
let ident_id = id_symbol.ident_id();
|
||||||
let ident =
|
let ident = env.ident_ids.get_name(ident_id).with_context(|| {
|
||||||
env
|
IdentIdNotFound {
|
||||||
.ident_ids
|
ident_id,
|
||||||
.get_name(ident_id)
|
env_ident_ids_str: format!("{:?}", env.ident_ids),
|
||||||
.with_context(|| IdentIdNotFound {
|
}
|
||||||
ident_id,
|
});
|
||||||
env_ident_ids_str: format!("{:?}", env.ident_ids),
|
|
||||||
});
|
|
||||||
|
|
||||||
ident
|
ident
|
||||||
},
|
}
|
||||||
other => {
|
other => {
|
||||||
todo!("TODO: support the following pattern2 as function arg: {:?}", other);
|
todo!(
|
||||||
|
"TODO: support the following pattern2 as function arg: {:?}",
|
||||||
|
other
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
)
|
.collect::<ASTResult<Vec<&Ident>>>()?;
|
||||||
.collect::<ASTResult<Vec<&Ident>>>()?;
|
|
||||||
|
|
||||||
let arg_names =
|
let arg_names = arg_idents
|
||||||
arg_idents.iter().map(|ident| {
|
.iter()
|
||||||
ident.as_inline_str().as_str()
|
.map(|ident| ident.as_inline_str().as_str());
|
||||||
});
|
|
||||||
|
let arg_mark_nodes =
|
||||||
|
arg_names.map(|arg_name| new_arg_name_mn(arg_name.to_string(), expr2_node_id));
|
||||||
|
|
||||||
|
let commas = (0..(arg_mark_nodes.len() - 1)).map(|_| new_comma_mn(expr2_node_id, None));
|
||||||
|
|
||||||
let arg_mark_nodes = arg_names.map(
|
|
||||||
|arg_name|
|
|
||||||
new_arg_name_mn(arg_name.to_string(), expr2_node_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
let commas =
|
|
||||||
(0..(arg_mark_nodes.len() - 1)).map(
|
|
||||||
|_|
|
|
||||||
new_comma_mn(expr2_node_id, None)
|
|
||||||
);
|
|
||||||
|
|
||||||
let args_with_commas: Vec<MarkupNode> = arg_mark_nodes.interleave(commas).collect_vec();
|
let args_with_commas: Vec<MarkupNode> = arg_mark_nodes.interleave(commas).collect_vec();
|
||||||
|
|
||||||
let mut args_with_commas_ids: Vec<MarkNodeId> =
|
let mut args_with_commas_ids: Vec<MarkNodeId> = args_with_commas
|
||||||
args_with_commas.into_iter().map(
|
.into_iter()
|
||||||
|mark_node|
|
.map(|mark_node| mark_node_pool.add(mark_node))
|
||||||
mark_node_pool.add(mark_node)
|
.collect();
|
||||||
).collect();
|
|
||||||
|
|
||||||
let arrow_mn =
|
let arrow_mn = new_arrow_mn(ASTNodeId::AExprId(expr2_node_id), 1);
|
||||||
new_arrow_mn(
|
|
||||||
ASTNodeId::AExprId(expr2_node_id),
|
|
||||||
1
|
|
||||||
);
|
|
||||||
let arrow_mn_id = mark_node_pool.add(arrow_mn);
|
let arrow_mn_id = mark_node_pool.add(arrow_mn);
|
||||||
|
|
||||||
let mut children_ids = vec![backslash_mn_id];
|
let mut children_ids = vec![backslash_mn_id];
|
||||||
children_ids.append(&mut args_with_commas_ids);
|
children_ids.append(&mut args_with_commas_ids);
|
||||||
children_ids.push(arrow_mn_id);
|
children_ids.push(arrow_mn_id);
|
||||||
|
|
||||||
let args_mn = MarkupNode::Nested {
|
let args_mn = MarkupNode::Nested {
|
||||||
ast_node_id: ASTNodeId::AExprId(expr2_node_id),
|
ast_node_id: ASTNodeId::AExprId(expr2_node_id),
|
||||||
children_ids,
|
children_ids,
|
||||||
|
@ -327,7 +344,7 @@ pub fn expr2_to_markup<'a, 'b>(
|
||||||
*body_id,
|
*body_id,
|
||||||
mark_node_pool,
|
mark_node_pool,
|
||||||
interns,
|
interns,
|
||||||
indent_level + 1
|
indent_level + 1,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let function_node = MarkupNode::Nested {
|
let function_node = MarkupNode::Nested {
|
||||||
|
@ -359,4 +376,4 @@ fn with_indent(indent_level: usize, some_str: &str) -> String {
|
||||||
full_string.push_str(some_str);
|
full_string.push_str(some_str);
|
||||||
|
|
||||||
full_string
|
full_string
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,17 @@
|
||||||
use roc_ast::lang::core::{ast::ASTNodeId, expr::expr2::ExprId, header::AppHeader};
|
use roc_ast::lang::core::{ast::ASTNodeId, expr::expr2::ExprId, header::AppHeader};
|
||||||
|
|
||||||
use crate::{markup::{attribute::Attributes, common_nodes::{new_comma_mn, new_left_accolade_mn, new_left_square_mn, new_right_accolade_mn, new_right_square_mn}, nodes::{MarkupNode, set_parent_for_all}}, slow_pool::{MarkNodeId, SlowPool}, syntax_highlight::HighlightStyle};
|
use crate::{
|
||||||
|
markup::{
|
||||||
|
attribute::Attributes,
|
||||||
|
common_nodes::{
|
||||||
|
new_comma_mn, new_left_accolade_mn, new_left_square_mn, new_right_accolade_mn,
|
||||||
|
new_right_square_mn,
|
||||||
|
},
|
||||||
|
nodes::{set_parent_for_all, MarkupNode},
|
||||||
|
},
|
||||||
|
slow_pool::{MarkNodeId, SlowPool},
|
||||||
|
syntax_highlight::HighlightStyle,
|
||||||
|
};
|
||||||
|
|
||||||
pub fn header_to_markup(app_header: &AppHeader, mark_node_pool: &mut SlowPool) -> MarkNodeId {
|
pub fn header_to_markup(app_header: &AppHeader, mark_node_pool: &mut SlowPool) -> MarkNodeId {
|
||||||
let expr_id = app_header.ast_node_id;
|
let expr_id = app_header.ast_node_id;
|
||||||
|
@ -192,4 +202,4 @@ fn header_val_mn(
|
||||||
};
|
};
|
||||||
|
|
||||||
mark_node_pool.add(mark_node)
|
mark_node_pool.add(mark_node)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
pub mod from_ast;
|
pub mod from_ast;
|
||||||
pub mod from_def2;
|
pub mod from_def2;
|
||||||
pub mod from_expr2;
|
pub mod from_expr2;
|
||||||
pub mod from_header;
|
pub mod from_header;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
pub mod attribute;
|
pub mod attribute;
|
||||||
pub mod common_nodes;
|
pub mod common_nodes;
|
||||||
pub mod nodes;
|
|
||||||
pub mod convert;
|
pub mod convert;
|
||||||
|
pub mod nodes;
|
||||||
pub mod top_level_def;
|
pub mod top_level_def;
|
||||||
|
|
|
@ -4,12 +4,13 @@ use crate::{
|
||||||
syntax_highlight::HighlightStyle,
|
syntax_highlight::HighlightStyle,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::attribute::Attributes;
|
||||||
attribute::Attributes
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::markup_error::{ExpectedTextNode, NestedNodeMissingChild, NestedNodeRequired};
|
use crate::markup_error::{ExpectedTextNode, NestedNodeMissingChild, NestedNodeRequired};
|
||||||
use roc_ast::{lang::{core::ast::ASTNodeId, env::Env}, mem_pool::pool_str::PoolStr};
|
use roc_ast::{
|
||||||
|
lang::{core::ast::ASTNodeId, env::Env},
|
||||||
|
mem_pool::pool_str::PoolStr,
|
||||||
|
};
|
||||||
use roc_utils::{index_of, slice_get};
|
use roc_utils::{index_of, slice_get};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
@ -39,7 +40,7 @@ pub enum MarkupNode {
|
||||||
ast_node_id: ASTNodeId,
|
ast_node_id: ASTNodeId,
|
||||||
indent_level: usize,
|
indent_level: usize,
|
||||||
parent_id_opt: Option<MarkNodeId>,
|
parent_id_opt: Option<MarkNodeId>,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MarkupNode {
|
impl MarkupNode {
|
||||||
|
@ -161,7 +162,9 @@ impl MarkupNode {
|
||||||
MarkupNode::Nested { .. } => "".to_owned(),
|
MarkupNode::Nested { .. } => "".to_owned(),
|
||||||
MarkupNode::Text { content, .. } => content.clone(),
|
MarkupNode::Text { content, .. } => content.clone(),
|
||||||
MarkupNode::Blank { .. } => BLANK_PLACEHOLDER.to_owned(),
|
MarkupNode::Blank { .. } => BLANK_PLACEHOLDER.to_owned(),
|
||||||
MarkupNode::Indent { indent_level, .. } => std::iter::repeat( SINGLE_INDENT).take(*indent_level).collect(),
|
MarkupNode::Indent { indent_level, .. } => std::iter::repeat(SINGLE_INDENT)
|
||||||
|
.take(*indent_level)
|
||||||
|
.collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,7 +297,7 @@ pub fn new_markup_node(
|
||||||
let indent_node = MarkupNode::Indent {
|
let indent_node = MarkupNode::Indent {
|
||||||
ast_node_id: node_id,
|
ast_node_id: node_id,
|
||||||
indent_level,
|
indent_level,
|
||||||
parent_id_opt: None
|
parent_id_opt: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let indent_node_id = mark_node_pool.add(indent_node);
|
let indent_node_id = mark_node_pool.add(indent_node);
|
||||||
|
@ -359,7 +362,6 @@ pub fn set_parent_for_all_helper(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl fmt::Display for MarkupNode {
|
impl fmt::Display for MarkupNode {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(
|
write!(
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
use roc_ast::{ast_error::{ASTResult}, lang::{
|
use roc_ast::{
|
||||||
core::{
|
ast_error::ASTResult,
|
||||||
ast::ASTNodeId
|
lang::{core::ast::ASTNodeId, env::Env},
|
||||||
},
|
};
|
||||||
env::Env,
|
use roc_module::symbol::IdentId;
|
||||||
}};
|
|
||||||
use roc_module::symbol::{IdentId};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
markup::{attribute::Attributes, common_nodes::new_equals_mn, nodes::MarkupNode},
|
markup::{attribute::Attributes, common_nodes::new_equals_mn, nodes::MarkupNode},
|
||||||
|
@ -17,10 +15,9 @@ pub fn tld_mark_node<'a>(
|
||||||
expr_mark_node_id: MarkNodeId,
|
expr_mark_node_id: MarkNodeId,
|
||||||
ast_node_id: ASTNodeId,
|
ast_node_id: ASTNodeId,
|
||||||
mark_node_pool: &mut SlowPool,
|
mark_node_pool: &mut SlowPool,
|
||||||
env: &Env<'a>
|
env: &Env<'a>,
|
||||||
) -> ASTResult<MarkupNode> {
|
) -> ASTResult<MarkupNode> {
|
||||||
let val_name =
|
let val_name = env.get_name_for_ident_id(identifier_id)?;
|
||||||
env.get_name_for_ident_id(identifier_id)?;
|
|
||||||
|
|
||||||
let val_name_mn = MarkupNode::Text {
|
let val_name_mn = MarkupNode::Text {
|
||||||
content: val_name.to_owned(),
|
content: val_name.to_owned(),
|
||||||
|
|
|
@ -137,7 +137,12 @@ fn run_event_loop(project_dir_path_opt: Option<&Path>) -> Result<(), Box<dyn Err
|
||||||
let dep_idents = IdentIds::exposed_builtins(8);
|
let dep_idents = IdentIds::exposed_builtins(8);
|
||||||
let exposed_ident_ids = IdentIds::default();
|
let exposed_ident_ids = IdentIds::default();
|
||||||
let module_ids = loaded_module.interns.module_ids.clone();
|
let module_ids = loaded_module.interns.module_ids.clone();
|
||||||
let all_ident_ids = loaded_module.interns.all_ident_ids.get(&loaded_module.module_id).unwrap().clone(); //TODO remove unwrap
|
let all_ident_ids = loaded_module
|
||||||
|
.interns
|
||||||
|
.all_ident_ids
|
||||||
|
.get(&loaded_module.module_id)
|
||||||
|
.unwrap()
|
||||||
|
.clone(); //TODO remove unwrap
|
||||||
|
|
||||||
let env = Env::new(
|
let env = Env::new(
|
||||||
loaded_module.module_id,
|
loaded_module.module_id,
|
||||||
|
|
|
@ -242,8 +242,13 @@ pub mod test_ed_model {
|
||||||
&mut ed_model_refs.var_store,
|
&mut ed_model_refs.var_store,
|
||||||
dep_idents,
|
dep_idents,
|
||||||
module_ids,
|
module_ids,
|
||||||
loaded_module.interns.all_ident_ids.get(&loaded_module.module_id).unwrap().clone(),
|
loaded_module
|
||||||
exposed_ident_ids
|
.interns
|
||||||
|
.all_ident_ids
|
||||||
|
.get(&loaded_module.module_id)
|
||||||
|
.unwrap()
|
||||||
|
.clone(),
|
||||||
|
exposed_ident_ids,
|
||||||
);
|
);
|
||||||
|
|
||||||
ed_model::init_model(
|
ed_model::init_model(
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
use roc_ast::{
|
use roc_ast::lang::{
|
||||||
lang::{
|
core::{ast::ASTNodeId, def::def2::Def2, expr::expr2::Expr2},
|
||||||
core::{
|
env::Env,
|
||||||
ast::ASTNodeId,
|
|
||||||
def::def2::Def2,
|
|
||||||
expr::expr2::Expr2,
|
|
||||||
},
|
|
||||||
env::Env,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use roc_code_markup::{
|
use roc_code_markup::{
|
||||||
markup::{
|
markup::{
|
||||||
|
@ -17,7 +11,7 @@ use roc_code_markup::{
|
||||||
slow_pool::{MarkNodeId, SlowPool},
|
slow_pool::{MarkNodeId, SlowPool},
|
||||||
syntax_highlight::HighlightStyle,
|
syntax_highlight::HighlightStyle,
|
||||||
};
|
};
|
||||||
use roc_module::symbol::{IdentId};
|
use roc_module::symbol::IdentId;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
editor::ed_error::{EdResult, FailedToUpdateIdentIdName, KeyNotFound},
|
editor::ed_error::{EdResult, FailedToUpdateIdentIdName, KeyNotFound},
|
||||||
|
@ -37,7 +31,7 @@ pub fn tld_mark_node<'a>(
|
||||||
expr_mark_node_id: MarkNodeId,
|
expr_mark_node_id: MarkNodeId,
|
||||||
ast_node_id: ASTNodeId,
|
ast_node_id: ASTNodeId,
|
||||||
mark_node_pool: &mut SlowPool,
|
mark_node_pool: &mut SlowPool,
|
||||||
env: &Env<'a>
|
env: &Env<'a>,
|
||||||
) -> EdResult<MarkupNode> {
|
) -> EdResult<MarkupNode> {
|
||||||
let val_name = env.get_name_for_ident_id(identifier_id)?;
|
let val_name = env.get_name_for_ident_id(identifier_id)?;
|
||||||
|
|
||||||
|
@ -108,7 +102,7 @@ pub fn start_new_tld_value(ed_model: &mut EdModel, new_char: &char) -> EdResult<
|
||||||
val_expr_mn_id,
|
val_expr_mn_id,
|
||||||
ast_node_id,
|
ast_node_id,
|
||||||
&mut ed_model.mark_node_pool,
|
&mut ed_model.mark_node_pool,
|
||||||
&ed_model.module.env
|
&ed_model.module.env,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let new_ast_node = Def2::ValueDef {
|
let new_ast_node = Def2::ValueDef {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::editor::{ed_error::EdResult, theme::EdTheme, util::map_get};
|
||||||
use crate::graphics::primitives::rect::Rect;
|
use crate::graphics::primitives::rect::Rect;
|
||||||
use crate::graphics::primitives::text as gr_text;
|
use crate::graphics::primitives::text as gr_text;
|
||||||
use cgmath::Vector2;
|
use cgmath::Vector2;
|
||||||
use roc_code_markup::markup::nodes::{BLANK_PLACEHOLDER, MarkupNode, SINGLE_INDENT};
|
use roc_code_markup::markup::nodes::{MarkupNode, BLANK_PLACEHOLDER, SINGLE_INDENT};
|
||||||
use roc_code_markup::slow_pool::{MarkNodeId, SlowPool};
|
use roc_code_markup::slow_pool::{MarkNodeId, SlowPool};
|
||||||
use roc_code_markup::syntax_highlight::HighlightStyle;
|
use roc_code_markup::syntax_highlight::HighlightStyle;
|
||||||
use winit::dpi::PhysicalSize;
|
use winit::dpi::PhysicalSize;
|
||||||
|
@ -157,7 +157,8 @@ fn markup_to_wgpu_helper<'a>(
|
||||||
.with_color(colors::to_slice(colors::WHITE))
|
.with_color(colors::to_slice(colors::WHITE))
|
||||||
.with_scale(code_style.font_size);
|
.with_scale(code_style.font_size);
|
||||||
|
|
||||||
let highlight_color = map_get(&code_style.ed_theme.syntax_high_map, &HighlightStyle::Blank)?;
|
let highlight_color =
|
||||||
|
map_get(&code_style.ed_theme.syntax_high_map, &HighlightStyle::Blank)?;
|
||||||
|
|
||||||
let char_width = code_style.glyph_dim_rect.width;
|
let char_width = code_style.glyph_dim_rect.width;
|
||||||
let char_height = code_style.glyph_dim_rect.height;
|
let char_height = code_style.glyph_dim_rect.height;
|
||||||
|
@ -193,7 +194,7 @@ fn markup_to_wgpu_helper<'a>(
|
||||||
.with_color(colors::to_slice(colors::WHITE))
|
.with_color(colors::to_slice(colors::WHITE))
|
||||||
.with_scale(code_style.font_size);
|
.with_scale(code_style.font_size);
|
||||||
|
|
||||||
wgpu_texts.push(glyph_text);
|
wgpu_texts.push(glyph_text);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue