diff --git a/src/example-based/ExampleDemo.hs b/src/example-based/ExampleDemo.hs index 2f344f0a3..1d5fabcaf 100644 --- a/src/example-based/ExampleDemo.hs +++ b/src/example-based/ExampleDemo.hs @@ -42,8 +42,8 @@ data Environ = Env {getTypeMap :: TypeMap, -- mapping between a } -getNext :: Environ -> ([MyFunc],[MyFunc]) -getNext env = +getNext :: Environ -> Environ -> ([MyFunc],[MyFunc]) +getNext env example_env = let sgs = getSigs env allfuncs = getAll env names = Set.fromList $ map getName $ concat $ Map.elems sgs diff --git a/src/example-based/ExampleService.hs b/src/example-based/ExampleService.hs index 0065fd4dd..185e4fd94 100644 --- a/src/example-based/ExampleService.hs +++ b/src/example-based/ExampleService.hs @@ -22,12 +22,16 @@ cgiMain' root cwd cache = do command <- getInp "command" environ <- parseEnviron =<< getInp "state" case command of - "possibilities" -> outputJSONP (E.getNext environ) - "provide_example" -> doProvideExample root cwd cache environ + "possibilities" -> doPossibilities environ + "provide_example" -> doProvideExample root cwd cache environ "abstract_example" -> doAbstractExample cwd cache environ - "test_function" -> doTestFunction cwd cache environ + "test_function" -> doTestFunction cwd cache environ _ -> throwCGIError 400 ("Unknown command: "++command) [] +doPossibilities environ = + do example_environ <- parseEnviron =<< getInp "example_state" + outputJSONP (E.getNext environ example_environ) + doProvideExample root cwd cache environ = do Just lang <- readInput "lang" fun <- getCId "fun" diff --git a/src/example-based/todo.txt b/src/example-based/todo.txt index ebecba435..196dbc097 100644 --- a/src/example-based/todo.txt +++ b/src/example-based/todo.txt @@ -1,7 +1,7 @@ Editor improvements for example-based grammar writing: + Remove the same language from the example language menu -- Send the other language environment to getNext ++ Send the other language environment to getNext - Compile a new .pgf automatically when needed - Update buttons automatically when functions are added or removed - Switch over to using AbsParadigmsEng.pgf instead of the old exprToAPI function diff --git a/src/www/gfse/example_based.js b/src/www/gfse/example_based.js index 1bbf17bd4..966dcbecd 100644 --- a/src/www/gfse/example_based.js +++ b/src/www/gfse/example_based.js @@ -51,8 +51,8 @@ function ask_possibilities(g,ci) { if(!conc.example_lang) conc.example_lang=g.concretes[0].langcode; reload_grammar(g); } - - exb_call(g,ci,"possibilities",{},show_poss) + var exci=conc_index(g,conc.example_lang); + exb_call(g,ci,"possibilities",{example_state:exb_state(g,exci)},show_poss) } var parser = { Eng: "ParseEngAbs.pgf", diff --git a/src/www/gfse/gf_abs.js b/src/www/gfse/gf_abs.js index 4efaab89a..ec47b6093 100644 --- a/src/www/gfse/gf_abs.js +++ b/src/www/gfse/gf_abs.js @@ -14,18 +14,29 @@ function defined_funs(g) { return df; } +// Return the type of a named function in the abstract syntax function function_type(g,fun) { with(g.abstract) for(var i in funs) if(funs[i].name==fun) return funs[i].type return null; } +// Return the lincat defined in a given concrete syntax for an abstract category function cat_lincat(conc,cat) { with(conc) for(var i in lincats) if(lincats[i].cat==cat) return lincats[i].type return null; } +// Return the index of the concrete syntax with a given langcode +function conc_index(g,langcode) { + var c=g.concretes; + for(var ix=0;ix