@intend-it/parser 1.3.1 → 1.3.2

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.
package/README.md CHANGED
@@ -113,6 +113,7 @@ interface IntentDeclaration {
113
113
  | **Invariants** | `invariant "rule"` | `invariant "Input must be positive"` |
114
114
  | **Ensures** | `ensure expression` | `ensure result is defined` |
115
115
  | **Imports** | `import { X } from "path"` | `import { User } from "./types"` |
116
+ | **Context** | `context "Message"` | `context "Handle currency as integers"` |
116
117
  | **Entry Points** | `entry intent Main()` | `export entry intent Main() -> void` |
117
118
 
118
119
  ## Related Packages
package/dist/index.js CHANGED
@@ -9158,6 +9158,7 @@ var BlockComment = createToken({
9158
9158
  var Import = createToken({ name: "Import", pattern: /import/ });
9159
9159
  var From = createToken({ name: "From", pattern: /from/ });
9160
9160
  var Intent = createToken({ name: "Intent", pattern: /intent/ });
9161
+ var Context = createToken({ name: "Context", pattern: /context/ });
9161
9162
  var Export = createToken({ name: "Export", pattern: /export/ });
9162
9163
  var Invariant = createToken({ name: "Invariant", pattern: /invariant/ });
9163
9164
  var Step = createToken({ name: "Step", pattern: /step/ });
@@ -9205,6 +9206,7 @@ var allTokens = [
9205
9206
  From,
9206
9207
  Export,
9207
9208
  Intent,
9209
+ Context,
9208
9210
  Invariant,
9209
9211
  Step,
9210
9212
  Ensure,
@@ -9243,6 +9245,9 @@ class IntendParser extends CstParser {
9243
9245
  this.performSelfAnalysis();
9244
9246
  }
9245
9247
  intendFile = this.RULE("intendFile", () => {
9248
+ this.OPTION(() => {
9249
+ this.SUBRULE(this.contextStatement);
9250
+ });
9246
9251
  this.MANY(() => {
9247
9252
  this.SUBRULE(this.importStatement);
9248
9253
  });
@@ -9250,6 +9255,13 @@ class IntendParser extends CstParser {
9250
9255
  this.SUBRULE(this.intentDeclaration);
9251
9256
  });
9252
9257
  });
9258
+ contextStatement = this.RULE("contextStatement", () => {
9259
+ this.CONSUME(Context);
9260
+ this.CONSUME(StringLiteral);
9261
+ this.OPTION(() => {
9262
+ this.CONSUME(Semicolon);
9263
+ });
9264
+ });
9253
9265
  intentDeclaration = this.RULE("intentDeclaration", () => {
9254
9266
  this.CONSUME(Export);
9255
9267
  this.OPTION3(() => {
@@ -9421,14 +9433,19 @@ class IntendASTVisitor extends BaseIntendVisitor {
9421
9433
  this.validateVisitor();
9422
9434
  }
9423
9435
  intendFile(ctx) {
9436
+ const context = ctx.contextStatement ? this.visit(ctx.contextStatement[0]) : undefined;
9424
9437
  const imports = ctx.importStatement ? ctx.importStatement.map((imp) => this.visit(imp)) : [];
9425
9438
  const intents = ctx.intentDeclaration ? ctx.intentDeclaration.map((d) => this.visit(d)) : [];
9426
9439
  return {
9427
9440
  type: "IntendFile",
9441
+ context,
9428
9442
  imports,
9429
9443
  intents
9430
9444
  };
9431
9445
  }
9446
+ contextStatement(ctx) {
9447
+ return this.unquoteString(ctx.StringLiteral[0].image);
9448
+ }
9432
9449
  intentDeclaration(ctx) {
9433
9450
  const entryPoint = !!ctx.Entry && ctx.Entry.length > 0;
9434
9451
  const name = ctx.Identifier[0].image;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intend-it/parser",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Parser for the Intend programming language",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",