From 94ab24ca6b44c5de185eb83e5ce0524ddfccef28 Mon Sep 17 00:00:00 2001 From: chee Date: Fri, 5 May 2017 02:24:00 +0100 Subject: [PATCH] handle nested arrays and dictionaries --- code/parse.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/code/parse.js b/code/parse.js index 1aba31f..39f9f3f 100644 --- a/code/parse.js +++ b/code/parse.js @@ -22,10 +22,10 @@ const escapes = { } const escape = string => - string.replace(/\\(.)/g, (_, character) => escapes[character]) + string.replace(/\\([\"])/g, (_, character) => escapes[character]) // TODO add support for binary data -const tokens = /^\s*(?:([,;=(){}])|"((?:[^\\"]|\\["\\])*)")/ +const tokens = /^\s*(?:([,;=(){}])|"((?:\\"|[^"])*)")/ // string.js const stringAction = { @@ -99,6 +99,14 @@ const action = { container = last.container key = last.key state = last.state + }, + // trailing ; in dictionary definitions + [dictKey] () { + const last = stack.pop() + value = container + container = last.container + key = last.key + state = last.state } }, '(': { @@ -113,18 +121,24 @@ const action = { key, state: dictSeparator }) + container = [] + state = firstArrayValue }, [firstArrayValue] () { stack.push({ container, state: arraySeparator }) + container = [] + state = firstArrayValue }, [arrayValue] () { stack.push({ container, state: arraySeparator }) + container = [] + state = firstArrayValue } }, ')': {