diff options
| author | Marc Vertes <mvertes@free.fr> | 2024-04-02 11:27:13 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-02 11:27:13 +0200 |
| commit | 1bff92c52b27b9a516599e172fe9852c3d99be38 (patch) | |
| tree | 26b30b5ec1a5537dcafd806d23e03a062475705d /parser/tokens.go | |
| parent | 362f7c9c45598b429c92e67756f41b690043e0c4 (diff) | |
chore: add linters and some lint fixes (#8)
* chore: add linters and some lint fixes
Configure some golangci-lint linters to get the code quality right.
Apply the first fixes.
Next step will be to add github actions to run lint and tests in
github CI.
* chore: more lint, fixed comments and variable names. no semantic change.
* chore: add Makefile
This makefile is intended to be used as a local substitute to github
actions.
Diffstat (limited to 'parser/tokens.go')
| -rw-r--r-- | parser/tokens.go | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/parser/tokens.go b/parser/tokens.go index 51085d9..78467c6 100644 --- a/parser/tokens.go +++ b/parser/tokens.go @@ -5,6 +5,7 @@ import ( "github.com/mvertes/parscan/scanner" ) +// Tokens represents slice of tokens. type Tokens []scanner.Token func (toks Tokens) String() (s string) { @@ -14,27 +15,30 @@ func (toks Tokens) String() (s string) { return s } -func (toks Tokens) Index(id lang.TokenId) int { +// Index returns the index in toks of the first matching tok, or -1. +func (toks Tokens) Index(tok lang.Token) int { for i, t := range toks { - if t.Id == id { + if t.Tok == tok { return i } } return -1 } -func (toks Tokens) LastIndex(id lang.TokenId) int { +// LastIndex returns the index in toks of the last matching tok, or -1. +func (toks Tokens) LastIndex(tok lang.Token) int { for i := len(toks) - 1; i >= 0; i-- { - if toks[i].Id == id { + if toks[i].Tok == tok { return i } } return -1 } -func (toks Tokens) Split(id lang.TokenId) (result []Tokens) { +// Split returns a slice of token arrays, separated by tok. +func (toks Tokens) Split(tok lang.Token) (result []Tokens) { for { - i := toks.Index(id) + i := toks.Index(tok) if i < 0 { return append(result, toks) } @@ -43,9 +47,10 @@ func (toks Tokens) Split(id lang.TokenId) (result []Tokens) { } } -func (toks Tokens) SplitStart(id lang.TokenId) (result []Tokens) { +// SplitStart is similar to Split, except the first token in toks is skipped. +func (toks Tokens) SplitStart(tok lang.Token) (result []Tokens) { for { - i := toks[1:].Index(id) + i := toks[1:].Index(tok) if i < 0 { return append(result, toks) } |
