Skip to content

Commit

Permalink
Merge pull request #51 from RSDuck/master
Browse files Browse the repository at this point in the history
Fix #50
  • Loading branch information
kosz78 committed May 30, 2017
2 parents 5bd14c1 + 456ae0a commit c18890a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/elrpc/sexp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function toString(sexp: SExp) {
case 'ident':
return sexp.ident;
case 'string':
return '\"' + sexp.str.replace('\n', '\\n').replace('\r', '\\r').replace('\\', '\\\\').replace('\"', '\\\"') + '\"';
return JSON.stringify(sexp.str);
case 'nil':
return 'nil';
}
Expand All @@ -55,7 +55,7 @@ export function parseSExp(input: string): /*SExp*/ any[] | string {

function parseSymbol(): /*SExpIdent | SExpNumber | SExpNil*/ string | number | null {
let symbolStart = ptr;
while (ptr < input.length && !input[ptr].match(/[ )]/)) {
while (ptr < input.length && !(input[ptr] == ' ' || input[ptr] == ')')) {
if (input[ptr] === '\\' && input[ptr + 1] === ' ')
ptr += 2;
else
Expand Down Expand Up @@ -93,15 +93,15 @@ export function parseSExp(input: string): /*SExp*/ any[] | string {
}
let str = input.substring(startPos, ptr);
// return { kind: "string", str: hasEscapes ? JSON.parse("\"" + string + "\"") : string };
return hasEscapes ? JSON.parse('\"' + str + '\"') : str;
return hasEscapes ? JSON.parse(input.substring(startPos - 1, ptr + 1)) : input.substring(startPos, ptr);
}

function parseListOrCon(root?: boolean): /*SExpList | SExpCons*/ any[] {
// let items: SExp[] = [];
let items = [];
let cons = false;
while (ptr < input.length) {
if (/[^() "]/.test(input[ptr])) {
if (input[ptr] != '(' && input[ptr] != ')' && input[ptr] != ' ' && input[ptr] != '"') {
let sym = parseSymbol();
// if (sym.kind == "ident" && sym.ident == ".") {
if (sym === '.') {
Expand Down

0 comments on commit c18890a

Please sign in to comment.