;; {(start-production "document")} ;; {(define-name "json-grammar")} ;; {(define-toplevel #t)} {(?-default ignore)} document <- ws ( object / array ) ws ws <- `[ \t\n\r]* ;; FIXME: \r gets parsed as #\newline for some reason begin-array <- #\[ begin-object <- #\{ end-array <- #\] end-object <- #\} name-separator <- #\: value-separator <- #\, value <- ws ( null / false / true / object / array / number / string ) ws false <- "false" -> handle-false true <- "true" -> handle-true null <- "null" -> handle-null object <- begin-object ws ( member ( value-separator member )* )? end-object -> handle-object member <- ws raw-string ws name-separator value -> handle-member array <- begin-array ws ( value ( value-separator value )* )? end-array -> handle-array number <- ,"-"? int frac? exp? -> handle-number exp <- [Ee] ([+-])? ([[:digit:]])+ -> as-string frac <- ,#\. ([[:digit:]])+ -> as-string int <- ,"0" / ( [123456789] ([[:digit:]])* ) -> as-string raw-string <- #\" char* #\" -> handle-string/raw string <- raw-string -> handle-string char <- #\\ ( escape / unicode ) / (![[:cntrl:]"\\] .) escape <- ["\\/bfnrt] -> handle-escape unicode <- #\u [[:xdigit:]]{4} -> handle-unicode