summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/compiler/SimpleEditor/Convert.hs9
-rw-r--r--src/compiler/SimpleEditor/JSON.hs34
-rw-r--r--src/www/gfse/editor.js11
-rw-r--r--src/www/gfse/gf_abs.js28
4 files changed, 38 insertions, 44 deletions
diff --git a/src/compiler/SimpleEditor/Convert.hs b/src/compiler/SimpleEditor/Convert.hs
index e2fc20358..e6cb98124 100644
--- a/src/compiler/SimpleEditor/Convert.hs
+++ b/src/compiler/SimpleEditor/Convert.hs
@@ -24,14 +24,13 @@ import SimpleEditor.JSON
parseModule (path,source) =
- prop path $
+ (path.=) $
case runP pModDef (BS.pack source) of
Left (Pn l c,msg) ->
- makeObj [prop "error" msg,
- prop "location" (show l++":"++show c)]
+ makeObj ["error".=msg, "location".= show l++":"++show c]
Right mod -> case convModule mod of
- Ok g -> makeObj [prop "converted" g]
- Bad msg -> makeObj [prop "parsed" msg]
+ Ok g -> makeObj ["converted".=g]
+ Bad msg -> makeObj ["parsed".=msg]
{-
convAbstractFile path =
diff --git a/src/compiler/SimpleEditor/JSON.hs b/src/compiler/SimpleEditor/JSON.hs
index 3c15e731b..8f607dc84 100644
--- a/src/compiler/SimpleEditor/JSON.hs
+++ b/src/compiler/SimpleEditor/JSON.hs
@@ -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)
diff --git a/src/www/gfse/editor.js b/src/www/gfse/editor.js
index e59afdefb..703886ab5 100644
--- a/src/www/gfse/editor.js
+++ b/src/www/gfse/editor.js
@@ -1277,12 +1277,13 @@ function draw_opers(g,ci) {
}
function delete_lin(g,ci,fun) {
- var i;
var c=g.concretes[ci];
- for(i=0;i<c.lins.length && c.lins[i].fun!=fun;i++);
- if(i<c.lins.length) c.lins=delete_ix(c.lins,i);
- timestamp(c);
- reload_grammar(g);
+ var i=lin_index(c,fun);
+ if(i!=null) {
+ c.lins=delete_ix(c.lins,i);
+ timestamp(c);
+ reload_grammar(g);
+ }
}
/* -------------------------------------------------------------------------- */
diff --git a/src/www/gfse/gf_abs.js b/src/www/gfse/gf_abs.js
index 69ca4d799..eb405bae7 100644
--- a/src/www/gfse/gf_abs.js
+++ b/src/www/gfse/gf_abs.js
@@ -71,7 +71,7 @@ function all_inherited_funs(igs,df) {
}
// Return the index of the function the given name in the abstract syntax
-// find_function :: Grammar -> FunId -> (Int|null)
+// fun_index :: Grammar -> FunId -> (Int|null)
function fun_index(g,fun) {
with(g.abstract)
for(var i in funs) if(funs[i].name==fun) return i
@@ -93,10 +93,18 @@ function cat_lincat(conc,cat) {
return null;
}
+// Return the index of the lin in a given concrete syntax for an abstract function
+// lin_index :: Concrete -> FunId -> (Int|null)
+function lin_index(conc,fun) {
+ with(conc) for(var i in lins) if(lins[i].fun==fun) return i
+ return null;
+}
+
// Return the lin defined in a given concrete syntax for an abstract function
// fun_lin :: Concrete -> FunId -> (Lin|null)
function fun_lin(conc,fun) {
- with(conc) for(var i in lins) if(lins[i].fun==fun) return lins[i]
+ var i=lin_index(conc,fun)
+ if(i!=null) return conc.lins[i]
return null;
}
@@ -138,25 +146,21 @@ function rename_category(g,oldcat,newcat) {
return g;
}
-// rename_function :: Grammar -> Id -> Id -> Grammar // destructive update
+// rename_function :: Grammar -> FunId -> FunId -> Grammar // destructive update
function rename_function(g,oldfun,newfun) {
- function rename_lin(lin) {
- if(lin.fun==oldfun) lin.fun=newfun;
- }
function rename_concrete(c) {
- for(var i in c.lins) rename_lin(c.lins[i]);
+ var i=lin_index(c,oldfun)
+ if(i!=null) c.lins[i].fun=newfun;
}
for(var i in g.concretes) rename_concrete(g.concretes[i]);
return g;
}
-// change_lin_lhs :: Grammar -> Id -> Grammar // destructive update
+// change_lin_lhs :: Grammar -> Fun -> Grammar // destructive update
function change_lin_lhs(g,fun) {
- function change_lin(lin) {
- if(lin.fun==fun.name) lin.args=arg_names(fun.type);
- }
function change_concrete(c) {
- for(var i in c.lins) change_lin(c.lins[i]);
+ var i=lin_index(c,fun.name)
+ if(i!=null) c.lins[i].args=arg_names(fun.type);
}
for(var i in g.concretes) change_concrete(g.concretes[i]);
return g;