morphir-python 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- morphir/__init__.py +14 -0
- morphir/ir/__init__.py +110 -0
- morphir/ir/access_controlled.py +15 -0
- morphir/ir/decorations.py +19 -0
- morphir/ir/diagnostics.py +105 -0
- morphir/ir/distribution.py +21 -0
- morphir/ir/document.py +37 -0
- morphir/ir/documented.py +11 -0
- morphir/ir/format_version.py +483 -0
- morphir/ir/fqname.py +9 -0
- morphir/ir/json.py +11 -0
- morphir/ir/literal.py +25 -0
- morphir/ir/meta.py +11 -0
- morphir/ir/migrate.py +1267 -0
- morphir/ir/module.py +17 -0
- morphir/ir/name.py +27 -0
- morphir/ir/package.py +15 -0
- morphir/ir/path.py +25 -0
- morphir/ir/qname.py +9 -0
- morphir/ir/ref.py +17 -0
- morphir/ir/type.py +37 -0
- morphir/ir/type_constraints.py +33 -0
- morphir/ir/type_def.py +19 -0
- morphir/ir/type_spec.py +25 -0
- morphir/ir/v3/__init__.py +64 -0
- morphir/ir/v3/_legacy_value.py +201 -0
- morphir/ir/v3/access_controlled.py +31 -0
- morphir/ir/v3/codec.py +1275 -0
- morphir/ir/v3/codec_v1.py +491 -0
- morphir/ir/v3/codec_v2.py +187 -0
- morphir/ir/v3/distribution.py +42 -0
- morphir/ir/v3/documented.py +13 -0
- morphir/ir/v3/fqname.py +30 -0
- morphir/ir/v3/literal.py +46 -0
- morphir/ir/v3/module.py +32 -0
- morphir/ir/v3/name.py +42 -0
- morphir/ir/v3/package.py +23 -0
- morphir/ir/v3/path.py +29 -0
- morphir/ir/v3/qname.py +16 -0
- morphir/ir/v3/type.py +126 -0
- morphir/ir/v3/value.py +235 -0
- morphir/ir/v4/__init__.py +160 -0
- morphir/ir/v4/access_controlled.py +17 -0
- morphir/ir/v4/annotation.py +75 -0
- morphir/ir/v4/codec.py +2161 -0
- morphir/ir/v4/decorations.py +88 -0
- morphir/ir/v4/distribution.py +56 -0
- morphir/ir/v4/document.py +69 -0
- morphir/ir/v4/documented.py +10 -0
- morphir/ir/v4/fqname.py +69 -0
- morphir/ir/v4/incompleteness.py +78 -0
- morphir/ir/v4/json.py +103 -0
- morphir/ir/v4/literal.py +51 -0
- morphir/ir/v4/meta.py +27 -0
- morphir/ir/v4/module.py +30 -0
- morphir/ir/v4/name.py +69 -0
- morphir/ir/v4/package.py +19 -0
- morphir/ir/v4/path.py +50 -0
- morphir/ir/v4/qname.py +34 -0
- morphir/ir/v4/ref.py +35 -0
- morphir/ir/v4/type.py +140 -0
- morphir/ir/v4/type_constraints.py +91 -0
- morphir/ir/v4/type_def.py +38 -0
- morphir/ir/v4/type_spec.py +64 -0
- morphir/ir/v4/value.py +480 -0
- morphir/ir/value.py +81 -0
- morphir/py.typed +0 -0
- morphir/sdk/__init__.py +110 -0
- morphir/sdk/_compare.py +187 -0
- morphir/sdk/aggregate.py +421 -0
- morphir/sdk/basics.py +504 -0
- morphir/sdk/char.py +110 -0
- morphir/sdk/decimal.py +311 -0
- morphir/sdk/dict.py +336 -0
- morphir/sdk/instant.py +118 -0
- morphir/sdk/int.py +86 -0
- morphir/sdk/key.py +522 -0
- morphir/sdk/list.py +356 -0
- morphir/sdk/local_date.py +436 -0
- morphir/sdk/local_time.py +267 -0
- morphir/sdk/maybe.py +135 -0
- morphir/sdk/number.py +237 -0
- morphir/sdk/regex.py +287 -0
- morphir/sdk/result.py +162 -0
- morphir/sdk/result_list.py +169 -0
- morphir/sdk/rule.py +103 -0
- morphir/sdk/set.py +214 -0
- morphir/sdk/stateful_app.py +49 -0
- morphir/sdk/string.py +427 -0
- morphir/sdk/tuple.py +43 -0
- morphir/sdk/uuid.py +209 -0
- morphir_python-0.0.1.dist-info/METADATA +269 -0
- morphir_python-0.0.1.dist-info/RECORD +99 -0
- morphir_python-0.0.1.dist-info/WHEEL +4 -0
- morphir_python-0.0.1.dist-info/entry_points.txt +2 -0
- morphir_python-0.0.1.dist-info/licenses/LICENSE +201 -0
- morphir_tools/__init__.py +13 -0
- morphir_tools/cli.py +223 -0
- morphir_tools/py.typed +0 -0
morphir/ir/module.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Compatibility shim: re-exports `morphir.ir.v4.module`."""
|
|
2
|
+
|
|
3
|
+
from morphir.ir.v4.access_controlled import AccessControlled
|
|
4
|
+
from morphir.ir.v4.module import (
|
|
5
|
+
Definition,
|
|
6
|
+
ModuleName,
|
|
7
|
+
QualifiedModuleName,
|
|
8
|
+
Specification,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"AccessControlled",
|
|
13
|
+
"Definition",
|
|
14
|
+
"ModuleName",
|
|
15
|
+
"QualifiedModuleName",
|
|
16
|
+
"Specification",
|
|
17
|
+
]
|
morphir/ir/name.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Compatibility shim: re-exports `morphir.ir.v4.name`."""
|
|
2
|
+
|
|
3
|
+
from morphir.ir.v4.name import (
|
|
4
|
+
Name,
|
|
5
|
+
from_list,
|
|
6
|
+
from_string,
|
|
7
|
+
to_camel_case,
|
|
8
|
+
to_human_words,
|
|
9
|
+
to_kebab_case,
|
|
10
|
+
to_list,
|
|
11
|
+
to_snake_case,
|
|
12
|
+
to_string,
|
|
13
|
+
to_title_case,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"Name",
|
|
18
|
+
"from_list",
|
|
19
|
+
"from_string",
|
|
20
|
+
"to_camel_case",
|
|
21
|
+
"to_human_words",
|
|
22
|
+
"to_kebab_case",
|
|
23
|
+
"to_list",
|
|
24
|
+
"to_snake_case",
|
|
25
|
+
"to_string",
|
|
26
|
+
"to_title_case",
|
|
27
|
+
]
|
morphir/ir/package.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Compatibility shim: re-exports `morphir.ir.v4.package`."""
|
|
2
|
+
|
|
3
|
+
from morphir.ir.v4.access_controlled import AccessControlled
|
|
4
|
+
from morphir.ir.v4.package import (
|
|
5
|
+
Definition,
|
|
6
|
+
PackageName,
|
|
7
|
+
Specification,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"AccessControlled",
|
|
12
|
+
"Definition",
|
|
13
|
+
"PackageName",
|
|
14
|
+
"Specification",
|
|
15
|
+
]
|
morphir/ir/path.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Compatibility shim: re-exports `morphir.ir.v4.path`."""
|
|
2
|
+
|
|
3
|
+
from morphir.ir.v4.path import (
|
|
4
|
+
Path,
|
|
5
|
+
append,
|
|
6
|
+
concat,
|
|
7
|
+
empty,
|
|
8
|
+
from_list,
|
|
9
|
+
from_string,
|
|
10
|
+
is_prefix_of,
|
|
11
|
+
to_list,
|
|
12
|
+
to_string,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"Path",
|
|
17
|
+
"append",
|
|
18
|
+
"concat",
|
|
19
|
+
"empty",
|
|
20
|
+
"from_list",
|
|
21
|
+
"from_string",
|
|
22
|
+
"is_prefix_of",
|
|
23
|
+
"to_list",
|
|
24
|
+
"to_string",
|
|
25
|
+
]
|
morphir/ir/qname.py
ADDED
morphir/ir/ref.py
ADDED
morphir/ir/type.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Compatibility shim: re-exports `morphir.ir.v4.type`."""
|
|
2
|
+
|
|
3
|
+
from morphir.ir.v4.type import (
|
|
4
|
+
EMPTY_TYPE_ATTRIBUTES,
|
|
5
|
+
ExtensibleRecord,
|
|
6
|
+
Field,
|
|
7
|
+
Function,
|
|
8
|
+
Record,
|
|
9
|
+
Reference,
|
|
10
|
+
SourceLocation,
|
|
11
|
+
Tuple,
|
|
12
|
+
Type,
|
|
13
|
+
TypeAttributes,
|
|
14
|
+
Union,
|
|
15
|
+
Unit,
|
|
16
|
+
Variable,
|
|
17
|
+
get_attributes,
|
|
18
|
+
map_attributes,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"EMPTY_TYPE_ATTRIBUTES",
|
|
23
|
+
"ExtensibleRecord",
|
|
24
|
+
"Field",
|
|
25
|
+
"Function",
|
|
26
|
+
"Record",
|
|
27
|
+
"Reference",
|
|
28
|
+
"SourceLocation",
|
|
29
|
+
"Tuple",
|
|
30
|
+
"Type",
|
|
31
|
+
"TypeAttributes",
|
|
32
|
+
"Union",
|
|
33
|
+
"Unit",
|
|
34
|
+
"Variable",
|
|
35
|
+
"get_attributes",
|
|
36
|
+
"map_attributes",
|
|
37
|
+
]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Compatibility shim: re-exports `morphir.ir.v4.type_constraints`."""
|
|
2
|
+
|
|
3
|
+
from morphir.ir.v4.type_constraints import (
|
|
4
|
+
Bounded,
|
|
5
|
+
CollectionConstraint,
|
|
6
|
+
CustomConstraint,
|
|
7
|
+
Decimal,
|
|
8
|
+
FloatingPoint,
|
|
9
|
+
FloatWidth,
|
|
10
|
+
IntWidth,
|
|
11
|
+
NumericConstraint,
|
|
12
|
+
Signed,
|
|
13
|
+
StringConstraint,
|
|
14
|
+
StringEncoding,
|
|
15
|
+
TypeConstraints,
|
|
16
|
+
Unsigned,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"Bounded",
|
|
21
|
+
"CollectionConstraint",
|
|
22
|
+
"CustomConstraint",
|
|
23
|
+
"Decimal",
|
|
24
|
+
"FloatWidth",
|
|
25
|
+
"FloatingPoint",
|
|
26
|
+
"IntWidth",
|
|
27
|
+
"NumericConstraint",
|
|
28
|
+
"Signed",
|
|
29
|
+
"StringConstraint",
|
|
30
|
+
"StringEncoding",
|
|
31
|
+
"TypeConstraints",
|
|
32
|
+
"Unsigned",
|
|
33
|
+
]
|
morphir/ir/type_def.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Compatibility shim: re-exports `morphir.ir.v4.type_def`."""
|
|
2
|
+
|
|
3
|
+
from morphir.ir.v4.access_controlled import AccessControlled
|
|
4
|
+
from morphir.ir.v4.type import Type
|
|
5
|
+
from morphir.ir.v4.type_def import (
|
|
6
|
+
CustomTypeDefinition,
|
|
7
|
+
Definition,
|
|
8
|
+
TypeAliasDefinition,
|
|
9
|
+
)
|
|
10
|
+
from morphir.ir.v4.type_spec import Constructors
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"AccessControlled",
|
|
14
|
+
"Constructors",
|
|
15
|
+
"CustomTypeDefinition",
|
|
16
|
+
"Definition",
|
|
17
|
+
"Type",
|
|
18
|
+
"TypeAliasDefinition",
|
|
19
|
+
]
|
morphir/ir/type_spec.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Compatibility shim: re-exports `morphir.ir.v4.type_spec`."""
|
|
2
|
+
|
|
3
|
+
from morphir.ir.v4.type import Type
|
|
4
|
+
from morphir.ir.v4.type_spec import (
|
|
5
|
+
ConstructorArgs,
|
|
6
|
+
Constructors,
|
|
7
|
+
CustomTypeSpecification,
|
|
8
|
+
DerivedTypeSpecification,
|
|
9
|
+
DerivedTypeSpecificationDetails,
|
|
10
|
+
OpaqueTypeSpecification,
|
|
11
|
+
Specification,
|
|
12
|
+
TypeAliasSpecification,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"ConstructorArgs",
|
|
17
|
+
"Constructors",
|
|
18
|
+
"CustomTypeSpecification",
|
|
19
|
+
"DerivedTypeSpecification",
|
|
20
|
+
"DerivedTypeSpecificationDetails",
|
|
21
|
+
"OpaqueTypeSpecification",
|
|
22
|
+
"Specification",
|
|
23
|
+
"Type",
|
|
24
|
+
"TypeAliasSpecification",
|
|
25
|
+
]
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""Morphir IR format 3, the format morphir-elm writes today, and its 3.1.0 revision.
|
|
2
|
+
|
|
3
|
+
morphir-elm (commit bc99af69) is normative for the 3.0.0 model and its JSON
|
|
4
|
+
shapes. What 3.1.0 adds, the `Specs` distribution, follows the finos/morphir v3
|
|
5
|
+
specification (decision record 0018). The classes here are distinct from
|
|
6
|
+
`morphir.ir.v4`; use `morphir.ir.migrate` to move between versions.
|
|
7
|
+
|
|
8
|
+
`morphir.ir.v3.codec_v1` and `morphir.ir.v3.codec_v2` read the legacy formats 1
|
|
9
|
+
and 2 into the 3.0.0 `Library` model, which upgrades them to format 3.0.0.
|
|
10
|
+
Nothing writes them.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from . import (
|
|
14
|
+
access_controlled,
|
|
15
|
+
codec,
|
|
16
|
+
codec_v1,
|
|
17
|
+
codec_v2,
|
|
18
|
+
distribution,
|
|
19
|
+
documented,
|
|
20
|
+
fqname,
|
|
21
|
+
literal,
|
|
22
|
+
module,
|
|
23
|
+
name,
|
|
24
|
+
package,
|
|
25
|
+
path,
|
|
26
|
+
qname,
|
|
27
|
+
type,
|
|
28
|
+
value,
|
|
29
|
+
)
|
|
30
|
+
from .access_controlled import Access, AccessControlled
|
|
31
|
+
from .distribution import Distribution, Library, Specs
|
|
32
|
+
from .documented import Documented
|
|
33
|
+
from .fqname import FQName
|
|
34
|
+
from .name import Name
|
|
35
|
+
from .path import Path
|
|
36
|
+
from .qname import QName
|
|
37
|
+
|
|
38
|
+
__all__ = [
|
|
39
|
+
"Access",
|
|
40
|
+
"AccessControlled",
|
|
41
|
+
"Distribution",
|
|
42
|
+
"Documented",
|
|
43
|
+
"FQName",
|
|
44
|
+
"Library",
|
|
45
|
+
"Name",
|
|
46
|
+
"Path",
|
|
47
|
+
"QName",
|
|
48
|
+
"Specs",
|
|
49
|
+
"access_controlled",
|
|
50
|
+
"codec",
|
|
51
|
+
"codec_v1",
|
|
52
|
+
"codec_v2",
|
|
53
|
+
"distribution",
|
|
54
|
+
"documented",
|
|
55
|
+
"fqname",
|
|
56
|
+
"literal",
|
|
57
|
+
"module",
|
|
58
|
+
"name",
|
|
59
|
+
"package",
|
|
60
|
+
"path",
|
|
61
|
+
"qname",
|
|
62
|
+
"type",
|
|
63
|
+
"value",
|
|
64
|
+
]
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"""Value and pattern decoders with the snake_case tags of formats 1 and 2.
|
|
2
|
+
|
|
3
|
+
morphir-elm wrote value and pattern tags in snake_case (``"let_definition"``,
|
|
4
|
+
``"wildcard_pattern"``) in formats 1 and 2, and in TitleCase from format 3
|
|
5
|
+
(commit 02aa36af). The node shapes did not change. Literals and types inside
|
|
6
|
+
values did change between format 1 and format 2, so each decoder here takes the
|
|
7
|
+
literal decoder and the type decoder of its format.
|
|
8
|
+
|
|
9
|
+
Port of the decoders in ``Value/CodecV1.elm`` (morphir-elm bc99af69) and in
|
|
10
|
+
``Value/CodecV2.elm`` (morphir-elm 02aa36af, removed in 7cb7b300).
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from ..diagnostics import Location
|
|
16
|
+
from . import literal as lit
|
|
17
|
+
from . import type as t
|
|
18
|
+
from . import value as v
|
|
19
|
+
from .codec import (
|
|
20
|
+
Decoder,
|
|
21
|
+
_expect_list,
|
|
22
|
+
_expect_object,
|
|
23
|
+
_field,
|
|
24
|
+
_index,
|
|
25
|
+
_list_of,
|
|
26
|
+
_pair_list_to_dict,
|
|
27
|
+
_tag,
|
|
28
|
+
_unknown,
|
|
29
|
+
decode_fqname,
|
|
30
|
+
decode_name,
|
|
31
|
+
)
|
|
32
|
+
from .name import Name
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def decode_pattern[A](
|
|
36
|
+
decode_literal: Decoder[lit.Literal], decode_attributes: Decoder[A]
|
|
37
|
+
) -> Decoder[v.Pattern[A]]:
|
|
38
|
+
"""Build a snake_case pattern decoder (elm ``decodePattern``)."""
|
|
39
|
+
|
|
40
|
+
def decode(j: object, loc: Location = ()) -> v.Pattern[A]:
|
|
41
|
+
tag, items = _tag(j, loc, "Pattern")
|
|
42
|
+
|
|
43
|
+
def at(i: int) -> tuple[object, Location]:
|
|
44
|
+
return _index(items, i, loc, tag), (*loc, i)
|
|
45
|
+
|
|
46
|
+
match tag:
|
|
47
|
+
case "wildcard_pattern":
|
|
48
|
+
return v.WildcardPattern(decode_attributes(*at(1)))
|
|
49
|
+
case "as_pattern":
|
|
50
|
+
return v.AsPattern(
|
|
51
|
+
decode_attributes(*at(1)), decode(*at(2)), decode_name(*at(3))
|
|
52
|
+
)
|
|
53
|
+
case "tuple_pattern":
|
|
54
|
+
return v.TuplePattern(
|
|
55
|
+
decode_attributes(*at(1)), _list_of(decode, *at(2), "Pattern")
|
|
56
|
+
)
|
|
57
|
+
case "constructor_pattern":
|
|
58
|
+
return v.ConstructorPattern(
|
|
59
|
+
decode_attributes(*at(1)),
|
|
60
|
+
decode_fqname(*at(2)),
|
|
61
|
+
_list_of(decode, *at(3), "Pattern"),
|
|
62
|
+
)
|
|
63
|
+
case "empty_list_pattern":
|
|
64
|
+
return v.EmptyListPattern(decode_attributes(*at(1)))
|
|
65
|
+
case "head_tail_pattern":
|
|
66
|
+
return v.HeadTailPattern(
|
|
67
|
+
decode_attributes(*at(1)), decode(*at(2)), decode(*at(3))
|
|
68
|
+
)
|
|
69
|
+
case "literal_pattern":
|
|
70
|
+
return v.LiteralPattern(
|
|
71
|
+
decode_attributes(*at(1)), decode_literal(*at(2))
|
|
72
|
+
)
|
|
73
|
+
case "unit_pattern":
|
|
74
|
+
return v.UnitPattern(decode_attributes(*at(1)))
|
|
75
|
+
case _:
|
|
76
|
+
raise _unknown(tag, loc, "Pattern")
|
|
77
|
+
|
|
78
|
+
return decode
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def decode_value_definition[TA, VA](
|
|
82
|
+
decode_type: Decoder[t.Type[TA]],
|
|
83
|
+
decode_value_attributes: Decoder[VA],
|
|
84
|
+
decode_body: Decoder[v.Value[TA, VA]],
|
|
85
|
+
) -> Decoder[v.Definition[TA, VA]]:
|
|
86
|
+
"""Build a decoder for ``{"inputTypes", "outputType", "body"}``."""
|
|
87
|
+
construct = "ValueDefinition"
|
|
88
|
+
|
|
89
|
+
def decode_input(j: object, loc: Location) -> tuple[Name, VA, t.Type[TA]]:
|
|
90
|
+
triple = _expect_list(j, loc, "Input")
|
|
91
|
+
return (
|
|
92
|
+
decode_name(_index(triple, 0, loc, "Input"), (*loc, 0)),
|
|
93
|
+
decode_value_attributes(_index(triple, 1, loc, "Input"), (*loc, 1)),
|
|
94
|
+
decode_type(_index(triple, 2, loc, "Input"), (*loc, 2)),
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
def decode(j: object, loc: Location = ()) -> v.Definition[TA, VA]:
|
|
98
|
+
obj = _expect_object(j, loc, construct)
|
|
99
|
+
return v.Definition(
|
|
100
|
+
_list_of(
|
|
101
|
+
decode_input,
|
|
102
|
+
_field(obj, "inputTypes", loc, construct),
|
|
103
|
+
(*loc, "inputTypes"),
|
|
104
|
+
"Input",
|
|
105
|
+
),
|
|
106
|
+
decode_type(
|
|
107
|
+
_field(obj, "outputType", loc, construct), (*loc, "outputType")
|
|
108
|
+
),
|
|
109
|
+
decode_body(_field(obj, "body", loc, construct), (*loc, "body")),
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
return decode
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def decode_value[TA, VA](
|
|
116
|
+
decode_literal: Decoder[lit.Literal],
|
|
117
|
+
decode_type: Decoder[t.Type[TA]],
|
|
118
|
+
decode_value_attributes: Decoder[VA],
|
|
119
|
+
) -> Decoder[v.Value[TA, VA]]:
|
|
120
|
+
"""Build a snake_case value decoder (elm ``decodeValue``).
|
|
121
|
+
|
|
122
|
+
Args:
|
|
123
|
+
decode_literal: The literal decoder of the format.
|
|
124
|
+
decode_type: The decoder for the types inside value definitions.
|
|
125
|
+
decode_value_attributes: The decoder for value and pattern attributes.
|
|
126
|
+
"""
|
|
127
|
+
decode_p = decode_pattern(decode_literal, decode_value_attributes)
|
|
128
|
+
|
|
129
|
+
def decode_named(j: object, loc: Location) -> dict[Name, v.Value[TA, VA]]:
|
|
130
|
+
return _pair_list_to_dict(decode_name, decode, j, loc, "Value")
|
|
131
|
+
|
|
132
|
+
def decode_case(j: object, loc: Location) -> tuple[v.Pattern[VA], v.Value[TA, VA]]:
|
|
133
|
+
pair = _expect_list(j, loc, "Case")
|
|
134
|
+
return (
|
|
135
|
+
decode_p(_index(pair, 0, loc, "Case"), (*loc, 0)),
|
|
136
|
+
decode(_index(pair, 1, loc, "Case"), (*loc, 1)),
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
def decode(j: object, loc: Location = ()) -> v.Value[TA, VA]:
|
|
140
|
+
tag, items = _tag(j, loc, "Value")
|
|
141
|
+
|
|
142
|
+
def at(i: int) -> tuple[object, Location]:
|
|
143
|
+
return _index(items, i, loc, tag), (*loc, i)
|
|
144
|
+
|
|
145
|
+
def attrs() -> VA:
|
|
146
|
+
return decode_value_attributes(*at(1))
|
|
147
|
+
|
|
148
|
+
match tag:
|
|
149
|
+
case "literal":
|
|
150
|
+
return v.LiteralValue(attrs(), decode_literal(*at(2)))
|
|
151
|
+
case "constructor":
|
|
152
|
+
return v.Constructor(attrs(), decode_fqname(*at(2)))
|
|
153
|
+
case "tuple":
|
|
154
|
+
return v.Tuple(attrs(), _list_of(decode, *at(2), "Value"))
|
|
155
|
+
case "list":
|
|
156
|
+
return v.List(attrs(), _list_of(decode, *at(2), "Value"))
|
|
157
|
+
case "record":
|
|
158
|
+
return v.Record(attrs(), decode_named(*at(2)))
|
|
159
|
+
case "variable":
|
|
160
|
+
return v.Variable(attrs(), decode_name(*at(2)))
|
|
161
|
+
case "reference":
|
|
162
|
+
return v.Reference(attrs(), decode_fqname(*at(2)))
|
|
163
|
+
case "field":
|
|
164
|
+
return v.Field(attrs(), decode(*at(2)), decode_name(*at(3)))
|
|
165
|
+
case "field_function":
|
|
166
|
+
return v.FieldFunction(attrs(), decode_name(*at(2)))
|
|
167
|
+
case "apply":
|
|
168
|
+
return v.Apply(attrs(), decode(*at(2)), decode(*at(3)))
|
|
169
|
+
case "lambda":
|
|
170
|
+
return v.Lambda(attrs(), decode_p(*at(2)), decode(*at(3)))
|
|
171
|
+
case "let_definition":
|
|
172
|
+
return v.LetDefinition(
|
|
173
|
+
attrs(), decode_name(*at(2)), decode_def(*at(3)), decode(*at(4))
|
|
174
|
+
)
|
|
175
|
+
case "let_recursion":
|
|
176
|
+
return v.LetRecursion(
|
|
177
|
+
attrs(),
|
|
178
|
+
_pair_list_to_dict(decode_name, decode_def, *at(2), "Definition"),
|
|
179
|
+
decode(*at(3)),
|
|
180
|
+
)
|
|
181
|
+
case "destructure":
|
|
182
|
+
return v.Destructure(
|
|
183
|
+
attrs(), decode_p(*at(2)), decode(*at(3)), decode(*at(4))
|
|
184
|
+
)
|
|
185
|
+
case "if_then_else":
|
|
186
|
+
return v.IfThenElse(
|
|
187
|
+
attrs(), decode(*at(2)), decode(*at(3)), decode(*at(4))
|
|
188
|
+
)
|
|
189
|
+
case "pattern_match":
|
|
190
|
+
return v.PatternMatch(
|
|
191
|
+
attrs(), decode(*at(2)), _list_of(decode_case, *at(3), "Case")
|
|
192
|
+
)
|
|
193
|
+
case "update_record":
|
|
194
|
+
return v.UpdateRecord(attrs(), decode(*at(2)), decode_named(*at(3)))
|
|
195
|
+
case "unit":
|
|
196
|
+
return v.Unit(attrs())
|
|
197
|
+
case _:
|
|
198
|
+
raise _unknown(tag, loc, "Value")
|
|
199
|
+
|
|
200
|
+
decode_def = decode_value_definition(decode_type, decode_value_attributes, decode)
|
|
201
|
+
return decode
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""V3 access control (morphir-elm ``Morphir.IR.AccessControlled``)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from enum import Enum
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Access(Enum):
|
|
10
|
+
"""Whether a member is visible outside its module or package."""
|
|
11
|
+
|
|
12
|
+
PUBLIC = "Public"
|
|
13
|
+
PRIVATE = "Private"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass(frozen=True)
|
|
17
|
+
class AccessControlled[T]:
|
|
18
|
+
"""A value with an access level, encoded as ``{"access", "value"}``."""
|
|
19
|
+
|
|
20
|
+
access: Access
|
|
21
|
+
value: T
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def public[T](value: T) -> AccessControlled[T]:
|
|
25
|
+
"""Wrap a value as public."""
|
|
26
|
+
return AccessControlled(Access.PUBLIC, value)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def private[T](value: T) -> AccessControlled[T]:
|
|
30
|
+
"""Wrap a value as private."""
|
|
31
|
+
return AccessControlled(Access.PRIVATE, value)
|