Skip to content

Commit

Permalink
Allow pop: 1
Browse files Browse the repository at this point in the history
  • Loading branch information
tjvr committed Jul 26, 2017
1 parent 4cd9a6f commit 7641fd1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 2 additions & 3 deletions moo.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,8 @@
if (state && !map[state]) {
throw new Error("Missing state '" + state + "' (in token '" + g.tokenType + "' of state '" + keys[i] + "')")
}
var pop = g && g.pop
if (pop && typeof pop !== 'boolean') {
throw new Error("pop must be true (in token '" + g.tokenType + "' of state '" + keys[i] + "')")
if (g && g.pop && +g.pop !== 1) {
throw new Error("pop must be 1 (in token '" + g.tokenType + "' of state '" + keys[i] + "')")
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,12 @@ describe('stateful lexer', () => {
})

test('warns for non-boolean pop', () => {
expect(() => moo.states({start: {bar: {match: 'bar', pop: 'cow'}}})).toThrow("pop must be true (in token 'bar' of state 'start')")
expect(() => moo.states({start: {bar: {match: 'bar', pop: 2}}})).toThrow("pop must be true (in token 'bar' of state 'start')")
expect(() => moo.states({start: {bar: {match: 'bar', pop: 'cow'}}})).toThrow("pop must be 1 (in token 'bar' of state 'start')")
expect(() => moo.states({start: {bar: {match: 'bar', pop: 2}}})).toThrow("pop must be 1 (in token 'bar' of state 'start')")
expect(() => moo.states({start: {bar: {match: 'bar', pop: true}}})).not.toThrow()
expect(() => moo.states({start: {bar: {match: 'bar', pop: 1}}})).not.toThrow()
expect(() => moo.states({start: {bar: {match: 'bar', pop: false}}})).not.toThrow()
expect(() => moo.states({start: {bar: {match: 'bar', pop: 0}}})).not.toThrow()
})

})
Expand Down

0 comments on commit 7641fd1

Please sign in to comment.