Added some comments to further my own understanding, plus updated the NPM script.

This commit is contained in:
Elf M. Sternberg 2012-05-04 11:53:14 -07:00
parent c74498686e
commit d184d0d4da
2 changed files with 12 additions and 2 deletions

View File

@ -9,5 +9,8 @@
"devDependencies": { "devDependencies": {
"docco": "0.3.x" "docco": "0.3.x"
}, },
"scripts": {
"pre-install": "mkdir -p lib && ./node_modules/.bin/coffee -o lib src/reparse.js"
},
"engine": "node >= 0.6.0" "engine": "node >= 0.6.0"
} }

View File

@ -103,7 +103,13 @@ exports.ReParse = class ReParse
# Match a regular expression against the input, returning the # Match a regular expression against the input, returning the
# first captured group. If no group is captured, return the # first captured group. If no group is captured, return the
# matched string. This can result in surprises, if you don't wrap # 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) => match: (pattern) =>
probe = @input.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` # `op` to the return of `method`. If there are less that `min`
# occurrences of `method`, `otherwise` is returned. Used, for # occurrences of `method`, `otherwise` is returned. Used, for
# example, to process a collection of mathematical productions of # 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) => chainl: (method, op, otherwise = null, min = null) =>
found = 0 found = 0