Added wildcard and dot-prefixed identifier support. Combined regex identifier into standard identifier

Signed-off-by: Landy Chan <landychan92@gmail.com>
This commit is contained in:
Landy Chan 2019-10-30 15:16:21 -07:00
parent e60179b91f
commit 9e38bec396
2 changed files with 11 additions and 6 deletions

View file

@ -18,19 +18,15 @@ class NginxParser < Parslet::Parser
end
rule(:standard_identifier) do
(match("[a-zA-Z]") >> match('\S').repeat).as(:identifier) >> space >> space.repeat
(match("[a-zA-Z~*.]") >> match('\S').repeat).as(:identifier) >> space >> space.repeat
end
rule(:quoted_identifier) do
str('"') >> (str('"').absent? >> any).repeat.as(:identifier) >> str('"') >> space.repeat
end
rule(:regex_identifier) do
(str("~") >> match('\S').repeat).as(:identifier) >> space >> space.repeat
end
rule(:identifier) do
standard_identifier | quoted_identifier | regex_identifier
standard_identifier | quoted_identifier
end
rule(:standard_value) do

View file

@ -89,6 +89,15 @@ describe NginxParser do
it "parses regex identifiers for assignments" do
_(parsestr(%{~^\/opcache-api 1;})).must_equal "[{:assignment=>{:identifier=>\"~^/opcache-api\"@0, :args=>[{:value=>\"1\"@15}]}}]"
end
it "parses wildcard identifiers for assignments" do
_(parsestr(%{*.example.org qa;})).must_equal "[{:assignment=>{:identifier=>\"*.example.org\"@0, :args=>[{:value=>\"qa\"@14}]}}]"
end
it "parses dot-prefixed identifiers for assignments" do
_(parsestr(%{.example.com test;})).must_equal "[{:assignment=>{:identifier=>\".example.com\"@0, :args=>[{:value=>\"test\"@13}]}}]"
end
end
describe NginxTransform do