From e8824bb91510c37867b9c7813e6d1c9fa2ace48e Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Sat, 16 May 2020 15:48:06 -0400 Subject: [PATCH] Additional fixes for placeholders --- lexers/c/caddyfile.go | 7 +++++-- lexers/testdata/caddyfile.actual | 4 +++- lexers/testdata/caddyfile.expected | 8 ++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lexers/c/caddyfile.go b/lexers/c/caddyfile.go index 43b535b61..4e3936cd8 100644 --- a/lexers/c/caddyfile.go +++ b/lexers/c/caddyfile.go @@ -125,7 +125,7 @@ var caddyfileCommon = Rules{ {`(https?://)?([a-z0-9.-]+)(:)([0-9]+)`, ByGroups(Name, Name, Punctuation, LiteralNumberInteger), nil}, {`[a-z-]+/[a-z-+]+`, LiteralString, nil}, {`[0-9]+[km]?\b`, LiteralNumberInteger, nil}, - {`\{[\w+.-]+\}`, LiteralStringEscape, nil}, // Placeholder + {`\{[\w+.\$-]+\}`, LiteralStringEscape, nil}, // Placeholder {`\[(?=[^#{}$]+\])`, Punctuation, nil}, {`\]|\|`, Punctuation, nil}, {`[^\s#{}$\]]+`, LiteralString, nil}, @@ -152,7 +152,7 @@ var Caddyfile = internal.Register(MustNewLexer( // Site label {`[^#{(\s,]+`, GenericHeading, Push("label")}, // Site label with placeholder - {`\{[\w+.-]+\}`, NameAttribute, Push("label")}, + {`\{[\w+.\$-]+\}`, LiteralStringEscape, Push("label")}, {`\s+`, Text, nil}, }, "globals": { @@ -173,6 +173,9 @@ var Caddyfile = internal.Register(MustNewLexer( // a comma means another label is coming {`,\s*\n?`, Text, nil}, {` `, Text, nil}, + // Site label with placeholder + {`\{[\w+.\$-]+\}`, LiteralStringEscape, nil}, + // Site label {`[^#{(\s,]+`, GenericHeading, nil}, // Comment after non-block label (hack because comments end in \n) {`#.*\n`, CommentSingle, Push("site_block")}, diff --git a/lexers/testdata/caddyfile.actual b/lexers/testdata/caddyfile.actual index 9f6767efb..d4214209a 100644 --- a/lexers/testdata/caddyfile.actual +++ b/lexers/testdata/caddyfile.actual @@ -13,9 +13,11 @@ redir @blocked / } -example.com, fake.org { +example.com, fake.org, {$ENV_SITE} { root * /srv + respond /get-env {$ENV_VAR} + tls off route { diff --git a/lexers/testdata/caddyfile.expected b/lexers/testdata/caddyfile.expected index 21efcff6d..97db4a198 100644 --- a/lexers/testdata/caddyfile.expected +++ b/lexers/testdata/caddyfile.expected @@ -50,6 +50,8 @@ {"type":"GenericHeading","value":"example.com"}, {"type":"Text","value":", "}, {"type":"GenericHeading","value":"fake.org"}, + {"type":"Text","value":", "}, + {"type":"LiteralStringEscape","value":"{$ENV_SITE}"}, {"type":"Text","value":" "}, {"type":"Punctuation","value":"{"}, {"type":"Text","value":"\n\t"}, @@ -59,6 +61,12 @@ {"type":"Text","value":" "}, {"type":"LiteralString","value":"/srv"}, {"type":"Text","value":"\n\n\t"}, + {"type":"Keyword","value":"respond"}, + {"type":"Text","value":" "}, + {"type":"NameDecorator","value":"/get-env"}, + {"type":"Text","value":" "}, + {"type":"LiteralStringEscape","value":"{$ENV_VAR}"}, + {"type":"Text","value":"\n\n\t"}, {"type":"Keyword","value":"tls"}, {"type":"Text","value":" "}, {"type":"NameConstant","value":"off"},