fmod SEXP-AUX is
  inc PARSE-SEXP-STRING .
  inc TEMPLATES .

  vars sexpl0 sexpl sexpl1 alist : SexpL .
  vars tag str str0 : String .

**** lookup a metadata entry

**** (a("s1") ... a("sn")) ~> "\"s1\" ... \"sn\"" 
  op sexpl2strs : SexpL String -> String . 
  eq sexpl2strs(nil,str) = str .
  eq sexpl2strs(a(str0) sexpl, str) = 
        sexpl2strs(sexpl,str + " " + squote(str0)) .

  op sexpl2str : SexpL String -> String . 
  eq sexpl2str(nil,str) = str .
  eq sexpl2str(a(str0) sexpl, str) =  sexpl2str(sexpl,str + " " + str0) .

  op alget : SexpL String -> SexpL .
  eq alget((sexpl0 [a(tag) sexpl] sexpl1),tag) = sexpl .
  eq alget(alist,tag) = nil [owise] .

**** metadata tag is expected to be a `list' of strings
  op getNames : SexpL String -> String .  
  eq getNames(alist,tag) = sexpl2strs(alget(alist,tag),"") .
 
**** alist where comment may be string list
  op getComment : SexpL -> String .  
  eq getComment(alist) = sexpl2str(alget(alist,"comment"),"") .


***(  from newgraph2g2d.maude -- which will go away

  op stringArrayTemplate : -> String [ctor] .
  eq stringArrayTemplate = "(array java.lang.String %strings )" .

  op objectArrayTemplate : -> String [ctor] .
  eq objectArrayTemplate = "(array java.lang.Object %strings )" .
)

*** mapping generic metadata alist to array of arrays

  op mkSexpLArrExp : SexpL String -> String .
  eq mkSexpLArrExp(nil,str) =
        fillTemplate(objectArrayTemplate, "%strings" :~ str)  .
  eq mkSexpLArrExp(a(str0) sexpl,str) = 
        mkSexpLArrExp(sexpl,str + " " + squote(str0)) .
  eq mkSexpLArrExp([sexpl0] sexpl,str) = 
       mkSexpLArrExp(sexpl,
                     str + " " + fillTemplate(stringArrayTemplate,
                                            "%strings" :~ sexpl2strs(sexpl0,"")) ) .

endfm

fmod TEST-SEXP-AUX is
  inc SEXP-AUX .
  op qpX : -> Sexp .
  op qpL : -> SexpL .

  eq qpX = [[a("q") a("a") a("b")] [a("p") a("c") a("d")]] .
  eq qpL = [a("q") a("a") a("b")] [a("p") a("c") a("d")] .

endfm


***(
red alget(qpL, "p") .

red getNames(qpL,"p") .
red sexpl2strs(alget(qpL,"q"),"") .

red mkSexpLArrExp(qpL,"") .
red mkSexpLArrExp(qpL a("xyz"),"") .

)

**** put this in jkbaux
***(
view String from TRIV to STRING is
  sort Elt to String .
endv

occurs(E, nil)
)

fmod STRING-LIST is
  protecting LIST{String} * 
      (sort NeList{String} to NeStringList, sort List{String} to StringList) .
  inc TEMPLATES .

  vars strl strl0 : StringList .
  vars str str0 sep : String .

  op strL2str : StringList String -> String .
  op strL2suffix : StringList String String -> String .
  eq strL2str(nil,sep) = "" .
  eq strL2str((str strl),sep) = strL2suffix(strl,sep,str) .
  eq strL2suffix(nil,sep,str) = str .
  eq strL2suffix((str0 strl),sep,str) = strL2suffix(strl,sep,str + sep + str0) .
  
  op strL2qstr : StringList String -> String .
  eq strL2qstr(nil,str) = str .
  eq strL2qstr((str0 strl),str) = strL2qstr(strl,str + " " + squote(str0))  .

  op lexSortStringL : StringList -> StringList .
  op lexSortStringLX : StringList StringList -> StringList .
  op lexInsertStr : StringList String StringList -> StringList .

  eq lexSortStringL(strl) = lexSortStringLX(strl,nil) .
  eq lexSortStringLX(nil,strl) = strl .
  eq lexSortStringLX((str strl0),strl) =  
         lexSortStringLX(strl0,lexInsertStr(strl,str,nil)) .

  eq lexInsertStr(nil,str,strl) = (strl str) .
  eq lexInsertStr((str0 strl0),str,strl) =
      (if str < str0
       then  (strl str str0 strl0)
       else  lexInsertStr(strl0, str,strl str0)
       fi) .



endfm

***(
red strL2str("a" "b" "c",":") .
red strL2qstr("a" "b" "c","") .
red lexInsertStr("a" "b" "c","1",nil) .
red lexInsertStr("a" "b" "c","aa",nil) .
red lexInsertStr("a" "b" "c","bb",nil) .

red lexSortStringL("x" "1" "a" "!") .


)