finos/morphir-elm/22.0.2

Formerly Morgan-Stanley/morphir-elm. Search finds this package by either name.

Morphir.IR.NodeId

A data type that represents a node in the IR

type NodeID
= TypeID FQName NodePath
| ValueID FQName NodePath
| ModuleID ( Path, Path )

Represents a node in the IR. Could be a Type, Value or Module

type alias NodePath =

Represents a path in the IR. This is a recursive structure made up of the following building blocks:

  • ChildByName traverses to a child node by name. It takes one argument
    • the name of the edge to follow (this will usually be a field name)
  • ChildByIndex traverses to a child node by index. It takes one argument
    • the index of the child node (the list of children will be determined by the type of the node that we are currently on)

The path should be constructed in a reverse order: the node at the top will be the last step in the path

Example usage:

type alias Foo =
    { field1 : Bool
    , field2 :
        { field1 : Int
        , field2 : ( String, Float )
        }
    }


NodePath.fromList [] -- Refers to type "Foo" itself


NodePath.fromList [ ChildByName "field1" ] -- Refers to Bool


NodePath.fromList [ ChildByName "field2", ChildByName "field1" ] -- Refers to Int


NodePath.fromList [ ChildByName "field2", ChildByName "field2", ChildByIndex 1 ] -- Refers to Float
= ChildByName Name
| ChildByIndex Int

Represents a path to a child node

nodeIdFromString : String -> Result Error NodeID

Try to parse a string into NodeID. Return an Error if it's not a valid NodeID.

Convert a NodeID to String.

nodePathFromString : String -> NodePath

Parse a String into a NodePath.

nodePathToString : NodePath -> String

Convert a NodePath to String.

getAttribute : Definition attr attr -> NodeID -> Result Error attr

Get attribute from a module, type or value by NodeID. Return error, if the NodeID is invalid.

mapPatternAttributesWithNodePath : (NodePath -> attr -> attr2) -> Pattern attr -> Pattern attr2

Applies the given map function to the attributes of every node of the given pattern.

mapTypeAttributeWithNodePath : (NodePath -> attr -> attr2) -> Type attr -> Type attr2

Applies the given map function to the attributes of every node of the given type.

mapValueAttributesWithNodePath : (NodePath -> attr -> attr2) -> Value attr attr -> Value attr2 attr2

Applies the given map function to the attributes of every node of the given value.

getTypeAttributeByPath : NodePath -> Type attr -> Result Error attr

Get type attribute by NodePath. Return an Error if the NodePath is invalid.

getValueAttributeByPath : NodePath -> Value attr attr -> Result Error attr

Get value attribute by NodePath. Return an Error if the NodePath is invalid.

type Error
= InvalidPath String
| InvalidNodeID String

Represents an error that might occur during node operations