diff --git a/grammars/mediawiki.js b/grammars/mediawiki.js index 02675b1..63e63aa 100644 --- a/grammars/mediawiki.js +++ b/grammars/mediawiki.js @@ -23,5 +23,5 @@ var mediawiki = { rr.Ref('nowiki'), rr.Ref('text') ), - 'wikidoc': rr.Node('wikidoc', rr.ZeroOrMore(rr.Ref('wikichunk'))), + 'wikidoc': rr.Node('wikidoc', rr.Sequence(rr.ZeroOrMore(rr.Ref('wikichunk')), rr.EndOfText())), }; diff --git a/recentrunes.js b/recentrunes.js index 5f45b22..bab93bb 100644 --- a/recentrunes.js +++ b/recentrunes.js @@ -493,22 +493,18 @@ rr.ZeroOrMore_ = function(child) { */ rr.ZeroOrMore_.prototype.match = function(context) { // Yield: - // 1) The results of SequentialPair(child, this) - // 2) An empty result + // 1) An empty result + // 2) The results of SequentialPair(child, this) // 3) Done // - // We must check for results from 1 that don't reduce context.remaining(); + // We must check for results from 2 that don't reduce context.remaining(); // that means infinite recursion. - var iterator = this.pair_.match(context); + var iterator = null; return { 'next': function() { if (!iterator) { - return { 'done': true }; - } - var next = iterator.next(); - if (next['done']) { - iterator = null; + iterator = this.pair_.match(context); return { 'done': false, 'value': { @@ -517,6 +513,10 @@ rr.ZeroOrMore_.prototype.match = function(context) { } }; } + var next = iterator.next(); + if (next['done']) { + return { 'done': true }; + } if (next['value']['context'].remaining() == context.remaining()) { throw "Child of ZeroOrMore didn't consume input; grammar bug?"; } diff --git a/test.js b/test.js index 89500fd..0dcb8a5 100644 --- a/test.js +++ b/test.js @@ -8,7 +8,7 @@ QUnit.test('Simple', function(assert) { var iterable = context.rules['wikidoc'].match(context); assert.equal(iterable.next().value.nodes[0].innerHTML, '