Skip to content

Commit

Permalink
Move unescape() to String.prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
veged committed Nov 15, 2009
1 parent 04d49a6 commit e566d88
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bs-js-compiler.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bs-js-compiler.txt
Expand Up @@ -10,7 +10,7 @@ ometa BSJSParser <: Parser {
number = digit+:ws ('.' digit+ | empty -> []):fs -> [#number,
parseFloat(ws.join('') + '.' +
fs.join(''))],
escapeChar = '\\' char:c -> unescape('\\' + c),
escapeChar = '\\' char:c -> ('\\' + c).unescape(),
str = seq('"""') (escapeChar | ~seq('"""') char)*:cs seq('"""') -> [#string, cs.join('')]
| '\'' (escapeChar | ~'\'' char)*:cs '\'' -> [#string, cs.join('')]
| '"' (escapeChar | ~'"' char)*:cs '"' -> [#string, cs.join('')]
Expand Down
2 changes: 1 addition & 1 deletion bs-ometa-compiler.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bs-ometa-compiler.txt
Expand Up @@ -5,7 +5,7 @@ ometa BSOMetaParser <: Parser {
nameRest = nameFirst | digit,
tsName = firstAndRest(#nameFirst, #nameRest):xs -> xs.join(''),
name = spaces tsName,
eChar = '\\' char:c -> unescape('\\' +c)
eChar = '\\' char:c -> ('\\' + c).unescape()
| char,
tsString = '\'' (~'\'' eChar)*:xs '\'' -> xs.join(''),
characters = '`' '`' (~('\'' '\'') eChar)*:xs '\'' '\'' -> [#App, #seq, xs.join('').toProgramString()],
Expand Down
4 changes: 3 additions & 1 deletion lib.js
Expand Up @@ -145,7 +145,8 @@ escapeChar = function(c) {
return charCode > 255 ? String.fromCharCode(charCode) : escapeStringFor[charCode]
}

function unescape(s) {
function unescape() {
var s = arguments[0] || this;
if (s[0] == '\\')
switch (s[1]) {
case '\\': return '\\'
Expand All @@ -157,6 +158,7 @@ function unescape(s) {
else
return s
}
String.prototype.unescape= unescape;

String.prototype.toProgramString = function() {
var ws = "\"".writeStream()
Expand Down

0 comments on commit e566d88

Please sign in to comment.