@words-lang/parser 0.1.0

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 (41) hide show
  1. package/dist/analyser/analyser.d.ts +106 -0
  2. package/dist/analyser/analyser.d.ts.map +1 -0
  3. package/dist/analyser/analyser.js +291 -0
  4. package/dist/analyser/analyser.js.map +1 -0
  5. package/dist/analyser/diagnostics.d.ts +166 -0
  6. package/dist/analyser/diagnostics.d.ts.map +1 -0
  7. package/dist/analyser/diagnostics.js +139 -0
  8. package/dist/analyser/diagnostics.js.map +1 -0
  9. package/dist/analyser/workspace.d.ts +198 -0
  10. package/dist/analyser/workspace.d.ts.map +1 -0
  11. package/dist/analyser/workspace.js +403 -0
  12. package/dist/analyser/workspace.js.map +1 -0
  13. package/dist/index.d.ts +8 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +31 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/lexer/lexer.d.ts +120 -0
  18. package/dist/lexer/lexer.d.ts.map +1 -0
  19. package/dist/lexer/lexer.js +365 -0
  20. package/dist/lexer/lexer.js.map +1 -0
  21. package/dist/lexer/token.d.ts +247 -0
  22. package/dist/lexer/token.d.ts.map +1 -0
  23. package/dist/lexer/token.js +250 -0
  24. package/dist/lexer/token.js.map +1 -0
  25. package/dist/parser/ast.d.ts +685 -0
  26. package/dist/parser/ast.d.ts.map +1 -0
  27. package/dist/parser/ast.js +3 -0
  28. package/dist/parser/ast.js.map +1 -0
  29. package/dist/parser/parser.d.ts +411 -0
  30. package/dist/parser/parser.d.ts.map +1 -0
  31. package/dist/parser/parser.js +1600 -0
  32. package/dist/parser/parser.js.map +1 -0
  33. package/package.json +23 -0
  34. package/src/analyser/analyser.ts +403 -0
  35. package/src/analyser/diagnostics.ts +232 -0
  36. package/src/analyser/workspace.ts +457 -0
  37. package/src/index.ts +7 -0
  38. package/src/lexer/lexer.ts +379 -0
  39. package/src/lexer/token.ts +331 -0
  40. package/src/parser/ast.ts +798 -0
  41. package/src/parser/parser.ts +1815 -0
@@ -0,0 +1,250 @@
1
+ "use strict";
2
+ /**
3
+ * token.ts
4
+ *
5
+ * Defines every token type the WORDS lexer can produce, the Token interface
6
+ * that carries a token's value and source location, and a convenience
7
+ * constructor for creating tokens in tests and the lexer itself.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.TokenType = void 0;
11
+ exports.token = token;
12
+ // ── Token types ───────────────────────────────────────────────────────────────
13
+ /**
14
+ * Every token type the WORDS lexer can produce.
15
+ *
16
+ * Grouped by category:
17
+ * - Top-level construct keywords (system, module, state, ...)
18
+ * - Block keywords (modules, props, uses, returns, ...)
19
+ * - Process / transition keywords (when, enter)
20
+ * - Control flow keywords (if, for, as, is, is not)
21
+ * - Primitive types (tstring, tinteger, ...)
22
+ * - Literals (string_lit, integer_lit, ...)
23
+ * - Identifiers (pascal_ident, camel_ident)
24
+ * - Punctuation ((, ), ,, .)
25
+ * - Special (comment, newline, eof, unknown)
26
+ *
27
+ * Enum values are the string representation of each token — useful for
28
+ * readable error messages and debug output without a separate lookup table.
29
+ *
30
+ * Note on naming conventions: method names, callback prop names, and handler
31
+ * method names (including names like `switch`, `onLoad`, `onSubmit`) are all
32
+ * plain camelCase identifiers chosen by the designer. None of them are
33
+ * reserved keywords in the WORDS language.
34
+ */
35
+ var TokenType;
36
+ (function (TokenType) {
37
+ // ── Top-level construct keywords ─────────────────────────────────────────
38
+ // These keywords open a named construct body at the top level of a file
39
+ // or inside a module definition.
40
+ /** `system` — opens the system declaration. Appears exactly once per project. */
41
+ TokenType["System"] = "system";
42
+ /**
43
+ * `module` — opens a module definition body, or appears alone on a line
44
+ * as an ownership declaration at the top of component files.
45
+ * e.g. `module AuthModule` (ownership) or `module AuthModule "..." (` (definition)
46
+ */
47
+ TokenType["Module"] = "module";
48
+ /** `process` — opens a process definition inside a module body. */
49
+ TokenType["Process"] = "process";
50
+ /** `state` — opens a state definition. */
51
+ TokenType["State"] = "state";
52
+ /** `context` — opens a context definition. */
53
+ TokenType["Context"] = "context";
54
+ /** `screen` — opens a screen definition, or activates a screen inside a `uses` block. */
55
+ TokenType["Screen"] = "screen";
56
+ /**
57
+ * `view` — opens a view definition, or activates a view inside a `uses` block.
58
+ * e.g. `view LoginFormSection "..." (` or `view UIModule.LoginForm (`
59
+ */
60
+ TokenType["View"] = "view";
61
+ /** `provider` — opens a provider definition, or activates a provider in a `uses` block. */
62
+ TokenType["Provider"] = "provider";
63
+ /**
64
+ * `adapter` — opens an adapter definition, or activates an adapter in a `uses` block.
65
+ * e.g. `adapter AuthAdapter.login credentials is state.context`
66
+ */
67
+ TokenType["Adapter"] = "adapter";
68
+ /**
69
+ * `interface` — opens an interface component definition, activates one in a
70
+ * `uses` block, or introduces an inline interface block inside a module body.
71
+ */
72
+ TokenType["Interface"] = "interface";
73
+ // ── Block keywords ────────────────────────────────────────────────────────
74
+ // These keywords open named sub-blocks inside a construct body.
75
+ /** `modules` — opens the module list inside a system body. */
76
+ TokenType["Modules"] = "modules";
77
+ /** `props` — opens the props block inside a view, provider, adapter, or interface. */
78
+ TokenType["Props"] = "props";
79
+ /** `uses` — opens the uses block inside a state, screen, view, provider, or interface. */
80
+ TokenType["Uses"] = "uses";
81
+ /**
82
+ * `returns` — appears in two roles:
83
+ * 1. Opens the returns clause inside a state: `returns AccountCredentials`
84
+ * 2. Declares the return type of a method: `getProducts returns(list(Product))`
85
+ */
86
+ TokenType["Returns"] = "returns";
87
+ /**
88
+ * `receives` — opens the receives clause on a state definition.
89
+ * e.g. `state Unauthenticated receives ?AuthError`
90
+ */
91
+ TokenType["Receives"] = "receives";
92
+ /**
93
+ * `start` — names the initial state of a module.
94
+ * e.g. `start Unauthenticated`
95
+ */
96
+ TokenType["Start"] = "start";
97
+ /**
98
+ * `implements` — opens a cross-module handler implementation block
99
+ * inside a module body.
100
+ * e.g. `implements RoutingModule.RouteSwitchHandler (`
101
+ */
102
+ TokenType["Implements"] = "implements";
103
+ // ── Process / transition keywords ────────────────────────────────────────
104
+ /**
105
+ * `when` — opens a transition rule inside a process body.
106
+ * e.g. `when Unauthenticated returns AccountCredentials`
107
+ */
108
+ TokenType["When"] = "when";
109
+ /**
110
+ * `enter` — names the next state to transition to in a `when` rule
111
+ * or an `implements` branch.
112
+ * e.g. `enter StartAuthenticating "The user tries to authenticate"`
113
+ */
114
+ TokenType["Enter"] = "enter";
115
+ // ── Control flow keywords ─────────────────────────────────────────────────
116
+ /**
117
+ * `if` — opens a conditional block inside a `uses` block or an
118
+ * `implements` handler body.
119
+ * e.g. `if state.context is AccountDeauthenticated (`
120
+ */
121
+ TokenType["If"] = "if";
122
+ /**
123
+ * `for` — opens an iteration block inside a `uses` block.
124
+ * e.g. `for state.context.notifications as notification (`
125
+ */
126
+ TokenType["For"] = "for";
127
+ /**
128
+ * `as` — binds the iteration variable(s) in a `for` block.
129
+ * For lists: `as notification` — one binding.
130
+ * For maps: `as category, products` — two bindings.
131
+ */
132
+ TokenType["As"] = "as";
133
+ /**
134
+ * `is` — the assignment and equality operator.
135
+ * As assignment: `type is "warning"`, `path is "/home"`
136
+ * As comparison: `if state.context is AccountDeauthenticated`
137
+ * Context determines which role it plays.
138
+ */
139
+ TokenType["Is"] = "is";
140
+ /**
141
+ * `is not` — the inequality operator, normalised from the two-word
142
+ * sequence `is not` into a single token during lexing.
143
+ * e.g. `if state.context is not AccountRecovered`
144
+ */
145
+ TokenType["IsNot"] = "is_not";
146
+ // ── Primitive types ───────────────────────────────────────────────────────
147
+ // These keywords name the built-in scalar and collection types.
148
+ /** `string` — text value type. Default: `""` */
149
+ TokenType["TString"] = "tstring";
150
+ /** `integer` — whole number type. Default: `0` */
151
+ TokenType["TInteger"] = "tinteger";
152
+ /** `float` — decimal number type. Default: `0.0` */
153
+ TokenType["TFloat"] = "tfloat";
154
+ /** `boolean` — true/false type. Default: `false` */
155
+ TokenType["TBoolean"] = "tboolean";
156
+ /**
157
+ * `context` — opaque context type used only in the system interface
158
+ * declaration for `getContext` and `setContext`.
159
+ */
160
+ TokenType["TContext"] = "tcontext";
161
+ /** `list` — ordered collection type. Parameterised: `list(Product)`. Default: `[]` */
162
+ TokenType["TList"] = "tlist";
163
+ /** `map` — key-value collection type. Parameterised: `map(string, OrderSummary)`. Default: `{}` */
164
+ TokenType["TMap"] = "tmap";
165
+ // ── Literals ──────────────────────────────────────────────────────────────
166
+ /**
167
+ * A double-quoted string literal.
168
+ * The token value includes the surrounding quotes.
169
+ * e.g. `"The user authenticated successfully"`, `"/home"`
170
+ */
171
+ TokenType["StringLit"] = "string_lit";
172
+ /**
173
+ * A whole number literal.
174
+ * e.g. `42`, `5000`, `0`
175
+ */
176
+ TokenType["IntegerLit"] = "integer_lit";
177
+ /**
178
+ * A decimal number literal.
179
+ * e.g. `0.0`, `3.14`
180
+ */
181
+ TokenType["FloatLit"] = "float_lit";
182
+ /**
183
+ * A boolean literal — `true` or `false`.
184
+ * Lexed as keyword-style tokens with value `"true"` or `"false"`.
185
+ */
186
+ TokenType["BooleanLit"] = "boolean_lit";
187
+ // ── Identifiers ───────────────────────────────────────────────────────────
188
+ /**
189
+ * A PascalCase identifier — names a construct (state, context, module, etc.)
190
+ * or a type reference.
191
+ * e.g. `AuthModule`, `AccountCredentials`, `LoginScreen`, `Product`
192
+ */
193
+ TokenType["PascalIdent"] = "pascal_ident";
194
+ /**
195
+ * A camelCase identifier — names a prop, method, argument, or iteration variable.
196
+ * This includes all designer-chosen names: callback prop names, method names,
197
+ * and handler method names regardless of what they are called.
198
+ * e.g. `onSubmit`, `credentials`, `fullName`, `notification`, `switch`, `onLoad`
199
+ */
200
+ TokenType["CamelIdent"] = "camel_ident";
201
+ // ── Punctuation ───────────────────────────────────────────────────────────
202
+ /** `(` — opens a body block or argument list. */
203
+ TokenType["LParen"] = "(";
204
+ /** `)` — closes a body block or argument list. */
205
+ TokenType["RParen"] = ")";
206
+ /** `,` — separates entries in a list — props, arguments, context names. */
207
+ TokenType["Comma"] = ",";
208
+ /** `.` — separates parts of a qualified name or access expression. */
209
+ TokenType["Dot"] = ".";
210
+ /**
211
+ * `?` — marks an optional type or receives clause.
212
+ * e.g. `?AuthError`, `?Product`
213
+ * Always immediately precedes a PascalIdent.
214
+ */
215
+ TokenType["Question"] = "?";
216
+ // ── Special ───────────────────────────────────────────────────────────────
217
+ /**
218
+ * A `//` line comment. The token value includes the `//` prefix and
219
+ * everything up to (but not including) the newline.
220
+ * Comments are included in the token stream so the parser can attach
221
+ * them to adjacent nodes for hover documentation.
222
+ */
223
+ TokenType["Comment"] = "comment";
224
+ /**
225
+ * A newline character `\n`.
226
+ * Newlines are significant in WORDS for distinguishing an ownership
227
+ * declaration (`module AuthModule` on its own line) from a construct
228
+ * opening (`module AuthModule "..." (`).
229
+ */
230
+ TokenType["Newline"] = "newline";
231
+ /**
232
+ * End of file sentinel. Always the last token in the stream.
233
+ * The parser uses this to detect unexpected end of input.
234
+ */
235
+ TokenType["EOF"] = "eof";
236
+ /**
237
+ * An unrecognised character. Emitted rather than throwing so the lexer
238
+ * can continue and collect all errors in a single pass.
239
+ */
240
+ TokenType["Unknown"] = "unknown";
241
+ })(TokenType || (exports.TokenType = TokenType = {}));
242
+ // ── Convenience constructor ───────────────────────────────────────────────────
243
+ /**
244
+ * Creates a Token with the given fields.
245
+ * Used internally by the lexer and in tests to avoid repetitive object literals.
246
+ */
247
+ function token(type, value, line, column, offset) {
248
+ return { type, value, line, column, offset };
249
+ }
250
+ //# sourceMappingURL=token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.js","sourceRoot":"","sources":["../../src/lexer/token.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AA4TH,sBAQC;AAlUD,iFAAiF;AAEjF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,IAAY,SAoQX;AApQD,WAAY,SAAS;IAEnB,4EAA4E;IAC5E,wEAAwE;IACxE,iCAAiC;IAEjC,iFAAiF;IACjF,8BAAiB,CAAA;IAEjB;;;;OAIG;IACH,8B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