@@ -27,43 +27,42 @@ import dyaml.exception;
2727// / Type of `regexes`
2828private alias RegexType = Tuple ! (string , " tag" , const Regex! char , " regexp" , string , " chars" );
2929
30- private immutable RegexType[] regexes = [
31- RegexType(" tag:yaml.org,2002:bool" ,
32- regex(r " ^(?:yes|Yes|YES|no|No|NO|true|True|TRUE" ~
33- " |false|False|FALSE|on|On|ON|off|Off|OFF)$" ),
34- " yYnNtTfFoO" ),
35- RegexType(" tag:yaml.org,2002:float" ,
36- regex(r " ^(?:[-+]?([0-9][0-9_]*)\\.[0-9_]*" ~
37- " (?:[eE][-+][0-9]+)?|[-+]?(?:[0-9][0-9_]" ~
38- " *)?\\ .[0-9_]+(?:[eE][-+][0-9]+)?|[-+]?" ~
39- " [0-9][0-9_]*(?::[0-5]?[0-9])+\\ .[0-9_]" ~
40- " *|[-+]?\\ .(?:inf|Inf|INF)|\\ ." ~
41- " (?:nan|NaN|NAN))$" ),
42- " -+0123456789." ),
43- RegexType(" tag:yaml.org,2002:int" ,
44- regex(r " ^(?:[-+]?0b[0-1_]+" ~
45- " |[-+]?0[0-7_]+" ~
46- " |[-+]?(?:0|[1-9][0-9_]*)" ~
47- " |[-+]?0x[0-9a-fA-F_]+" ~
48- " |[-+]?[1-9][0-9_]*(?::[0-5]?[0-9])+)$" ),
49- " -+0123456789" ),
50- RegexType(" tag:yaml.org,2002:merge" , regex(r " ^<<$" ), " <" ),
51- RegexType(" tag:yaml.org,2002:null" ,
52- regex(r " ^$|^(?:~|null|Null|NULL)$" ), " ~nN\0 " ),
53- RegexType(" tag:yaml.org,2002:timestamp" ,
54- regex(r " ^[0-9][0-9][0-9][0-9]-[0-9][0-9]-" ~
55- " [0-9][0-9]|[0-9][0-9][0-9][0-9]-[0-9]" ~
56- " [0-9]?-[0-9][0-9]?[Tt]|[ \t ]+[0-9]" ~
57- " [0-9]?:[0-9][0-9]:[0-9][0-9]" ~
58- " (?:\\ .[0-9]*)?(?:[ \t ]*Z|[-+][0-9]" ~
59- " [0-9]?(?::[0-9][0-9])?)?$" ),
60- " 0123456789" ),
61- RegexType(" tag:yaml.org,2002:value" , regex(r " ^=$" ), " =" ),
30+ // build this at runtime, to prevent build time costs
31+ private __gshared immutable RegexType[] regexes;
32+
33+ shared static this () {
34+ __gshared string forceRT;
35+ RegexType[] regexArray;
36+ Regex! char toBuild;
37+
38+ toBuild = regex(r " ^(?:yes|Yes|YES|no|No|NO|true|True|TRUE" ~ " |false|False|FALSE|on|On|ON|off|Off|OFF)$" ~ forceRT);
39+ regexArray ~= RegexType(" tag:yaml.org,2002:bool" , toBuild, " yYnNtTfFoO" );
40+
41+ toBuild = regex(r " ^(?:[-+]?([0-9][0-9_]*)\\.[0-9_]*" ~ " (?:[eE][-+][0-9]+)?|[-+]?(?:[0-9][0-9_]" ~ " *)?\\ .[0-9_]+(?:[eE][-+][0-9]+)?|[-+]?" ~ " [0-9][0-9_]*(?::[0-5]?[0-9])+\\ .[0-9_]" ~ " *|[-+]?\\ .(?:inf|Inf|INF)|\\ ." ~ " (?:nan|NaN|NAN))$" ~ forceRT);
42+ regexArray ~= RegexType(" tag:yaml.org,2002:float" , toBuild, " -+0123456789." );
43+
44+ toBuild = regex(r " ^(?:[-+]?0b[0-1_]+" ~ " |[-+]?0[0-7_]+" ~ " |[-+]?(?:0|[1-9][0-9_]*)" ~ " |[-+]?0x[0-9a-fA-F_]+" ~ " |[-+]?[1-9][0-9_]*(?::[0-5]?[0-9])+)$" ~ forceRT);
45+ regexArray ~= RegexType(" tag:yaml.org,2002:int" , toBuild, " -+0123456789" );
46+
47+ toBuild = regex(r " ^<<$" ~ forceRT);
48+ regexArray ~= RegexType(" tag:yaml.org,2002:merge" , toBuild, " <" );
49+
50+ toBuild = regex(r " ^$|^(?:~|null|Null|NULL)$" ~ forceRT);
51+ regexArray ~= RegexType(" tag:yaml.org,2002:null" , toBuild, " ~nN\0 " );
52+
53+ toBuild = regex(r " ^[0-9][0-9][0-9][0-9]-[0-9][0-9]-" ~ " [0-9][0-9]|[0-9][0-9][0-9][0-9]-[0-9]" ~ " [0-9]?-[0-9][0-9]?[Tt]|[ \t ]+[0-9]" ~ " [0-9]?:[0-9][0-9]:[0-9][0-9]" ~ " (?:\\ .[0-9]*)?(?:[ \t ]*Z|[-+][0-9]" ~ " [0-9]?(?::[0-9][0-9])?)?$" );
54+ regexArray ~= RegexType(" tag:yaml.org,2002:timestamp" , toBuild, " 0123456789" );
55+
56+ toBuild = regex(r " ^=$" );
57+ regexArray ~= RegexType(" tag:yaml.org,2002:value" , toBuild, " =" );
6258
6359 // The following resolver is only for documentation purposes. It cannot work
6460 // because plain scalars cannot start with '!', '&', or '*'.
65- RegexType(" tag:yaml.org,2002:yaml" , regex(r " ^(?:!|&|\*)$" ), " !&*" ),
66- ];
61+ toBuild = regex(r " ^(?:!|&|\*)$" );
62+ regexArray ~= RegexType(" tag:yaml.org,2002:yaml" , toBuild, " !&*" );
63+
64+ regexes = cast (immutable )regexArray;
65+ }
6766
6867/**
6968 * Resolves YAML tags (data types).
0 commit comments