11use cfgrammar:: Span ;
2- use lazy_static:: lazy_static;
32use lrpar:: LexerTypes ;
43use num_traits:: AsPrimitive ;
54use proc_macro2:: TokenStream ;
@@ -12,28 +11,34 @@ use crate::{
1211} ;
1312use std:: borrow:: { Borrow as _, Cow } ;
1413use std:: ops:: Not ;
14+ use std:: sync:: LazyLock ;
1515
1616type LexInternalBuildResult < T > = Result < T , LexBuildError > ;
1717
18- lazy_static ! {
19- static ref RE_START_STATE_NAME : Regex = Regex :: new( r"^[a-zA-Z][a-zA-Z0-9_.]*$" ) . unwrap( ) ;
20- static ref RE_INCLUSIVE_START_STATE_DECLARATION : Regex =
21- Regex :: new( r"^%[sS][a-zA-Z0-9]*$" ) . unwrap( ) ;
22- static ref RE_EXCLUSIVE_START_STATE_DECLARATION : Regex =
23- Regex :: new( r"^%[xX][a-zA-Z0-9]*$" ) . unwrap( ) ;
24- // Documented in `Escape sequences` in lexcompatibility.m
25- static ref RE_LEX_ESC_LITERAL : Regex =
26- Regex :: new( r"^(([xuU][[:xdigit:]])|[[:digit:]]|[afnrtv\\]|[pP]|[dDsSwW]|[Az])" ) . unwrap( ) ;
27- // Vertical line separators.
28- static ref RE_LINE_SEP : Regex = Regex :: new( r"[\p{Pattern_White_Space}&&[\p{Zl}\p{Zp}\n\r\v]]" ) . unwrap( ) ;
29- static ref RE_LEADING_LINE_SEPS : Regex = Regex :: new( r"^[\p{Pattern_White_Space}&&[\p{Zl}\p{Zp}\n\r\v]]*" ) . unwrap( ) ;
30- // Horizontal space separators
31- static ref RE_SPACE_SEP : Regex = Regex :: new( r"[\p{Pattern_White_Space}&&[\p{Zs}\t]]" ) . unwrap( ) ;
32- static ref RE_LEADING_SPACE_SEPS : Regex = Regex :: new( r"^[\p{Pattern_White_Space}&&[\p{Zs}\t]]*" ) . unwrap( ) ;
33- static ref RE_LEADING_WS : Regex = Regex :: new( r"^[\p{Pattern_White_Space}]*" ) . unwrap( ) ;
34- static ref RE_WS : Regex = Regex :: new( r"\p{Pattern_White_Space}" ) . unwrap( ) ;
35- static ref RE_LEADING_DIGITS : Regex = Regex :: new( r"^[0-9]+" ) . unwrap( ) ;
36- }
18+ static RE_START_STATE_NAME : LazyLock < Regex > =
19+ LazyLock :: new ( || Regex :: new ( r"^[a-zA-Z][a-zA-Z0-9_.]*$" ) . unwrap ( ) ) ;
20+ static RE_INCLUSIVE_START_STATE_DECLARATION : LazyLock < Regex > =
21+ LazyLock :: new ( || Regex :: new ( r"^%[sS][a-zA-Z0-9]*$" ) . unwrap ( ) ) ;
22+ static RE_EXCLUSIVE_START_STATE_DECLARATION : LazyLock < Regex > =
23+ LazyLock :: new ( || Regex :: new ( r"^%[xX][a-zA-Z0-9]*$" ) . unwrap ( ) ) ;
24+ // Documented in `Escape sequences` in lexcompatibility.m
25+ static RE_LEX_ESC_LITERAL : LazyLock < Regex > = LazyLock :: new ( || {
26+ Regex :: new ( r"^(([xuU][[:xdigit:]])|[[:digit:]]|[afnrtv\\]|[pP]|[dDsSwW]|[Az])" ) . unwrap ( )
27+ } ) ;
28+ // Vertical line separators.
29+ static RE_LINE_SEP : LazyLock < Regex > =
30+ LazyLock :: new ( || Regex :: new ( r"[\p{Pattern_White_Space}&&[\p{Zl}\p{Zp}\n\r\v]]" ) . unwrap ( ) ) ;
31+ static RE_LEADING_LINE_SEPS : LazyLock < Regex > =
32+ LazyLock :: new ( || Regex :: new ( r"^[\p{Pattern_White_Space}&&[\p{Zl}\p{Zp}\n\r\v]]*" ) . unwrap ( ) ) ;
33+ // Horizontal space separators
34+ static RE_SPACE_SEP : LazyLock < Regex > =
35+ LazyLock :: new ( || Regex :: new ( r"[\p{Pattern_White_Space}&&[\p{Zs}\t]]" ) . unwrap ( ) ) ;
36+ static RE_LEADING_SPACE_SEPS : LazyLock < Regex > =
37+ LazyLock :: new ( || Regex :: new ( r"^[\p{Pattern_White_Space}&&[\p{Zs}\t]]*" ) . unwrap ( ) ) ;
38+ static RE_LEADING_WS : LazyLock < Regex > =
39+ LazyLock :: new ( || Regex :: new ( r"^[\p{Pattern_White_Space}]*" ) . unwrap ( ) ) ;
40+ static RE_WS : LazyLock < Regex > = LazyLock :: new ( || Regex :: new ( r"\p{Pattern_White_Space}" ) . unwrap ( ) ) ;
41+
3742const INITIAL_START_STATE_NAME : & str = "INITIAL" ;
3843
3944#[ derive( Debug , Clone ) ]
0 commit comments