1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-21 10:37:58 +03:00

Fix unescaping in rexx, skew, vimscript

This commit is contained in:
Dov Murik 2017-09-27 07:02:07 +00:00 committed by Joel Martin
parent 8e59b7151b
commit e73fcefe8f
3 changed files with 16 additions and 7 deletions

View File

@ -95,9 +95,10 @@ is_number: procedure /* is_number(token) */
parse_string: procedure /* parse_string(token) */ parse_string: procedure /* parse_string(token) */
token = arg(1) token = arg(1)
res = substr(token, 2, length(token) - 2) /* Remove quotes */ res = substr(token, 2, length(token) - 2) /* Remove quotes */
res = changestr("\\", res, '01'x)
res = changestr("\n", res, '0A'x) res = changestr("\n", res, '0A'x)
res = changestr('\"', res, '"') res = changestr('\"', res, '"')
res = changestr("\\", res, '5C'x) res = changestr('01'x, res, '5C'x)
return res return res
parse_keyword: procedure /* parse_keyword(token) */ parse_keyword: procedure /* parse_keyword(token) */

View File

@ -30,7 +30,7 @@ def tokenize(str string) List<string> {
} }
def unescape(s string) string { def unescape(s string) string {
return s.replaceAll("\\\"", "\"").replaceAll("\\n", "\n").replaceAll("\\\\", "\\") return s.replaceAll("\\\\", "\x01").replaceAll("\\\"", "\"").replaceAll("\\n", "\n").replaceAll("\x01", "\\")
} }
def read_atom(rdr Reader) MalVal { def read_atom(rdr Reader) MalVal {

View File

@ -42,12 +42,20 @@ function Tokenize(str)
return tokens return tokens
endfunction endfunction
function UnescapeChar(seq)
if a:seq == '\"'
return '"'
elseif a:seq == '\n'
return "\n"
elseif a:seq == '\\'
return '\'
else
return a:seq
endif
endfunction
function ParseString(token) function ParseString(token)
let str = a:token[1:-2] return substitute(a:token[1:-2], '\\.', '\=UnescapeChar(submatch(0))', "g")
let str = substitute(str, '\\"', '"', "g")
let str = substitute(str, '\\n', "\n", "g")
let str = substitute(str, '\\\\', "\\", "g")
return str
endfunction endfunction
function ReadAtom(rdr) function ReadAtom(rdr)