gritzko/swarm

Spec object has `index` state which causes calls to be non-idempotent

Closed this issue · 1 comments

The Spec object has an internal index used for parsing which causes calls to be non-idempotent. For example:

var someSpec = ...
console.log(spec.token('!'))
// prints Object {quant: "!", body: "2QXIl03+A0017r~0", bare: "2QXIl03", ext: "A0017r~0"}
console.log(spec.token('!'))
// prints undefined
someSpec.index = 0
console.log(spec.token('!'))
// prints Object {quant: "!", body: "2QXIl03+A0017r~0", bare: "2QXIl03", ext: "A0017r~0"}

Presumably index should be reset with Spec at the beginning of each parse method?

Practically, index is not used anymore.
Removed it in 461dbb3
Thanks.