Skip to content

Commit

Permalink
Handle more Ruby string escapes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Suraci committed Apr 18, 2011
1 parent 2c4f883 commit 7d1bc9d
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/kpeg/format.kpeg
Expand Up @@ -25,13 +25,22 @@
var = < "-" | /[a-zA-Z][\-_a-zA-Z0-9]*/ > { text }
method = < /[a-zA-Z_][a-zA-Z0-9_]*/ > { text }

dbl_escapes = "\\\"" { '"' }
| "\\n" { "\n" }
| "\\t" { "\t" }
| "\\b" { "\b" }
| "\\\\" { "\\" }
dbl_escapes = "n" { "\n" }
| "s" { " " }
| "r" { "\r" }
| "t" { "\t" }
| "v" { "\v" }
| "f" { "\f" }
| "b" { "\b" }
| "a" { "\a" }
| "e" { "\e" }
| "\\" { "\\" }
| "\"" { "\"" }
| num_escapes
num_escapes = < /[0-7]{3}/ > { [text.to_i(8)].pack("U") }
| "x" < /[0-9a-fA-F]{2}/ > { [text.to_i(16)].pack("U") }
dbl_seq = < /[^\\"]+/ > { text }
dbl_not_quote = (dbl_escapes:s | dbl_seq:s)*:ary { Array(ary) }
dbl_not_quote = ("\\" dbl_escapes:s | dbl_seq:s)*:ary { Array(ary) }
dbl_string = "\"" dbl_not_quote:s "\"" { @g.str(s.join) }
sgl_escape_quote = "\\'" { "'" }
sgl_seq = < /[^']/ > { text }
Expand Down

0 comments on commit 7d1bc9d

Please sign in to comment.