Skip to content

Commit

Permalink
refactor(parser): remove error from variable function signature
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamel committed Nov 20, 2024
1 parent 2016129 commit 9aa82ac
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions engine/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ func (p *Parser) term0(maxPriority Integer) (Term, error) {
return p.dict()
}
p.backup()
return p.variable(t.val)
return p.variable(t.val), nil
case tokenOpenList:
if t, _ := p.next(); t.kind == tokenCloseList {
p.backup()
Expand Down Expand Up @@ -612,20 +612,20 @@ func (p *Parser) term0Atom(maxPriority Integer) (Term, error) {
return t, nil
}

func (p *Parser) variable(s string) (Term, error) {
func (p *Parser) variable(s string) Term {
if s == "_" {
return NewVariable(), nil
return NewVariable()
}
n := NewAtom(s)
for i, pv := range p.Vars {
if pv.Name == n {
p.Vars[i].Count++
return pv.Variable, nil
return pv.Variable
}
}
v := NewVariable()
p.Vars = append(p.Vars, ParsedVariable{Name: n, Variable: v, Count: 1})
return v, nil
return v
}

func (p *Parser) openClose() (Term, error) {
Expand Down Expand Up @@ -827,10 +827,8 @@ func (p *Parser) dict() (Term, error) {
}

Check warning on line 827 in engine/parser.go

View check run for this annotation

Codecov / codecov/patch

engine/parser.go#L826-L827

Added lines #L826 - L827 were not covered by tests
switch t.kind {
case tokenVariable:
tag, err = p.variable(t.val)
if err != nil {
return nil, err
}
tag = p.variable(t.val)

default:
return nil, errExpectation

Check warning on line 833 in engine/parser.go

View check run for this annotation

Codecov / codecov/patch

engine/parser.go#L832-L833

Added lines #L832 - L833 were not covered by tests
}
Expand Down

0 comments on commit 9aa82ac

Please sign in to comment.