From 1e6b6c7194f2f6a182d091edfc3e1ba49b1a0fea Mon Sep 17 00:00:00 2001 From: "Victor M. Alvarez" Date: Mon, 11 Nov 2024 22:08:53 +0100 Subject: [PATCH] fix: allow larger jumps in hex patterns. The limit was 65535 because 16-bits integers were used for storing the jump ranges. Now we are using 32-bits integers. Closes #238 --- lib/src/compiler/ir/hex2hir.rs | 4 ++-- lib/src/compiler/tests/testdata/errors/101.in | 2 +- lib/src/compiler/tests/testdata/errors/101.out | 4 ++-- parser/src/ast/cst2ast.rs | 4 ++-- parser/src/ast/mod.rs | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/src/compiler/ir/hex2hir.rs b/lib/src/compiler/ir/hex2hir.rs index 8a4f91556..1cfea8744 100644 --- a/lib/src/compiler/ir/hex2hir.rs +++ b/lib/src/compiler/ir/hex2hir.rs @@ -143,8 +143,8 @@ fn hex_sub_pattern_hir_from_ast( } hir_tokens.push(hir::Hir::repetition(hir::Repetition { - min: jump.start.map(|start| start as u32).unwrap_or(0), - max: jump.end.map(|end| end as u32), + min: jump.start.unwrap_or(0), + max: jump.end, greedy: false, sub: Box::new(hir::Hir::dot(hir::Dot::AnyByte)), })) diff --git a/lib/src/compiler/tests/testdata/errors/101.in b/lib/src/compiler/tests/testdata/errors/101.in index c76724b0e..baf7fc2cc 100644 --- a/lib/src/compiler/tests/testdata/errors/101.in +++ b/lib/src/compiler/tests/testdata/errors/101.in @@ -1,6 +1,6 @@ rule test { strings: - $a = { 11 [0-65536] 22 } + $a = { 11 [0-4294967296] 22 } condition: $a } \ No newline at end of file diff --git a/lib/src/compiler/tests/testdata/errors/101.out b/lib/src/compiler/tests/testdata/errors/101.out index a8c16da58..0f30f4d9c 100644 --- a/lib/src/compiler/tests/testdata/errors/101.out +++ b/lib/src/compiler/tests/testdata/errors/101.out @@ -1,6 +1,6 @@ error[E027]: invalid integer --> line:3:18 | -3 | $a = { 11 [0-65536] 22 } - | ^^^^^ this number is out of the valid range: [0, 65535] +3 | $a = { 11 [0-4294967296] 22 } + | ^^^^^^^^^^ this number is out of the valid range: [0, 4294967295] | \ No newline at end of file diff --git a/parser/src/ast/cst2ast.rs b/parser/src/ast/cst2ast.rs index 110958769..2e2ce0dc2 100644 --- a/parser/src/ast/cst2ast.rs +++ b/parser/src/ast/cst2ast.rs @@ -851,14 +851,14 @@ impl<'src> Builder<'src> { let mut end = None; if let Event::Token { kind: INTEGER_LIT, .. } = self.peek() { - let (value, _lit, _span) = self.integer_lit::()?; + let (value, _lit, _span) = self.integer_lit::()?; start = Some(value); }; if let Event::Token { kind: HYPHEN, .. } = self.peek() { self.expect(HYPHEN)?; if let Event::Token { kind: INTEGER_LIT, .. } = self.peek() { - let (value, _lit, _span) = self.integer_lit::()?; + let (value, _lit, _span) = self.integer_lit::()?; end = Some(value); }; } else { diff --git a/parser/src/ast/mod.rs b/parser/src/ast/mod.rs index 5abc9e9d0..20d53046b 100644 --- a/parser/src/ast/mod.rs +++ b/parser/src/ast/mod.rs @@ -319,13 +319,13 @@ impl HexAlternative { #[derive(Debug, Clone, Default)] pub struct HexJump { span: Span, - pub start: Option, - pub end: Option, + pub start: Option, + pub end: Option, } impl HexJump { #[doc(hidden)] - pub fn new(start: Option, end: Option) -> Self { + pub fn new(start: Option, end: Option) -> Self { Self { start, end, span: Span::default() } } }