hydra.scala.utils module

Utility functions for constructing Scala AST nodes.

hydra.scala.utils.name_of_type(cx: T0, t: Type) object

Extract the name from a type, if it is a named type.

hydra.scala.utils.qualify_union_field_name(dlft: str, sname: object, fname: Name) str

Qualify a union field name, optionally prefixing with the Scala type name.

hydra.scala.utils.sapply(fun: Data, args: Sequence[Data]) Data

Apply a Scala data expression to a list of arguments.

hydra.scala.utils.sapply_types(fun: Data, type_args: Sequence[Type]) Data

Apply explicit type parameters to a Scala expression (e.g. f[A, B]); a no-op for an empty type-arg list (#589).

hydra.scala.utils.sassign(lhs: Data, rhs: Data) Data

Create a Scala assignment expression.

hydra.scala.utils.scala_escape_enum_case_name(s: str) str

Like scalaEscapeName, but also renames ‘values’ to ‘values_’ to avoid conflict with Scala 3 enum’s synthesized values() method.

hydra.scala.utils.scala_escape_name(s: str) str

Sanitize a name for Scala: escape reserved words, replace invalid characters.

hydra.scala.utils.scala_type_name(qualify: bool, name: Name) str

Convert a Hydra name to a Scala type name.

hydra.scala.utils.slambda(v: str, body: Data, sdom: object) Data

Create a Scala lambda (function) expression.

hydra.scala.utils.sname(s: str) Data

Create a Scala name reference.

hydra.scala.utils.sprim(overlay_subs: Set[str], name: Name) Data

Create a Scala primitive reference from a Hydra name, redirecting hydra.lib.<sub>.<local> to hydra.overlay.scala.lib.<sub>.<local> when <sub> has an overlay implementation on this host (#630 – the on-disk overlaySubs existence signal). Unlike toPrimImport (which redirects a bare hydra.lib.<sub> MODULE name, always exactly 3 segments), a primitive reference is hydra.lib.<sub>.<local> – at least 4 segments, since it also carries the primitive’s own local name – so the sub to check against overlaySubs is parts[2] alone, not the whole post-prefix tail (#635).

hydra.scala.utils.stapply(t: Type, args: Sequence[Type]) Type

Apply a Scala type to a list of type arguments.

hydra.scala.utils.stapply1(t1: Type, t2: Type) Type

Apply a Scala type to one type argument.

hydra.scala.utils.stapply2(t1: Type, t2: Type, t3: Type) Type

Apply a Scala type to two type arguments.

hydra.scala.utils.stparam(name: Name) ParamType

Create a Scala type parameter from a Hydra name, capitalizing to avoid collision with value params.

hydra.scala.utils.stref(s: str) Type

Create a Scala type reference by name.

hydra.scala.utils.svar(name: Name) Pat

Create a Scala pattern variable.

hydra.scala.utils.type_to_string(t: Type) str

Convert a Scala type to its string representation.