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
Łukasz Nowak
caddy
Commits
e8e55955
Commit
e8e55955
authored
Aug 17, 2016
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Report error when loading the lexer
parent
8b8afd72
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
7 deletions
+21
-7
caddyfile/dispenser.go
caddyfile/dispenser.go
+2
-1
caddyfile/lexer.go
caddyfile/lexer.go
+4
-1
caddyfile/parse.go
caddyfile/parse.go
+11
-4
caddyfile/parse_test.go
caddyfile/parse_test.go
+4
-1
No files found.
caddyfile/dispenser.go
View file @
e8e55955
...
@@ -19,9 +19,10 @@ type Dispenser struct {
...
@@ -19,9 +19,10 @@ type Dispenser struct {
// NewDispenser returns a Dispenser, ready to use for parsing the given input.
// NewDispenser returns a Dispenser, ready to use for parsing the given input.
func
NewDispenser
(
filename
string
,
input
io
.
Reader
)
Dispenser
{
func
NewDispenser
(
filename
string
,
input
io
.
Reader
)
Dispenser
{
tokens
,
_
:=
allTokens
(
input
)
// ignoring error because nothing to do with it
return
Dispenser
{
return
Dispenser
{
filename
:
filename
,
filename
:
filename
,
tokens
:
allTokens
(
input
)
,
tokens
:
tokens
,
cursor
:
-
1
,
cursor
:
-
1
,
}
}
}
}
...
...
caddyfile/lexer.go
View file @
e8e55955
...
@@ -33,7 +33,10 @@ func (l *lexer) load(input io.Reader) error {
...
@@ -33,7 +33,10 @@ func (l *lexer) load(input io.Reader) error {
// discard byte order mark, if present
// discard byte order mark, if present
firstCh
,
_
,
err
:=
l
.
reader
.
ReadRune
()
firstCh
,
_
,
err
:=
l
.
reader
.
ReadRune
()
if
err
==
nil
&&
firstCh
!=
0xFEFF
{
if
err
!=
nil
{
return
err
}
if
firstCh
!=
0xFEFF
{
err
:=
l
.
reader
.
UnreadRune
()
err
:=
l
.
reader
.
UnreadRune
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
caddyfile/parse.go
View file @
e8e55955
...
@@ -22,13 +22,17 @@ func Parse(filename string, input io.Reader, validDirectives []string) ([]Server
...
@@ -22,13 +22,17 @@ func Parse(filename string, input io.Reader, validDirectives []string) ([]Server
// allTokens lexes the entire input, but does not parse it.
// allTokens lexes the entire input, but does not parse it.
// It returns all the tokens from the input, unstructured
// It returns all the tokens from the input, unstructured
// and in order.
// and in order.
func
allTokens
(
input
io
.
Reader
)
(
tokens
[]
Token
)
{
func
allTokens
(
input
io
.
Reader
)
(
[]
Token
,
error
)
{
l
:=
new
(
lexer
)
l
:=
new
(
lexer
)
l
.
load
(
input
)
err
:=
l
.
load
(
input
)
if
err
!=
nil
{
return
nil
,
err
}
var
tokens
[]
Token
for
l
.
next
()
{
for
l
.
next
()
{
tokens
=
append
(
tokens
,
l
.
token
)
tokens
=
append
(
tokens
,
l
.
token
)
}
}
return
return
tokens
,
nil
}
}
type
parser
struct
{
type
parser
struct
{
...
@@ -294,7 +298,10 @@ func (p *parser) doSingleImport(importFile string) ([]Token, error) {
...
@@ -294,7 +298,10 @@ func (p *parser) doSingleImport(importFile string) ([]Token, error) {
return
nil
,
p
.
Errf
(
"Could not import %s: is a directory"
,
importFile
)
return
nil
,
p
.
Errf
(
"Could not import %s: is a directory"
,
importFile
)
}
}
importedTokens
:=
allTokens
(
file
)
importedTokens
,
err
:=
allTokens
(
file
)
if
err
!=
nil
{
return
nil
,
p
.
Errf
(
"Could not read tokens while importing %s: %v"
,
importFile
,
err
)
}
// Tack the filename onto these tokens so errors show the imported file's name
// Tack the filename onto these tokens so errors show the imported file's name
filename
:=
filepath
.
Base
(
importFile
)
filename
:=
filepath
.
Base
(
importFile
)
...
...
caddyfile/parse_test.go
View file @
e8e55955
...
@@ -9,8 +9,11 @@ import (
...
@@ -9,8 +9,11 @@ import (
func
TestAllTokens
(
t
*
testing
.
T
)
{
func
TestAllTokens
(
t
*
testing
.
T
)
{
input
:=
strings
.
NewReader
(
"a b c
\n
d e"
)
input
:=
strings
.
NewReader
(
"a b c
\n
d e"
)
expected
:=
[]
string
{
"a"
,
"b"
,
"c"
,
"d"
,
"e"
}
expected
:=
[]
string
{
"a"
,
"b"
,
"c"
,
"d"
,
"e"
}
tokens
:=
allTokens
(
input
)
tokens
,
err
:=
allTokens
(
input
)
if
err
!=
nil
{
t
.
Fatalf
(
"Expected no error, got %v"
,
err
)
}
if
len
(
tokens
)
!=
len
(
expected
)
{
if
len
(
tokens
)
!=
len
(
expected
)
{
t
.
Fatalf
(
"Expected %d tokens, got %d"
,
len
(
expected
),
len
(
tokens
))
t
.
Fatalf
(
"Expected %d tokens, got %d"
,
len
(
expected
),
len
(
tokens
))
}
}
...
...
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