Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module defines the types and conversions from PureScript/CoreFn identifiers to Nix identifiers. This can be a tricky problem, since all three languages have different rules for what is and isn't allowed in certain kinds of identifiers. The goal of this module is to provide an API that takes care of all those concerns. In other words, the types in this module are as close to ready-to-print as possible.
The reasoning is that Key
and Var
are intended to be used in Expr
.
Expr
should represent a _valid_ Nix expression, and therefore Key
and Var
need to represent valid keys and binders, respectively.
We don't have to care about rejecting nonsensical values during printing.
Nix's rules for naked (non-quoted) identifiers are strictly more lenient than PureScripts (see links to specifications below), since nix allows -
in identifiers (they cannot start with a -
though).
Unfortunately, that doesn't mean we can just naively convert identifiers, for example:
- generated identifiers such as dictionary names in CoreFn can contain $
- module names can contain .
- keys might be quoted
- we shouldn't shadow Nix keywords, especially those that aren't also PureScript keywords
- we reserve any identifier starting with two leading underscores
Purescript identifiers: https://github.com/purescript/purescript/blob/master/lib/purescript-cst/src/Language/PureScript/CST/Lexer.hs#L689 Nix identifiers: https://github.com/cstrahan/tree-sitter-nix/blob/master/src/grammar.json#L19
Documentation
A valid (i.e. containing no illegal characters) variable binder.
Primarily constructed using mkVar
.
mkVar :: Ident -> Var Source #
Make a Nix variable binder from a CoreFn binder.
If a binder is a Nix keyword, we tick the binder with a hyphen. Since PureScript does not allow binders to contain hyphens, this should be safe.
Additionally, CoreFn can put dollar signs in generated names. We simply drop leading dollar signs, and the rest we convert to hyphens.
numberedVars :: Text -> [Var] Source #
A valid Nix attribute key
moduleKey :: ModuleName -> Key Source #
numberedKeys :: Text -> [Key] Source #