Skip to content

Commit

Permalink
fix byte span
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiscode committed Oct 10, 2024
1 parent 9746e3a commit 49aaa1b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
8 changes: 4 additions & 4 deletions text-utils-grammar/src/lr1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -550,7 +550,7 @@ impl LR1GrammarParser {
) -> Result<(LR1Parse<'_>, &'p [u8]), Box<dyn Error>> {
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,
Expand All @@ -572,7 +572,7 @@ impl LR1GrammarParser {
collapse_single: bool,
) -> Result<LR1Parse<'_>, Box<dyn Error>> {
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))
}
}

Expand Down

0 comments on commit 49aaa1b

Please sign in to comment.