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,45 +24,52 @@ import dyaml.node;
|
||||||
import dyaml.exception;
|
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 {
|
private immutable RegexType[] regexes;
|
||||||
regexes ~= tuple!("tag", "regexp", "chars")("tag:yaml.org,2002:bool",
|
|
||||||
regex(r"^(?:yes|Yes|YES|no|No|NO|true|True|TRUE" ~
|
shared static this() @safe
|
||||||
"|false|False|FALSE|on|On|ON|off|Off|OFF)$"),
|
{
|
||||||
"yYnNtTfFoO");
|
RegexType[] tmp;
|
||||||
regexes ~= tuple!("tag", "regexp", "chars")("tag:yaml.org,2002:float",
|
tmp ~= RegexType("tag:yaml.org,2002:bool",
|
||||||
regex(r"^(?:[-+]?([0-9][0-9_]*)\\.[0-9_]*" ~
|
regex(r"^(?:yes|Yes|YES|no|No|NO|true|True|TRUE" ~
|
||||||
"(?:[eE][-+][0-9]+)?|[-+]?(?:[0-9][0-9_]" ~
|
"|false|False|FALSE|on|On|ON|off|Off|OFF)$"),
|
||||||
"*)?\\.[0-9_]+(?:[eE][-+][0-9]+)?|[-+]?" ~
|
"yYnNtTfFoO");
|
||||||
"[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]" ~
|
tmp ~= RegexType("tag:yaml.org,2002:float",
|
||||||
"*|[-+]?\\.(?:inf|Inf|INF)|\\." ~
|
regex(r"^(?:[-+]?([0-9][0-9_]*)\\.[0-9_]*" ~
|
||||||
"(?:nan|NaN|NAN))$"),
|
"(?:[eE][-+][0-9]+)?|[-+]?(?:[0-9][0-9_]" ~
|
||||||
"-+0123456789.");
|
"*)?\\.[0-9_]+(?:[eE][-+][0-9]+)?|[-+]?" ~
|
||||||
regexes ~= tuple!("tag", "regexp", "chars")("tag:yaml.org,2002:int",
|
"[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]" ~
|
||||||
regex(r"^(?:[-+]?0b[0-1_]+" ~
|
"*|[-+]?\\.(?:inf|Inf|INF)|\\." ~
|
||||||
"|[-+]?0[0-7_]+" ~
|
"(?:nan|NaN|NAN))$"),
|
||||||
"|[-+]?(?:0|[1-9][0-9_]*)" ~
|
"-+0123456789.");
|
||||||
"|[-+]?0x[0-9a-fA-F_]+" ~
|
tmp ~= RegexType("tag:yaml.org,2002:int",
|
||||||
"|[-+]?[1-9][0-9_]*(?::[0-5]?[0-9])+)$"),
|
regex(r"^(?:[-+]?0b[0-1_]+" ~
|
||||||
"-+0123456789");
|
"|[-+]?0[0-7_]+" ~
|
||||||
regexes ~= tuple!("tag", "regexp", "chars")("tag:yaml.org,2002:merge", regex(r"^<<$"), "<");
|
"|[-+]?(?:0|[1-9][0-9_]*)" ~
|
||||||
regexes ~= tuple!("tag", "regexp", "chars")("tag:yaml.org,2002:null",
|
"|[-+]?0x[0-9a-fA-F_]+" ~
|
||||||
regex(r"^$|^(?:~|null|Null|NULL)$"), "~nN\0");
|
"|[-+]?[1-9][0-9_]*(?::[0-5]?[0-9])+)$"),
|
||||||
regexes ~= tuple!("tag", "regexp", "chars")("tag:yaml.org,2002:timestamp",
|
"-+0123456789");
|
||||||
regex(r"^[0-9][0-9][0-9][0-9]-[0-9][0-9]-" ~
|
tmp ~= RegexType("tag:yaml.org,2002:merge", regex(r"^<<$"), "<");
|
||||||
"[0-9][0-9]|[0-9][0-9][0-9][0-9]-[0-9]" ~
|
tmp ~= RegexType("tag:yaml.org,2002:null",
|
||||||
"[0-9]?-[0-9][0-9]?[Tt]|[ \t]+[0-9]" ~
|
regex(r"^$|^(?:~|null|Null|NULL)$"), "~nN\0");
|
||||||
"[0-9]?:[0-9][0-9]:[0-9][0-9]" ~
|
tmp ~= RegexType("tag:yaml.org,2002:timestamp",
|
||||||
"(?:\\.[0-9]*)?(?:[ \t]*Z|[-+][0-9]" ~
|
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]" ~
|
||||||
"0123456789");
|
"[0-9]?-[0-9][0-9]?[Tt]|[ \t]+[0-9]" ~
|
||||||
regexes ~= tuple!("tag", "regexp", "chars")("tag:yaml.org,2002:value", regex(r"^=$"), "=");
|
"[0-9]?:[0-9][0-9]:[0-9][0-9]" ~
|
||||||
|
"(?:\\.[0-9]*)?(?:[ \t]*Z|[-+][0-9]" ~
|
||||||
|
"[0-9]?(?::[0-9][0-9])?)?$"),
|
||||||
|
"0123456789");
|
||||||
|
tmp ~= RegexType("tag:yaml.org,2002:value", regex(r"^=$"), "=");
|
||||||
|
|
||||||
|
|
||||||
//The following resolver is only for documentation purposes. It cannot work
|
//The following resolver is only for documentation purposes. It cannot work
|
||||||
//because plain scalars cannot start with '!', '&', or '*'.
|
//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,
|
* Each tuple stores regular expression the scalar must match,
|
||||||
* and tag to assign to it if it matches.
|
* and tag to assign to it if it matches.
|
||||||
*/
|
*/
|
||||||
Tuple!(string, Regex!char)[][dchar] yamlImplicitResolvers_;
|
Tuple!(string, const Regex!char)[][dchar] yamlImplicitResolvers_;
|
||||||
|
|
||||||
package:
|
package:
|
||||||
static auto withDefaultResolvers() @safe
|
static auto withDefaultResolvers() @safe
|
||||||
|
@ -120,7 +127,7 @@ struct Resolver
|
||||||
* first = String of possible starting characters of the scalar.
|
* 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
|
pure @safe
|
||||||
{
|
{
|
||||||
foreach(const dchar c; first)
|
foreach(const dchar c; first)
|
||||||
|
|
Loading…
Reference in a new issue