Simplify and make the code of resolver more const-correct
Before it would trigger every time a thread was started.
This commit is contained in:
parent
974a6edd1a
commit
6e31faf9a3
|
@ -24,14 +24,19 @@ import dyaml.node;
|
|||
import dyaml.exception;
|
||||
|
||||
|
||||
static Tuple!(string, "tag", Regex!char, "regexp", string, "chars")[] regexes;
|
||||
/// Type of `regexes`
|
||||
private alias RegexType = Tuple!(string, "tag", const Regex!char, "regexp", string, "chars");
|
||||
|
||||
static this() @safe {
|
||||
regexes ~= tuple!("tag", "regexp", "chars")("tag:yaml.org,2002:bool",
|
||||
private immutable RegexType[] regexes;
|
||||
|
||||
shared static this() @safe
|
||||
{
|
||||
RegexType[] tmp;
|
||||
tmp ~= RegexType("tag:yaml.org,2002:bool",
|
||||
regex(r"^(?:yes|Yes|YES|no|No|NO|true|True|TRUE" ~
|
||||
"|false|False|FALSE|on|On|ON|off|Off|OFF)$"),
|
||||
"yYnNtTfFoO");
|
||||
regexes ~= tuple!("tag", "regexp", "chars")("tag:yaml.org,2002:float",
|
||||
tmp ~= RegexType("tag:yaml.org,2002:float",
|
||||
regex(r"^(?:[-+]?([0-9][0-9_]*)\\.[0-9_]*" ~
|
||||
"(?:[eE][-+][0-9]+)?|[-+]?(?:[0-9][0-9_]" ~
|
||||
"*)?\\.[0-9_]+(?:[eE][-+][0-9]+)?|[-+]?" ~
|
||||
|
@ -39,17 +44,17 @@ static this() @safe {
|
|||
"*|[-+]?\\.(?:inf|Inf|INF)|\\." ~
|
||||
"(?:nan|NaN|NAN))$"),
|
||||
"-+0123456789.");
|
||||
regexes ~= tuple!("tag", "regexp", "chars")("tag:yaml.org,2002:int",
|
||||
tmp ~= RegexType("tag:yaml.org,2002:int",
|
||||
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])+)$"),
|
||||
"-+0123456789");
|
||||
regexes ~= tuple!("tag", "regexp", "chars")("tag:yaml.org,2002:merge", regex(r"^<<$"), "<");
|
||||
regexes ~= tuple!("tag", "regexp", "chars")("tag:yaml.org,2002:null",
|
||||
tmp ~= RegexType("tag:yaml.org,2002:merge", regex(r"^<<$"), "<");
|
||||
tmp ~= RegexType("tag:yaml.org,2002:null",
|
||||
regex(r"^$|^(?:~|null|Null|NULL)$"), "~nN\0");
|
||||
regexes ~= tuple!("tag", "regexp", "chars")("tag:yaml.org,2002:timestamp",
|
||||
tmp ~= RegexType("tag:yaml.org,2002:timestamp",
|
||||
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]" ~
|
||||
|
@ -57,12 +62,14 @@ static this() @safe {
|
|||
"(?:\\.[0-9]*)?(?:[ \t]*Z|[-+][0-9]" ~
|
||||
"[0-9]?(?::[0-9][0-9])?)?$"),
|
||||
"0123456789");
|
||||
regexes ~= tuple!("tag", "regexp", "chars")("tag:yaml.org,2002:value", regex(r"^=$"), "=");
|
||||
tmp ~= RegexType("tag:yaml.org,2002:value", regex(r"^=$"), "=");
|
||||
|
||||
|
||||
//The following resolver is only for documentation purposes. It cannot work
|
||||
//because plain scalars cannot start with '!', '&', or '*'.
|
||||
regexes ~= tuple!("tag", "regexp", "chars")("tag:yaml.org,2002:yaml", regex(r"^(?:!|&|\*)$"), "!&*");
|
||||
tmp ~= RegexType("tag:yaml.org,2002:yaml", regex(r"^(?:!|&|\*)$"), "!&*");
|
||||
|
||||
regexes = () @trusted { return cast(immutable)tmp; }();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -86,7 +93,7 @@ struct Resolver
|
|||
* Each tuple stores regular expression the scalar must match,
|
||||
* and tag to assign to it if it matches.
|
||||
*/
|
||||
Tuple!(string, Regex!char)[][dchar] yamlImplicitResolvers_;
|
||||
Tuple!(string, const Regex!char)[][dchar] yamlImplicitResolvers_;
|
||||
|
||||
package:
|
||||
static auto withDefaultResolvers() @safe
|
||||
|
@ -120,7 +127,7 @@ struct Resolver
|
|||
* first = String of possible starting characters of the scalar.
|
||||
*
|
||||
*/
|
||||
void addImplicitResolver(string tag, Regex!char regexp, string first)
|
||||
void addImplicitResolver(string tag, const Regex!char regexp, string first)
|
||||
pure @safe
|
||||
{
|
||||
foreach(const dchar c; first)
|
||||
|
|
Loading…
Reference in a new issue