From d184d0d4daf0b91e315c788dda843c4935b196f5 Mon Sep 17 00:00:00 2001 From: "Elf M. Sternberg" Date: Fri, 4 May 2012 11:53:14 -0700 Subject: [PATCH] Added some comments to further my own understanding, plus updated the NPM script. --- package.json | 3 +++ src/reparse.coffee | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c19580b..a01118a 100644 --- a/package.json +++ b/package.json @@ -9,5 +9,8 @@ "devDependencies": { "docco": "0.3.x" }, + "scripts": { + "pre-install": "mkdir -p lib && ./node_modules/.bin/coffee -o lib src/reparse.js" + }, "engine": "node >= 0.6.0" } diff --git a/src/reparse.coffee b/src/reparse.coffee index 2bb35e0..a14a334 100644 --- a/src/reparse.coffee +++ b/src/reparse.coffee @@ -103,7 +103,13 @@ exports.ReParse = class ReParse # Match a regular expression against the input, returning the # first captured group. If no group is captured, return the # matched string. This can result in surprises, if you don't wrap - # your groups exactly right, which is common in ()? regexps. + # your groups exactly right, which is common in ()? regexps. Note + # that this is where the input consumption happens: upon a match, + # the input is reduced to whatever did not match. (Note that as + # the tree of productions is followed, backups of existing input + # are kept and restored when a possible parse fails. If your + # source is very large, this can become problematic in both time + # and space.) match: (pattern) => probe = @input.match pattern @@ -256,7 +262,8 @@ exports.ReParse = class ReParse # `op` to the return of `method`. If there are less that `min` # occurrences of `method`, `otherwise` is returned. Used, for # example, to process a collection of mathematical productions of - # the same precedence. + # the same precedence. This is analogous to the reduce() function + # of python, ruby, and ECMA5. chainl: (method, op, otherwise = null, min = null) => found = 0