Created
April 24, 2012 19:07
-
-
Save fables-tales/2482767 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Parser where | |
-- import Text.ParserCombinators.Parsec | |
type Var = String | |
type Value = String | |
type Assign = (Var, Value) | |
type Object = [Assign] | |
type Array = [Value] | |
data Token = Open_object | Close_object | Open_array | Close_array | List_delim | | |
Assign_delim | Quote | String_literal String deriving (Show, Eq, Read) | |
tokens :: [(String, Token)] | |
tokens = [ | |
('{', Open_object), | |
('}', Close_object), | |
('[', Open_array), | |
(']', Close_array), | |
(',', List_delim), | |
(':', Assign_delim), | |
('"', Quote) | |
] | |
token_list = map fst tokens | |
--open_object = "{" | |
--close_object = "}" | |
--open_array = "[" | |
--close_array = "]" | |
--list_delim = "," | |
--assign_delim = ":" | |
--quote = "\"" | |
object_sample = "{\"var\": \"val\"}" | |
array_sample = "[\"x1\", \"x2\"]" | |
tokenize :: String -> [Token] | |
tokenize "" = [] | |
tokenize (a : rest) = let token = lookup a tokens in | |
case token of | |
Nothing -> takeWhile (\x -> x \= '"') rest | |
Just t -> t : tokenize rest | |
main = do | |
print "hello json" | |
print (tokenize array_sample) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment