mirror of
https://github.com/valitydev/yamerl.git
synced 2024-11-06 02:45:23 +00:00
Extend accepted values to yes/no/on/off
Those values are defined in the YAML tag repository, not by the YAML 1.2 specifications.
This commit is contained in:
parent
5088f74e60
commit
98530d13a8
@ -14,6 +14,18 @@
|
||||
|
||||
-define(TAG, "tag:yaml.org,2002:bool").
|
||||
|
||||
-define(IS_TRUE(S),
|
||||
S == "true" orelse S == "True" orelse S == "TRUE" orelse
|
||||
S == "y" orelse S == "Y" orelse
|
||||
S == "yes" orelse S == "Yes" orelse S == "YES" orelse
|
||||
S == "on" orelse S == "On" orelse S == "ON").
|
||||
|
||||
-define(IS_FALSE(S),
|
||||
S == "false" orelse S == "False" orelse S == "FALSE" orelse
|
||||
S == "n" orelse S == "N" orelse
|
||||
S == "no" orelse S == "No" orelse S == "NO" orelse
|
||||
S == "off" orelse S == "Off" orelse S == "OFF").
|
||||
|
||||
%% -------------------------------------------------------------------
|
||||
%% Public API.
|
||||
%% -------------------------------------------------------------------
|
||||
@ -22,34 +34,19 @@ tags() -> [?TAG].
|
||||
|
||||
try_represent_token(Repr, Node,
|
||||
#yaml_scalar{tag = #yaml_tag{uri = {non_specific, "?"}},
|
||||
text = Text} = Token) when
|
||||
Text == "true" orelse
|
||||
Text == "True" orelse
|
||||
Text == "TRUE" orelse
|
||||
Text == "false" orelse
|
||||
Text == "False" orelse
|
||||
Text == "FALSE" ->
|
||||
text = Text} = Token) when ?IS_TRUE(Text) orelse ?IS_FALSE(Text) ->
|
||||
represent_token(Repr, Node, Token);
|
||||
try_represent_token(_, _, _) ->
|
||||
unrecognized.
|
||||
|
||||
represent_token(#yaml_repr{simple_structs = true},
|
||||
undefined, #yaml_scalar{text = Text}) when
|
||||
Text == "true" orelse
|
||||
Text == "True" orelse
|
||||
Text == "TRUE" ->
|
||||
undefined, #yaml_scalar{text = Text}) when ?IS_TRUE(Text) ->
|
||||
{finished, true};
|
||||
represent_token(#yaml_repr{simple_structs = true},
|
||||
undefined, #yaml_scalar{text = Text}) when
|
||||
Text == "false" orelse
|
||||
Text == "False" orelse
|
||||
Text == "FALSE" ->
|
||||
undefined, #yaml_scalar{text = Text}) when ?IS_FALSE(Text) ->
|
||||
{finished, false};
|
||||
represent_token(#yaml_repr{simple_structs = false},
|
||||
undefined, #yaml_scalar{text = Text} = Token) when
|
||||
Text == "true" orelse
|
||||
Text == "True" orelse
|
||||
Text == "TRUE" ->
|
||||
undefined, #yaml_scalar{text = Text} = Token) when ?IS_TRUE(Text) ->
|
||||
Pres = yaml_repr:get_pres_details(Token),
|
||||
Node = #yaml_bool{
|
||||
module = ?MODULE,
|
||||
@ -59,10 +56,7 @@ represent_token(#yaml_repr{simple_structs = false},
|
||||
},
|
||||
{finished, Node};
|
||||
represent_token(#yaml_repr{simple_structs = false},
|
||||
undefined, #yaml_scalar{text = Text} = Token) when
|
||||
Text == "false" orelse
|
||||
Text == "False" orelse
|
||||
Text == "FALSE" ->
|
||||
undefined, #yaml_scalar{text = Text} = Token) when ?IS_FALSE(Text) ->
|
||||
Pres = yaml_repr:get_pres_details(Token),
|
||||
Node = #yaml_bool{
|
||||
module = ?MODULE,
|
||||
|
Loading…
Reference in New Issue
Block a user