Skip to content
Browse files

Updated README.

  • Loading branch information...
1 parent 8a964b1 commit cab4695a4b254b7f9d525e62b1d86e29d403fe57 @weaver committed Aug 18, 2010
Showing with 17 additions and 13 deletions.
  1. +17 −13 README.md
View
30 README.md
@@ -12,19 +12,22 @@ Download `lib/reparse.js` and add it to your project.
## API ##
To use ReParse, construct a `new ReParse(input)` object, then call the
-`.start()`, passing it the top-level production of your grammar. Each
-production may be a RegExp or a function.
+`.start()` method, passing it the top-level production of your
+grammar. Each production may be a RegExp or a function.
A RegExp will produce the first captured group or the entire value it
matched if there are no groups. Functions are called with `this`
bound to the parser. They take no arguments. A function should
invoke one or more parser methods, optionally transforming the results
into an appropriate return value.
-This is a grammar for a subset of JSON that supports arrays and
+Here is a grammar for a subset of JSON that supports arrays and
positive integers. See `examples/json.js` for a more complete
example:
+ // e.g: parse("[1, [2]]")
+ var ReParse = require('reparse');
+
function parse(data) {
return (new ReParse(data, true)).start(value);
}
@@ -70,7 +73,7 @@ Return `true` if the input is exhausted.
#### .fail() ####
-Call this method to indicate that a production has failed; an
+Calling this method indicates that a production has failed; an
exception will be raised and caught by the previous production.
#### .produce(method) ####
@@ -79,8 +82,8 @@ Apply the production `method` to the input and return the result.
#### .maybe(method) ####
-Apply the production `method` to the input, restoring the input to its
-previous state if it fails.
+Apply the production `method` to the input and return the result. If
+`method` fails, restoring the input to its previous state.
#### .option(method, otherwise) ####
@@ -94,14 +97,15 @@ captured group. If no group is captured, return the matched string.
#### .choice(alt1, alt2, ...) ####
-Try several alternatives, returning the value of the first one that's
-successful.
+Try alternatives from left to right, returning the value of the first
+one that's successful.
-#### .seq(group1, group2, ...) ####
+#### .seq(p1, p2, ...) ####
-All groups must match the input. Return an array of capture groups
-like a regular expression match would. Index 0 is the entire matched
-string, index 1 corresponds to `group1`, etc.
+Apply a sequence of productions from left to right. They must all
+succeed. Return an array of capture groups (like a regular expression
+match would). Index 0 is the entire matched string, index 1
+corresponds to `p1`, etc.
#### .many(method) ####
@@ -113,7 +117,7 @@ Return an array of one or more values produced by `method`.
#### .between(left, right, body) ####
-This is equivalent to `.seq(left, body, right)[0]`.
+This is equivalent to `.seq(left, body, right)[2]`.
#### .skip(method) ####

0 comments on commit cab4695

Please sign in to comment.
Something went wrong with that request. Please try again.