First commit of partial RosettaCode contents.

Pushing this for testing purposes. Lots of work still needed.
This commit is contained in:
Ingy döt Net 2013-04-08 13:02:41 -07:00
commit 1e05ecd7ee
781 changed files with 9080 additions and 0 deletions

49
Task/JSON/PicoLisp/json.l Normal file
View 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 "}") ) ) )