Skip to content

Commit

Permalink
Additional fixes for placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie committed May 16, 2020
1 parent d94559b commit e8824bb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lexers/c/caddyfile.go
Expand Up @@ -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},
Expand All @@ -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": {
Expand All @@ -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")},
Expand Down
4 changes: 3 additions & 1 deletion lexers/testdata/caddyfile.actual
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions lexers/testdata/caddyfile.expected
Expand Up @@ -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"},
Expand All @@ -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"},
Expand Down

0 comments on commit e8824bb

Please sign in to comment.