mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Config reporting with line and error position
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
This commit is contained in:
30
conf/lex.go
30
conf/lex.go
@@ -101,12 +101,19 @@ type lexer struct {
|
||||
// Used for processing escapable substrings in double-quoted and raw strings
|
||||
stringParts []string
|
||||
stringStateFn stateFn
|
||||
|
||||
// lstart is the start position of the current line.
|
||||
lstart int
|
||||
|
||||
// ilstart is the start position of the line from the current item.
|
||||
ilstart int
|
||||
}
|
||||
|
||||
type item struct {
|
||||
typ itemType
|
||||
val string
|
||||
line int
|
||||
pos int
|
||||
}
|
||||
|
||||
func (lx *lexer) nextItem() item {
|
||||
@@ -147,8 +154,13 @@ func (lx *lexer) pop() stateFn {
|
||||
}
|
||||
|
||||
func (lx *lexer) emit(typ itemType) {
|
||||
lx.items <- item{typ, strings.Join(lx.stringParts, "") + lx.input[lx.start:lx.pos], lx.line}
|
||||
val := strings.Join(lx.stringParts, "") + lx.input[lx.start:lx.pos]
|
||||
|
||||
// Position of item in line where it started.
|
||||
pos := lx.pos - lx.ilstart - len(val)
|
||||
lx.items <- item{typ, val, lx.line, pos}
|
||||
lx.start = lx.pos
|
||||
lx.ilstart = lx.lstart
|
||||
}
|
||||
|
||||
func (lx *lexer) emitString() {
|
||||
@@ -159,8 +171,11 @@ func (lx *lexer) emitString() {
|
||||
} else {
|
||||
finalString = lx.input[lx.start:lx.pos]
|
||||
}
|
||||
lx.items <- item{itemString, finalString, lx.line}
|
||||
// Position of string in line where it started.
|
||||
pos := lx.pos - lx.ilstart - len(finalString)
|
||||
lx.items <- item{itemString, finalString, lx.line, pos}
|
||||
lx.start = lx.pos
|
||||
lx.ilstart = lx.lstart
|
||||
}
|
||||
|
||||
func (lx *lexer) addCurrentStringPart(offset int) {
|
||||
@@ -186,15 +201,20 @@ func (lx *lexer) next() (r rune) {
|
||||
|
||||
if lx.input[lx.pos] == '\n' {
|
||||
lx.line++
|
||||
|
||||
// Mark start position of current line.
|
||||
lx.lstart = lx.pos
|
||||
}
|
||||
r, lx.width = utf8.DecodeRuneInString(lx.input[lx.pos:])
|
||||
lx.pos += lx.width
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// ignore skips over the pending input before this point.
|
||||
func (lx *lexer) ignore() {
|
||||
lx.start = lx.pos
|
||||
lx.ilstart = lx.lstart
|
||||
}
|
||||
|
||||
// backup steps back one rune. Can be called only once per call of next.
|
||||
@@ -221,10 +241,14 @@ func (lx *lexer) errorf(format string, values ...interface{}) stateFn {
|
||||
values[i] = escapeSpecial(v)
|
||||
}
|
||||
}
|
||||
|
||||
// Position of error in current line.
|
||||
pos := lx.pos - lx.lstart
|
||||
lx.items <- item{
|
||||
itemError,
|
||||
fmt.Sprintf(format, values...),
|
||||
lx.line,
|
||||
pos,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1131,7 +1155,7 @@ func (itype itemType) String() string {
|
||||
}
|
||||
|
||||
func (item item) String() string {
|
||||
return fmt.Sprintf("(%s, '%s', %d)", item.typ.String(), item.val, item.line)
|
||||
return fmt.Sprintf("(%s, '%s', %d, %d)", item.typ.String(), item.val, item.line, item.pos)
|
||||
}
|
||||
|
||||
func escapeSpecial(c rune) string {
|
||||
|
||||
Reference in New Issue
Block a user