2021-10-06 09:30:38 +00:00
|
|
|
|
|
|
|
import
|
2024-01-06 11:59:38 +00:00
|
|
|
preserves, std/tables, std/options
|
2021-10-06 09:30:38 +00:00
|
|
|
|
|
|
|
type
|
2022-03-07 23:53:05 +00:00
|
|
|
PCompoundKind* {.pure.} = enum
|
|
|
|
`rec`, `arr`, `dict`
|
2023-12-31 17:15:06 +00:00
|
|
|
PCompoundRec* {.preservesRecord: "rec".} = object
|
|
|
|
`label`*: Value
|
|
|
|
`fields`*: seq[Pattern]
|
2021-09-24 19:25:47 +00:00
|
|
|
|
2023-12-31 17:15:06 +00:00
|
|
|
PCompoundArr* {.preservesRecord: "arr".} = object
|
|
|
|
`items`*: seq[Pattern]
|
2021-10-06 09:30:38 +00:00
|
|
|
|
2023-12-31 17:15:06 +00:00
|
|
|
PCompoundDict* {.preservesRecord: "dict".} = object
|
|
|
|
`entries`*: Table[Value, Pattern]
|
2021-09-24 19:25:47 +00:00
|
|
|
|
2023-12-31 17:15:06 +00:00
|
|
|
`PCompound`* {.preservesOr.} = object
|
2022-03-07 23:53:05 +00:00
|
|
|
case orKind*: PCompoundKind
|
|
|
|
of PCompoundKind.`rec`:
|
2023-12-31 17:15:06 +00:00
|
|
|
`rec`*: PCompoundRec
|
2022-03-07 23:53:05 +00:00
|
|
|
|
|
|
|
of PCompoundKind.`arr`:
|
2023-12-31 17:15:06 +00:00
|
|
|
`arr`*: PCompoundArr
|
2022-03-07 23:53:05 +00:00
|
|
|
|
|
|
|
of PCompoundKind.`dict`:
|
2023-12-31 17:15:06 +00:00
|
|
|
`dict`*: PCompoundDict
|
2021-09-24 19:25:47 +00:00
|
|
|
|
2022-12-08 08:15:01 +00:00
|
|
|
|
2023-12-31 17:15:06 +00:00
|
|
|
Reject* {.preservesRecord: "reject".} = object
|
|
|
|
`pattern`*: Pattern
|
2023-05-18 10:20:44 +00:00
|
|
|
|
|
|
|
CaveatsFieldKind* {.pure.} = enum
|
|
|
|
`present`, `invalid`, `absent`
|
2023-12-31 17:15:06 +00:00
|
|
|
CaveatsFieldPresent* {.preservesDictionary.} = object
|
|
|
|
`caveats`*: seq[Caveat]
|
2023-05-18 10:20:44 +00:00
|
|
|
|
2023-12-31 17:15:06 +00:00
|
|
|
CaveatsFieldInvalid* {.preservesDictionary.} = object
|
|
|
|
`caveats`*: Value
|
2023-05-18 10:20:44 +00:00
|
|
|
|
|
|
|
CaveatsFieldAbsent* {.preservesDictionary.} = object
|
|
|
|
|
2023-12-31 17:15:06 +00:00
|
|
|
`CaveatsField`* {.preservesOr.} = object
|
2023-05-18 10:20:44 +00:00
|
|
|
case orKind*: CaveatsFieldKind
|
|
|
|
of CaveatsFieldKind.`present`:
|
2023-12-31 17:15:06 +00:00
|
|
|
`present`*: CaveatsFieldPresent
|
2023-05-18 10:20:44 +00:00
|
|
|
|
|
|
|
of CaveatsFieldKind.`invalid`:
|
2023-12-31 17:15:06 +00:00
|
|
|
`invalid`*: CaveatsFieldInvalid
|
2023-05-18 10:20:44 +00:00
|
|
|
|
|
|
|
of CaveatsFieldKind.`absent`:
|
|
|
|
`absent`*: CaveatsFieldAbsent
|
|
|
|
|
|
|
|
|
2023-12-31 17:15:06 +00:00
|
|
|
SturdyDescriptionDetail* {.preservesDictionary.} = object
|
2023-05-18 10:20:44 +00:00
|
|
|
`key`*: seq[byte]
|
2023-12-31 17:15:06 +00:00
|
|
|
`oid`*: Value
|
2023-05-18 10:20:44 +00:00
|
|
|
|
2023-12-31 17:15:06 +00:00
|
|
|
PAnd* {.preservesRecord: "and".} = object
|
|
|
|
`patterns`*: seq[Pattern]
|
2021-09-24 19:25:47 +00:00
|
|
|
|
2023-12-31 17:15:06 +00:00
|
|
|
SturdyStepDetail* = Parameters
|
|
|
|
Rewrite* {.preservesRecord: "rewrite".} = object
|
|
|
|
`pattern`*: Pattern
|
|
|
|
`template`*: Template
|
2021-09-24 19:25:47 +00:00
|
|
|
|
2024-01-06 11:59:38 +00:00
|
|
|
ParametersCaveats* = Option[Value]
|
|
|
|
ParametersOid* = Value
|
|
|
|
ParametersSig* = seq[byte]
|
|
|
|
`Parameters`* {.preservesDictionary.} = object
|
|
|
|
`caveats`*: Option[Value]
|
|
|
|
`oid`*: Value
|
|
|
|
`sig`*: seq[byte]
|
|
|
|
|
2021-09-24 19:25:47 +00:00
|
|
|
TRef* {.preservesRecord: "ref".} = object
|
2022-07-08 12:49:24 +00:00
|
|
|
`binding`*: BiggestInt
|
2021-09-24 19:25:47 +00:00
|
|
|
|
2023-12-31 17:15:06 +00:00
|
|
|
PBind* {.preservesRecord: "bind".} = object
|
|
|
|
`pattern`*: Pattern
|
2021-09-24 19:25:47 +00:00
|
|
|
|
2023-12-31 17:15:06 +00:00
|
|
|
Lit* {.preservesRecord: "lit".} = object
|
|
|
|
`value`*: Value
|
2021-09-24 19:25:47 +00:00
|
|
|
|
2022-03-07 23:53:05 +00:00
|
|
|
TCompoundKind* {.pure.} = enum
|
|
|
|
`rec`, `arr`, `dict`
|
2023-12-31 17:15:06 +00:00
|
|
|
TCompoundRec* {.preservesRecord: "rec".} = object
|
|
|
|
`label`*: Value
|
|
|
|
`fields`*: seq[Template]
|
2022-03-07 23:53:05 +00:00
|
|
|
|
2023-12-31 17:15:06 +00:00
|
|
|
TCompoundArr* {.preservesRecord: "arr".} = object
|
|
|
|
`items`*: seq[Template]
|
2022-03-07 23:53:05 +00:00
|
|
|
|
2023-12-31 17:15:06 +00:00
|
|
|
TCompoundDict* {.preservesRecord: "dict".} = object
|
|
|
|
`entries`*: Table[Value, Template]
|
2022-03-07 23:53:05 +00:00
|
|
|
|
2023-12-31 17:15:06 +00:00
|
|
|
`TCompound`* {.preservesOr.} = object
|
2022-03-07 23:53:05 +00:00
|
|
|
case orKind*: TCompoundKind
|
|
|
|
of TCompoundKind.`rec`:
|
2023-12-31 17:15:06 +00:00
|
|
|
`rec`*: TCompoundRec
|
2022-03-07 23:53:05 +00:00
|
|
|
|
|
|
|
of TCompoundKind.`arr`:
|
2023-12-31 17:15:06 +00:00
|
|
|
`arr`*: TCompoundArr
|
2021-09-24 19:25:47 +00:00
|
|
|
|
2022-03-07 23:53:05 +00:00
|
|
|
of TCompoundKind.`dict`:
|
2023-12-31 17:15:06 +00:00
|
|
|
`dict`*: TCompoundDict
|
2022-03-07 23:53:05 +00:00
|
|
|
|
2022-12-08 08:15:01 +00:00
|
|
|
|
2023-12-31 17:15:06 +00:00
|
|
|
SturdyPathStepDetail* = Parameters
|
2022-03-07 23:53:05 +00:00
|
|
|
`PAtom`* {.preservesOr, pure.} = enum
|
2024-02-08 15:25:31 +00:00
|
|
|
`Boolean`, `Double`, `SignedInteger`, `String`, `ByteString`, `Symbol`
|
2021-09-24 19:25:47 +00:00
|
|
|
PDiscard* {.preservesRecord: "_".} = object
|
2022-12-08 08:15:01 +00:00
|
|
|
|
2021-09-24 19:25:47 +00:00
|
|
|
TemplateKind* {.pure.} = enum
|
|
|
|
`TAttenuate`, `TRef`, `Lit`, `TCompound`
|
2023-12-31 17:15:06 +00:00
|
|
|
`Template`* {.acyclic, preservesOr.} = ref object
|
2021-09-24 19:25:47 +00:00
|
|
|
case orKind*: TemplateKind
|
|
|
|
of TemplateKind.`TAttenuate`:
|
2023-12-31 17:15:06 +00:00
|
|
|
`tattenuate`*: TAttenuate
|
2021-09-24 19:25:47 +00:00
|
|
|
|
|
|
|
of TemplateKind.`TRef`:
|
|
|
|
`tref`*: TRef
|
|
|
|
|
|
|
|
of TemplateKind.`Lit`:
|
2023-12-31 17:15:06 +00:00
|
|
|
`lit`*: Lit
|
2021-09-24 19:25:47 +00:00
|
|
|
|
|
|
|
of TemplateKind.`TCompound`:
|
2023-12-31 17:15:06 +00:00
|
|
|
`tcompound`*: TCompound
|
2022-03-07 23:53:05 +00:00
|
|
|
|
2022-12-08 08:15:01 +00:00
|
|
|
|
2021-10-06 09:30:38 +00:00
|
|
|
CaveatKind* {.pure.} = enum
|
2023-05-18 10:20:44 +00:00
|
|
|
`Rewrite`, `Alts`, `Reject`, `unknown`
|
2023-12-31 17:15:06 +00:00
|
|
|
`Caveat`* {.preservesOr.} = object
|
2021-09-24 19:25:47 +00:00
|
|
|
case orKind*: CaveatKind
|
2021-10-06 09:30:38 +00:00
|
|
|
of CaveatKind.`Rewrite`:
|
2023-12-31 17:15:06 +00:00
|
|
|
`rewrite`*: Rewrite
|
2021-10-06 09:30:38 +00:00
|
|
|
|
|
|
|
of CaveatKind.`Alts`:
|
2023-12-31 17:15:06 +00:00
|
|
|
`alts`*: Alts
|
2021-09-24 19:25:47 +00:00
|
|
|
|
2023-05-18 10:20:44 +00:00
|
|
|
of CaveatKind.`Reject`:
|
2023-12-31 17:15:06 +00:00
|
|
|
`reject`*: Reject
|
2023-05-18 10:20:44 +00:00
|
|
|
|
|
|
|
of CaveatKind.`unknown`:
|
2024-01-07 22:11:59 +00:00
|
|
|
`unknown`*: Value
|
2023-05-18 10:20:44 +00:00
|
|
|
|
2022-12-08 08:15:01 +00:00
|
|
|
|
2023-12-31 17:15:06 +00:00
|
|
|
PNot* {.preservesRecord: "not".} = object
|
|
|
|
`pattern`*: Pattern
|
2021-10-06 09:30:38 +00:00
|
|
|
|
2023-12-31 17:15:06 +00:00
|
|
|
SturdyRef* {.preservesRecord: "ref".} = object
|
|
|
|
`parameters`*: Parameters
|
2021-10-06 09:30:38 +00:00
|
|
|
|
2021-09-24 19:25:47 +00:00
|
|
|
WireRefKind* {.pure.} = enum
|
2021-10-06 09:30:38 +00:00
|
|
|
`mine`, `yours`
|
2021-09-24 19:25:47 +00:00
|
|
|
WireRefMine* {.preservesTuple.} = object
|
2023-05-06 19:22:21 +00:00
|
|
|
`field0`* {.preservesLiteral: "0".}: tuple[]
|
2021-09-24 19:25:47 +00:00
|
|
|
`oid`*: Oid
|
2021-10-06 09:30:38 +00:00
|
|
|
|
2023-12-31 17:15:06 +00:00
|
|
|
WireRefYours* {.preservesTuple.} = object
|
2023-05-06 19:22:21 +00:00
|
|
|
`field0`* {.preservesLiteral: "1".}: tuple[]
|
2021-09-24 19:25:47 +00:00
|
|
|
`oid`*: Oid
|
2023-12-31 17:15:06 +00:00
|
|
|
`attenuation`* {.preservesTupleTail.}: seq[Caveat]
|
2021-10-06 09:30:38 +00:00
|
|
|
|
2023-12-31 17:15:06 +00:00
|
|
|
`WireRef`* {.preservesOr.} = object
|
2021-09-24 19:25:47 +00:00
|
|
|
case orKind*: WireRefKind
|
|
|
|
of WireRefKind.`mine`:
|
|
|
|
`mine`*: WireRefMine
|
2021-10-06 09:30:38 +00:00
|
|
|
|
2021-09-24 19:25:47 +00:00
|
|
|
of WireRefKind.`yours`:
|
2023-12-31 17:15:06 +00:00
|
|
|
`yours`*: WireRefYours
|
2021-10-06 09:30:38 +00:00
|
|
|
|
2022-07-08 12:49:24 +00:00
|
|
|
|
2023-12-31 17:15:06 +00:00
|
|
|
TAttenuate* {.preservesRecord: "attenuate".} = object
|
|
|
|
`template`*: Template
|
|
|
|
`attenuation`*: seq[Caveat]
|
2021-10-06 09:30:38 +00:00
|
|
|
|
2022-07-08 12:49:24 +00:00
|
|
|
Oid* = BiggestInt
|
2023-12-31 17:15:06 +00:00
|
|
|
Alts* {.preservesRecord: "or".} = object
|
|
|
|
`alternatives`*: seq[Rewrite]
|
2021-10-06 09:30:38 +00:00
|
|
|
|
|
|
|
PatternKind* {.pure.} = enum
|
2021-09-24 19:25:47 +00:00
|
|
|
`PDiscard`, `PAtom`, `PEmbedded`, `PBind`, `PAnd`, `PNot`, `Lit`,
|
|
|
|
`PCompound`
|
2023-12-31 17:15:06 +00:00
|
|
|
`Pattern`* {.acyclic, preservesOr.} = ref object
|
2021-09-24 19:25:47 +00:00
|
|
|
case orKind*: PatternKind
|
|
|
|
of PatternKind.`PDiscard`:
|
2021-10-06 09:30:38 +00:00
|
|
|
`pdiscard`*: PDiscard
|
|
|
|
|
2021-09-24 19:25:47 +00:00
|
|
|
of PatternKind.`PAtom`:
|
2021-10-06 09:30:38 +00:00
|
|
|
`patom`*: PAtom
|
|
|
|
|
2021-09-24 19:25:47 +00:00
|
|
|
of PatternKind.`PEmbedded`:
|
|
|
|
`pembedded`* {.preservesLiteral: "Embedded".}: bool
|
2021-10-06 09:30:38 +00:00
|
|
|
|
2021-09-24 19:25:47 +00:00
|
|
|
of PatternKind.`PBind`:
|
2023-12-31 17:15:06 +00:00
|
|
|
`pbind`*: PBind
|
2021-10-06 09:30:38 +00:00
|
|
|
|
2021-09-24 19:25:47 +00:00
|
|
|
of PatternKind.`PAnd`:
|
2023-12-31 17:15:06 +00:00
|
|
|
`pand`*: PAnd
|
2021-10-06 09:30:38 +00:00
|
|
|
|
2021-09-24 19:25:47 +00:00
|
|
|
of PatternKind.`PNot`:
|
2023-12-31 17:15:06 +00:00
|
|
|
`pnot`*: PNot
|
2021-10-06 09:30:38 +00:00
|
|
|
|
|
|
|
of PatternKind.`Lit`:
|
2023-12-31 17:15:06 +00:00
|
|
|
`lit`*: Lit
|
2021-10-06 09:30:38 +00:00
|
|
|
|
2021-09-24 19:25:47 +00:00
|
|
|
of PatternKind.`PCompound`:
|
2023-12-31 17:15:06 +00:00
|
|
|
`pcompound`*: PCompound
|
2022-12-08 08:15:01 +00:00
|
|
|
|
|
|
|
|
2023-12-31 17:15:06 +00:00
|
|
|
proc `$`*(x: PCompound | Reject | CaveatsField | SturdyDescriptionDetail | PAnd |
|
|
|
|
SturdyStepDetail |
|
|
|
|
Rewrite |
|
|
|
|
Parameters |
|
|
|
|
TRef |
|
|
|
|
PBind |
|
|
|
|
Lit |
|
|
|
|
TCompound |
|
|
|
|
SturdyPathStepDetail |
|
|
|
|
PDiscard |
|
|
|
|
Template |
|
|
|
|
Caveat |
|
|
|
|
PNot |
|
|
|
|
SturdyRef |
|
|
|
|
WireRef |
|
|
|
|
TAttenuate |
|
|
|
|
Oid |
|
|
|
|
Alts |
|
|
|
|
Pattern): string =
|
|
|
|
`$`(toPreserves(x))
|
|
|
|
|
|
|
|
proc encode*(x: PCompound | Reject | CaveatsField | SturdyDescriptionDetail |
|
|
|
|
PAnd |
|
|
|
|
SturdyStepDetail |
|
|
|
|
Rewrite |
|
|
|
|
Parameters |
|
|
|
|
TRef |
|
|
|
|
PBind |
|
|
|
|
Lit |
|
|
|
|
TCompound |
|
|
|
|
SturdyPathStepDetail |
|
|
|
|
PDiscard |
|
|
|
|
Template |
|
|
|
|
Caveat |
|
|
|
|
PNot |
|
|
|
|
SturdyRef |
|
|
|
|
WireRef |
|
|
|
|
TAttenuate |
|
|
|
|
Oid |
|
|
|
|
Alts |
|
|
|
|
Pattern): seq[byte] =
|
|
|
|
encode(toPreserves(x))
|