Skip to content

Commit

Permalink
fix #407 - asIteration is missing from TS types
Browse files Browse the repository at this point in the history
  • Loading branch information
pdubroy committed Dec 19, 2022
1 parent f165c19 commit 662394e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/ohm-js/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,14 @@ declare namespace ohm {
*/
isOptional(): boolean;

/**
* A built-in operation which can convert certain NonterminalNodes into
* IterationNodes. This operation is defined for the built-in list rules
* (ListOf, EmptyListOf, NonemptyListOf, listOf, ...), and can also be
* defined for user-defined rules.
*/
asIteration(): IterationNode;

/**
* In addition to the properties defined above, within a given
* semantics, every node also has a method/property corresponding to
Expand Down
8 changes: 8 additions & 0 deletions packages/ohm-js/scripts/data/index.d.ts.template
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,14 @@ declare namespace ohm {
*/
isOptional(): boolean;

/**
* A built-in operation which can convert certain NonterminalNodes into
* IterationNodes. This operation is defined for the built-in list rules
* (ListOf, EmptyListOf, NonemptyListOf, listOf, ...), and can also be
* defined for user-defined rules.
*/
asIteration(): IterationNode;

/**
* In addition to the properties defined above, within a given
* semantics, every node also has a method/property corresponding to
Expand Down
15 changes: 15 additions & 0 deletions packages/ohm-js/test/test-typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,18 @@ test('getLineAndColumn - #410', t => {
t.is(lineAndCol.prevLine, null);
t.is(lineAndCol.nextLine, null);
});

test('asIteration - #407', t => {
const g = ohm.grammar(`
G {
start = letters
letters = listOf<letter, "">
}
`);
const s = g.createSemantics().addOperation('x', {
start(letters) {
return letters.asIteration().isIteration()
}
});
t.is(s(g.match('abc')).x(), true);
});

0 comments on commit 662394e

Please sign in to comment.