Skip to content

Commit

Permalink
handle nested arrays and dictionaries
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed May 5, 2017
1 parent 3fb3858 commit 94ab24c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions code/parse.js
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
}
},
'(': {
Expand All @@ -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
}
},
')': {
Expand Down

0 comments on commit 94ab24c

Please sign in to comment.