summaryrefslogtreecommitdiff
path: root/conf
diff options
context:
space:
mode:
Diffstat (limited to 'conf')
-rw-r--r--conf/parser.go13
-rw-r--r--conf/scanner.go26
2 files changed, 27 insertions, 12 deletions
diff --git a/conf/parser.go b/conf/parser.go
index cc85054..3d584f6 100644
--- a/conf/parser.go
+++ b/conf/parser.go
@@ -59,10 +59,12 @@ func (p *parser) advanceOneToken(place string) {
p.last = p.cur
p.cur, err = p.s.Scan()
- if err != nil {
- fmt.Fprintf(os.Stderr, "error when parsing %s. Scanner returned an error %v.\n", place, err)
- os.Exit(1)
+ for err == nil {
+ fmt.Fprintf(os.Stderr, "tokentype: %v, token: %q offset: %d, line: %d\n", p.cur.Type, p.cur.Lit, p.cur.Offset, p.cur.LineNr)
+ p.last = p.cur
+ p.cur, err = p.s.Scan()
}
+ fmt.Fprintf(os.Stderr, "Error: tokentype: %v, token: %q, err: %v\n", p.cur.Type, p.cur.Lit, err)
}
func (p *parser) module(firstname string) {
@@ -75,7 +77,7 @@ func (p *parser) module(firstname string) {
}
p.advanceOneToken("module")
- if p.cur.Type != ObjectDelimiter {
+ if p.cur.Type != ObjectOpen {
fmt.Fprintf(os.Stderr, "error when parsing module. We were expecting an opening bracket but got %q at line %d offset %d.\n", p.cur.Lit, p.cur.LineNr, p.cur.Offset)
}
@@ -110,7 +112,6 @@ func (p *parser) object() {
break
}
}
-
}
func (p *parser) keyvalue() bool {
@@ -138,7 +139,7 @@ func (p *parser) keyvalue() bool {
}
fmt.Fprintf(os.Stderr, "peeked %q (type %d) at line %d offset %d.\n", tok.Lit, tok.Type, tok.LineNr, tok.Offset)
- if tok.Type == ObjectDelimiter {
+ if tok.Type == ObjectClose {
p.advanceOneToken("keyvaluelast")
return false
}
diff --git a/conf/scanner.go b/conf/scanner.go
index 74e66e8..975a8e4 100644
--- a/conf/scanner.go
+++ b/conf/scanner.go
@@ -14,14 +14,24 @@ type tokentype int
const (
Name tokentype = iota
Literal
- ListDelimiter
- ObjectDelimiter
+ ListOpen
+ ListClose
+ ObjectOpen
+ ObjectClose
EmptyList
EmptyObject
Nothing
IfStatement
)
+var tokentypestrings []string = []string{Name: "Name", Literal: "Literal",
+ ListOpen: "List Open", ListClose: "List Close", ObjectOpen: "Object Open",
+ ObjectClose: "Object Close", Nothing: "Nothing", IfStatement: "If statement"}
+
+func (tt tokentype) String() string {
+ return tokentypestrings[tt]
+}
+
type token struct {
Type tokentype
Offset int
@@ -57,10 +67,14 @@ func getTokenType(s []byte) tokentype {
switch s[0] {
case '"', '\'':
return Literal
- case '[', ']':
- return ListDelimiter
- case '{', '}':
- return ObjectDelimiter
+ case '[':
+ return ListOpen
+ case ']':
+ return ListClose
+ case '{':
+ return ObjectOpen
+ case '}':
+ return ObjectClose
}
return Name