From b7d48b48fda36038ac1f13e622b9faa0b7a9ce01 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 24 Oct 2023 16:36:50 +0000 Subject: [PATCH] chore(cli): update to regex-syntax 0.8 regex-syntax has restructured the Ast enum a bit, rather than having a Class member it now has seperate members for different types of Class. --- cli/Cargo.toml | 2 +- .../generate/prepare_grammar/expand_tokens.rs | 66 +++++++++---------- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 4d38eecc..6206f60e 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -38,7 +38,7 @@ lazy_static = "1.4.0" memchr = "2.6.3" path-slash = "0.2.1" regex = "1.9.1" -regex-syntax = "0.7.4" +regex-syntax = "0.8" rustc-hash = "1.1.0" semver = "1.0.18" serde = "1.0.188" diff --git a/cli/src/generate/prepare_grammar/expand_tokens.rs b/cli/src/generate/prepare_grammar/expand_tokens.rs index 395e5fb7..55bdc617 100644 --- a/cli/src/generate/prepare_grammar/expand_tokens.rs +++ b/cli/src/generate/prepare_grammar/expand_tokens.rs @@ -6,8 +6,8 @@ use anyhow::{anyhow, Context, Result}; use lazy_static::lazy_static; use regex::Regex; use regex_syntax::ast::{ - parse, Ast, Class, ClassPerlKind, ClassSet, ClassSetBinaryOpKind, ClassSetItem, - ClassUnicodeKind, RepetitionKind, RepetitionRange, + parse, Ast, ClassPerlKind, ClassSet, ClassSetBinaryOpKind, ClassSetItem, ClassUnicodeKind, + RepetitionKind, RepetitionRange, }; use std::collections::HashMap; use std::i32; @@ -251,41 +251,39 @@ impl NfaBuilder { Ok(true) } Ast::Assertion(_) => Err(anyhow!("Regex error: Assertions are not supported")), - Ast::Class(class) => match class { - Class::Unicode(class) => { - let mut chars = self.expand_unicode_character_class(&class.kind)?; - if class.negated { - chars = chars.negate(); - } - if case_insensitive { - chars = with_inverse_char(chars); - } - self.push_advance(chars, next_state_id); - Ok(true) + Ast::ClassUnicode(class) => { + let mut chars = self.expand_unicode_character_class(&class.kind)?; + if class.negated { + chars = chars.negate(); } - Class::Perl(class) => { - let mut chars = self.expand_perl_character_class(&class.kind); - if class.negated { - chars = chars.negate(); - } - if case_insensitive { - chars = with_inverse_char(chars); - } - self.push_advance(chars, next_state_id); - Ok(true) + if case_insensitive { + chars = with_inverse_char(chars); } - Class::Bracketed(class) => { - let mut chars = self.translate_class_set(&class.kind)?; - if class.negated { - chars = chars.negate(); - } - if case_insensitive { - chars = with_inverse_char(chars); - } - self.push_advance(chars, next_state_id); - Ok(true) + self.push_advance(chars, next_state_id); + Ok(true) + } + Ast::ClassPerl(class) => { + let mut chars = self.expand_perl_character_class(&class.kind); + if class.negated { + chars = chars.negate(); } - }, + if case_insensitive { + chars = with_inverse_char(chars); + } + self.push_advance(chars, next_state_id); + Ok(true) + } + Ast::ClassBracketed(class) => { + let mut chars = self.translate_class_set(&class.kind)?; + if class.negated { + chars = chars.negate(); + } + if case_insensitive { + chars = with_inverse_char(chars); + } + self.push_advance(chars, next_state_id); + Ok(true) + } Ast::Repetition(repetition) => match repetition.op.kind { RepetitionKind::ZeroOrOne => { self.expand_zero_or_one(&repetition.ast, next_state_id, case_insensitive)