ttr-parser 0.1.0__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.
ttr_parser/__init__.py ADDED
@@ -0,0 +1,166 @@
1
+ """ttr_parser — Python parser, walker and reference resolver for the TTR modeling language.
2
+
3
+ Public API is re-exported here from `model`, `diagnostics`, `dedent`,
4
+ `loader`. The `loader` module is the entry point — `parse_string` /
5
+ `parse_file` / `parse_directory` boot ANTLR, run the walker, and surface a
6
+ typed `ParseResult`. The model types (`Definition` subtypes,
7
+ `PropertyValue` variants, `SourceLocation`, …) are pure data and live in
8
+ `model`.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ from .dedent import DedentResult, dedent, dedent_with_indent
14
+ from .diagnostics import DiagnosticCode, DiagnosticSeverity
15
+ from .loader import parse_directory, parse_file, parse_string
16
+ from .model import (
17
+ AttributeDef,
18
+ BoolValue,
19
+ ColumnDef,
20
+ ConstraintDef,
21
+ DataType,
22
+ Definition,
23
+ DrillMapDef,
24
+ EntityDef,
25
+ Er2CncRoleDef,
26
+ Er2DbAttributeDef,
27
+ Er2DbEntityDef,
28
+ Er2DbRelationDef,
29
+ FkDef,
30
+ FunctionCall,
31
+ IdValue,
32
+ ImportStatement,
33
+ IndexDef,
34
+ LanguageKind,
35
+ ListValue,
36
+ LocalizedStringListValue,
37
+ LocalizedStringValue,
38
+ MappingColumnBareId,
39
+ MappingColumnEntry,
40
+ MappingColumnObject,
41
+ MappingColumnValue,
42
+ MappingProperty,
43
+ MappingPropertyBareId,
44
+ MappingPropertyBlock,
45
+ ModelDef,
46
+ NullValue,
47
+ NumberValue,
48
+ ObjectValue,
49
+ PackageDeclaration,
50
+ ParseError,
51
+ ParseResult,
52
+ ParseWarning,
53
+ ProcedureDef,
54
+ PropertyValue,
55
+ QueryDef,
56
+ Reference,
57
+ RelationDef,
58
+ RoleDef,
59
+ SchemaDirective,
60
+ SearchHintsValue,
61
+ SourceLocation,
62
+ StringValue,
63
+ TableDef,
64
+ TaggedBlockValue,
65
+ TargetObjectValue,
66
+ TargetReferenceValue,
67
+ TargetValue,
68
+ TripleStringValue,
69
+ ViewDef,
70
+ )
71
+
72
+ __version__ = "0.0.0"
73
+
74
+ # Common semantics entry points, re-exported for convenience (the full surface
75
+ # lives in `ttr_parser.semantics`). Imported after the model/loader names above
76
+ # so the subpackage's `from ..loader import …` resolves cleanly.
77
+ from .semantics import Project, load_project # noqa: E402
78
+
79
+
80
+ def extract_reference(value: PropertyValue) -> Reference | None:
81
+ """Walker-style helper: extract a `Reference` from an `IdValue`; else `None`.
82
+
83
+ Mirrors `walker.ts` `extractReference` — only `IdValue` carries a reference;
84
+ every other `PropertyValue` variant (including lists/objects containing ids)
85
+ returns `None`. Defined here so consumers can import it without the walker.
86
+ """
87
+ if isinstance(value, IdValue) and value.ref is not None:
88
+ return value.ref
89
+ return None
90
+
91
+
92
+ __all__ = [
93
+ "__version__",
94
+ "extract_reference",
95
+ # semantics convenience entry points (full surface in ttr_parser.semantics)
96
+ "Project",
97
+ "load_project",
98
+ # diagnostics
99
+ "DiagnosticCode",
100
+ "DiagnosticSeverity",
101
+ # loader entry points (P2.3)
102
+ "parse_string",
103
+ "parse_file",
104
+ "parse_directory",
105
+ # dedent helper (P2.3 — public for consumers that need it)
106
+ "dedent",
107
+ "dedent_with_indent",
108
+ "DedentResult",
109
+ # model — Definition hierarchy
110
+ "Definition",
111
+ "ModelDef",
112
+ "TableDef",
113
+ "ViewDef",
114
+ "ColumnDef",
115
+ "IndexDef",
116
+ "ConstraintDef",
117
+ "FkDef",
118
+ "ProcedureDef",
119
+ "EntityDef",
120
+ "AttributeDef",
121
+ "RelationDef",
122
+ "Er2DbEntityDef",
123
+ "Er2DbAttributeDef",
124
+ "Er2DbRelationDef",
125
+ "QueryDef",
126
+ "RoleDef",
127
+ "Er2CncRoleDef",
128
+ "DrillMapDef",
129
+ # model — PropertyValue hierarchy
130
+ "PropertyValue",
131
+ "StringValue",
132
+ "TripleStringValue",
133
+ "NumberValue",
134
+ "BoolValue",
135
+ "NullValue",
136
+ "IdValue",
137
+ "ListValue",
138
+ "ObjectValue",
139
+ "FunctionCall",
140
+ "TaggedBlockValue",
141
+ "LanguageKind",
142
+ # model — supporting types
143
+ "SourceLocation",
144
+ "Reference",
145
+ "DataType",
146
+ "SearchHintsValue",
147
+ "LocalizedStringValue",
148
+ "LocalizedStringListValue",
149
+ "SchemaDirective",
150
+ "ImportStatement",
151
+ "PackageDeclaration",
152
+ "ParseError",
153
+ "ParseWarning",
154
+ "ParseResult",
155
+ # model — mapping types
156
+ "MappingProperty",
157
+ "MappingPropertyBareId",
158
+ "MappingPropertyBlock",
159
+ "TargetValue",
160
+ "TargetObjectValue",
161
+ "TargetReferenceValue",
162
+ "MappingColumnEntry",
163
+ "MappingColumnValue",
164
+ "MappingColumnBareId",
165
+ "MappingColumnObject",
166
+ ]