From 2eddc116e676b249d300e930263255bfab057622 Mon Sep 17 00:00:00 2001 From: hallgren Date: Tue, 21 Feb 2012 16:58:18 +0000 Subject: gfse: edit abstract syntax in text mode with instant syntax error reporting This is an experimental feature. It requires server support for parsing and is thus not available while offline, unlike most other editing functionality. --- src/compiler/SimpleEditor/JSON.hs | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/compiler/SimpleEditor/JSON.hs (limited to 'src/compiler/SimpleEditor/JSON.hs') diff --git a/src/compiler/SimpleEditor/JSON.hs b/src/compiler/SimpleEditor/JSON.hs new file mode 100644 index 000000000..3c15e731b --- /dev/null +++ b/src/compiler/SimpleEditor/JSON.hs @@ -0,0 +1,47 @@ +module SimpleEditor.JSON where + +import Text.JSON + +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] + +instance JSON Abstract where + showJSON (Abstract startcat cats funs) = + makeObj [prop "startcat" startcat, + prop "cats" cats, + prop "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] + +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] + +instance JSON Lincat where + showJSON (Lincat cat lintype) = + makeObj [prop "cat" cat,prop "type" lintype] + +instance JSON Lin where + showJSON (Lin fun args lin) = + makeObj [prop "fun" fun, + prop "args" args, + prop "lin" lin] + +prop name v = (name,showJSON v) -- cgit v1.2.3