Browse files

Merge branch 'master' into feature.seq

  • Loading branch information...
2 parents 02c2b05 + 92be8da commit d03e29760a7e3252d42c0f5ae66c2512e62fa418 @jneen committed Jan 21, 2014
Showing with 27 additions and 19 deletions.
  1. +10 −0 CHANGELOG.md
  2. +10 −11 README.md
  3. +1 −1 package.json
  4. +2 −4 src/parsimmon.js
  5. +4 −3 test/parsimmon.test.js
View
10 CHANGELOG.md
@@ -1,3 +1,13 @@
+## version 0.1.0 (2014-01-09)
+
+* Uses less stack space with a non-cps implementation
+* Added `Parsimmon.index` and `Parser::mark()`
+* fantasyland compatibility
+
+## version 0.0.6 (2013-12-02)
+
+* Better error messages: use the message from the furthest backtrack.
+
## version 0.0.5 (2013-04-10)
* Fix a "build directory nonexistent" bug :\
View
21 README.md
@@ -15,8 +15,8 @@ var regex = Parsimmon.regex;
var string = Parsimmon.string;
var optWhitespace = Parsimmon.optWhitespace;
-var id = regex(/^[a-z_]\w*/i);
-var number = regex(/^[0-9]+/).map(parseInt);
+var id = regex(/[a-z_]\w*/i);
+var number = regex(/[0-9]+/).map(parseInt);
var atom = number.or(id);
@@ -87,9 +87,8 @@ a `'b'`, and fail otherwise.
### Included parsers / parser generators:
- `Parsimmon.string("my-string")` is a parser that expects to find
`"my-string"`, and will yield the same.
- - `Parsimmon.regex(/^myregex/)` is a parser that expects the stream
- to match the given regex. **Due to limitations in javascript's regex
- API, the regex must be anchored (with `^` at the beginning).**
+ - `Parsimmon.regex(/myregex/)` is a parser that expects the stream
+ to match the given regex.
- `Parsimmon.succeed(result)` is a parser that doesn't consume any of
the string, and yields `result`.
- `Parsimmon.seq(parsers)` accepts an array of parsers that it expects to find in order,
@@ -98,12 +97,12 @@ a `'b'`, and fail otherwise.
first time the parser is used. This is useful for referencing parsers that haven't yet
been defined.
- `Parsimmon.fail(message)`
- - `Parsimmon.letter` is equivalent to `Parsimmon.regex(/^[a-z]/i)`
- - `Parsimmon.letters` is equivalent to `Parsimmon.regex(/^[a-z]*/i)`
- - `Parsimmon.digit` is equivalent to `Parsimmon.regex(/^[0-9]/)`
- - `Parsimmon.digits` is equivalent to `Parsimmon.regex(/^[0-9]*/)`
- - `Parsimmon.whitespace` is equivalent to `Parsimmon.regex(/^\s+/)`
- - `Parsimmon.optWhitespace` is equivalent to `Parsimmon.regex(/^\s*/)`
+ - `Parsimmon.letter` is equivalent to `Parsimmon.regex(/[a-z]/i)`
+ - `Parsimmon.letters` is equivalent to `Parsimmon.regex(/[a-z]*/i)`
+ - `Parsimmon.digit` is equivalent to `Parsimmon.regex(/[0-9]/)`
+ - `Parsimmon.digits` is equivalent to `Parsimmon.regex(/[0-9]*/)`
+ - `Parsimmon.whitespace` is equivalent to `Parsimmon.regex(/\s+/)`
+ - `Parsimmon.optWhitespace` is equivalent to `Parsimmon.regex(/\s*/)`
- `Parsimmon.any` consumes and yields the next character of the stream.
- `Parsimmon.all` consumes and yields the entire remainder of the stream.
- `Parsimmon.eof` expects the end of the stream.
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "parsimmon",
- "version": "0.0.6",
+ "version": "0.1.0",
"description": "A monadic LL(infinity) parser combinator library",
"keywords": ["parsing", "parse", "parser combinators"],
"author": "Jay Adkisson <jjmadkisson at gmail dot com>",
View
6 src/parsimmon.js
@@ -231,12 +231,10 @@ Parsimmon.Parser = P(function(_, _super, Parser) {
};
var regex = Parsimmon.regex = function(re) {
- if (re.source[0] !== '^') throw 'regex '+re+' must be anchored';
-
- var expected = ''+re;
+ var anchored = RegExp('^(?:'+re.source+')', (''+re).slice((''+re).lastIndexOf('/')+1));
return Parser(function(stream, i) {
- var match = re.exec(stream.slice(i));
+ var match = anchored.exec(stream.slice(i));
if (match) {
var result = match[0];
View
7 test/parsimmon.test.js
@@ -18,13 +18,14 @@ suite('parser', function() {
});
test('Parsimmon.regex', function() {
- var parser = regex(/^[0-9]/);
+ var parser = regex(/[0-9]/);
assert.equal(parser.parse('1'), '1');
assert.equal(parser.parse('4'), '4');
assert.throws(function() { parser.parse('x'); },
- "Parse Error: expected /^[0-9]/ at character 0, got 'x'\n parsing: 'x'");
- assert.throws(function() { regex(/./) }, 'must be anchored');
+ "Parse Error: expected /[0-9]/ at character 0, got 'x'\n parsing: 'x'");
+ assert.throws(function() { parser.parse('x0'); },
+ "Parse Error: expected /[0-9]/ at character 0, got 'x0'\n parsing: 'x0'");
});
suite('then', function() {

0 comments on commit d03e297

Please sign in to comment.