Skip to content

Commit

Permalink
idl: replace internal.Position with ast.Position (#505)
Browse files Browse the repository at this point in the history
With idl.Position moved to ast.Position, there's no need for a separate
internal.Position type.
  • Loading branch information
jparise authored Jun 25, 2021
1 parent c63ad44 commit d7c4d71
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 39 deletions.
2 changes: 1 addition & 1 deletion idl/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func newParseError(errors []internal.ParseError) error {
errs := make([]Error, len(errors))
for i, err := range errors {
errs[i] = Error{
Pos: ast.Position{Line: err.Pos.Line},
Pos: err.Pos,
Err: err.Err,
}
}
Expand Down
4 changes: 2 additions & 2 deletions idl/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
func TestPos(t *testing.T) {
tests := []struct {
node ast.Node
pos *internal.Position
pos *ast.Position
want ast.Position
}{
{
Expand All @@ -44,7 +44,7 @@ func TestPos(t *testing.T) {
},
{
node: ast.ConstantString("s"),
pos: &internal.Position{Line: 1},
pos: &ast.Position{Line: 1},
want: ast.Position{Line: 1},
},
}
Expand Down
4 changes: 3 additions & 1 deletion idl/internal/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

package internal

import "go.uber.org/thriftrw/ast"

// ParseError holds a parse error and the position that caused it.
type ParseError struct {
Pos Position
Pos ast.Position
Err error
}
4 changes: 2 additions & 2 deletions idl/internal/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -16607,11 +16607,11 @@ func (lex *lexer) Error(e string) {

func (lex *lexer) AppendError(err error) {
lex.parseFailed = true
lex.errors = append(lex.errors, ParseError{Pos: Position{Line: lex.line}, Err: err})
lex.errors = append(lex.errors, ParseError{Pos: ast.Position{Line: lex.line}, Err: err})
}

func (lex *lexer) RecordPosition(n ast.Node) {
lex.nodePositions[n] = Position{Line: lex.line}
lex.nodePositions[n] = ast.Position{Line: lex.line}
}

func (lex *lexer) LastDocstring() string {
Expand Down
4 changes: 2 additions & 2 deletions idl/internal/lex.rl
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,11 @@ func (lex *lexer) Error(e string) {

func (lex *lexer) AppendError(err error) {
lex.parseFailed = true
lex.errors = append(lex.errors, ParseError{Pos: Position{Line: lex.line}, Err: err})
lex.errors = append(lex.errors, ParseError{Pos: ast.Position{Line: lex.line}, Err: err})
}

func (lex* lexer) RecordPosition(n ast.Node) {
lex.nodePositions[n] = Position{Line: lex.line}
lex.nodePositions[n] = ast.Position{Line: lex.line}
}

func (lex *lexer) LastDocstring() string {
Expand Down
3 changes: 3 additions & 0 deletions idl/internal/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func init() {
yyErrorVerbose = true
}

// NodePositions maps (hashable) nodes to their document positions.
type NodePositions map[ast.Node]ast.Position

// ParseResult holds the result of a successful Parse.
type ParseResult struct {
Program *ast.Program
Expand Down
31 changes: 0 additions & 31 deletions idl/internal/position.go

This file was deleted.

0 comments on commit d7c4d71

Please sign in to comment.