Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
49
Task/JSON/PicoLisp/json.l
Normal file
49
Task/JSON/PicoLisp/json.l
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
(de checkJson (X Item)
|
||||
(unless (= X Item)
|
||||
(quit "Bad JSON" Item) ) )
|
||||
|
||||
(de readJson ()
|
||||
(case (read "_")
|
||||
("{"
|
||||
(make
|
||||
(for (X (readJson) (not (= "}" X)) (readJson))
|
||||
(checkJson ":" (readJson))
|
||||
(link (cons X (readJson)))
|
||||
(T (= "}" (setq X (readJson))))
|
||||
(checkJson "," X) ) ) )
|
||||
("["
|
||||
(make
|
||||
(link T) # Array marker
|
||||
(for (X (readJson) (not (= "]" X)) (readJson))
|
||||
(link X)
|
||||
(T (= "]" (setq X (readJson))))
|
||||
(checkJson "," X) ) ) )
|
||||
(T
|
||||
(let X @
|
||||
(cond
|
||||
((pair X) (pack X))
|
||||
((and (= "-" X) (format (peek)))
|
||||
(- (read)) )
|
||||
(T X) ) ) ) ) )
|
||||
|
||||
(de printJson (Item) # For simplicity, without indentation
|
||||
(cond
|
||||
((atom Item) (if Item (print @) (prin "{}")))
|
||||
((=T (car Item))
|
||||
(prin "[")
|
||||
(map
|
||||
'((X)
|
||||
(printJson (car X))
|
||||
(and (cdr X) (prin ", ")) )
|
||||
(cdr Item) )
|
||||
(prin "]") )
|
||||
(T
|
||||
(prin "{")
|
||||
(map
|
||||
'((X)
|
||||
(print (caar X))
|
||||
(prin ": ")
|
||||
(printJson (cdar X))
|
||||
(and (cdr X) (prin ", ")) )
|
||||
Item )
|
||||
(prin "}") ) ) )
|
||||
Loading…
Add table
Add a link
Reference in a new issue