feat(variform): allow hyphens in identifiers

Fixes https://emqx.atlassian.net/browse/EMQX-12683
This commit is contained in:
Thales Macedo Garitezi 2024-07-11 11:59:50 -03:00
parent a4cc3ba9e8
commit 44e4b3616d
2 changed files with 11 additions and 2 deletions

View File

@ -1,6 +1,6 @@
Definitions.
%% Define regular expressions for tokens
IDENTIFIER = [a-zA-Z][a-zA-Z0-9_.]*
IDENTIFIER = [a-zA-Z][-a-zA-Z0-9_.]*
SQ_STRING = \'[^\']*\'
DQ_STRING = \"[^\"]*\"
INTEGER = [+-]?[0-9]+

View File

@ -23,7 +23,7 @@
-define(SYNTAX_ERROR, {error, "syntax error before:" ++ _}).
redner_test_() ->
render_test_() ->
[
{"direct var reference", fun() -> ?assertEqual({ok, <<"1">>}, render("a", #{a => 1})) end},
{"concat strings", fun() ->
@ -32,6 +32,15 @@ redner_test_() ->
{"concat empty string", fun() ->
?assertEqual({ok, <<"">>}, render("concat([''])", #{}))
end},
{"identifier with hyphen", fun() ->
?assertEqual(
{ok, <<"10">>},
render(
"pub_props.Message-Expiry-Interval",
#{pub_props => #{'Message-Expiry-Interval' => 10}}
)
)
end},
{"tokens 1st", fun() ->
?assertEqual({ok, <<"a">>}, render("nth(1,tokens(var, ','))", #{var => <<"a,b">>}))
end},