Skip to content

Commit

Permalink
add position for bind expression
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperphoton committed Jan 28, 2022
1 parent 2258646 commit 5d2a063
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ func (lit *BoolLit) String() string {

type BindExpr struct {
Name string // binding name
Pos int // binding position
}

// String returns the string representation of the expression.
Expand Down
12 changes: 7 additions & 5 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ var (
type Parser struct {
l *Lexer

pos Pos // current position
tok Token // current token
lit string // current literal value
full bool // buffer full
pos Pos // current position
tok Token // current token
lit string // current literal value
full bool // buffer full
binds int // bind count
}

// NewParser returns a new instance of Parser that reads from r.
Expand Down Expand Up @@ -897,7 +898,8 @@ func (p *Parser) parseOperand() (expr Expr, err error) {
case TRUE, FALSE:
return &BoolLit{Value: tok == TRUE}, nil
case BIND:
return &BindExpr{Name: lit}, nil
p.binds += 1
return &BindExpr{Name: lit, Pos: p.binds - 1}, nil
case PLUS, MINUS:
expr, err = p.parseOperand()
if err != nil {
Expand Down

0 comments on commit 5d2a063

Please sign in to comment.