Files
zeekayandClaude Opus 5 2c2f0e6bf3 Go 1.27.1, and the code it can say more simply
Modules declare go 1.27.1 and the build images follow. go fix applied the
modernizers, and the interpreter's parseArg, evaluateExprAs and
evaluateOptExprAs are now generic methods on the parser and program state
they take. omitzero is not applied, since it changes what the JSON says.

Co-Authored-By: Claude Opus 5 <[email protected]>
2026-09-16 19:52:45 -07:00

44 lines
822 B
Go

package interpreter
import "github.com/formancehq/numscript/internal/parser"
type argsParser struct {
parsedArgsCount int
args []Value
err InterpreterError
}
func NewArgsParser(args []Value) *argsParser {
return &argsParser{
args: args,
}
}
func (p *argsParser) parseArg[T any](r parser.Range, expect func(Value, parser.Range) (*T, InterpreterError)) *T {
index := p.parsedArgsCount
p.parsedArgsCount++
if p.err != nil || index >= len(p.args) {
return nil
}
arg := p.args[index]
parsed, err := expect(arg, r)
if err != nil {
p.err = err
return nil
}
return parsed
}
func (p *argsParser) parse() InterpreterError {
if len(p.args) != p.parsedArgsCount {
p.err = BadArityErr{
ExpectedArity: p.parsedArgsCount,
GivenArguments: len(p.args),
}
}
return p.err
}