mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
feat: start to render some AST nodes
This commit is contained in:
parent
55d2586316
commit
141c881cf9
3 changed files with 57 additions and 1 deletions
|
@ -16,6 +16,10 @@ use roc_module::low_level::LowLevel;
|
||||||
use roc_module::operator::CalledVia;
|
use roc_module::operator::CalledVia;
|
||||||
use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol};
|
use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol};
|
||||||
use roc_parse::ast::StrLiteral;
|
use roc_parse::ast::StrLiteral;
|
||||||
|
use roc_parse::ast::{self, Attempting};
|
||||||
|
use roc_parse::blankspace::space0_before;
|
||||||
|
use roc_parse::expr::expr;
|
||||||
|
use roc_parse::parser::{loc, Fail, Parser, State};
|
||||||
use roc_problem::can::{Problem, RuntimeError};
|
use roc_problem::can::{Problem, RuntimeError};
|
||||||
use roc_region::all::{Located, Region};
|
use roc_region::all::{Located, Region};
|
||||||
use roc_types::subs::{VarStore, Variable};
|
use roc_types::subs::{VarStore, Variable};
|
||||||
|
@ -222,6 +226,23 @@ pub fn to_expr_id<'a>(
|
||||||
(env.add(expr, region), output)
|
(env.add(expr, region), output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn str_to_expr2<'a>(
|
||||||
|
arena: &'a Bump,
|
||||||
|
input: &'a str,
|
||||||
|
env: &mut Env<'a>,
|
||||||
|
scope: &mut Scope,
|
||||||
|
region: Region,
|
||||||
|
) -> Result<(Expr2, self::Output), Fail> {
|
||||||
|
let state = State::new(input.trim().as_bytes(), Attempting::Module);
|
||||||
|
let parser = space0_before(loc(expr(0)), 0);
|
||||||
|
let answer = parser.parse(&arena, state);
|
||||||
|
|
||||||
|
answer
|
||||||
|
.map(|(loc_expr, _)| loc_expr)
|
||||||
|
.map(|loc_expr| to_expr2(env, scope, &loc_expr.value, region))
|
||||||
|
.map_err(|(fail, _)| fail)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn to_expr2<'a>(
|
pub fn to_expr2<'a>(
|
||||||
env: &mut Env<'a>,
|
env: &mut Env<'a>,
|
||||||
scope: &mut Scope,
|
scope: &mut Scope,
|
||||||
|
|
|
@ -3,7 +3,7 @@ mod def;
|
||||||
mod expr;
|
mod expr;
|
||||||
mod module;
|
mod module;
|
||||||
mod pattern;
|
mod pattern;
|
||||||
mod pool;
|
pub mod pool;
|
||||||
pub mod roc_file;
|
pub mod roc_file;
|
||||||
mod scope;
|
mod scope;
|
||||||
mod types;
|
mod types;
|
||||||
|
|
|
@ -266,6 +266,8 @@ fn run_event_loop(file_path_opt: Option<&Path>) -> Result<(), Box<dyn Error>> {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
queue_no_file_text(&size, NOTHING_OPENED, CODE_TXT_XY.into(), &mut glyph_brush);
|
queue_no_file_text(&size, NOTHING_OPENED, CODE_TXT_XY.into(), &mut glyph_brush);
|
||||||
|
let ast = crate::lang::expr::str_to_expr2();
|
||||||
|
render_node(&size, ast, CODE_TXT_XY.into(), &mut glyph_brush);
|
||||||
}
|
}
|
||||||
|
|
||||||
match draw_all_rects(
|
match draw_all_rects(
|
||||||
|
@ -364,6 +366,39 @@ fn begin_render_pass<'a>(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn render_node(
|
||||||
|
size: &PhysicalSize<u32>,
|
||||||
|
ast: Expr2,
|
||||||
|
position: Vector2<f32>,
|
||||||
|
glyph_brush: &mut GlyphBrush<()>,
|
||||||
|
) {
|
||||||
|
use Expr2::*;
|
||||||
|
|
||||||
|
let area_bounds = (size.width as f32, size.height as f32).into();
|
||||||
|
|
||||||
|
match ast {
|
||||||
|
SmallInt {
|
||||||
|
number,
|
||||||
|
..
|
||||||
|
// text,
|
||||||
|
// style, pretending always decimal for now
|
||||||
|
// var,
|
||||||
|
} => {
|
||||||
|
let code_text = Text {
|
||||||
|
position,
|
||||||
|
area_bounds,
|
||||||
|
color: CODE_COLOR.into(),
|
||||||
|
text: number.into(),
|
||||||
|
size: CODE_FONT_SIZE,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
queue_code_text_draw(&code_text, glyph_brush);
|
||||||
|
}
|
||||||
|
_ =>
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// returns bounding boxes for every glyph
|
// returns bounding boxes for every glyph
|
||||||
fn queue_editor_text(
|
fn queue_editor_text(
|
||||||
size: &PhysicalSize<u32>,
|
size: &PhysicalSize<u32>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue