purenix-1.1: Nix backend for PureScript. Transpile PureScript code to Nix.
Safe HaskellSafe-Inferred
LanguageHaskell2010

PureNix.Identifiers

Description

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

Synopsis

Documentation

newtype Var Source #

A valid (i.e. containing no illegal characters) variable binder. Primarily constructed using mkVar.

Constructors

UnsafeVar 

Fields

Instances

Instances details
IsString Var Source # 
Instance details

Defined in PureNix.Identifiers

Methods

fromString :: String -> Var #

Show Var Source # 
Instance details

Defined in PureNix.Identifiers

Methods

showsPrec :: Int -> Var -> ShowS #

show :: Var -> String #

showList :: [Var] -> ShowS #

Eq Var Source # 
Instance details

Defined in PureNix.Identifiers

Methods

(==) :: Var -> Var -> Bool #

(/=) :: Var -> Var -> Bool #

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.

newtype Key Source #

A valid Nix attribute key

Constructors

UnsafeKey 

Fields

Instances

Instances details
IsString Key Source # 
Instance details

Defined in PureNix.Identifiers

Methods

fromString :: String -> Key #

Show Key Source # 
Instance details

Defined in PureNix.Identifiers

Methods

showsPrec :: Int -> Key -> ShowS #

show :: Key -> String #

showList :: [Key] -> ShowS #

Eq Key Source # 
Instance details

Defined in PureNix.Identifiers

Methods

(==) :: Key -> Key -> Bool #

(/=) :: Key -> Key -> Bool #