From cfc9153c280abcf6167343965f44edb3194db737 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 20 Aug 2023 16:25:57 -0400 Subject: [PATCH] Handle nodes that do not have a contents begin like fixed width areas. --- src/owner_tree.rs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/owner_tree.rs b/src/owner_tree.rs index 048a511..ce56a79 100644 --- a/src/owner_tree.rs +++ b/src/owner_tree.rs @@ -98,12 +98,25 @@ fn build_ast_node<'a>( .as_atom()?; let position = get_bounds(original_source, current_token)?; let mut children = Vec::new(); - let mut contents_begin = get_contents_begin(current_token)?; - for child in parameters.into_iter().skip(2) { - let new_ast_node = build_ast_node(original_source, Some(contents_begin), child)?; - contents_begin = new_ast_node.position.end_character; - children.push(new_ast_node); - } + let original_contents_begin = get_contents_begin(current_token); + match original_contents_begin { + Ok(original_contents_begin) => { + let mut contents_begin = original_contents_begin; + for child in parameters.into_iter().skip(2) { + let new_ast_node = + build_ast_node(original_source, Some(contents_begin), child)?; + contents_begin = new_ast_node.position.end_character; + children.push(new_ast_node); + } + } + Err(_) => { + // Some nodes don't have a contents begin, so hopefully plain text can't be inside them. + for child in parameters.into_iter().skip(2) { + let new_ast_node = build_ast_node(original_source, None, child)?; + children.push(new_ast_node); + } + } + }; AstNode { name: name.to_owned(),