|
|
@ -3,10 +3,11 @@ package wikilink
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
// "unicode"
|
|
|
|
// "unicode"
|
|
|
|
"unicode/utf8"
|
|
|
|
"unicode/utf8"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
const (
|
|
|
@ -35,6 +36,7 @@ const (
|
|
|
|
|
|
|
|
|
|
|
|
func Lex(name, input string) *Lexer {
|
|
|
|
func Lex(name, input string) *Lexer {
|
|
|
|
l := &Lexer{
|
|
|
|
l := &Lexer{
|
|
|
|
|
|
|
|
L: zap.NewExample().Sugar().Named("lexer"),
|
|
|
|
name: name,
|
|
|
|
name: name,
|
|
|
|
input: input,
|
|
|
|
input: input,
|
|
|
|
state: lexText,
|
|
|
|
state: lexText,
|
|
|
@ -72,6 +74,7 @@ func (l *Lexer) backup() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type Lexer struct {
|
|
|
|
type Lexer struct {
|
|
|
|
|
|
|
|
L *zap.SugaredLogger
|
|
|
|
name, input string
|
|
|
|
name, input string
|
|
|
|
start, pos, width int
|
|
|
|
start, pos, width int
|
|
|
|
state stateFn
|
|
|
|
state stateFn
|
|
|
@ -103,18 +106,29 @@ func (l *Lexer) acceptRun(valid string) {
|
|
|
|
|
|
|
|
|
|
|
|
func (l *Lexer) emit(t ItemType) {
|
|
|
|
func (l *Lexer) emit(t ItemType) {
|
|
|
|
i := Item{t, l.input[l.start:l.pos]}
|
|
|
|
i := Item{t, l.input[l.start:l.pos]}
|
|
|
|
log.Printf("emitting Item: %s\n", i.String())
|
|
|
|
L := l.L.With(
|
|
|
|
|
|
|
|
zap.Int("pos", l.pos),
|
|
|
|
|
|
|
|
zap.Int("width", l.width),
|
|
|
|
|
|
|
|
).Named("emit")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
L.Debugw("emitting item",
|
|
|
|
|
|
|
|
zap.String("item", i.String()),
|
|
|
|
|
|
|
|
)
|
|
|
|
l.items <- i
|
|
|
|
l.items <- i
|
|
|
|
l.start = l.pos
|
|
|
|
l.start = l.pos
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (l *Lexer) errorf(format string, args ...interface{}) stateFn {
|
|
|
|
func (l *Lexer) errorf(format string, args ...interface{}) stateFn {
|
|
|
|
log.Printf("entering errorf: %q\n", format)
|
|
|
|
L := l.L.Named("errorf")
|
|
|
|
l.items <- Item{
|
|
|
|
errorItem := Item{
|
|
|
|
ItemError,
|
|
|
|
ItemError,
|
|
|
|
fmt.Sprintf(format, args...),
|
|
|
|
fmt.Sprintf(format, args...),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
L.Debugw("emitting errorItem",
|
|
|
|
|
|
|
|
zap.String("error", errorItem.String()),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
l.items <- errorItem
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|