style: renamed token index to column
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user