diff --git a/src/emit/mod.rs b/src/emit/mod.rs index 11985e8..daf8e0d 100644 --- a/src/emit/mod.rs +++ b/src/emit/mod.rs @@ -123,14 +123,16 @@ fn emit_ast_expr( { previous_post_whitespace_content = post_whitespace_content; if let Some(ws) = prev_whitespace_content { + let idx = end_indices.last().copied(); eval.insert( - eval.len() - 2, + idx.unwrap_or(eval.len()), Instruction::AppendContent { content: ws.source().clone(), }, ); - let index_index = end_indices.len() - 1; - end_indices[index_index] += 1; + if let Some(idx) = end_indices.last_mut() { + *idx += 1; + } } if let TemplateAstExpr::IfConditional { expression } = &**expression { diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 20f2a14..a9171f0 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -383,10 +383,10 @@ fn parse_block_token<'input>(input: &mut Input<'input>) -> PResult<'input, Templ "parse_block_token", alt(( parse_ident, - parse_literal, - parse_condition_if, - parse_condition_else, - parse_end, + terminated(parse_literal, ident_terminator_check), + terminated(parse_condition_if, ident_terminator_check), + terminated(parse_condition_else, ident_terminator_check), + terminated(parse_end, ident_terminator_check), parse_whitespace, )), ) diff --git a/tests/checks.rs b/tests/checks.rs new file mode 100644 index 0000000..900fd9f --- /dev/null +++ b/tests/checks.rs @@ -0,0 +1,14 @@ +#[test] +fn check_files() { + let files = std::fs::read_dir("tests/checks/").unwrap(); + + for file in files { + let input = std::fs::read_to_string(file.unwrap().path()).unwrap(); + + let parsed = nomo::parser::parse(input.into()).unwrap(); + + let ast = nomo::ast::parse(parsed.tokens()).unwrap(); + + let _emit = nomo::emit::emit_machine(ast); + } +} diff --git a/tests/checks/minimized-from-20a1f84df1a8d2c7ef7e9d538d6270e0379ab83e b/tests/checks/minimized-from-20a1f84df1a8d2c7ef7e9d538d6270e0379ab83e new file mode 100644 index 0000000..94cc156 --- /dev/null +++ b/tests/checks/minimized-from-20a1f84df1a8d2c7ef7e9d538d6270e0379ab83e @@ -0,0 +1,2 @@ + +{{if en}}{{ end}} \ No newline at end of file