viv-compiler 0.1.1__tar.gz → 0.1.2__tar.gz

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.
Files changed (39) hide show
  1. {viv_compiler-0.1.1/src/viv_compiler.egg-info → viv_compiler-0.1.2}/PKG-INFO +14 -14
  2. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/README.md +13 -13
  3. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/pyproject.toml +1 -1
  4. {viv_compiler-0.1.1/src/viv_compiler/utils → viv_compiler-0.1.2/src/viv_compiler}/_version.py +1 -1
  5. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/cli.py +5 -4
  6. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/config/config.py +17 -18
  7. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/core/core.py +2 -2
  8. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/core/metadata.py +8 -6
  9. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/core/validation.py +202 -64
  10. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/core/visitor.py +143 -128
  11. viv_compiler-0.1.2/src/viv_compiler/grammar/viv.peg +460 -0
  12. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/types/content_public_schemas.py +32 -27
  13. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/types/dsl_public_schemas.py +75 -79
  14. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/utils/utils.py +93 -33
  15. {viv_compiler-0.1.1 → viv_compiler-0.1.2/src/viv_compiler.egg-info}/PKG-INFO +14 -14
  16. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler.egg-info/SOURCES.txt +1 -1
  17. viv_compiler-0.1.1/src/viv_compiler/grammar/viv.peg +0 -233
  18. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/LICENSE +0 -0
  19. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/setup.cfg +0 -0
  20. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/__init__.py +0 -0
  21. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/__main__.py +0 -0
  22. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/_samples/__init__.py +0 -0
  23. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/_samples/smoke-test.viv +0 -0
  24. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/api.py +0 -0
  25. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/backports/__init__.py +0 -0
  26. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/backports/backports.py +0 -0
  27. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/config/__init__.py +0 -0
  28. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/core/__init__.py +0 -0
  29. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/core/includes.py +0 -0
  30. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/core/postprocessing.py +0 -0
  31. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/grammar/__init__.py +0 -0
  32. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/py.typed +0 -0
  33. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/types/__init__.py +0 -0
  34. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/types/internal_types.py +0 -0
  35. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler/utils/__init__.py +0 -0
  36. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler.egg-info/dependency_links.txt +0 -0
  37. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler.egg-info/entry_points.txt +0 -0
  38. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler.egg-info/requires.txt +0 -0
  39. {viv_compiler-0.1.1 → viv_compiler-0.1.2}/src/viv_compiler.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: viv-compiler
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Compiler for the DSL of Viv, an action system for emergent narrative.
5
5
  Author-email: James Ryan <mail@jamesryan.ai>
6
6
  License: MIT License
@@ -45,7 +45,7 @@ Dynamic: license-file
45
45
 
46
46
  This package contains the reference compiler for the domain-specific language (DSL) at the heart of [Viv](https://github.com/james-owen-ryan/viv), an action system for emergent narrative.
47
47
 
48
- The Viv compiler accepts a *Viv source file* (`.viv`) and produces a *Viv content bundle* in a JSON-serializable format conforming to the `CompiledContentBundle` schema defined [here](https://github.com/james-owen-ryan/viv/blob/main/compiler/src/viv_compiler/types/dsl_public_schemas.py), making it ready for usage in any Viv runtime.
48
+ The Viv compiler accepts a **Viv source file** (`.viv`) and produces a **Viv content bundle** in a JSON-serializable format conforming to the `CompiledContentBundle` schema defined [here](https://github.com/james-owen-ryan/viv/blob/main/compiler/src/viv_compiler/types/dsl_public_schemas.py), making it ready for usage in any Viv runtime with the same version number as the compiler.
49
49
 
50
50
  Once you've installed this package, you'll have access to the two compiler interfaces that are documented below:
51
51
 
@@ -65,17 +65,17 @@ Once you've installed this package, you'll have access to the two compiler inter
65
65
 
66
66
  ## Installation
67
67
 
68
- Install from PyPI:
68
+ * Install from PyPI:
69
69
 
70
- ```
71
- pip install viv-compiler
72
- ```
70
+ ```
71
+ pip install viv-compiler
72
+ ```
73
73
 
74
- Smoke test to confirm your installation looks good:
74
+ * Run a smoke test to confirm your installation looks good:
75
75
 
76
- ```
77
- vivc --test
78
- ```
76
+ ```
77
+ vivc --test
78
+ ```
79
79
 
80
80
 
81
81
  ## Command-Line Interface (CLI)
@@ -226,13 +226,13 @@ Once you've installed `viv-compiler`, the Viv compiler Python API can be invoked
226
226
 
227
227
  ```python
228
228
  from pathlib import Path
229
- from viv_compiler import compile_from_path
229
+ from viv_compiler import compile_from_path, VivCompileError
230
230
 
231
231
  try:
232
- content_bundle = compile_from_path(source_file_path=Path("my-actions.viv"))
233
- print("Compilation succeeded:", content_bundle)
232
+ content_bundle = compile_from_path(source_file_path=Path("my-actions.viv"))
233
+ print("Compilation succeeded:", content_bundle)
234
234
  except VivCompileError as e:
235
- print("Compilation failed:", e)
235
+ print("Compilation failed:", e)
236
236
  ```
237
237
 
238
238
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  This package contains the reference compiler for the domain-specific language (DSL) at the heart of [Viv](https://github.com/james-owen-ryan/viv), an action system for emergent narrative.
4
4
 
5
- The Viv compiler accepts a *Viv source file* (`.viv`) and produces a *Viv content bundle* in a JSON-serializable format conforming to the `CompiledContentBundle` schema defined [here](https://github.com/james-owen-ryan/viv/blob/main/compiler/src/viv_compiler/types/dsl_public_schemas.py), making it ready for usage in any Viv runtime.
5
+ The Viv compiler accepts a **Viv source file** (`.viv`) and produces a **Viv content bundle** in a JSON-serializable format conforming to the `CompiledContentBundle` schema defined [here](https://github.com/james-owen-ryan/viv/blob/main/compiler/src/viv_compiler/types/dsl_public_schemas.py), making it ready for usage in any Viv runtime with the same version number as the compiler.
6
6
 
7
7
  Once you've installed this package, you'll have access to the two compiler interfaces that are documented below:
8
8
 
@@ -22,17 +22,17 @@ Once you've installed this package, you'll have access to the two compiler inter
22
22
 
23
23
  ## Installation
24
24
 
25
- Install from PyPI:
25
+ * Install from PyPI:
26
26
 
27
- ```
28
- pip install viv-compiler
29
- ```
27
+ ```
28
+ pip install viv-compiler
29
+ ```
30
30
 
31
- Smoke test to confirm your installation looks good:
31
+ * Run a smoke test to confirm your installation looks good:
32
32
 
33
- ```
34
- vivc --test
35
- ```
33
+ ```
34
+ vivc --test
35
+ ```
36
36
 
37
37
 
38
38
  ## Command-Line Interface (CLI)
@@ -183,13 +183,13 @@ Once you've installed `viv-compiler`, the Viv compiler Python API can be invoked
183
183
 
184
184
  ```python
185
185
  from pathlib import Path
186
- from viv_compiler import compile_from_path
186
+ from viv_compiler import compile_from_path, VivCompileError
187
187
 
188
188
  try:
189
- content_bundle = compile_from_path(source_file_path=Path("my-actions.viv"))
190
- print("Compilation succeeded:", content_bundle)
189
+ content_bundle = compile_from_path(source_file_path=Path("my-actions.viv"))
190
+ print("Compilation succeeded:", content_bundle)
191
191
  except VivCompileError as e:
192
- print("Compilation failed:", e)
192
+ print("Compilation failed:", e)
193
193
  ```
194
194
 
195
195
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "viv-compiler"
7
- version = "0.1.1" # This gets updated programmatically by `viv/scripts/bump_version.sh`
7
+ version = "0.1.2" # This gets updated programmatically by `viv/scripts/bump_version.sh`
8
8
  description = "Compiler for the DSL of Viv, an action system for emergent narrative."
9
9
  license = { file = "LICENSE" }
10
10
  authors = [{ name = "James Ryan", email = "mail@jamesryan.ai" }]
@@ -1,2 +1,2 @@
1
1
  # This is programmatically updated by viv/scripts/bump_version.sh
2
- __version__ = "0.1.0"
2
+ __version__ = "0.1.2"
@@ -10,6 +10,8 @@ import traceback
10
10
  import viv_compiler.config
11
11
  from pathlib import Path
12
12
  from importlib import resources
13
+
14
+ from viv_compiler import VivCompileError
13
15
  from .api import compile_from_path, get_version
14
16
  from viv_compiler.types import CompiledContentBundle
15
17
 
@@ -189,10 +191,9 @@ def _invoke_compiler(args: argparse.Namespace) -> CompiledContentBundle:
189
191
  except Exception:
190
192
  pass
191
193
  sys.exit(1)
192
- except Exception as e:
193
- print(f"Error encountered during compilation: {e}", file=sys.stderr)
194
- if args.debug:
195
- traceback.print_exc()
194
+ except VivCompileError as e:
195
+ cause = e.__cause__ or e
196
+ print(f"Error encountered during compilation:\n\n{cause}\n", file=sys.stderr)
196
197
  sys.exit(1)
197
198
 
198
199
 
@@ -25,9 +25,9 @@ NEGATABLE_EXPRESSION_TYPES = {
25
25
  ExpressionDiscriminator.CONJUNCTION,
26
26
  ExpressionDiscriminator.DISJUNCTION,
27
27
  ExpressionDiscriminator.ENTITY_REFERENCE,
28
- ExpressionDiscriminator.LOCAL_VARIABLE_REFERENCE,
29
28
  ExpressionDiscriminator.LOOP,
30
29
  ExpressionDiscriminator.MEMBERSHIP_TEST,
30
+ ExpressionDiscriminator.SYMBOL_REFERENCE,
31
31
  ExpressionDiscriminator.TROPE_FIT_EXPRESSION,
32
32
  }
33
33
 
@@ -56,28 +56,21 @@ REACTION_FIELD_DEFAULT_OPTIONS = {
56
56
  "abandonmentConditions": [],
57
57
  }
58
58
 
59
- # The path to which the global-variable sigil `$` expands. This sigil is really just syntactic sugar for
59
+ # Name for the special action self-reference role, which is always bound to the action itself
60
+ ACTION_SELF_REFERENCE_ROLE_NAME = 'this'
61
+
62
+ # A set containing the special role names that are automatically created by Viv at various points
63
+ SPECIAL_ROLE_NAMES = {'hearer', ACTION_SELF_REFERENCE_ROLE_NAME}
64
+
65
+ # The path to which the scratch-variable sigil `$` expands. This sigil is really just syntactic sugar for
60
66
  # the path `@this.scratch`, which stores a blackboard local to a performed action. For instance, the scratch
61
- # operation `$foo.bar = 99` is syntactic sugar for the expression `@this.scratch.foo.bar = 99`.
62
- GLOBAL_VARIABLE_REFERENCE_ANCHOR = "this"
63
- GLOBAL_VARIABLE_REFERENCE_PATH_PREFIX = [{
67
+ # operation `$@foo.bar = 99` is syntactic sugar for the expression `@this.scratch.foo.bar = 99`.
68
+ SCRATCH_VARIABLE_REFERENCE_ANCHOR = ACTION_SELF_REFERENCE_ROLE_NAME
69
+ SCRATCH_VARIABLE_REFERENCE_PATH_PREFIX = [{
64
70
  "type": ReferencePathComponentDiscriminator.REFERENCE_PATH_COMPONENT_PROPERTY_NAME,
65
71
  "name": "scratch",
66
72
  }]
67
73
 
68
- # The path to which the local-variable sigil `$$` expands. This sigil is really just a property lookup in
69
- # the special `__locals__` field of an evaluation context, which is a temporary store for scoped local
70
- # variables. For instance, the local-variable reference `$$c` defines an attempt to access `__locals__.c`
71
- # in an evaluation context. Unlike the `$` sigil, this is not syntactic sugar, since the Viv author has
72
- # no other way to reference local variables.
73
- LOCAL_VARIABLE_REFERENCE_PATH = ["__locals__"]
74
-
75
- # Name for the variable to which each character is set when computing their salience for an action
76
- SALIENCES_VARIABLE_NAME = "c"
77
-
78
- # Name for the variable to which each character is set when computing their associations for an action
79
- ASSOCIATIONS_VARIABLE_NAME = "c"
80
-
81
74
  # A default salience value, to be used when the API caller does not provide one
82
75
  DEFAULT_SALIENCE_VALUE = 1.0
83
76
 
@@ -86,3 +79,9 @@ DEFAULT_ASSOCIATIONS_VALUE = []
86
79
 
87
80
  # A default reaction priority value, to be used when the API caller does not provide one
88
81
  DEFAULT_REACTION_PRIORITY_VALUE = 1.0
82
+
83
+ # A list containing the names of action fields in which assignments are permitted
84
+ ACTION_FIELDS_PERMITTING_ASSIGNMENTS = ("scratch", "effects",)
85
+
86
+ # A list containing the names of action fields in which reactions are permitted
87
+ ACTION_FIELDS_PERMITTING_REACTIONS = ("reactions",)
@@ -106,7 +106,7 @@ def _honor_user_supplied_config_parameters(
106
106
  """
107
107
  viv_compiler.config.ACTION_DEFINITION_OPTIONAL_FIELD_DEFAULT_VALUES["saliences"] = {
108
108
  "default": {'type': 'float', 'value': default_salience},
109
- "variable": viv_compiler.config.SALIENCES_VARIABLE_NAME,
109
+ "variable": None,
110
110
  "body": [],
111
111
  }
112
112
  default_associations_expression = {
@@ -115,7 +115,7 @@ def _honor_user_supplied_config_parameters(
115
115
  }
116
116
  viv_compiler.config.ACTION_DEFINITION_OPTIONAL_FIELD_DEFAULT_VALUES["associations"] = {
117
117
  "default": default_associations_expression,
118
- "variable": viv_compiler.config.ASSOCIATIONS_VARIABLE_NAME,
118
+ "variable": None,
119
119
  "body": [],
120
120
  }
121
121
  viv_compiler.config.REACTION_FIELD_DEFAULT_OPTIONS["priority"] = {
@@ -33,15 +33,17 @@ def create_metadata(
33
33
  "buildRoles": [],
34
34
  "timeOfDayConstrainedReactions": []
35
35
  }
36
+ all_referenced_enum_names = []
37
+ all_referenced_function_names = []
36
38
  for ast_chunk in action_definitions + trope_definitions:
37
39
  # Compile all referenced enums
38
- all_referenced_enum_names = set(viv_compiler.utils.get_all_referenced_enum_names(ast_chunk=ast_chunk))
39
- metadata["referencedEnums"].extend(all_referenced_enum_names)
40
+ all_referenced_enum_names.extend(viv_compiler.utils.get_all_referenced_enum_names(ast_chunk=ast_chunk))
40
41
  # Compile all referenced adapter functions
41
- all_referenced_function_names = set(
42
- viv_compiler.utils.get_all_referenced_adapter_function_names(ast_chunk=ast_chunk)
43
- )
44
- metadata["referencedFunctionNames"].extend(all_referenced_function_names)
42
+ all_referenced_function_names.extend(viv_compiler.utils.get_all_referenced_adapter_function_names(
43
+ ast_chunk=ast_chunk
44
+ ))
45
+ metadata["referencedEnums"].extend(sorted(set(all_referenced_enum_names)))
46
+ metadata["referencedFunctionNames"].extend(sorted(set(all_referenced_function_names)))
45
47
  for action_definition in action_definitions:
46
48
  # Compile all roles carrying 'item' and 'build' labels
47
49
  for role_definition in action_definition["roles"].values():