From bf0edfc59323a5bc26aa00306a9cef429a944037 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 27 Dec 2025 02:43:17 -0500 Subject: [PATCH] style: renamed token index to column --- pkg/saccharine/parser.go | 12 ++++++------ pkg/saccharine/token/token.go | 30 +++++++++++++++--------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pkg/saccharine/parser.go b/pkg/saccharine/parser.go index bed529d..b2cda63 100644 --- a/pkg/saccharine/parser.go +++ b/pkg/saccharine/parser.go @@ -37,7 +37,7 @@ func parseExpression(i *TokenIterator) (ast.Expression, error) { case token.Atom: exp, err = parseAtom(i) default: - return nil, fmt.Errorf("expected expression, got '%v' (col %d)", peek.Value, peek.Index) + return nil, fmt.Errorf("expected expression, got '%v' (col %d)", peek.Value, peek.Column) } return exp, err @@ -63,11 +63,11 @@ func parseAbstraction(i *TokenIterator) (*ast.Abstraction, error) { i2 := i.Copy() if _, err := parseToken(i2, token.Slash); err != nil { - return nil, trace.WrapError(fmt.Errorf("no function slash (col %d)", i2.MustGet().Index), err) + return nil, trace.WrapError(fmt.Errorf("no function slash (col %d)", i2.MustGet().Column), err) } else if parameters, err := parseParameters(i2); err != nil { return nil, err } else if _, err = parseToken(i2, token.Dot); err != nil { - return nil, trace.WrapError(fmt.Errorf("no function dot (col %d)", i2.MustGet().Index), err) + return nil, trace.WrapError(fmt.Errorf("no function dot (col %d)", i2.MustGet().Column), err) } else if body, err := parseExpression(i2); err != nil { return nil, err } else { @@ -81,7 +81,7 @@ func parseApplication(i *TokenIterator) (*ast.Application, error) { expressions := []ast.Expression{} if _, err := parseToken(i2, token.OpenParen); err != nil { - return nil, trace.WrapError(fmt.Errorf("no openning brackets (col %d)", i2.MustGet().Index), err) + return nil, trace.WrapError(fmt.Errorf("no openning brackets (col %d)", i2.MustGet().Column), err) } for { @@ -96,7 +96,7 @@ func parseApplication(i *TokenIterator) (*ast.Application, error) { } if _, err := parseToken(i2, token.CloseParen); err != nil { - return nil, trace.WrapError(fmt.Errorf("no closing brackets (col %d)", i2.MustGet().Index), err) + return nil, trace.WrapError(fmt.Errorf("no closing brackets (col %d)", i2.MustGet().Column), err) } i.Sync(i2) @@ -120,7 +120,7 @@ func Parse(tokens []token.Token) (ast.Expression, error) { } if !i.Done() { - return nil, fmt.Errorf("expected EOF, found more code (col %d)", i.MustGet().Index) + return nil, fmt.Errorf("expected EOF, found more code (col %d)", i.MustGet().Column) } return exp, nil diff --git a/pkg/saccharine/token/token.go b/pkg/saccharine/token/token.go index f7b143b..74630f8 100644 --- a/pkg/saccharine/token/token.go +++ b/pkg/saccharine/token/token.go @@ -14,33 +14,33 @@ const ( // A representation of a token in source code. type Token struct { - Index int // Where the token begins in the source text. - Type Type // What type the token is. - Value string // The value of the token. + Column int // Where the token begins in the source text. + Type Type // What type the token is. + Value string // The value of the token. } -func NewOpenParen(index int) *Token { - return &Token{Type: OpenParen, Index: index, Value: "("} +func NewOpenParen(column int) *Token { + return &Token{Type: OpenParen, Column: column, Value: "("} } -func NewCloseParen(index int) *Token { - return &Token{Type: CloseParen, Index: index, Value: ")"} +func NewCloseParen(column int) *Token { + return &Token{Type: CloseParen, Column: column, Value: ")"} } -func NewDot(index int) *Token { - return &Token{Type: Dot, Index: index, Value: "."} +func NewDot(column int) *Token { + return &Token{Type: Dot, Column: column, Value: "."} } -func NewSlash(index int) *Token { - return &Token{Type: Slash, Index: index, Value: "\\"} +func NewSlash(column int) *Token { + return &Token{Type: Slash, Column: column, Value: "\\"} } -func NewAtom(name string, index int) *Token { - return &Token{Type: Atom, Index: index, Value: name} +func NewAtom(name string, column int) *Token { + return &Token{Type: Atom, Column: column, Value: name} } -func NewNewline(index int) *Token { - return &Token{Type: Newline, Index: index, Value: "\\n"} +func NewNewline(column int) *Token { + return &Token{Type: Newline, Column: column, Value: "\\n"} } func Name(typ Type) string {