Skip to content

Commit

Permalink
need space in duo; throw on null AST
Browse files Browse the repository at this point in the history
  • Loading branch information
nmushegian committed May 22, 2022
1 parent 210b570 commit 7798772
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions jams.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const read = gram(`
jam ::= obj | arr | str
obj ::= WS* '{' WS* (duo (WS* duo)*)? WS* '}' WS*
arr ::= WS* '[' WS* (jam (WS* jam)*)? WS* ']' WS*
duo ::= str WS* jam
duo ::= str WS+ jam
str ::= bare_str | '"' quoted_str '"'
bare_str ::= SAFE+
quoted_str ::= ANY*
Expand All @@ -26,9 +26,14 @@ SYN ::= '{' | '}' | '[' | ']'
ANY ::= (SAFE | WS | SYN)
SAFE ::= #x21 | [#x24-#x5A] | [#x5E-#x7A] | #x7C | #x7E
`)
// Cast as string as it might be a buffer as from
// readFilySync
export const jams =s=> _jams(read(String(s)))

export const jams =s=> {
// Cast as string so we can accept a few other types
str = String(str)
const ast = read(str)
if (ast === null) throw new Error('Syntax error')
return _jams(ast)
}

const _jams =ast=> {
switch (ast.type) {
Expand Down

0 comments on commit 7798772

Please sign in to comment.