gfse: some refactoring

This commit is contained in:
hallgren
2012-10-03 13:22:50 +00:00
parent 432a354b91
commit edc51c6a2f
4 changed files with 38 additions and 44 deletions

View File

@@ -7,41 +7,31 @@ import SimpleEditor.Syntax
instance JSON Grammar where
showJSON (Grammar name extends abstract concretes) =
makeObj [prop "basename" name,
prop "extends" extends,
prop "abstract" abstract,
prop "concretes" concretes]
makeObj ["basename".=name, "extends".=extends,
"abstract".=abstract, "concretes".=concretes]
instance JSON Abstract where
showJSON (Abstract startcat cats funs) =
makeObj [prop "startcat" startcat,
prop "cats" cats,
prop "funs" funs]
makeObj ["startcat".=startcat, "cats".=cats, "funs".=funs]
instance JSON Fun where showJSON (Fun name typ) = signature name typ
instance JSON Param where showJSON (Param name rhs) = definition name rhs
instance JSON Oper where showJSON (Oper name rhs) = definition name rhs
signature name typ = makeObj [prop "name" name,prop "type" typ]
definition name rhs = makeObj [prop "name" name,prop "rhs" rhs]
signature name typ = makeObj ["name".=name,"type".=typ]
definition name rhs = makeObj ["name".=name,"rhs".=rhs]
instance JSON Concrete where
showJSON (Concrete langcode opens params lincats opers lins) =
makeObj [prop "langcode" langcode,
prop "opens" opens,
prop "params" params,
prop "lincats" lincats,
prop "opers" opers,
prop "lins" lins]
makeObj ["langcode".=langcode, "opens".=opens,
"params".=params, "opers".=opers,
"lincats".=lincats, "lins".=lins]
instance JSON Lincat where
showJSON (Lincat cat lintype) =
makeObj [prop "cat" cat,prop "type" lintype]
showJSON (Lincat cat lintype) = makeObj ["cat".=cat, "type".=lintype]
instance JSON Lin where
showJSON (Lin fun args lin) =
makeObj [prop "fun" fun,
prop "args" args,
prop "lin" lin]
showJSON (Lin fun args lin) = makeObj ["fun".=fun, "args".=args, "lin".=lin]
prop name v = (name,showJSON v)
infix 1 .=
name .= v = (name,showJSON v)