ianmackenzie/elm-iso-10303/7.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 i a

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.

parse : String -> Result String File

Attempt to parse a given string as a STEP file.

single : Decoder Entity a -> File -> Result String a

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 a -> File -> Result String (List a)

Find all entities in a file matching the given decoder.

get : Int -> Decoder Entity a -> File -> Result String a

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.

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

Complex entities

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

a
-> Decoder Int (a -> b)
-> Decoder SubEntity (b -> c)
a
-> Decoder Int (a -> b)
-> Decoder SubEntity (b -> c)
-> Decoder SubEntity (c -> d)
a
-> Decoder Int (a -> b)
-> Decoder SubEntity (b -> c)
-> Decoder SubEntity (c -> d)
-> Decoder SubEntity (d -> e)
a
-> Decoder Int (a -> b)
-> Decoder SubEntity (b -> c)
-> Decoder SubEntity (c -> d)
-> Decoder SubEntity (d -> e)
-> Decoder SubEntity (e -> f)
a
-> Decoder Int (a -> b)
-> Decoder SubEntity (b -> c)
-> Decoder SubEntity (c -> d)
-> Decoder SubEntity (d -> e)
-> Decoder SubEntity (e -> f)
-> Decoder SubEntity (f -> g)
a
-> Decoder Int (a -> b)
-> Decoder SubEntity (b -> c)
-> Decoder SubEntity (c -> d)
-> Decoder SubEntity (d -> e)
-> Decoder SubEntity (e -> f)
-> Decoder SubEntity (f -> g)
-> Decoder SubEntity (g -> h)
a
-> Decoder Int (a -> b)
-> Decoder SubEntity (b -> c)
-> Decoder SubEntity (c -> d)
-> Decoder SubEntity (d -> e)
-> Decoder SubEntity (e -> f)
-> Decoder SubEntity (f -> g)
-> Decoder SubEntity (g -> h)
-> Decoder SubEntity (h -> i)
a
-> Decoder Int (a -> b)
-> Decoder SubEntity (b -> c)
-> Decoder SubEntity (c -> d)
-> Decoder SubEntity (d -> e)
-> Decoder SubEntity (e -> f)
-> Decoder SubEntity (f -> g)
-> Decoder SubEntity (g -> h)
-> Decoder SubEntity (h -> i)
-> Decoder SubEntity (i -> j)
a
-> Decoder Int (a -> b)
-> Decoder SubEntity (b -> c)
-> Decoder SubEntity (c -> d)
-> Decoder SubEntity (d -> e)
-> Decoder SubEntity (e -> f)
-> Decoder SubEntity (f -> g)
-> Decoder SubEntity (g -> h)
-> Decoder SubEntity (h -> i)
-> Decoder SubEntity (i -> j)
-> Decoder SubEntity (j -> k)
a
-> Decoder Int (a -> b)
-> Decoder SubEntity (b -> c)
-> Decoder SubEntity (c -> d)
-> Decoder SubEntity (d -> e)
-> Decoder SubEntity (e -> f)
-> Decoder SubEntity (f -> g)
-> Decoder SubEntity (g -> h)
-> Decoder SubEntity (h -> i)
-> Decoder SubEntity (i -> j)
-> Decoder SubEntity (j -> k)
-> Decoder SubEntity (k -> l)
a
-> Decoder Int (a -> b)
-> Decoder SubEntity (b -> c)
-> Decoder SubEntity (c -> d)
-> Decoder SubEntity (d -> e)
-> Decoder SubEntity (e -> f)
-> Decoder SubEntity (f -> g)
-> Decoder SubEntity (g -> h)
-> Decoder SubEntity (h -> i)
-> Decoder SubEntity (i -> j)
-> Decoder SubEntity (j -> k)
-> Decoder SubEntity (k -> l)
-> Decoder SubEntity (l -> m)
a
-> Decoder Int (a -> b)
-> Decoder SubEntity (b -> c)
-> Decoder SubEntity (c -> d)
-> Decoder SubEntity (d -> e)
-> Decoder SubEntity (e -> f)
-> Decoder SubEntity (f -> g)
-> Decoder SubEntity (g -> h)
-> Decoder SubEntity (h -> i)
-> Decoder SubEntity (i -> j)
-> Decoder SubEntity (j -> k)
-> Decoder SubEntity (k -> l)
-> Decoder SubEntity (l -> m)
-> Decoder SubEntity (m -> n)

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 (a -> a)
subEntity1 : String -> Decoder Attribute (a -> b) -> Decoder SubEntity (a -> b)
String
-> Decoder Attribute (a -> b)
-> Decoder Attribute (b -> c)
-> Decoder SubEntity (a -> c)
String
-> Decoder Attribute (a -> b)
-> Decoder Attribute (b -> c)
-> Decoder Attribute (c -> d)
-> Decoder SubEntity (a -> d)
String
-> Decoder Attribute (a -> b)
-> Decoder Attribute (b -> c)
-> Decoder Attribute (c -> d)
-> Decoder Attribute (d -> e)
-> Decoder SubEntity (a -> e)
String
-> Decoder Attribute (a -> b)
-> Decoder Attribute (b -> c)
-> Decoder Attribute (c -> d)
-> Decoder Attribute (d -> e)
-> Decoder Attribute (e -> f)
-> Decoder SubEntity (a -> f)
String
-> Decoder Attribute (a -> b)
-> Decoder Attribute (b -> c)
-> Decoder Attribute (c -> d)
-> Decoder Attribute (d -> e)
-> Decoder Attribute (e -> f)
-> Decoder Attribute (f -> g)
-> Decoder SubEntity (a -> g)
String
-> Decoder Attribute (a -> b)
-> Decoder Attribute (b -> c)
-> Decoder Attribute (c -> d)
-> Decoder Attribute (d -> e)
-> Decoder Attribute (e -> f)
-> Decoder Attribute (f -> g)
-> Decoder Attribute (g -> h)
-> Decoder SubEntity (a -> h)
String
-> Decoder Attribute (a -> b)
-> Decoder Attribute (b -> c)
-> Decoder Attribute (c -> d)
-> Decoder Attribute (d -> e)
-> Decoder Attribute (e -> f)
-> Decoder Attribute (f -> g)
-> Decoder Attribute (g -> h)
-> Decoder Attribute (h -> i)
-> Decoder SubEntity (a -> i)
String
-> Decoder Attribute (a -> b)
-> Decoder Attribute (b -> c)
-> Decoder Attribute (c -> d)
-> Decoder Attribute (d -> e)
-> Decoder Attribute (e -> f)
-> Decoder Attribute (f -> g)
-> Decoder Attribute (g -> h)
-> Decoder Attribute (h -> i)
-> Decoder Attribute (i -> j)
-> Decoder SubEntity (a -> j)
String
-> Decoder Attribute (a -> b)
-> Decoder Attribute (b -> c)
-> Decoder Attribute (c -> d)
-> Decoder Attribute (d -> e)
-> Decoder Attribute (e -> f)
-> Decoder Attribute (f -> g)
-> Decoder Attribute (g -> h)
-> Decoder Attribute (h -> i)
-> Decoder Attribute (i -> j)
-> Decoder Attribute (j -> k)
-> Decoder SubEntity (a -> k)
String
-> Decoder Attribute (a -> b)
-> Decoder Attribute (b -> c)
-> Decoder Attribute (c -> d)
-> Decoder Attribute (d -> e)
-> Decoder Attribute (e -> f)
-> Decoder Attribute (f -> g)
-> Decoder Attribute (g -> h)
-> Decoder Attribute (h -> i)
-> Decoder Attribute (i -> j)
-> Decoder Attribute (j -> k)
-> Decoder Attribute (k -> l)
-> Decoder SubEntity (a -> l)
String
-> Decoder Attribute (a -> b)
-> Decoder Attribute (b -> c)
-> Decoder Attribute (c -> d)
-> Decoder Attribute (d -> e)
-> Decoder Attribute (e -> f)
-> Decoder Attribute (f -> g)
-> Decoder Attribute (g -> h)
-> Decoder Attribute (h -> i)
-> Decoder Attribute (i -> j)
-> Decoder Attribute (j -> k)
-> Decoder Attribute (k -> l)
-> Decoder Attribute (l -> m)
-> Decoder SubEntity (a -> m)

Alternatives

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

Entity ID

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

Get the ID of an entity while decoding.

ignoreId : Decoder Int (a -> a)

Ignore the ID of an entity while decoding.

Attributes

keep : Decoder Attribute a -> Decoder Attribute ((a -> b) -> b)

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

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

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

Decode a single attribute as an Int.

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

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 a

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

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

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

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

enum : List ( String, a ) -> Decoder Attribute 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.)

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

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

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

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.

referenceWithId : (Int -> a -> b) -> Decoder Entity a -> Decoder Attribute 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.

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 i a -> Decoder i b

Map the value produced by a decoder.

validate : (a -> Result String b) -> Decoder i a -> Decoder i 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.

resolve : Decoder i (Result String a) -> Decoder i a

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.

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.

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 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 a) -> Decoder Entity 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.