@ohm-js/wasm 0.6.1 → 0.6.3

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.
@@ -1,5 +1,8 @@
1
1
  import type { CstNode, MatchResult } from './miniohm.ts';
2
- export type AstMapping = Record<string, unknown>;
2
+ export type AstNodeTemplate = {
3
+ [property: string]: number | string | boolean | object | null | ((this: AstBuilder, children: CstNode[]) => any);
4
+ };
5
+ export type AstMapping = Record<string, AstNodeTemplate | number | ((this: AstBuilder, ...children: CstNode[]) => any)>;
3
6
  export declare class AstBuilder {
4
7
  currNode?: CstNode;
5
8
  private _mapping;
@@ -1,4 +1,8 @@
1
+ import type { Grammar as GrammarJs } from 'ohm-js';
1
2
  import { WasmGrammar } from './miniohm.ts';
2
- export declare function grammar(source: string): WasmGrammar;
3
- export declare function grammars(source: string): Record<string, WasmGrammar>;
3
+ export interface Grammar extends WasmGrammar {
4
+ rules: GrammarJs['rules'];
5
+ }
6
+ export declare function grammar(source: string): Grammar;
7
+ export declare function grammars(source: string): Record<string, Grammar>;
4
8
  //# sourceMappingURL=compat.d.ts.map
@@ -1,17 +1,23 @@
1
1
  import { grammars as grammarsJs, grammar as grammarJs } from 'ohm-js';
2
2
  import { Compiler } from './Compiler.js';
3
3
  import { WasmGrammar } from "./miniohm.js";
4
+ class CompatGrammar extends WasmGrammar {
5
+ rules;
6
+ constructor(wasmModule, rules) {
7
+ super(wasmModule);
8
+ this.rules = rules;
9
+ }
10
+ }
4
11
  // TODO: Support a namespace parameter.
5
12
  export function grammar(source) {
6
- const compiler = new Compiler(grammarJs(source));
7
- return new WasmGrammar(compiler.compile());
13
+ return Object.values(grammars(source))[0];
8
14
  }
9
15
  // TODO: Support a namespace parameter.
10
16
  export function grammars(source) {
11
17
  const ans = {};
12
18
  for (const g of Object.values(grammarsJs(source))) {
13
19
  const compiler = new Compiler(g);
14
- ans[g.name] = new WasmGrammar(compiler.compile());
20
+ ans[g.name] = new CompatGrammar(compiler.compile(), g.rules);
15
21
  }
16
22
  return ans;
17
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ohm-js/wasm",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "Compile Ohm.js grammars to WebAsssembly",
5
5
  "main": "dist/index.js",
6
6
  "exports": {