ianmackenzie/elm-iso-10303/8.0.0

NOTE: the latest version is 8.0.1

Formerly ianmackenzie/elm-step-file. Search finds this package by either name.

Step.Decode

type Decoder input context output

A Decoder describes how to attempt to decode some input of type i (an entity or an attribute) and produce some output of type a.

type File

Represents an entire STEP file composed of a header and a list of entities. You can get the header from a file or extract data from it using entity decoders.

type Context

Represents a 'context' value that is threaded through decoding after being passed in at the top level (and possibly updated/transformed during decoding).

parse : String -> Result String File

Attempt to parse a given string as a STEP file.

Decoder Entity context output
-> File
-> context
-> Result String output

Attempt to find exactly one entity in a file that matches the given decoder. If there are no matching entities or more than one matching entity, an error message will be returned.

all :
Decoder Entity context output
-> File
-> context
-> Result String (List output)

Find all entities in a file matching the given decoder.

get :
Int
-> Decoder Entity context output
-> File
-> context
-> Result String output

Decode a single entity from a file by ID, using the given decoder. Usually you will want to use single instead.

Entities

The simpleEntity* functions all attempt to decode a simple STEP entity with the given number of attributes.

callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> String
-> Decoder Attribute context (b -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> String
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> String
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder Attribute context (d -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> String
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder Attribute context (d -> e)
-> Decoder Attribute context (e -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> String
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder Attribute context (d -> e)
-> Decoder Attribute context (e -> f)
-> Decoder Attribute context (f -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> String
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder Attribute context (d -> e)
-> Decoder Attribute context (e -> f)
-> Decoder Attribute context (f -> g)
-> Decoder Attribute context (g -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> String
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder Attribute context (d -> e)
-> Decoder Attribute context (e -> f)
-> Decoder Attribute context (f -> g)
-> Decoder Attribute context (g -> h)
-> Decoder Attribute context (h -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> String
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder Attribute context (d -> e)
-> Decoder Attribute context (e -> f)
-> Decoder Attribute context (f -> g)
-> Decoder Attribute context (g -> h)
-> Decoder Attribute context (h -> i)
-> Decoder Attribute context (i -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> String
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder Attribute context (d -> e)
-> Decoder Attribute context (e -> f)
-> Decoder Attribute context (f -> g)
-> Decoder Attribute context (g -> h)
-> Decoder Attribute context (h -> i)
-> Decoder Attribute context (i -> j)
-> Decoder Attribute context (j -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> String
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder Attribute context (d -> e)
-> Decoder Attribute context (e -> f)
-> Decoder Attribute context (f -> g)
-> Decoder Attribute context (g -> h)
-> Decoder Attribute context (h -> i)
-> Decoder Attribute context (i -> j)
-> Decoder Attribute context (j -> k)
-> Decoder Attribute context (k -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> String
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder Attribute context (d -> e)
-> Decoder Attribute context (e -> f)
-> Decoder Attribute context (f -> g)
-> Decoder Attribute context (g -> h)
-> Decoder Attribute context (h -> i)
-> Decoder Attribute context (i -> j)
-> Decoder Attribute context (j -> k)
-> Decoder Attribute context (k -> l)
-> Decoder Attribute context (l -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> String
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder Attribute context (d -> e)
-> Decoder Attribute context (e -> f)
-> Decoder Attribute context (f -> g)
-> Decoder Attribute context (g -> h)
-> Decoder Attribute context (h -> i)
-> Decoder Attribute context (i -> j)
-> Decoder Attribute context (j -> k)
-> Decoder Attribute context (k -> l)
-> Decoder Attribute context (l -> m)
-> Decoder Attribute context (m -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> String
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder Attribute context (d -> e)
-> Decoder Attribute context (e -> f)
-> Decoder Attribute context (f -> g)
-> Decoder Attribute context (g -> h)
-> Decoder Attribute context (h -> i)
-> Decoder Attribute context (i -> j)
-> Decoder Attribute context (j -> k)
-> Decoder Attribute context (k -> l)
-> Decoder Attribute context (l -> m)
-> Decoder Attribute context (m -> n)
-> Decoder Attribute context (n -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> String
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder Attribute context (d -> e)
-> Decoder Attribute context (e -> f)
-> Decoder Attribute context (f -> g)
-> Decoder Attribute context (g -> h)
-> Decoder Attribute context (h -> i)
-> Decoder Attribute context (i -> j)
-> Decoder Attribute context (j -> k)
-> Decoder Attribute context (k -> l)
-> Decoder Attribute context (l -> m)
-> Decoder Attribute context (m -> n)
-> Decoder Attribute context (n -> o)
-> Decoder Attribute context (o -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> String
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder Attribute context (d -> e)
-> Decoder Attribute context (e -> f)
-> Decoder Attribute context (f -> g)
-> Decoder Attribute context (g -> h)
-> Decoder Attribute context (h -> i)
-> Decoder Attribute context (i -> j)
-> Decoder Attribute context (j -> k)
-> Decoder Attribute context (k -> l)
-> Decoder Attribute context (l -> m)
-> Decoder Attribute context (m -> n)
-> Decoder Attribute context (n -> o)
-> Decoder Attribute context (o -> p)
-> Decoder Attribute context (p -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> String
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder Attribute context (d -> e)
-> Decoder Attribute context (e -> f)
-> Decoder Attribute context (f -> g)
-> Decoder Attribute context (g -> h)
-> Decoder Attribute context (h -> i)
-> Decoder Attribute context (i -> j)
-> Decoder Attribute context (j -> k)
-> Decoder Attribute context (k -> l)
-> Decoder Attribute context (l -> m)
-> Decoder Attribute context (m -> n)
-> Decoder Attribute context (n -> o)
-> Decoder Attribute context (o -> p)
-> Decoder Attribute context (p -> q)
-> Decoder Attribute context (q -> output)
-> Decoder Entity context output

Complex entities

The complexEntity* functions all attempt to decode a complex STEP entity with the given number of sub-entities.

callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> Decoder SubEntity context (b -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> Decoder SubEntity context (b -> c)
-> Decoder SubEntity context (c -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> Decoder SubEntity context (b -> c)
-> Decoder SubEntity context (c -> d)
-> Decoder SubEntity context (d -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> Decoder SubEntity context (b -> c)
-> Decoder SubEntity context (c -> d)
-> Decoder SubEntity context (d -> e)
-> Decoder SubEntity context (e -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> Decoder SubEntity context (b -> c)
-> Decoder SubEntity context (c -> d)
-> Decoder SubEntity context (d -> e)
-> Decoder SubEntity context (e -> f)
-> Decoder SubEntity context (f -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> Decoder SubEntity context (b -> c)
-> Decoder SubEntity context (c -> d)
-> Decoder SubEntity context (d -> e)
-> Decoder SubEntity context (e -> f)
-> Decoder SubEntity context (f -> g)
-> Decoder SubEntity context (g -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> Decoder SubEntity context (b -> c)
-> Decoder SubEntity context (c -> d)
-> Decoder SubEntity context (d -> e)
-> Decoder SubEntity context (e -> f)
-> Decoder SubEntity context (f -> g)
-> Decoder SubEntity context (g -> h)
-> Decoder SubEntity context (h -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> Decoder SubEntity context (b -> c)
-> Decoder SubEntity context (c -> d)
-> Decoder SubEntity context (d -> e)
-> Decoder SubEntity context (e -> f)
-> Decoder SubEntity context (f -> g)
-> Decoder SubEntity context (g -> h)
-> Decoder SubEntity context (h -> i)
-> Decoder SubEntity context (i -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> Decoder SubEntity context (b -> c)
-> Decoder SubEntity context (c -> d)
-> Decoder SubEntity context (d -> e)
-> Decoder SubEntity context (e -> f)
-> Decoder SubEntity context (f -> g)
-> Decoder SubEntity context (g -> h)
-> Decoder SubEntity context (h -> i)
-> Decoder SubEntity context (i -> j)
-> Decoder SubEntity context (j -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> Decoder SubEntity context (b -> c)
-> Decoder SubEntity context (c -> d)
-> Decoder SubEntity context (d -> e)
-> Decoder SubEntity context (e -> f)
-> Decoder SubEntity context (f -> g)
-> Decoder SubEntity context (g -> h)
-> Decoder SubEntity context (h -> i)
-> Decoder SubEntity context (i -> j)
-> Decoder SubEntity context (j -> k)
-> Decoder SubEntity context (k -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> Decoder SubEntity context (b -> c)
-> Decoder SubEntity context (c -> d)
-> Decoder SubEntity context (d -> e)
-> Decoder SubEntity context (e -> f)
-> Decoder SubEntity context (f -> g)
-> Decoder SubEntity context (g -> h)
-> Decoder SubEntity context (h -> i)
-> Decoder SubEntity context (i -> j)
-> Decoder SubEntity context (j -> k)
-> Decoder SubEntity context (k -> l)
-> Decoder SubEntity context (l -> output)
-> Decoder Entity context output
callback
-> Decoder Context context (callback -> a)
-> Decoder Int context (a -> b)
-> Decoder SubEntity context (b -> c)
-> Decoder SubEntity context (c -> d)
-> Decoder SubEntity context (d -> e)
-> Decoder SubEntity context (e -> f)
-> Decoder SubEntity context (f -> g)
-> Decoder SubEntity context (g -> h)
-> Decoder SubEntity context (h -> i)
-> Decoder SubEntity context (i -> j)
-> Decoder SubEntity context (j -> k)
-> Decoder SubEntity context (k -> l)
-> Decoder SubEntity context (l -> m)
-> Decoder SubEntity context (m -> output)
-> Decoder Entity context output

The subEntity* functions all attempt to decode a sub-entity (of a complex STEP entity) with the given number of attributes.

subEntity0 : String -> Decoder SubEntity context (a -> a)
String
-> Decoder Attribute context (a -> b)
-> Decoder SubEntity context (a -> b)
String
-> Decoder Attribute context (a -> b)
-> Decoder Attribute context (b -> c)
-> Decoder SubEntity context (a -> c)
String
-> Decoder Attribute context (a -> b)
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder SubEntity context (a -> d)
String
-> Decoder Attribute context (a -> b)
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder Attribute context (d -> e)
-> Decoder SubEntity context (a -> e)
String
-> Decoder Attribute context (a -> b)
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder Attribute context (d -> e)
-> Decoder Attribute context (e -> f)
-> Decoder SubEntity context (a -> f)
String
-> Decoder Attribute context (a -> b)
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder Attribute context (d -> e)
-> Decoder Attribute context (e -> f)
-> Decoder Attribute context (f -> g)
-> Decoder SubEntity context (a -> g)
String
-> Decoder Attribute context (a -> b)
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder Attribute context (d -> e)
-> Decoder Attribute context (e -> f)
-> Decoder Attribute context (f -> g)
-> Decoder Attribute context (g -> h)
-> Decoder SubEntity context (a -> h)
String
-> Decoder Attribute context (a -> b)
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder Attribute context (d -> e)
-> Decoder Attribute context (e -> f)
-> Decoder Attribute context (f -> g)
-> Decoder Attribute context (g -> h)
-> Decoder Attribute context (h -> i)
-> Decoder SubEntity context (a -> i)
String
-> Decoder Attribute context (a -> b)
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder Attribute context (d -> e)
-> Decoder Attribute context (e -> f)
-> Decoder Attribute context (f -> g)
-> Decoder Attribute context (g -> h)
-> Decoder Attribute context (h -> i)
-> Decoder Attribute context (i -> j)
-> Decoder SubEntity context (a -> j)
String
-> Decoder Attribute context (a -> b)
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder Attribute context (d -> e)
-> Decoder Attribute context (e -> f)
-> Decoder Attribute context (f -> g)
-> Decoder Attribute context (g -> h)
-> Decoder Attribute context (h -> i)
-> Decoder Attribute context (i -> j)
-> Decoder Attribute context (j -> k)
-> Decoder SubEntity context (a -> k)
String
-> Decoder Attribute context (a -> b)
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder Attribute context (d -> e)
-> Decoder Attribute context (e -> f)
-> Decoder Attribute context (f -> g)
-> Decoder Attribute context (g -> h)
-> Decoder Attribute context (h -> i)
-> Decoder Attribute context (i -> j)
-> Decoder Attribute context (j -> k)
-> Decoder Attribute context (k -> l)
-> Decoder SubEntity context (a -> l)
String
-> Decoder Attribute context (a -> b)
-> Decoder Attribute context (b -> c)
-> Decoder Attribute context (c -> d)
-> Decoder Attribute context (d -> e)
-> Decoder Attribute context (e -> f)
-> Decoder Attribute context (f -> g)
-> Decoder Attribute context (g -> h)
-> Decoder Attribute context (h -> i)
-> Decoder Attribute context (i -> j)
-> Decoder Attribute context (j -> k)
-> Decoder Attribute context (k -> l)
-> Decoder Attribute context (l -> m)
-> Decoder SubEntity context (a -> m)

Alternatives

oneOf : List (Decoder Entity context a) -> Decoder Entity context a

Construct an entity decoder that tries several other entity decoders in sequence.

Context

keepContext : Decoder Context context ((context -> a) -> a)

Get the current context while decoding.

ignoreContext : Decoder Context context (a -> a)

Ignore the current context while decoding.

Entity ID

keepId : Decoder Int context ((Int -> a) -> a)

Get the ID of an entity while decoding.

ignoreId : Decoder Int context (a -> a)

Ignore the ID of an entity while decoding.

Attributes

Decoder Attribute context a
-> Decoder Attribute context ((a -> b) -> b)

Keep a particular attribute value to pass to the callback function for the entity being decoded.

ignore : Decoder Attribute context a -> Decoder Attribute context (b -> b)

Ignore a particular attribute so that it does not get passed to the callback function for the entity being decoded.

bool : Decoder Attribute context Bool

Decode a single attribute as a Bool (from the special STEP enum values .T. and .F.).

int : Decoder Attribute context Int

Decode a single attribute as an Int.

float : Decoder Attribute context Float

Decode a single attribute as a Float. Note that unlike JSON, STEP has different encodings for Int and Float values so you cannot use this function to decode integer values; if you want to decode an integer value as a Float you will need to use

Decode.map toFloat Decode.int
string : Decoder Attribute context String

Decode a single attribute as a String.

Decode a single attribute as a string which must be empty (whitespace only). Useful when used with ignore to check that the string being ignored is in fact empty.

binaryData : Decoder a -> Decoder Attribute context a

Decode a single attribute as a blob of binary data, using the given binary decoder.

derivedValue : a -> Decoder Attribute context a

Decode the special 'derived value' attribute (*) as the given value.

null : a -> Decoder Attribute context a

Decode the special 'null' attribute ($) as the given value.

Decoder Attribute context output
-> Decoder Attribute context (Maybe output)

Decode an attribute that may be null, returning Nothing if it is.

enum : List ( String, a ) -> Decoder Attribute context a

Decode a single enum attribute, by passing a list of enum cases as their STEP type name and corresponding Elm value. For example, given a STEP enum with values RED, YELLOW and GREEN you might write:

type LightColor
    = Red
    | Yellow
    | Green


lightColorDecoder : Decoder Attribute LightColor
lightColorDecoder =
    Decode.enum
        [ ( "RED", Red )
        , ( "YELLOW", Yellow )
        , ( "GREEN", Green )
        ]

(Note that the given strings will be normalized, so case does not matter.)

list : Decoder Attribute context a -> Decoder Attribute context (List a)

Decode an attribute as a list, passing the decoder to be used for each list item.

tuple2 : Decoder Attribute context a -> Decoder Attribute context ( a, a )

Decode a list of exactly two elements, passing the decoder to be used for the two elements.

Decoder Attribute context a
-> Decoder Attribute context ( a, a, a )

Decode a list of exactly three elements, passing the decoder to be used for the two elements.

referenceTo : Decoder Entity context a -> Decoder Attribute context a

Decode an attribute which is a reference to another entity, by providing the decoder to use for that entity.

Decode just the ID from an entity reference attribute. This may be useful for deferred decoding/processing.

(Int -> a -> b)
-> Decoder Entity context a
-> Decoder Attribute context b

Decode an attribute which is a reference to another entity, and additionally get the ID of that entity. You will need to pass a function that combines the ID and decoded value into whatever you want; for example if you pass Tuple.pair then you will get an ( Int, a ) value back.

String
-> Decoder Attribute context a
-> Decoder Attribute context a

Decode a 'typed attribute'; for example if someone's age was stored as an integer, then it might be encoded directly as an integer like 38 or as a typed integer like AGE(38) or YEARS(38) or similar.

Working with decoders

map : (a -> b) -> Decoder input context a -> Decoder input context b

Map the value produced by a decoder.

(a -> Result String b)
-> Decoder input context a
-> Decoder input context b

Post-process the result of a decoder, either succeeding with a new value (possibly of a different type) or failing with an error message. This is a restricted form of andThen that does not have the same performance concerns, so use validate instead of andThen wherever possible.

Decoder input context (Result String output)
-> Decoder input context output

If a decoder produces a Result String a instead of simply a value of type a (for example if the callback function can fail) then this can 'resolve' that back into a regular decoder. It is equivalent to (and implemented as) validate identity.

(a -> Decoder Entity context b)
-> Decoder Entity context a
-> Decoder Entity context b

Based on the result of one entity decoder, produce a second decoder to run on the same entity.

WARNING: This is sometimes necessary but can be a major performance issue! Wherever possible, ensure decoders are created once instead of on the fly inside an andThen callback. For example, in some cases you may be able to create a few static decoders and then have logic inside and andThen simply choose which of those to use.

succeed : a -> Decoder Entity context a

A trivial decoder that always succeeds with the given value. May be useful in combination with andThen, but consider using validate instead.

fail : String -> Decoder Entity context a

A trivial decoder that always failes with the given error message. May be useful in combination with andThen, but consider using validate instead.

lazy : (() -> Decoder Entity context a) -> Decoder Entity context a

Define a decoder lazily such that it is only constructed if needed. This is primarily used to break circular reference chains between decoders.

For efficiency reasons, you should make sure that the provided callback function simply returns an already-existing decoder value; it should not construct one on the fly.

Context

(context1 -> output1 -> context2)
-> Decoder Entity context1 output1
-> Decoder Entity context2 output2
-> Decoder Entity context1 output2

Chain two decoders together so that the output of the first can affect the behavior of the second. Given two decoders, you must additionally pass a function that takes the context of the first decoder and its output, and produces the context to feed into the second decoder. The result is a combined decoder that accepts the context of the first and produces the output of the second.

(context1 -> output1 -> Maybe context2)
-> Decoder Entity context1 output1
-> Decoder Entity context2 output2
-> Decoder Entity context1 (Maybe output2)

A variant of chain that additionally allows you to stop decoding after the first step (never run the second decoder) by returning Nothing instead of Just context from the callback function. In that case the output of the combined decoder will also be Nothing.

(outerContext -> innerContext)
-> Decoder input innerContext output
-> Decoder input outerContext output

Take a decoder that expects a particular type of context, and 'inject' part of the current context into it.

(context -> a -> b)
-> Decoder input context a
-> Decoder input context b

Transform the result of a decoder using its context. This works just like map but additionally passes the current context to the mapping function.