~ghost08/wt

b0690411cc01b974c47311d90dcfe80868e6ba0f — VladimĂ­r Magyar 2 years ago 9205077
fix: make staticcheck happy
5 files changed, 7 insertions(+), 68 deletions(-)

M go.mod
M go.sum
M lexer.go
M main.go
M parser.go
M go.mod => go.mod +1 -1
@@ 21,5 21,5 @@ require (
	github.com/pkg/errors v0.9.1 // indirect
	github.com/posener/script v1.1.5 // indirect
	github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
	golang.org/x/sys v0.0.0-20220315194320-039c03cc5b86 // indirect
	golang.org/x/sys v0.0.0-20220406163625-3f8b81556e12 // indirect
)

M go.sum => go.sum +2 -0
@@ 52,6 52,8 @@ golang.org/x/sys v0.0.0-20220111092808-5a964db01320 h1:0jf+tOCoZ3LyutmCOWpVni1ch
golang.org/x/sys v0.0.0-20220111092808-5a964db01320/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220315194320-039c03cc5b86 h1:A9i04dxx7Cribqbs8jf3FQLogkL/CV2YN7hj9KWJCkc=
golang.org/x/sys v0.0.0-20220315194320-039c03cc5b86/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220406163625-3f8b81556e12 h1:QyVthZKMsyaQwBTJE04jdNN0Pp5Fn9Qga0mrgxyERQM=
golang.org/x/sys v0.0.0-20220406163625-3f8b81556e12/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

M lexer.go => lexer.go +0 -63
@@ 115,22 115,6 @@ func (l *lexer) peek() rune {
	return r
}

//readLetters reads all runes that are letters
func (l *lexer) readLetters() string {
	var buf strings.Builder
	for {
		ch := l.read()
		if ch == eof {
			break
		} else if !unicode.IsLetter(ch) {
			l.unread()
			break
		}
		buf.WriteRune(ch)
	}
	return buf.String()
}

//readDigits reads all runes that are letters
func (l *lexer) readDigits() string {
	for {


@@ 201,28 185,6 @@ func (l *lexer) readTime() {
	l.emit(itemTime)
}

//acceptToLineBreak reads entire string to line break
func (l *lexer) acceptToLineBreak() {
	for {
		if ch := l.read(); ch == eof {
			break
		} else if ch == '\r' || ch == '\n' {
			if ch == '\r' {
				r, _, _ := l.input.ReadRune()
				if r != '\n' {
					l.input.UnreadRune()
				}
			}
			if ch = l.read(); unicode.IsSpace(ch) {
				continue
			}
			l.unread()
			l.unread()
			break
		}
	}
}

func (l *lexer) acceptToTab() {
	for {
		ch := l.read()


@@ 244,31 206,6 @@ func (l *lexer) accept(valid string) {
	l.unread()
}

func (l *lexer) acceptWhitespace() {
	l.accept(" \t\n\r")
	l.buf.Reset()
}

func (l *lexer) ignoreWhitespace() {
	for {
		ch, _, err := l.input.ReadRune()
		if ch == '\n' {
			l.line++
			l.prevpos = l.pos
			l.pos = 0
		} else {
			if !unicode.IsSpace(ch) {
				l.input.UnreadRune()
				return
			}
			l.pos++
			if err != nil {
				return
			}
		}
	}
}

//errorf returns an error token and terminates the scan
//by passing back a nil pointer that will be the next
//state, terminating l.run.

M main.go => main.go +2 -2
@@ 227,7 227,7 @@ func end() error {
		color.FgLightWhite.Render(last.Description),
		color.Style{color.FgLightWhite, color.OpBold}.Render("start"),
		last.Start.Format("15:04:05"),
		color.FgMagenta.Sprint(time.Now().Sub(last.Start)),
		color.FgMagenta.Sprint(time.Since(last.Start)),
	)
	return nil
}


@@ 248,7 248,7 @@ func status() error {
			color.Style{color.FgLightWhite, color.OpBold}.Render("start"),
			last.Start.Format("15:04:05"),
			color.Style{color.FgLightWhite, color.OpBold}.Render("duration"),
			color.FgMagenta.Sprint(time.Now().Sub(last.Start)),
			color.FgMagenta.Sprint(time.Since(last.Start)),
		)
	}
	y, m, d := time.Now().Date()

M parser.go => parser.go +2 -2
@@ 59,11 59,11 @@ func parseDay(s *scanner) (Entries, error) {
		return nil, nil
	}
	if dateItem.typ != itemDate {
		return nil, fmt.Errorf("Expected date item")
		return nil, fmt.Errorf("expected date item")
	}
	d, err := time.ParseInLocation("2006-01-02", dateItem.val, time.Local)
	if err != nil {
		return nil, fmt.Errorf("Error parsing date at %s: %w", s.l.posString(), err)
		return nil, fmt.Errorf("error parsing date at %s: %w", s.l.posString(), err)
	}
	var entries Entries
	for {