Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
ad2956fd
Commit
ad2956fd
authored
Oct 31, 2017
by
Craig Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
snippets now
parent
5c9fc3a4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
17 deletions
+17
-17
caddyfile/parse.go
caddyfile/parse.go
+16
-16
caddyfile/parse_test.go
caddyfile/parse_test.go
+1
-1
No files found.
caddyfile/parse.go
View file @
ad2956fd
...
...
@@ -54,7 +54,7 @@ type parser struct {
block
ServerBlock
// current server block being parsed
validDirectives
[]
string
// a directive must be valid or it's an error
eof
bool
// if we encounter a valid EOF in a hard place
defined
Macros
map
[
string
][]
Token
defined
Snippets
map
[
string
][]
Token
}
func
(
p
*
parser
)
parseAll
()
([]
ServerBlock
,
error
)
{
...
...
@@ -96,19 +96,19 @@ func (p *parser) begin() error {
return
nil
}
if
ok
,
name
:=
p
.
is
Macro
();
ok
{
if
p
.
defined
Macro
s
==
nil
{
p
.
defined
Macro
s
=
map
[
string
][]
Token
{}
if
ok
,
name
:=
p
.
is
Snippet
();
ok
{
if
p
.
defined
Snippet
s
==
nil
{
p
.
defined
Snippet
s
=
map
[
string
][]
Token
{}
}
if
_
,
found
:=
p
.
defined
Macro
s
[
name
];
found
{
return
p
.
Errf
(
"redeclaration of previously declared
macro
%s"
,
name
)
if
_
,
found
:=
p
.
defined
Snippet
s
[
name
];
found
{
return
p
.
Errf
(
"redeclaration of previously declared
snippet
%s"
,
name
)
}
// consume all tokens til matched close brace
tokens
,
err
:=
p
.
macro
Tokens
()
tokens
,
err
:=
p
.
snippet
Tokens
()
if
err
!=
nil
{
return
err
}
p
.
defined
Macro
s
[
name
]
=
tokens
p
.
defined
Snippet
s
[
name
]
=
tokens
// empty block keys so we don't save this block as a real server.
p
.
block
.
Keys
=
nil
return
nil
...
...
@@ -245,9 +245,9 @@ func (p *parser) doImport() error {
tokensAfter
:=
p
.
tokens
[
p
.
cursor
+
1
:
]
var
importedTokens
[]
Token
// first check
macro
s. That is a simple, non-recursive replacement
if
p
.
defined
Macros
!=
nil
&&
p
.
definedMacro
s
[
importPattern
]
!=
nil
{
importedTokens
=
p
.
defined
Macro
s
[
importPattern
]
// first check
snippet
s. That is a simple, non-recursive replacement
if
p
.
defined
Snippets
!=
nil
&&
p
.
definedSnippet
s
[
importPattern
]
!=
nil
{
importedTokens
=
p
.
defined
Snippet
s
[
importPattern
]
}
else
{
// make path relative to Caddyfile rather than current working directory (issue #867)
// and then use glob to get list of matching filenames
...
...
@@ -458,9 +458,9 @@ type ServerBlock struct {
Tokens
map
[
string
][]
Token
}
func
(
p
*
parser
)
is
Macro
()
(
bool
,
string
)
{
func
(
p
*
parser
)
is
Snippet
()
(
bool
,
string
)
{
keys
:=
p
.
block
.
Keys
// A
macro
block is a single key with parens. Nothing else qualifies.
// A
snippet
block is a single key with parens. Nothing else qualifies.
if
len
(
keys
)
==
1
&&
strings
.
HasPrefix
(
keys
[
0
],
"("
)
&&
strings
.
HasSuffix
(
keys
[
0
],
")"
)
{
return
true
,
strings
.
TrimSuffix
(
keys
[
0
][
1
:
],
")"
)
}
...
...
@@ -468,9 +468,9 @@ func (p *parser) isMacro() (bool, string) {
}
// read and store everything in a block for later replay.
func
(
p
*
parser
)
macro
Tokens
()
([]
Token
,
error
)
{
// TODO: disallow imports in
macro
s for simplicity at import time
//
macro
must have curlies.
func
(
p
*
parser
)
snippet
Tokens
()
([]
Token
,
error
)
{
// TODO: disallow imports in
snippet
s for simplicity at import time
//
snippet
must have curlies.
err
:=
p
.
openCurlyBrace
()
if
err
!=
nil
{
return
nil
,
err
...
...
caddyfile/parse_test.go
View file @
ad2956fd
...
...
@@ -515,7 +515,7 @@ func testParser(input string) parser {
return
p
}
func
Test
Macro
(
t
*
testing
.
T
)
{
func
Test
Snippets
(
t
*
testing
.
T
)
{
p
:=
testParser
(
`(common) {
gzip foo
errors stderr
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment