Skip to content

Commit

Permalink
Fix include bug with fast matching
Browse files Browse the repository at this point in the history
  • Loading branch information
tjvr committed Jan 3, 2019
1 parent 4c3a977 commit 13e1157
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion moo.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
errorRule = options
}

var match = options.match
var match = options.match.slice()
if (fastAllowed) {
while (match.length && typeof match[0] === 'string' && match[0].length === 1) {
var word = match.shift()
Expand Down
37 changes: 37 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,43 @@ describe('example: tosh', () => {

describe('include', () => {

test('handles fast matching', () => {
const l = moo.states({
main: {
"{": "{",
include: 'shared',
},
shared: {
'*': '*',
word: /[a-z]+/,
}
})

l.reset("{foo*")
Array.from(l)
})

test('handles multiple states with same fast match', () => {
const l = moo.states({
main: {
include: 'shared',
"{": {match: "{", push: "inner"},
},
inner: {
"}": {match: "}", pop: 1},
include: 'shared',
},
shared: {
'*': '*',
word: /[a-z]+/,
},
x: 1,
})

l.reset("foo{bar*}")
Array.from(l)
})

test('handles cycles', () => {
const lexer = moo.states({
$all: {
Expand Down

0 comments on commit 13e1157

Please sign in to comment.