Permalink
Browse files

fixed up character parsing a bit

  • Loading branch information...
1 parent 47ca99c commit 84da5c2f91eb608d26f22705c37a507eeaa87a74 @gnarmis committed Sep 17, 2012
Showing with 59 additions and 7 deletions.
  1. +12 −4 lib/edn.js
  2. +30 −1 spec/coffee/simple_spec.coffee
  3. +9 −1 spec/js/simple_spec.js
  4. +8 −1 src/edn.pegjs
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -15,4 +15,33 @@ describe "Simple Specs", ->
).toEqual(undefined)
it "should consumer integers", ->
-
+ expect(
+ EDN.parse("42").integer
+ ).toEqual("42")&&
+ expect(
+ EDN.parse("-42").integer
+ ).toEqual("-42")&&
+ expect(
+ EDN.parse("42N").precision
+ ).toEqual("N")
+
+ it "should consume characters", ->
+ expect(
+ EDN.parse("\\\\").character
+ ).toEqual("\\\\")&&
+ expect(
+ EDN.parse("\\newline").character
+ ).toEqual("\\newline")&&
+ expect(
+ EDN.parse("\\space").character
+ ).toEqual("\\space")&&
+ expect(
+ EDN.parse("\\tab").character
+ ).toEqual("\\tab")
+
+ it "should not recognize \\ followed by a space as a character", ->
+ expect(
+ EDN.parse("\\ ")
+ ).toEqual(undefined)
+
+
View
@@ -12,7 +12,15 @@
it("should consume nil values", function() {
return expect(EDN.parse("nil")).toEqual(void 0);
});
- return it("should consumer integers", function() {});
+ it("should consumer integers", function() {
+ return expect(EDN.parse("42").integer).toEqual("42") && expect(EDN.parse("-42").integer).toEqual("-42") && expect(EDN.parse("42N").precision).toEqual("N");
+ });
+ it("should consume characters", function() {
+ return expect(EDN.parse("\\\\").character).toEqual("\\\\") && expect(EDN.parse("\\newline").character).toEqual("\\newline") && expect(EDN.parse("\\space").character).toEqual("\\space") && expect(EDN.parse("\\tab").character).toEqual("\\tab");
+ });
+ return it("should not recognize \\ followed by a space as a character", function() {
+ return expect(EDN.parse("\\ ")).toEqual(void 0);
+ });
});
}).call(this);
View
@@ -1,3 +1,4 @@
+
/*
* Grammar for edn
* The generated parser will be able to produce a JSON AST
@@ -28,4 +29,10 @@ integer
space = a:[ ,]+ {return a.join("");}
character
- = a:(x:"\\" b:("newline"/"space"/"tab"/.?)?) { return a.join("").match(/[\x21-\x7e]/)!==null ? a.join("") : "";}
+ = a:"\\"
+ b:("newline"/"space"/"tab"/(b:.
+ {if (b.match(/[\x21-\x7e]/)!==null)
+ {
+ return b;
+ }}))
+ { c=a+b;return c.match(/(undefined)/)!==null ? undefined : {character: c};}

0 comments on commit 84da5c2

Please sign in to comment.