From cfaad790622b0c68ad4d592be5d2f91e39396ca8 Mon Sep 17 00:00:00 2001 From: Kyle Lahnakoski Date: Wed, 26 Jun 2024 21:45:43 -0400 Subject: [PATCH] better ident parsing --- mo_sql_parsing/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mo_sql_parsing/utils.py b/mo_sql_parsing/utils.py index 620174d..8439e03 100644 --- a/mo_sql_parsing/utils.py +++ b/mo_sql_parsing/utils.py @@ -908,8 +908,9 @@ def no_dashes(tokens, start, string): digit = Char("0123456789") with whitespaces.NO_WHITESPACE: - ident_w_dash = Char(FIRST_IDENT_CHAR) + (Regex("(?<=[^ 0-9])\\-(?=[^ 0-9])") | Char(IDENT_CHAR))[...] - ident_w_dash_warning = Regex(ident_w_dash.__regex__()[1]).set_parser_name("identifier_with_dashes") / no_dashes + # repack the expression into a regex for faster parsing ident_w_dash + ident_w_dash = Regex((Char(FIRST_IDENT_CHAR) + (Regex("(?<=[^ 0-9])\\-(?=[^ 0-9])") | Char(IDENT_CHAR))[...]).__regex__()[1]) + ident_w_dash_warning = ident_w_dash.set_parser_name("identifier_with_dashes") / no_dashes simple_ident = Word(FIRST_IDENT_CHAR, IDENT_CHAR).set_parser_name("identifier") sqlserver_local_ident = Word("@" + FIRST_IDENT_CHAR, IDENT_CHAR).set_parser_name("identifier")