mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-10 18:08:55 +03:00
no more compile errors :)
This commit is contained in:
parent
45629a38d1
commit
435789b807
@ -43,6 +43,13 @@ pub enum EdError {
|
||||
backtrace: Backtrace,
|
||||
},
|
||||
|
||||
#[snafu(display(
|
||||
"EmptyCodeString: I need to have a code string (code_str) that contains either an app, interface or Package-Config header. The code string was empty.",
|
||||
))]
|
||||
EmptyCodeString {
|
||||
backtrace: Backtrace,
|
||||
},
|
||||
|
||||
#[snafu(display("GetContentOnNestedNode: tried to get string content from Nested MarkupNode. Can only get content from Text or Blank nodes."))]
|
||||
GetContentOnNestedNode { backtrace: Backtrace },
|
||||
|
||||
|
@ -1,10 +1,9 @@
|
||||
use crate::editor::code_lines::CodeLines;
|
||||
use crate::editor::grid_node_map::GridNodeMap;
|
||||
use crate::editor::markup::common_nodes::new_blank_mn;
|
||||
use crate::editor::slow_pool::{MarkNodeId, SlowPool};
|
||||
use crate::editor::{
|
||||
ed_error::EdError::SrcParseError,
|
||||
ed_error::{EdResult, MissingParent, NoNodeAtCaretPosition},
|
||||
ed_error::{EdResult, MissingParent, NoNodeAtCaretPosition, EmptyCodeString},
|
||||
markup::nodes::{expr2_to_markup, set_parent_for_all},
|
||||
};
|
||||
use crate::graphics::primitives::rect::Rect;
|
||||
@ -29,7 +28,7 @@ pub struct EdModel<'a> {
|
||||
pub code_lines: CodeLines,
|
||||
// allows us to map window coordinates to MarkNodeId's
|
||||
pub grid_node_map: GridNodeMap,
|
||||
pub markup_root_id: MarkNodeId,
|
||||
pub markup_ids: Vec<MarkNodeId>, // one root node for every expression
|
||||
pub markup_node_pool: SlowPool,
|
||||
// contains single char dimensions, used to calculate line height, column width...
|
||||
pub glyph_dim_rect_opt: Option<Rect>,
|
||||
@ -59,39 +58,45 @@ pub fn init_model<'a>(
|
||||
|
||||
let mut module = EdModule::new(&code_str, env, &code_arena)?;
|
||||
|
||||
let ast_root_id = module.ast_root_id;
|
||||
let mut markup_node_pool = SlowPool::new();
|
||||
|
||||
let markup_root_id = if code_str.is_empty() {
|
||||
markup_node_pool
|
||||
.add(
|
||||
new_blank_mn(ast_root_id, None)
|
||||
)
|
||||
let markup_ids = if code_str.is_empty() {
|
||||
|
||||
EmptyCodeString{}.fail()
|
||||
|
||||
} else {
|
||||
let ast_root = &module.env.pool.get(ast_root_id);
|
||||
let mut temp_markup_ids = Vec::new();
|
||||
|
||||
let temp_markup_root_id = expr2_to_markup(
|
||||
&code_arena,
|
||||
&mut module.env,
|
||||
ast_root,
|
||||
ast_root_id,
|
||||
&mut markup_node_pool,
|
||||
&loaded_module.interns
|
||||
)?;
|
||||
set_parent_for_all(temp_markup_root_id, &mut markup_node_pool);
|
||||
for &expr_id in module.ast.expression_ids.iter() {
|
||||
let expr2 = module.env.pool.get(expr_id);
|
||||
|
||||
temp_markup_root_id
|
||||
};
|
||||
let temp_markup_id = expr2_to_markup(
|
||||
&code_arena,
|
||||
&mut module.env,
|
||||
expr2,
|
||||
expr_id,
|
||||
&mut markup_node_pool,
|
||||
&loaded_module.interns
|
||||
)?;
|
||||
|
||||
let code_lines = EdModel::build_code_lines_from_markup(markup_root_id, &markup_node_pool)?;
|
||||
let grid_node_map = EdModel::build_node_map_from_markup(markup_root_id, &markup_node_pool)?;
|
||||
// it's easier to set the parent of the MarkupNodes afterwards
|
||||
set_parent_for_all(temp_markup_id, &mut markup_node_pool);
|
||||
|
||||
temp_markup_ids.push(temp_markup_id);
|
||||
}
|
||||
|
||||
Ok(temp_markup_ids)
|
||||
}?;
|
||||
|
||||
let code_lines = EdModel::build_code_lines_from_markup(&markup_ids, &markup_node_pool)?;
|
||||
let grid_node_map = EdModel::build_node_map_from_markup(&markup_ids, &markup_node_pool)?;
|
||||
|
||||
Ok(EdModel {
|
||||
module,
|
||||
file_path,
|
||||
code_lines,
|
||||
grid_node_map,
|
||||
markup_root_id,
|
||||
markup_ids,
|
||||
markup_node_pool,
|
||||
glyph_dim_rect_opt: None,
|
||||
has_focus: true,
|
||||
@ -167,7 +172,7 @@ impl<'a> EdModule<'a> {
|
||||
pub fn new(code_str: &'a str, mut env: Env<'a>, ast_arena: &'a Bump) -> EdResult<EdModule<'a>> {
|
||||
if !code_str.is_empty() {
|
||||
|
||||
let parse_res = AST::parse_from_string(code_str, env, ast_arena);
|
||||
let parse_res = AST::parse_from_string(code_str, &mut env, ast_arena);
|
||||
|
||||
match parse_res {
|
||||
Ok(ast) => {
|
||||
@ -184,17 +189,7 @@ impl<'a> EdModule<'a> {
|
||||
}
|
||||
|
||||
} else {
|
||||
let ast_root_id = env.pool.add(Expr2::Blank);
|
||||
|
||||
Ok(
|
||||
EdModule {
|
||||
env,
|
||||
ast: AST {
|
||||
header: "".to_string(),
|
||||
expressions: vec![ast_root_id],
|
||||
}
|
||||
}
|
||||
)
|
||||
EmptyCodeString{}.fail()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -93,12 +93,16 @@ impl<'a> EdModel<'a> {
|
||||
}
|
||||
|
||||
pub fn build_node_map_from_markup(
|
||||
markup_root_id: MarkNodeId,
|
||||
markup_ids: &[MarkNodeId],
|
||||
markup_node_pool: &SlowPool,
|
||||
) -> EdResult<GridNodeMap> {
|
||||
let mut grid_node_map = GridNodeMap::new();
|
||||
|
||||
EdModel::build_grid_node_map(markup_root_id, &mut grid_node_map, markup_node_pool)?;
|
||||
for mark_id in markup_ids.iter() {
|
||||
EdModel::build_grid_node_map(*mark_id, &mut grid_node_map, markup_node_pool)?;
|
||||
|
||||
grid_node_map.lines.push(Vec::new());
|
||||
}
|
||||
|
||||
Ok(grid_node_map)
|
||||
}
|
||||
@ -128,12 +132,16 @@ impl<'a> EdModel<'a> {
|
||||
}
|
||||
|
||||
pub fn build_code_lines_from_markup(
|
||||
markup_root_id: MarkNodeId,
|
||||
markup_node_ids: &[MarkNodeId],
|
||||
markup_node_pool: &SlowPool,
|
||||
) -> EdResult<CodeLines> {
|
||||
let mut all_code_string = String::new();
|
||||
|
||||
EdModel::build_markup_string(markup_root_id, &mut all_code_string, markup_node_pool)?;
|
||||
for mark_node_id in markup_node_ids.iter() {
|
||||
EdModel::build_markup_string(*mark_node_id, &mut all_code_string, markup_node_pool)?;
|
||||
|
||||
all_code_string.push_str("\n")
|
||||
}
|
||||
|
||||
let code_lines = CodeLines::from_str(&all_code_string);
|
||||
|
||||
|
@ -75,7 +75,7 @@ pub fn model_to_wgpu<'a>(
|
||||
all_rendered.add_text(start_tip_text);
|
||||
|
||||
let rendered_code_graphics = build_code_graphics(
|
||||
ed_model.markup_node_pool.get(ed_model.markup_root_id),
|
||||
&ed_model.markup_ids,
|
||||
size,
|
||||
txt_coords,
|
||||
config,
|
||||
|
@ -1,4 +1,5 @@
|
||||
use super::markup::nodes::{MarkupNode, BLANK_PLACEHOLDER};
|
||||
use super::slow_pool::MarkNodeId;
|
||||
use crate::editor::mvc::ed_view::RenderedWgpu;
|
||||
use crate::editor::slow_pool::SlowPool;
|
||||
use crate::editor::{ed_error::EdResult, theme::EdTheme, util::map_get};
|
||||
@ -10,7 +11,7 @@ use winit::dpi::PhysicalSize;
|
||||
use crate::{editor::config::Config, graphics::colors};
|
||||
|
||||
pub fn build_code_graphics<'a>(
|
||||
markup_node: &'a MarkupNode,
|
||||
markup_ids: &[MarkNodeId],
|
||||
size: &PhysicalSize<u32>,
|
||||
txt_coords: Vector2<f32>,
|
||||
config: &Config,
|
||||
@ -21,25 +22,35 @@ pub fn build_code_graphics<'a>(
|
||||
let layout = wgpu_glyph::Layout::default().h_align(wgpu_glyph::HorizontalAlign::Left);
|
||||
let mut rendered_wgpu = RenderedWgpu::new();
|
||||
|
||||
let (glyph_text_vec, rects) = markup_to_wgpu(
|
||||
markup_node,
|
||||
&CodeStyle {
|
||||
ed_theme: &config.ed_theme,
|
||||
font_size: config.code_font_size,
|
||||
txt_coords,
|
||||
glyph_dim_rect,
|
||||
},
|
||||
markup_node_pool,
|
||||
)?;
|
||||
let mut all_glyph_text_vec = vec![];
|
||||
let mut all_rects = vec![];
|
||||
|
||||
for markup_id in markup_ids.iter() {
|
||||
let mark_node = markup_node_pool.get(*markup_id);
|
||||
|
||||
let (mut glyph_text_vec, mut rects) = markup_to_wgpu(
|
||||
mark_node,
|
||||
&CodeStyle {
|
||||
ed_theme: &config.ed_theme,
|
||||
font_size: config.code_font_size,
|
||||
txt_coords,
|
||||
glyph_dim_rect,
|
||||
},
|
||||
markup_node_pool,
|
||||
)?;
|
||||
|
||||
all_glyph_text_vec.append(&mut glyph_text_vec);
|
||||
all_rects.append(&mut rects)
|
||||
}
|
||||
|
||||
let section = gr_text::owned_section_from_glyph_texts(
|
||||
glyph_text_vec,
|
||||
all_glyph_text_vec,
|
||||
txt_coords.into(),
|
||||
area_bounds,
|
||||
layout,
|
||||
);
|
||||
|
||||
rendered_wgpu.add_rects(rects);
|
||||
rendered_wgpu.add_rects(all_rects);
|
||||
rendered_wgpu.add_text(section);
|
||||
|
||||
Ok(rendered_wgpu)
|
||||
|
@ -29,10 +29,22 @@ pub fn build_debug_graphics(
|
||||
.with_color(colors::to_slice(from_hsb(0, 49, 96)))
|
||||
.with_scale(config.code_font_size);
|
||||
|
||||
let mark_node_tree_text = glyph_brush::OwnedText::new(tree_as_string(
|
||||
ed_model.markup_root_id,
|
||||
&ed_model.markup_node_pool,
|
||||
))
|
||||
let mut mark_node_trees_string = "mark node trees:\n".to_owned();
|
||||
|
||||
for mark_id in ed_model.markup_ids.iter() {
|
||||
|
||||
mark_node_trees_string.push_str(
|
||||
&tree_as_string(
|
||||
*mark_id,
|
||||
&ed_model.markup_node_pool,
|
||||
));
|
||||
|
||||
mark_node_trees_string.push_str("\n");
|
||||
}
|
||||
|
||||
let mark_node_tree_text = glyph_brush::OwnedText::new(
|
||||
mark_node_trees_string
|
||||
)
|
||||
.with_color(colors::to_slice(from_hsb(266, 31, 96)))
|
||||
.with_scale(config.code_font_size);
|
||||
|
||||
@ -40,10 +52,18 @@ pub fn build_debug_graphics(
|
||||
.with_color(colors::to_slice(from_hsb(110, 45, 82)))
|
||||
.with_scale(config.code_font_size);
|
||||
|
||||
let ast_node_text = glyph_brush::OwnedText::new(format!(
|
||||
"\n\n(ast_root)\n{}",
|
||||
expr2_to_string(ed_model.module.ast_root_id, ed_model.module.env.pool)
|
||||
))
|
||||
|
||||
let mut ast_node_text_str = "AST:\n".to_owned();
|
||||
|
||||
for expr_id in ed_model.module.ast.expression_ids.iter() {
|
||||
ast_node_text_str.push_str(
|
||||
&expr2_to_string(*expr_id, ed_model.module.env.pool)
|
||||
)
|
||||
}
|
||||
|
||||
let ast_node_text = glyph_brush::OwnedText::new(
|
||||
ast_node_text_str
|
||||
)
|
||||
.with_color(colors::to_slice(from_hsb(211, 80, 100)))
|
||||
.with_scale(config.code_font_size);
|
||||
|
||||
|
@ -296,7 +296,6 @@ pub fn str_to_expr2<'a>(
|
||||
) -> Result<(Expr2, self::Output), SyntaxError<'a>> {
|
||||
match roc_parse::test_helpers::parse_loc_with(arena, input.trim()) {
|
||||
Ok(loc_expr) => {
|
||||
dbg!(loc_expr);
|
||||
let desugared_loc_expr = desugar_expr(arena, arena.alloc(loc_expr));
|
||||
|
||||
Ok(to_expr2(
|
||||
|
@ -11,13 +11,13 @@ use super::{ast::ExprId, expr::{Env, str_to_expr2}};
|
||||
#[derive(Debug)]
|
||||
pub struct AST {
|
||||
pub header: String,
|
||||
pub expressions: Vec<ExprId>,
|
||||
pub expression_ids: Vec<ExprId>,
|
||||
}
|
||||
|
||||
impl AST {
|
||||
pub fn parse_from_string<'a>(code_str: &str, mut env: Env<'a>, ast_arena: &Bump) -> Result<AST, SyntaxError<'a>> {
|
||||
pub fn parse_from_string<'a>(code_str: &'a str, env: &mut Env<'a>, ast_arena: &'a Bump) -> Result<AST, SyntaxError<'a>> {
|
||||
|
||||
let mut split_string = code_str.split("\n\n");
|
||||
let split_string = code_str.split("\n\n");
|
||||
|
||||
let split_code_vec: Vec<&str> = split_string.collect();
|
||||
|
||||
@ -27,24 +27,21 @@ impl AST {
|
||||
|
||||
let region = Region::new(0, 0, 0, 0);
|
||||
|
||||
let expressions =
|
||||
tail
|
||||
.iter()
|
||||
.map(|&expr_str|
|
||||
{
|
||||
let (expr2, _output) = str_to_expr2(&ast_arena, code_str, &mut env, &mut scope, region)?;
|
||||
let mut expression_ids = Vec::<ExprId>::new();
|
||||
|
||||
let expr_id = env.pool.add(expr2);
|
||||
for &expr_str in tail.iter() {
|
||||
let (expr2, _output) = str_to_expr2(&ast_arena, expr_str, env, &mut scope, region)?;
|
||||
|
||||
expr_id
|
||||
}
|
||||
).collect::<Vec<_>>();
|
||||
let expr_id = env.pool.add(expr2);
|
||||
|
||||
expression_ids.push(expr_id);
|
||||
}
|
||||
|
||||
|
||||
Ok(
|
||||
AST {
|
||||
header: head.to_string(),
|
||||
expressions,
|
||||
expression_ids,
|
||||
}
|
||||
)
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user