Rui Barreiroadded jsonbb6aaad6 years agoHistory
80 lines · 2.0 KB · Text
RawDownload
module Language.JSON.Parser import Language.JSON.Dataimport Text.Parserimport Text.Tokenimport Data.List import public Language.JSON.Tokens %default total privatepunct : Punctuation -> Grammar JSONToken True ()punct p = match $ JTPunct p privaterawString : Grammar JSONToken True StringrawString = do mstr <- match JTString               the (Grammar _ False _) $                   case mstr of                        Just str => pure str                        Nothing => fail "invalid string" mutual  private  json : Grammar JSONToken True JSON  json = object     <|> array     <|> string     <|> boolean     <|> number     <|> null   private  object : Grammar JSONToken True JSON  object = do punct $ Curly Open              commit              props <- properties              punct $ Curly Close              pure $ JObject props    where      properties : Grammar JSONToken False (List (String, JSON))      properties = sepBy (punct Comma) $                         do key <- rawString                            punct Colon                            value <- json                            pure (key, value)   private  array : Grammar JSONToken True JSON  array = do punct (Square Open)             commit             vals <- values             punct (Square Close)             pure (JArray vals)    where      values : Grammar JSONToken False (List JSON)      values = sepBy (punct Comma) json   private  string : Grammar JSONToken True JSON  string = map JString rawString   private  boolean : Grammar JSONToken True JSON  boolean = map JBoolean $ match JTBoolean   private  number : Grammar JSONToken True JSON  number = map JNumber $ match JTNumber   private  null : Grammar JSONToken True JSON  null = map (const JNull) $ match JTNull exportparseJSON : List JSONToken -> Maybe JSONparseJSON toks = case parse json $ filter (not . ignored) toks of                      Right (j, []) => Just j                      _ => Nothing

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t