From 49aaa1bcd13551a37866b82db275908dfaf85154 Mon Sep 17 00:00:00 2001 From: Sebastian Walter Date: Thu, 10 Oct 2024 17:22:42 +0200 Subject: [PATCH] fix byte span --- src/grammar.rs | 4 ++-- text-utils-grammar/src/lr1.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/grammar.rs b/src/grammar.rs index d3a86bc..3bbf4cc 100644 --- a/src/grammar.rs +++ b/src/grammar.rs @@ -479,9 +479,9 @@ fn parse_into_py( } LR1Parse::Terminal(name, span, value) => { dict.set_item("name", name)?; - let &(start, len) = span; + let &(start, end) = span; dict.set_item("value", String::from_utf8_lossy(value))?; - dict.set_item("byte_span", (start, start + len))?; + dict.set_item("byte_span", (start, end))?; } LR1Parse::NonTerminal(name, children) => { dict.set_item("name", name)?; diff --git a/text-utils-grammar/src/lr1.rs b/text-utils-grammar/src/lr1.rs index 3d51323..395b234 100644 --- a/text-utils-grammar/src/lr1.rs +++ b/text-utils-grammar/src/lr1.rs @@ -516,13 +516,13 @@ impl LR1GrammarParser { }) } - fn filter_lr1(node: LR1Parse<'_>, skip_empty: bool, collapse_single: bool) -> LR1Parse<'_> { + fn filter_parse(node: LR1Parse<'_>, skip_empty: bool, collapse_single: bool) -> LR1Parse<'_> { match node { LR1Parse::NonTerminal(name, children) => { let children: Vec<_> = children .into_iter() .filter_map(|node| { - let node = Self::filter_lr1(node, skip_empty, collapse_single); + let node = Self::filter_parse(node, skip_empty, collapse_single); if node.is_empty() && skip_empty { None } else { @@ -550,7 +550,7 @@ impl LR1GrammarParser { ) -> Result<(LR1Parse<'_>, &'p [u8]), Box> { let tree = self .parse_tree(prefix, true) - .map(|tree| Self::filter_lr1(tree, skip_empty, collapse_single))?; + .map(|tree| Self::filter_parse(tree, skip_empty, collapse_single))?; fn find_end(parse: &LR1Parse<'_>, end: usize) -> usize { match parse { LR1Parse::Empty(..) => end, @@ -572,7 +572,7 @@ impl LR1GrammarParser { collapse_single: bool, ) -> Result, Box> { self.parse_tree(text, false) - .map(|tree| Self::filter_lr1(tree, skip_empty, collapse_single)) + .map(|tree| Self::filter_parse(tree, skip_empty, collapse_single)) } }