viv-compiler 0.1.0__py3-none-any.whl → 0.1.2__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.
- viv_compiler/{utils/_version.py → _version.py} +1 -1
- viv_compiler/cli.py +14 -12
- viv_compiler/config/config.py +17 -18
- viv_compiler/core/__init__.py +3 -3
- viv_compiler/core/core.py +7 -7
- viv_compiler/core/{importer.py → includes.py} +5 -5
- viv_compiler/core/metadata.py +71 -0
- viv_compiler/core/{postprocessor.py → postprocessing.py} +6 -32
- viv_compiler/core/{validator.py → validation.py} +203 -88
- viv_compiler/core/visitor.py +184 -139
- viv_compiler/grammar/viv.peg +450 -218
- viv_compiler/types/content_public_schemas.py +59 -31
- viv_compiler/types/dsl_public_schemas.py +84 -82
- viv_compiler/utils/utils.py +93 -33
- {viv_compiler-0.1.0.dist-info → viv_compiler-0.1.2.dist-info}/METADATA +120 -82
- viv_compiler-0.1.2.dist-info/RECORD +33 -0
- viv_compiler-0.1.0.dist-info/RECORD +0 -32
- {viv_compiler-0.1.0.dist-info → viv_compiler-0.1.2.dist-info}/WHEEL +0 -0
- {viv_compiler-0.1.0.dist-info → viv_compiler-0.1.2.dist-info}/entry_points.txt +0 -0
- {viv_compiler-0.1.0.dist-info → viv_compiler-0.1.2.dist-info}/licenses/LICENSE +0 -0
- {viv_compiler-0.1.0.dist-info → viv_compiler-0.1.2.dist-info}/top_level.txt +0 -0
@@ -20,6 +20,7 @@ if TYPE_CHECKING:
|
|
20
20
|
FloatField,
|
21
21
|
IntField,
|
22
22
|
ListField,
|
23
|
+
LocalVariable,
|
23
24
|
ObjectField,
|
24
25
|
StringField,
|
25
26
|
TemplateStringField,
|
@@ -29,12 +30,12 @@ if TYPE_CHECKING:
|
|
29
30
|
|
30
31
|
class CompiledContentBundle(TypedDict):
|
31
32
|
"""A content bundle in the format produced by the Viv compiler."""
|
33
|
+
# Metadata for the content bundle, which is currently used for validation purposes
|
34
|
+
meta: CompiledContentBundleMetadata
|
32
35
|
# Trope definitions, keyed by name
|
33
36
|
tropes: dict[TropeName, TropeDefinition]
|
34
37
|
# Action definitions, keyed by name
|
35
38
|
actions: dict[ActionName, ActionDefinition]
|
36
|
-
# Metadata for the content bundle, which is currently used for validation purposes
|
37
|
-
meta: CompiledContentBundleMetadata
|
38
39
|
|
39
40
|
|
40
41
|
class CompiledContentBundleMetadata(TypedDict):
|
@@ -46,9 +47,9 @@ class CompiledContentBundleMetadata(TypedDict):
|
|
46
47
|
The metadata here is also used to support validation during initialization of a target application's
|
47
48
|
Viv adapter by, e.g., confirming that any referenced enums and adapter functions actually exist.
|
48
49
|
"""
|
49
|
-
# The Viv compiler version at the time of compiling this content bundle.
|
50
|
-
# version
|
51
|
-
#
|
50
|
+
# The Viv compiler version at the time of compiling this content bundle. This will be a
|
51
|
+
# `MAJOR.MINOR.PATCH` version, and all Viv runtimes will require that the `MAJOR.MINOR`
|
52
|
+
# portion matches that of the runtime version at hand.
|
52
53
|
vivVersion: str
|
53
54
|
# An array containing the names of all enums referenced in the content bundle. This is
|
54
55
|
# used for validation during the initialization of a target application's Viv adapter.
|
@@ -57,6 +58,31 @@ class CompiledContentBundleMetadata(TypedDict):
|
|
57
58
|
# content bundle. This is used for validation during the initialization of
|
58
59
|
# a target application's Viv adapter.
|
59
60
|
referencedFunctionNames: list[AdapterFunctionName]
|
61
|
+
# An array specifying all role definitions carrying the `item` label. This is used
|
62
|
+
# for validation during the initialization of a target application's Viv adapter.
|
63
|
+
itemRoles: list[CompiledContentBundleMetadataRoleEntry]
|
64
|
+
# An array specifying all role definitions carrying the `build` label. This is used
|
65
|
+
# for validation during the initialization of a target application's Viv adapter.
|
66
|
+
buildRoles: list[CompiledContentBundleMetadataRoleEntry]
|
67
|
+
# An array specifying all reactions that are constrained by the time of day. This is used
|
68
|
+
# for validation during the initialization of a target application's Viv adapter.
|
69
|
+
timeOfDayConstrainedReactions: list[CompiledContentBundleMetadataTimeOfDayConstrainedReaction]
|
70
|
+
|
71
|
+
|
72
|
+
class CompiledContentBundleMetadataRoleEntry(TypedDict):
|
73
|
+
"""A simple record of a case of a role carrying a `build` label, used for validation purposes."""
|
74
|
+
# The name of the action containing a role carrying the `build` label
|
75
|
+
action: ActionName
|
76
|
+
# The name of the role carrying the `build` label
|
77
|
+
role: RoleName
|
78
|
+
|
79
|
+
|
80
|
+
class CompiledContentBundleMetadataTimeOfDayConstrainedReaction(TypedDict):
|
81
|
+
"""A simple record of a case of reaction that is constrained by the time of day, used for validation purposes."""
|
82
|
+
# The name of the action containing a reaction that is constrained by the time of day
|
83
|
+
action: ActionName
|
84
|
+
# The name of the target action of the reaction that is constrained by the time of day
|
85
|
+
reaction: ActionName
|
60
86
|
|
61
87
|
|
62
88
|
# Unique name for an arbitrary function exposed in a target application's Viv adapter
|
@@ -69,7 +95,7 @@ class TropeDefinition(TypedDict):
|
|
69
95
|
name: TropeName
|
70
96
|
# The parameters for the trope. These take entity references as arguments,
|
71
97
|
# allowing the conditions to refer to those entities.
|
72
|
-
params: list[
|
98
|
+
params: list[TropeParam]
|
73
99
|
# The ordered set of conditions composing the trope
|
74
100
|
conditions: list[Expression]
|
75
101
|
|
@@ -77,6 +103,16 @@ class TropeDefinition(TypedDict):
|
|
77
103
|
# A unique name for a trope
|
78
104
|
TropeName = str
|
79
105
|
|
106
|
+
|
107
|
+
class TropeParam(TypedDict):
|
108
|
+
"""A trope parameter."""
|
109
|
+
# The name of the trope parameter (unique only within the trope definition)
|
110
|
+
name: TropeParamName
|
111
|
+
# Whether this is an entity trope parameter, in which case arguments
|
112
|
+
# for this parameter should be entity IDs.
|
113
|
+
isEntityParam: bool
|
114
|
+
|
115
|
+
|
80
116
|
# A unique trope parameter name
|
81
117
|
TropeParamName = str
|
82
118
|
|
@@ -104,8 +140,8 @@ class ActionDefinition(TypedDict):
|
|
104
140
|
preconditions: dict[RoleName, list[WrappedExpression]]
|
105
141
|
# An ordered set of expressions that prepare a set of temporary variables that may be referenced
|
106
142
|
# downstream in the action definition. These temporary variables can be referenced by an author
|
107
|
-
# using the `$` sigil, but this is syntactic sugar for `@this.scratch` — e.g.,
|
108
|
-
# to `@this.scratch.foo
|
143
|
+
# using the `$` sigil, but this is syntactic sugar for `@this.scratch` — e.g., `$&foo` is equivalent
|
144
|
+
# to `@this.scratch.foo`, with the second sigil indicating the type of the scratch variable.
|
109
145
|
scratch: list[Expression]
|
110
146
|
# An ordered set of expressions that, when executed, cause updates to the target application state
|
111
147
|
effects: list[WrappedExpression]
|
@@ -175,8 +211,6 @@ class RoleDefinition(TypedDict, total=False):
|
|
175
211
|
recipient: bool
|
176
212
|
# Whether an entity cast in this role is an uninvolved witness to the associated action
|
177
213
|
bystander: bool
|
178
|
-
# Whether an entity cast in this role is the subject of the associated action
|
179
|
-
subject: bool
|
180
214
|
# Whether an entity cast in this role is a character who is not physically present for the associated action
|
181
215
|
absent: bool
|
182
216
|
# Whether this role must be precast via reaction bindings. See Reaction docs for details
|
@@ -227,25 +261,19 @@ class ReactionValue(TypedDict):
|
|
227
261
|
# The name of the target action, i.e., the one queued up by this reaction
|
228
262
|
actionName: ActionName
|
229
263
|
# Specification for how to precast entities in (a subset of) the roles of the target action
|
230
|
-
bindings: list[
|
264
|
+
bindings: list[ReactionRoleBindings]
|
231
265
|
# Parameterization of the reaction along various options
|
232
266
|
options: ReactionOptions
|
233
267
|
|
234
268
|
|
235
|
-
class
|
269
|
+
class ReactionRoleBindings(TypedDict):
|
236
270
|
"""An expression specifying how to precast a particular role in a reaction's target action."""
|
237
|
-
#
|
238
|
-
type: Literal[ExpressionDiscriminator.BINDING]
|
239
|
-
# The actual expression value
|
240
|
-
value: ReactionBindingValue
|
241
|
-
|
242
|
-
|
243
|
-
class ReactionBindingValue(TypedDict):
|
244
|
-
"""Value of a binding expression."""
|
245
|
-
# The name of the role in the target action that will be precast via this binding
|
271
|
+
# The name of the role in the target action that will be precast via these bindings
|
246
272
|
role: RoleName
|
247
|
-
#
|
248
|
-
|
273
|
+
# Whether the bindings are marked as being associated with an entity role
|
274
|
+
isEntityRole: bool
|
275
|
+
# An expression that should evaluate to the candidate(s) to precast in the role associated with this binding
|
276
|
+
candidates: Expression
|
249
277
|
|
250
278
|
|
251
279
|
class ReactionOptions(TypedDict, total=False):
|
@@ -290,10 +318,10 @@ class Saliences(TypedDict):
|
|
290
318
|
# which no `body` expressions hold. This will always be structured as a Viv enum,
|
291
319
|
# int, or float, where even the enum should resolve to a numeric value.
|
292
320
|
default: Union[Enum, IntField, FloatField]
|
293
|
-
#
|
294
|
-
# them. This allows for evaluation of the body expressions, which may refer to this
|
295
|
-
# in order to do things like conditionalize salience based on the character at hand.
|
296
|
-
variable:
|
321
|
+
# If there is a non-empty body, the local variable to which a character will be bound when computing
|
322
|
+
# a salience for them. This allows for evaluation of the body expressions, which may refer to this
|
323
|
+
# variable in order to do things like conditionalize salience based on the character at hand.
|
324
|
+
variable: LocalVariable | None
|
297
325
|
# An ordered array of Viv expressions that will each evaluate to a numeric value, as in the
|
298
326
|
# `default` property. These will be evaluated in turn, with the first numeric evaluated value
|
299
327
|
# being assigned as the character's salience. If no body expression evaluates to a numeric
|
@@ -309,10 +337,10 @@ class Associations(TypedDict):
|
|
309
337
|
# `body` expressions hold. This will always be structured as a Viv list whose elements will be
|
310
338
|
# simple Viv string expressions.
|
311
339
|
default: ListField
|
312
|
-
#
|
313
|
-
# them. This allows for evaluation of the body expressions, which may refer to this
|
314
|
-
# in order to do things like conditionalize associations based on the character at hand.
|
315
|
-
variable:
|
340
|
+
# If there is a non-empty body, the local variable to which a character will be bound when computing
|
341
|
+
# associations for them. This allows for evaluation of the body expressions, which may refer to this
|
342
|
+
# variable in order to do things like conditionalize associations based on the character at hand.
|
343
|
+
variable: LocalVariable | None
|
316
344
|
# An ordered array of Viv expressions that will each evaluate to Viv lists containing simple
|
317
345
|
# Viv string expressions, as in the `default` property. These will be evaluated in turn, with
|
318
346
|
# all the results being concatenated together to compose the associations for the character
|
@@ -36,7 +36,6 @@ Expression: TypeAlias = Annotated[
|
|
36
36
|
"FloatField",
|
37
37
|
"IntField",
|
38
38
|
"ListField",
|
39
|
-
"LocalVariableReference",
|
40
39
|
"Loop",
|
41
40
|
"MembershipTest",
|
42
41
|
"NullField",
|
@@ -44,6 +43,7 @@ Expression: TypeAlias = Annotated[
|
|
44
43
|
"Reaction",
|
45
44
|
"RoleUnpacking",
|
46
45
|
"StringField",
|
46
|
+
"SymbolReference",
|
47
47
|
"TemplateStringField",
|
48
48
|
"TropeFitExpression",
|
49
49
|
],
|
@@ -56,7 +56,6 @@ class ExpressionDiscriminator(StrEnum):
|
|
56
56
|
ADAPTER_FUNCTION_CALL = "adapterFunctionCall"
|
57
57
|
ASSIGNMENT = "assignment"
|
58
58
|
ARITHMETIC_EXPRESSION = "arithmeticExpression"
|
59
|
-
BINDING = "binding"
|
60
59
|
BOOL = "bool"
|
61
60
|
CHANCE_EXPRESSION = "chanceExpression"
|
62
61
|
COMPARISON = "comparison"
|
@@ -69,7 +68,6 @@ class ExpressionDiscriminator(StrEnum):
|
|
69
68
|
FLOAT = "float"
|
70
69
|
INT = "int"
|
71
70
|
LIST = "list"
|
72
|
-
LOCAL_VARIABLE_REFERENCE = "localVariableReference"
|
73
71
|
LOOP = "loop"
|
74
72
|
MEMBERSHIP_TEST = "membershipTest"
|
75
73
|
NULL_TYPE = "nullType"
|
@@ -77,6 +75,7 @@ class ExpressionDiscriminator(StrEnum):
|
|
77
75
|
REACTION = "reaction"
|
78
76
|
ROLE_UNPACKING = "roleUnpacking"
|
79
77
|
STRING = "string"
|
78
|
+
SYMBOL_REFERENCE = "symbolReference"
|
80
79
|
TEMPLATE_STRING = "templateString"
|
81
80
|
TROPE_FIT_EXPRESSION = "tropeFitExpression"
|
82
81
|
|
@@ -97,7 +96,7 @@ class AdapterFunctionCall(NegatableExpression):
|
|
97
96
|
`transport()` exposed in the adapter. The Viv runtime confirms the existence of all
|
98
97
|
referenced function names during adapter initialization.
|
99
98
|
"""
|
100
|
-
#
|
99
|
+
# Discriminator for a Viv adapter function call
|
101
100
|
type: Literal[ExpressionDiscriminator.ADAPTER_FUNCTION_CALL]
|
102
101
|
# The actual expression value
|
103
102
|
value: AdapterFunctionCallValue
|
@@ -122,7 +121,7 @@ AdapterFunctionName = str
|
|
122
121
|
|
123
122
|
class ArithmeticExpression(TypedDict):
|
124
123
|
"""A Viv arithmetic expression, which accepts two numeric operands and evaluates to a number."""
|
125
|
-
#
|
124
|
+
# Discriminator for a Viv arithmetic expression
|
126
125
|
type: Literal[ExpressionDiscriminator.ARITHMETIC_EXPRESSION]
|
127
126
|
# The actual expression value
|
128
127
|
value: ArithmeticExpressionValue
|
@@ -144,7 +143,7 @@ ArithmeticOperator = Literal["+", "-", "*", "/"]
|
|
144
143
|
|
145
144
|
class Assignment(TypedDict):
|
146
145
|
"""A Viv assignment (or update)."""
|
147
|
-
#
|
146
|
+
# Discriminator for a Viv assignment
|
148
147
|
type: Literal[ExpressionDiscriminator.ASSIGNMENT]
|
149
148
|
# The actual expression value
|
150
149
|
value: AssignmentValue
|
@@ -153,10 +152,13 @@ class Assignment(TypedDict):
|
|
153
152
|
class AssignmentValue(TypedDict):
|
154
153
|
"""The actual expression value for a Viv assignment."""
|
155
154
|
# An expression whose evaluation will be used as the left operand in the assignment/update
|
156
|
-
left:
|
155
|
+
left: Union[EntityReference, SymbolReference]
|
157
156
|
# The assignment/update operator
|
158
157
|
operator: AssignmentOperator
|
159
|
-
# An expression whose evaluation will be used as the right operand in the assignment/update
|
158
|
+
# An expression whose evaluation will be used as the right operand in the assignment/update. Note
|
159
|
+
# that for assignments that update persistent entity data, the value will always be proactively
|
160
|
+
# dehydrated, such that all entity data included in the value will be converted into the associated
|
161
|
+
# entity ID. We do this to prevent several potential issues, and the data can be rehydrated later on.
|
160
162
|
right: Expression
|
161
163
|
|
162
164
|
|
@@ -166,7 +168,7 @@ AssignmentOperator = Literal["=", "+=", "-=", "*=", "/=", "append", "remove"]
|
|
166
168
|
|
167
169
|
class BoolField(TypedDict):
|
168
170
|
"""A Viv boolean."""
|
169
|
-
#
|
171
|
+
# Discriminator for a Viv boolean
|
170
172
|
type: Literal[ExpressionDiscriminator.BOOL]
|
171
173
|
# The boolean literal to which this expression will evaluate
|
172
174
|
value: bool
|
@@ -178,7 +180,7 @@ class ChanceExpression(TypedDict):
|
|
178
180
|
This is a kind of condition that evaluates to True if the specified probability value (a number
|
179
181
|
between 0.0 and 1.0) exceeds a pseudorandom number generated by the Viv interpreter.
|
180
182
|
"""
|
181
|
-
#
|
183
|
+
# Discriminator for a Viv chance expression
|
182
184
|
type: Literal[ExpressionDiscriminator.CHANCE_EXPRESSION]
|
183
185
|
# The specified probability, which the compiler guarantees to be a number in the range [0, 1]
|
184
186
|
value: float
|
@@ -186,7 +188,7 @@ class ChanceExpression(TypedDict):
|
|
186
188
|
|
187
189
|
class Comparison(NegatableExpression):
|
188
190
|
"""A Viv comparison, whereby two values are compared using a comparator."""
|
189
|
-
#
|
191
|
+
# Discriminator for a Viv comparison
|
190
192
|
type: Literal[ExpressionDiscriminator.COMPARISON]
|
191
193
|
# The actual expression value
|
192
194
|
value: ComparisonValue
|
@@ -208,7 +210,7 @@ Comparator = Literal["==", ">", ">=", "<", "<=", "!="]
|
|
208
210
|
|
209
211
|
class Conditional(TypedDict):
|
210
212
|
"""A Viv conditional expression, allowing for branching based on the value of a test."""
|
211
|
-
#
|
213
|
+
# Discriminator for a Viv conditional
|
212
214
|
type: Literal[ExpressionDiscriminator.CONDITIONAL]
|
213
215
|
# The actual expression value
|
214
216
|
value: ConditionalValue
|
@@ -216,13 +218,19 @@ class Conditional(TypedDict):
|
|
216
218
|
|
217
219
|
class ConditionalValue(TypedDict, total=False):
|
218
220
|
"""The actual expression value for a Viv conditional."""
|
221
|
+
# Branches representing the `if` and `elif` clauses in this conditional expression
|
222
|
+
branches: list[ConditionalBranch]
|
223
|
+
# If an author has provided an alternative body (via an `else` clause), a list
|
224
|
+
# of expressions that will be evaluated/executed should the condition not hold.
|
225
|
+
alternative: list[Expression]
|
226
|
+
|
227
|
+
|
228
|
+
class ConditionalBranch(TypedDict):
|
229
|
+
"""A Viv conditional branch, representing an `if` or `elif` clause."""
|
219
230
|
# The condition that will be tested, which holds if its evaluation is truthy
|
220
231
|
condition: Expression
|
221
232
|
# A list of expressions that will be evaluated/executed should the condition hold
|
222
233
|
consequent: list[Expression]
|
223
|
-
# If an author has provided an alternative body (via an `else` clause), a list
|
224
|
-
# of expressions that will be evaluated/executed should the condition not hold.
|
225
|
-
alternative: list[Expression]
|
226
234
|
|
227
235
|
|
228
236
|
class Conjunction(NegatableExpression):
|
@@ -231,7 +239,7 @@ class Conjunction(NegatableExpression):
|
|
231
239
|
This kind of expression takes multiple expressions as operands and evaluates to
|
232
240
|
`True` if and only if all the respective expressions evaluate to truthy values.
|
233
241
|
"""
|
234
|
-
#
|
242
|
+
# Discriminator for a Viv conjunction
|
235
243
|
type: Literal[ExpressionDiscriminator.CONJUNCTION]
|
236
244
|
# The actual expression value
|
237
245
|
value: ConjunctionValue
|
@@ -251,7 +259,7 @@ class Disjunction(NegatableExpression):
|
|
251
259
|
This kind which takes multiple expressions and evaluates to `True` if and only
|
252
260
|
if at least one of the respective expressions evaluate to a truthy value.
|
253
261
|
"""
|
254
|
-
#
|
262
|
+
# Discriminator for a Viv disjunction
|
255
263
|
type: Literal[ExpressionDiscriminator.DISJUNCTION]
|
256
264
|
# The actual expression value
|
257
265
|
value: DisjunctionValue
|
@@ -266,39 +274,49 @@ class DisjunctionValue(TypedDict):
|
|
266
274
|
|
267
275
|
|
268
276
|
class EntityReference(NegatableExpression):
|
269
|
-
"""A Viv entity reference, structured as an anchor
|
277
|
+
"""A Viv entity reference, structured as an anchor name and a (possibly empty) path to a specific property value.
|
270
278
|
|
271
|
-
Usually, the property is on the
|
272
|
-
|
273
|
-
|
274
|
-
anchor role `@person`.
|
279
|
+
Usually, the property is on the anchor entity, but this is not the case if the reference contains
|
280
|
+
a pointer. For instance, `@person.boss->boss->traits.cruel` would return the value stored at the
|
281
|
+
path `traits.cruel` on the boss of the boss of the entity cast in the anchor role `@person`.
|
275
282
|
|
276
|
-
Note that the compiler
|
277
|
-
symbol role, which allows the interpreter to assume that the anchor role binds an entity.
|
283
|
+
Note that the compiler prevents an author from anchoring an entity reference in a symbol.
|
278
284
|
|
279
|
-
Also note that references anchored in
|
280
|
-
to
|
281
|
-
|
285
|
+
Also note that references anchored in scratch variables, e.g. `$@foo.bar.baz`, are compiled
|
286
|
+
to entity references -- this is because `$` is really just syntactic sugar for `@this.scratch.`,
|
287
|
+
with the next sigil indicating the type of the scratch variable.
|
282
288
|
"""
|
283
|
-
#
|
289
|
+
# Discriminator for a Viv entity reference
|
284
290
|
type: Literal[ExpressionDiscriminator.ENTITY_REFERENCE]
|
285
291
|
# The actual expression value
|
286
|
-
value:
|
292
|
+
value: ReferenceValue
|
287
293
|
|
288
294
|
|
289
|
-
class
|
290
|
-
"""
|
291
|
-
#
|
292
|
-
|
293
|
-
#
|
294
|
-
|
295
|
-
|
295
|
+
class SymbolReference(NegatableExpression):
|
296
|
+
"""A Viv symbol reference, structured as an anchor name and a (possibly empty) path to a specific property value."""
|
297
|
+
# Discriminator for a Viv symbol reference
|
298
|
+
type: Literal[ExpressionDiscriminator.SYMBOL_REFERENCE]
|
299
|
+
# The actual expression value
|
300
|
+
value: ReferenceValue
|
301
|
+
|
302
|
+
|
303
|
+
class ReferenceValue(TypedDict):
|
304
|
+
"""The actual expression value for a Viv entity reference or symbol reference."""
|
305
|
+
# Whether the anchor is a local variable. This is a common pattern when an author loops over a role
|
306
|
+
# unpacking, where the members of the group role can only be referenced individually by setting each
|
307
|
+
# one to a local variable (the loop variable).
|
308
|
+
local: bool
|
309
|
+
# The name anchoring this reference
|
310
|
+
anchor: Union[RoleName, VariableName]
|
311
|
+
# If applicable, the path to a specified property value. If the reference is just to the entity
|
312
|
+
# or symbol itself, this will be an empty list. Otherwise, it will specify a path to a specific
|
313
|
+
# property value, either on that entity or symbol or another entity (via a pointer).
|
296
314
|
path: list[ReferencePathComponent]
|
297
315
|
|
298
316
|
|
299
317
|
class ReferencePathComponentPropertyName(TypedDict, total=False):
|
300
318
|
"""A component of a Viv reference path specifying a property to access."""
|
301
|
-
#
|
319
|
+
# Discriminator for a property-name reference path component
|
302
320
|
type: Literal[ReferencePathComponentDiscriminator.REFERENCE_PATH_COMPONENT_PROPERTY_NAME]
|
303
321
|
# The name of the property to access
|
304
322
|
name: str
|
@@ -309,7 +327,7 @@ class ReferencePathComponentPropertyName(TypedDict, total=False):
|
|
309
327
|
|
310
328
|
class ReferencePathComponentPointer(TypedDict, total=False):
|
311
329
|
"""A component of a Viv reference path specifying a pointer to dereference."""
|
312
|
-
#
|
330
|
+
# Discriminator for a pointer reference path component
|
313
331
|
type: Literal[ReferencePathComponentDiscriminator.REFERENCE_PATH_COMPONENT_POINTER]
|
314
332
|
# The name of the property to access in the entity data of the entity targeted by the pointer
|
315
333
|
propertyName: str
|
@@ -324,7 +342,7 @@ class ReferencePathComponentLookup(TypedDict, total=False):
|
|
324
342
|
|
325
343
|
The key/index can be specified by an arbitrary Viv expression.
|
326
344
|
"""
|
327
|
-
#
|
345
|
+
# Discriminator for a lookup reference path component
|
328
346
|
type: Literal[ReferencePathComponentDiscriminator.REFERENCE_PATH_COMPONENT_LOOKUP]
|
329
347
|
# An expression that should evaluate to a valid property key (string or integer)
|
330
348
|
key: Expression
|
@@ -335,11 +353,11 @@ class ReferencePathComponentLookup(TypedDict, total=False):
|
|
335
353
|
|
336
354
|
class ReferencePathComponentDiscriminator(StrEnum):
|
337
355
|
"""Enum containing discriminators for the possible reference path components."""
|
338
|
-
#
|
356
|
+
# Discriminator for a property-name reference path component
|
339
357
|
REFERENCE_PATH_COMPONENT_PROPERTY_NAME = "referencePathComponentPropertyName"
|
340
|
-
#
|
358
|
+
# Discriminator for a pointer reference path component
|
341
359
|
REFERENCE_PATH_COMPONENT_POINTER = "referencePathComponentPointer"
|
342
|
-
#
|
360
|
+
# Discriminator for a lookup reference path component
|
343
361
|
REFERENCE_PATH_COMPONENT_LOOKUP = "referencePathComponentLookup"
|
344
362
|
|
345
363
|
|
@@ -356,7 +374,7 @@ class Enum(TypedDict):
|
|
356
374
|
|
357
375
|
Enums are resolved by the target application at runtime.
|
358
376
|
"""
|
359
|
-
#
|
377
|
+
# Discriminator for a Viv enum
|
360
378
|
type: Literal[ExpressionDiscriminator.ENUM]
|
361
379
|
# The actual expression value
|
362
380
|
value: EnumValue
|
@@ -389,13 +407,13 @@ class EvalFailSafeField(TypedDict):
|
|
389
407
|
A Viv author may specify an attempt to access a property that may not exist, safely,
|
390
408
|
via the eval fail-safe operator `?`, as in this example: `@foo.bar?.baz`.
|
391
409
|
"""
|
392
|
-
#
|
410
|
+
# Discriminator for the Viv eval fail-safe operator
|
393
411
|
type: Literal[ExpressionDiscriminator.EVAL_FAIL_SAFE]
|
394
412
|
|
395
413
|
|
396
414
|
class FloatField(TypedDict):
|
397
415
|
"""A Viv floating-point number."""
|
398
|
-
#
|
416
|
+
# Discriminator for a Viv floating-point number
|
399
417
|
type: Literal[ExpressionDiscriminator.FLOAT]
|
400
418
|
# The float literal to which this expression will evaluate
|
401
419
|
value: float
|
@@ -403,7 +421,7 @@ class FloatField(TypedDict):
|
|
403
421
|
|
404
422
|
class IntField(TypedDict):
|
405
423
|
"""A Viv integer."""
|
406
|
-
#
|
424
|
+
# Discriminator for a Viv integer
|
407
425
|
type: Literal[ExpressionDiscriminator.INT]
|
408
426
|
# The integer literal to which this expression will evaluate
|
409
427
|
value: int
|
@@ -414,38 +432,15 @@ class ListField(TypedDict):
|
|
414
432
|
|
415
433
|
Once evaluated, the result will contain the respective evaluations of the expressions, in that same order.
|
416
434
|
"""
|
417
|
-
#
|
435
|
+
# Discriminator for a Viv list
|
418
436
|
type: Literal[ExpressionDiscriminator.LIST]
|
419
437
|
# The actual expression value
|
420
438
|
value: list[Expression]
|
421
439
|
|
422
440
|
|
423
|
-
class LocalVariableReference(NegatableExpression):
|
424
|
-
"""A Viv local-variable reference, meaning a reference anchored in a local variable.
|
425
|
-
|
426
|
-
This kind of expression is structured as an anchor (the local variable name) with a subsequent path
|
427
|
-
to a specific property value. If a local variable is bound to an entity, this works just like an
|
428
|
-
entity reference — common when looping over role unpackings. Local variables may, however, hold
|
429
|
-
arbitrary values to which authors can refer.
|
430
|
-
"""
|
431
|
-
# Discriminant for a Viv local-variable reference
|
432
|
-
type: Literal[ExpressionDiscriminator.LOCAL_VARIABLE_REFERENCE]
|
433
|
-
# The actual expression value
|
434
|
-
value: LocalVariableReferenceValue
|
435
|
-
|
436
|
-
|
437
|
-
class LocalVariableReferenceValue(TypedDict):
|
438
|
-
"""The actual expression value for a Viv local-variable reference."""
|
439
|
-
# The name of the local variable that anchors this reference
|
440
|
-
anchor: VariableName
|
441
|
-
# If applicable, the path to a specified property value. If the reference is just to the
|
442
|
-
# variable's value itself, this will be an empty list. Otherwise, it specifies the path.
|
443
|
-
path: list[ReferencePathComponent]
|
444
|
-
|
445
|
-
|
446
441
|
class Loop(TypedDict):
|
447
442
|
"""A Viv loop, allowing for iteration over some iterable value."""
|
448
|
-
#
|
443
|
+
# Discriminator for a Viv loop
|
449
444
|
type: Literal[ExpressionDiscriminator.LOOP]
|
450
445
|
# The actual expression value
|
451
446
|
value: LoopValue
|
@@ -455,15 +450,22 @@ class LoopValue(TypedDict):
|
|
455
450
|
"""The actual expression value for a Viv loop."""
|
456
451
|
# An expression that should evaluate to a value that is iterable in the runtime at hand.
|
457
452
|
iterable: Expression
|
458
|
-
#
|
459
|
-
|
460
|
-
variable: VariableName
|
453
|
+
# The local variable to which each member of the iterable is assigned on its respective iteration of the loop
|
454
|
+
variable: LocalVariable
|
461
455
|
# The body of the loop, structured as a list of expressions that will each be interpreted,
|
462
456
|
# in order, on each iteration. These body expressions can reference the loop variable,
|
463
457
|
# allowing for Viv code that acts on each member of an iterable.
|
464
458
|
body: list[Expression]
|
465
459
|
|
466
460
|
|
461
|
+
class LocalVariable(TypedDict):
|
462
|
+
"""A Viv local variable."""
|
463
|
+
# The name of the local variable
|
464
|
+
name: VariableName
|
465
|
+
# Whether the variable is marked as binding an entity (as opposed to a symbol)
|
466
|
+
isEntityVariable: bool
|
467
|
+
|
468
|
+
|
467
469
|
# The name for a variable used in an assignment or a loop
|
468
470
|
VariableName = str
|
469
471
|
|
@@ -474,7 +476,7 @@ class MembershipTest(NegatableExpression):
|
|
474
476
|
This kind of expression takes two expressions as operands and evaluates to `True` if the evaluation
|
475
477
|
of the first expression is a member of the (iterable) evaluation of the second expression.
|
476
478
|
"""
|
477
|
-
#
|
479
|
+
# Discriminator for a Viv membership test
|
478
480
|
type: Literal[ExpressionDiscriminator.MEMBERSHIP_TEST]
|
479
481
|
# The actual expression value
|
480
482
|
value: MembershipTestValue
|
@@ -494,7 +496,7 @@ class MembershipTestValue(TypedDict):
|
|
494
496
|
|
495
497
|
class NullField(TypedDict):
|
496
498
|
"""A Viv null value."""
|
497
|
-
#
|
499
|
+
# Discriminator for a Viv null value
|
498
500
|
type: Literal[ExpressionDiscriminator.NULL_TYPE]
|
499
501
|
# Python's `None`, which serializes to JSON's `null`. In any Viv runtime, expressions of this
|
500
502
|
# type evaluate to the null-like value in the language at hand.
|
@@ -507,7 +509,7 @@ class ObjectField(TypedDict):
|
|
507
509
|
Expressions of this type maps keys (string literals) to Viv expressions. Once evaluated,
|
508
510
|
the result will map those same keys to the respective evaluations of the Viv expressions.
|
509
511
|
"""
|
510
|
-
#
|
512
|
+
# Discriminator for a Viv object literal
|
511
513
|
type: Literal[ExpressionDiscriminator.OBJECT]
|
512
514
|
# The actual expression value
|
513
515
|
value: dict[str, "Expression"]
|
@@ -520,7 +522,7 @@ class RoleUnpacking(TypedDict):
|
|
520
522
|
that role. This allows for iterating over multiple entities cast into the same role, e.g.,
|
521
523
|
to carry out effects on each.
|
522
524
|
"""
|
523
|
-
#
|
525
|
+
# Discriminator for a Viv role-unpacking expression
|
524
526
|
type: Literal[ExpressionDiscriminator.ROLE_UNPACKING]
|
525
527
|
# The actual expression value
|
526
528
|
value: RoleName
|
@@ -528,7 +530,7 @@ class RoleUnpacking(TypedDict):
|
|
528
530
|
|
529
531
|
class StringField(TypedDict):
|
530
532
|
"""A Viv string literal."""
|
531
|
-
#
|
533
|
+
# Discriminator for a Viv string literal
|
532
534
|
type: Literal[ExpressionDiscriminator.STRING]
|
533
535
|
# The string literal to which this expression will evaluate
|
534
536
|
value: str
|
@@ -540,10 +542,10 @@ class TemplateStringField(TypedDict):
|
|
540
542
|
This kind of expression is structured as an ordered list of string literals and string-producing
|
541
543
|
references, the evaluations of which are concatenated to form the rendered string.
|
542
544
|
"""
|
543
|
-
#
|
545
|
+
# Discriminator for a Viv templated string
|
544
546
|
type: Literal[ExpressionDiscriminator.TEMPLATE_STRING]
|
545
547
|
# The actual expression value
|
546
|
-
value: list[Union[str, EntityReference,
|
548
|
+
value: list[Union[str, EntityReference, SymbolReference, RoleUnpacking]]
|
547
549
|
|
548
550
|
|
549
551
|
class TropeFitExpression(NegatableExpression):
|
@@ -551,7 +553,7 @@ class TropeFitExpression(NegatableExpression):
|
|
551
553
|
|
552
554
|
This kind of expression evaluates to `True` if the trope holds with the given arguments.
|
553
555
|
"""
|
554
|
-
#
|
556
|
+
# Discriminator for a Viv trope-fit expression
|
555
557
|
type: Literal[ExpressionDiscriminator.TROPE_FIT_EXPRESSION]
|
556
558
|
# The actual expression value
|
557
559
|
value: TropeFitExpressionValue
|