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
2dc39fea
Commit
2dc39fea
authored
Mar 28, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tweak to parser and main's error handling
parent
09aad777
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
9 deletions
+15
-9
config/parser.go
config/parser.go
+12
-6
config/parsing.go
config/parsing.go
+2
-2
main.go
main.go
+1
-1
No files found.
config/parser.go
View file @
2dc39fea
...
@@ -16,7 +16,7 @@ type (
...
@@ -16,7 +16,7 @@ type (
cfg
Config
// each server gets one Config; this is the one we're currently building
cfg
Config
// each server gets one Config; this is the one we're currently building
other
[]
locationContext
// tokens to be 'parsed' later by middleware generators
other
[]
locationContext
// tokens to be 'parsed' later by middleware generators
scope
*
locationContext
// the current location context (path scope) being populated
scope
*
locationContext
// the current location context (path scope) being populated
unused
bool
// sometimes a token will be read but not immediately consumed
unused
*
token
// sometimes a token will be read but not immediately consumed
}
}
// locationContext represents a location context
// locationContext represents a location context
...
@@ -62,13 +62,13 @@ func (p *parser) parse() ([]Config, error) {
...
@@ -62,13 +62,13 @@ func (p *parser) parse() ([]Config, error) {
// nextArg loads the next token if it is on the same line.
// nextArg loads the next token if it is on the same line.
// Returns true if a token was loaded; false otherwise.
// Returns true if a token was loaded; false otherwise.
func
(
p
*
parser
)
nextArg
()
bool
{
func
(
p
*
parser
)
nextArg
()
bool
{
if
p
.
unused
{
if
p
.
unused
!=
nil
{
return
false
return
false
}
}
line
:=
p
.
line
()
line
,
tkn
:=
p
.
line
(),
p
.
lexer
.
token
if
p
.
next
()
{
if
p
.
next
()
{
if
p
.
line
()
>
line
{
if
p
.
line
()
>
line
{
p
.
unused
=
true
p
.
unused
=
&
tkn
return
false
return
false
}
}
return
true
return
true
...
@@ -79,8 +79,8 @@ func (p *parser) nextArg() bool {
...
@@ -79,8 +79,8 @@ func (p *parser) nextArg() bool {
// next loads the next token and returns true if a token
// next loads the next token and returns true if a token
// was loaded; false otherwise.
// was loaded; false otherwise.
func
(
p
*
parser
)
next
()
bool
{
func
(
p
*
parser
)
next
()
bool
{
if
p
.
unused
{
if
p
.
unused
!=
nil
{
p
.
unused
=
false
p
.
unused
=
nil
return
true
return
true
}
else
{
}
else
{
return
p
.
lexer
.
next
()
return
p
.
lexer
.
next
()
...
@@ -151,11 +151,17 @@ func (p *parser) unwrap() error {
...
@@ -151,11 +151,17 @@ func (p *parser) unwrap() error {
// tkn is shorthand to get the text/value of the current token.
// tkn is shorthand to get the text/value of the current token.
func
(
p
*
parser
)
tkn
()
string
{
func
(
p
*
parser
)
tkn
()
string
{
if
p
.
unused
!=
nil
{
return
p
.
unused
.
text
}
return
p
.
lexer
.
token
.
text
return
p
.
lexer
.
token
.
text
}
}
// line is shorthand to get the line number of the current token.
// line is shorthand to get the line number of the current token.
func
(
p
*
parser
)
line
()
int
{
func
(
p
*
parser
)
line
()
int
{
if
p
.
unused
!=
nil
{
return
p
.
unused
.
line
}
return
p
.
lexer
.
token
.
line
return
p
.
lexer
.
token
.
line
}
}
...
...
config/parsing.go
View file @
2dc39fea
...
@@ -48,7 +48,7 @@ func (p *parser) addressBlock() error {
...
@@ -48,7 +48,7 @@ func (p *parser) addressBlock() error {
err
:=
p
.
openCurlyBrace
()
err
:=
p
.
openCurlyBrace
()
if
err
!=
nil
{
if
err
!=
nil
{
// meh, single-server configs don't need curly braces
// meh, single-server configs don't need curly braces
p
.
unused
=
true
// we read the token but aren't consuming it
p
.
unused
=
&
p
.
lexer
.
token
// we read the token but aren't consuming it
return
p
.
directives
()
return
p
.
directives
()
}
}
...
@@ -224,7 +224,7 @@ func (p *parser) collectTokens() error {
...
@@ -224,7 +224,7 @@ func (p *parser) collectTokens() error {
if
p
.
tkn
()
==
"{"
{
if
p
.
tkn
()
==
"{"
{
nesting
++
nesting
++
}
else
if
p
.
line
()
>
line
&&
nesting
==
0
{
}
else
if
p
.
line
()
>
line
&&
nesting
==
0
{
p
.
unused
=
true
p
.
unused
=
&
p
.
lexer
.
token
breakOk
=
true
breakOk
=
true
break
break
}
else
if
p
.
tkn
()
==
"}"
&&
nesting
>
0
{
}
else
if
p
.
tkn
()
==
"}"
&&
nesting
>
0
{
...
...
main.go
View file @
2dc39fea
...
@@ -39,7 +39,7 @@ func main() {
...
@@ -39,7 +39,7 @@ func main() {
defer
wg
.
Done
()
defer
wg
.
Done
()
err
:=
s
.
Serve
()
err
:=
s
.
Serve
()
if
err
!=
nil
{
if
err
!=
nil
{
s
.
Log
(
err
)
log
.
Println
(
err
)
}
}
}(
s
)
}(
s
)
}
}
...
...
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