func newUnexpectedTokenErrorNext(buf *token.Buffer) error { t, err := buf.Read() if err != nil { return err } return newUnexpectedTokenError(t) }
func termNumber(buf *token.Buffer) (node ast.Node, err error) { origPos := buf.Pos() defer func() { if err != nil { buf.MustSeek(origPos) } }() if t, err := buf.Read(); err != nil { return nil, err } else if t.Class == token.Number { return &ast.Number{ Value: t.Value, }, nil } else { return nil, newUnexpectedTokenError(t) } }
func termOp(buf *token.Buffer) (node ast.Node, err error) { origPos := buf.Pos() defer func() { if err != nil { buf.MustSeek(origPos) } }() t, err := buf.Read() if err != nil { return nil, err } switch t.Class { case token.Add: return &ast.Operator{ Class: ast.OpAdd, }, nil case token.Subtract: return &ast.Operator{ Class: ast.OpSubtract, }, nil } return nil, newUnexpectedTokenError(t) }