style: renamed token index to column

This commit is contained in:
2025-12-27 02:43:17 -05:00
parent 7f5298c8ed
commit bf0edfc593
2 changed files with 21 additions and 21 deletions

View File

@@ -37,7 +37,7 @@ func parseExpression(i *TokenIterator) (ast.Expression, error) {
case token.Atom: case token.Atom:
exp, err = parseAtom(i) exp, err = parseAtom(i)
default: 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 return exp, err
@@ -63,11 +63,11 @@ func parseAbstraction(i *TokenIterator) (*ast.Abstraction, error) {
i2 := i.Copy() i2 := i.Copy()
if _, err := parseToken(i2, token.Slash); err != nil { 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 { } else if parameters, err := parseParameters(i2); err != nil {
return nil, err return nil, err
} else if _, err = parseToken(i2, token.Dot); err != nil { } 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 { } else if body, err := parseExpression(i2); err != nil {
return nil, err return nil, err
} else { } else {
@@ -81,7 +81,7 @@ func parseApplication(i *TokenIterator) (*ast.Application, error) {
expressions := []ast.Expression{} expressions := []ast.Expression{}
if _, err := parseToken(i2, token.OpenParen); err != nil { 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 { for {
@@ -96,7 +96,7 @@ func parseApplication(i *TokenIterator) (*ast.Application, error) {
} }
if _, err := parseToken(i2, token.CloseParen); err != nil { 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) i.Sync(i2)
@@ -120,7 +120,7 @@ func Parse(tokens []token.Token) (ast.Expression, error) {
} }
if !i.Done() { 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 return exp, nil

View File

@@ -14,33 +14,33 @@ const (
// A representation of a token in source code. // A representation of a token in source code.
type Token struct { type Token struct {
Index int // Where the token begins in the source text. Column int // Where the token begins in the source text.
Type Type // What type the token is. Type Type // What type the token is.
Value string // The value of the token. Value string // The value of the token.
} }
func NewOpenParen(index int) *Token { func NewOpenParen(column int) *Token {
return &Token{Type: OpenParen, Index: index, Value: "("} return &Token{Type: OpenParen, Column: column, Value: "("}
} }
func NewCloseParen(index int) *Token { func NewCloseParen(column int) *Token {
return &Token{Type: CloseParen, Index: index, Value: ")"} return &Token{Type: CloseParen, Column: column, Value: ")"}
} }
func NewDot(index int) *Token { func NewDot(column int) *Token {
return &Token{Type: Dot, Index: index, Value: "."} return &Token{Type: Dot, Column: column, Value: "."}
} }
func NewSlash(index int) *Token { func NewSlash(column int) *Token {
return &Token{Type: Slash, Index: index, Value: "\\"} return &Token{Type: Slash, Column: column, Value: "\\"}
} }
func NewAtom(name string, index int) *Token { func NewAtom(name string, column int) *Token {
return &Token{Type: Atom, Index: index, Value: name} return &Token{Type: Atom, Column: column, Value: name}
} }
func NewNewline(index int) *Token { func NewNewline(column int) *Token {
return &Token{Type: Newline, Index: index, Value: "\\n"} return &Token{Type: Newline, Column: column, Value: "\\n"}
} }
func Name(typ Type) string { func Name(typ Type) string {