var Nil=null, Undefined=undefined; var True=true, False=false; var SERVER=(typeof window)=="undefined"; function stop(errno) { if (SERVER) process.exit(errno); else nofunc(); } var ERRLI=-1,ERRCOL=-1; function errlicolSet(LI,COL) { ERRLI=LI,ERRCOL=COL; } function error(msg) { if (ERRLI>0) msg+="; LI="+ERRLI.toString(); if (ERRCOL>0) msg+="; COL="+ERRCOL.toString(); (SERVER?console.log:alert)(msg); stop(1); } function prototype(X) { var RES=Object.getPrototypeOf(X); if (RES==Nil) return Object.prototype; return RES; } function constructor(X) { return prototype(X).constructor; } function isa0(O,C,REC) { if (isNil(O)) return False; if (constructor(O)==C) return True; if (isUndefined(REC)) REC=True; if (!REC || constructor(O)==Object) return False; return isa0(prototype(O),C,REC); } function eqNil(O) { return O===Nil; } function isDefined(O) { return O!==Undefined; } function isUndefined(O) { return O===Undefined; } function isNil(O) { return isUndefined(O) || O==BoxedUndefined || eqNil(O) || O==BoxedNil; } function isSymbol(O) { return isa0(O,Symbol); } function isBoolean(O) { return isa0(O,Boolean); } function isNumber(O) { return isa0(O,Number); } function isString(O) { return isa0(O,String); } function isNumStr(O) { return isNumber(O) || strIsNum(O); } function isAtom(O) { return isNil(O) || isSymbol(O) || isBoolean(O) || isNumber(O) || isString(O); } function isArray(O) { return isa0(O,Array); } function isFunction(O) { return isa0(O,Function); } var _SY={}; function sy(S) { if (isString(S)) { _SY[S]=1;return Symbol.for(S); } else if (isSymbol(S)) return Symbol.keyFor(S); else error("sy"); } function syExists(S) { return isDefined(_SY[S]); } var CharNatNone=0,CharNatUnknown=CharNatNone, CharNatAlf=1,CharNatQuote=2,CharNatDQuote=3, CharNatOmg=4,CharNatDigit=5,CharNatBlank=6 var CharNat=[]; function asc(c) { return c.charCodeAt(0)&255; } function chr(i) { return String.fromCharCode(i); } function charnat(c) { return CharNat[asc(c)]; } function charnatSet(c,n) { return CharNat[asc(c)]=n; } function charIsAlpha(C) { return charnat(C)==CharNatAlf; } function charIsOmg(C) { return charnat(C)==CharNatOmg; } function charIsDigit(C) { return charnat(C)==CharNatDigit; } function charIsBlank(C) { return charnat(C)==CharNatBlank; } function charIsUnknown(C) { return charnat(C)==CharNatUnknown; } function charIs(C,N) { return charnat(C)==N; } function strIs(S,N) { if (!isString(S)) return False; for (var I=0;I=0 && chars.indexOf(a[i])!=-1) { a[i]=null; i--; } } for (i=0;ilength(S) || length(A[1])>length(S)) return False; return startsWith(S,0,A[0]) && endsWith(substring(S,length(A[0]),length(S)),A[1]); } if (length(A)==3) { if (A[0]=="" && A[1]=="" && A[2]=="") return True; if (A[0]=="" && A[1]!="" && A[2]=="") return strFind(S,A[1])!=-1; } error("strMatch"); } function substring(S,I0,I1) { return S.substring(I0,I1); } function splitTrim(s,chars) { var a=s.split(chars); for (var i=0;i0) res+="|"; res+=display(o[i]); } res+="]"; displaying.pop(); } else { displaying.push(o); res="{"; var first=true; for (var val in o) { if (!first) res+="|"; else first=false; if (val!="parent") { res+=val+"="+display(o[val]); } } res+="}"; displaying.pop(); } return res; } var origin; if (SERVER) origin=global; else origin=window; function basicsInit() { charsInit(); } function fileExists(fname) { if (SERVER) return fs.existsSync(fname); else return httpSend("GET","http://localhost:8080/fileExists?"+fname); } function fileIsDir(fname) { var fd=fs.openSync(fname,"r"); var stats=fs.fstatSync(fd); return stats.isDirectory(); } function fileRead(fname,encoding) { if (SERVER) { if (!fileExists(fname)) error("File not found: "+fname); var RES=fs.readFileSync(fname,"latin1"); RES=Buffer.from(RES,"latin1").toString("utf8"); return RES; } else return httpSend("GET","http://localhost:8080/"+fname); } function filePath(fname) { return path.dirname(fname); } function fileName0(fname) { var a=fname.split("/"); return a[length(a)-1]; } function fileName(fname) { var a=fname.split("."); return fileName0(a[0]); } function fileExt(fname) { var a=fname.split("."); return length(a)>1?a[length(a)-1]:Undefined; } function fileWrite(fname,str) { try { fs.writeFileSync(fname,str,"latin1"); } catch (err) { error("Can't write file: "+fname); } } function fileDelete(fname) { fs.unlinkSync(fname); } function dirCreate(fname) { try { fs.mkdirSync(fname); } catch (err) { error("Can't create directory: "+fname); } } function vfileCreate(fname,isDir,parent,val) { return {"fname":fname,"isDir":isDir,isModified:false,"val":val, "parent":parent}; } _READ={}; function fileReadSet(ext,readFunc) { _READ[ext]=readFunc; } function dirRead(fname,mask) { function fileRead(fname) { var dir=path.dirname(fname)+"/"; fname=path.basename(fname); var val=""; var readFunc=_READ[fileExt(fname)]; if (readFunc!=undefined) { val=readFunc(dir+fname); val=replaceAll(val,"\r\n","\n"); } return val; } var predir=path.dirname(fname)+"/"; fname=path.basename(fname); var d=vfileCreate(fname,true,null,{}); var dir=fname; if (predir!="") dir=predir+"/"+fname; var a=fs.readdirSync(dir); for (var i=0;i') c=">"; if (c=='&') c="&"; res+=c; } return res; } function htmlEscapeBlanks(html) { var res=""; for (var i=0;i "; res+=c; } return res; } var OUTS=Nil; function startOutS() { OUTS=""; } function stopOutS() { OUTS=Nil; } function getOutS() { return OUTS; } function _out0(S) { if (!isString(S)) { console.log("<"+display(S)+">");error("out0"); } if (OUTS==Nil) if (SERVER) process.stdout.write(S); else document.write(S); else OUTS+=S; } function out0(S) { return _out0(S); } function _out(S) { if (SERVER || OUTS!=Nil) out0(S); else out0(htmlEscapeBlanks(htmlEscapeChars(S))); } function out(O) { return _out(O); } function outd(O) { out(display(O)); } function br(s) { out0("
"); } function hr(s) { out0("
"); } function esc(C) { if (SERVER) return "\x1b["+C+"m"; else { C=HTMLColor[C]; return C==undefined?"":""; } } function color(C) { if (C[0]=="b") out0(esc(ColorBright)),C=substring(C,1,length(C)); else out0(esc(ColorNoBright)); out0(esc(C)); } function cr() { out("\n"); } function spc(N,C) { var RES=""; if (isUndefined(C)) C=" "; while (N--) RES+=C; return RES; } function indent(N) { while (N--) out(" "); } var OUTINDENT=0; function outIndent() { indent(OUTINDENT); } function outIndentInc(N) { OUTINDENT+=N; } function crIndent() { cr(); outIndent(); } function consoleInit() { ColorBlue=env("TERM")=="cygwin"?"37":"34"; ColorWhite=env("TERM")=="cygwin"?"34":"37"; } function env(VAR) { if (SERVER) return process.env[VAR]; else return ""; } function argvRemove(argv,j) { splice(argv,j,1,[]); } var fs,path,url; function filesInit() { if (SERVER) { fs=require('fs'); path=require('path'); url=require('url'); } consoleInit(); } function setprop(O,NAME,VAL,E,W,C) { if (!isString(NAME)) error("setprop"); if (isUndefined(E)) E=False; if (isUndefined(W)) W=False; if (isUndefined(C)) C=False; Object.defineProperty(O,NAME,{ "value": VAL, "enumerable": E, "writable": W, "configurable": C }); } var getPrototypeOf=Object.getPrototypeOf || function (O) { return O.__proto__; } var setPrototypeOf=Object.setPrototypeOf || function (O,PROTO) { O.__proto__=PROTO; return O; } function hasPrototype(O,P) { O=getPrototypeOf(O); while (O!=Nil) { if (O==P) return True; O=getPrototypeOf(O); } return False; } var SymbolType=Symbol("type"); function _mtypeOf() { var OBJ=this; if (!isNil(this.typeOf)) OBJ=prototype(this); return OBJ[SymbolType]; } function jsprotoCreate(JSPROTO,TYPE,JSPARENT) { var CLASS=Object; if (!isNil(JSPARENT)) CLASS=JSPARENT.constructor; var RES=JSPROTO; if (JSPROTO==Nil) RES=(class extends CLASS {}).prototype; RES[SymbolType]=TYPE; setprop(RES,"typeOf",_mtypeOf); setprop(RES,"init0",function () {},False,True); return RES; } function jsprotoIsAtom(PROTO) { return PROTO==Symbol.prototype || PROTO==Boolean.prototype || PROTO==Number.prototype || PROTO==String.prototype; } function jsprotoInheritsAtom(PROTO) { if (PROTO==Nil) return False; if (jsprotoIsAtom(PROTO)) return True; return jsprotoInheritsAtom(Object.getPrototypeOf(PROTO)); } function _createObject(CONT) { var RES=new this.JSPROTO.constructor(); if (!isUndefined(CONT)) { if (!isContainer(CONT)) error("_createObject"); CONT.store(RES); } RES.init0(); return RES; } function _consObject(JSPROTO,VAL,CONT) { if (!isUndefined(VAL) && constructor(VAL)!=Object && constructor(VAL)!=Array) { if (!isContainer(VAL) || !isUndefined(CONT)) error("_consObject"); CONT=VAL; VAL=Undefined; } var RES=({ "_":_createObject, "JSPROTO":JSPROTO })._(CONT); RES.init(); if (isDefined(VAL)) Object.assign(RES,VAL); return RES; } function _createAtom(VAL,CONT) { var RES=new this.JSPROTO.constructor(VAL); if (!isUndefined(CONT)) CONT.store(RES); RES.init0(); return RES; } function _consAtom(JSPROTO,VAL,CONT) { var RES=({ "_":_createAtom, "JSPROTO":JSPROTO })._(VAL,CONT); RES.init(); return RES; } var TYPEPROTO=jsprotoCreate(Nil,Nil); setprop(TYPEPROTO,"init0",function () { this.NAME=Nil; this.PARENT=Nil; this.JSPROTO=Nil; this.ATTRS=[]; setprop(this,"create",_createObject,False,True); }); var TYPES={}; var type=function (CONS,O) { var PARENT=Nil; if (!isNil(O)) PARENT=O.PARENT; var JSPARENT=Nil; if (PARENT!=Nil) JSPARENT=PARENT.JSPROTO; var JSPROTO=Nil; if (CONS==type) JSPROTO=TYPEPROTO; else if (!isNil(O) && !isNil(O.JSPROTO)) JSPROTO=O.JSPROTO; if (isNil(CONS) || CONS!=type) JSPROTO=jsprotoCreate(JSPROTO,CONS,JSPARENT); var CREATE=jsprotoInheritsAtom(JSPROTO) ?_createAtom :_createObject; if (isNil(CONS)) { CONS=CREATE==_createObject ?function (VAL,CONT) { return _consObject(JSPROTO,VAL,CONT); } :function (VAL,CONT) { return _consAtom(JSPROTO,VAL,CONT); }; } JSPROTO[SymbolType]=CONS; Object.setPrototypeOf(CONS,TYPEPROTO); CONS.init0(); CONS.PARENT=PARENT; CONS.JSPROTO=JSPROTO; if (!isNil(O)) { if (!isNil(O.NAME)) { CONS.NAME=O.NAME; TYPES[O.NAME]=CONS; } CONS.ATTRS=[]; if (!isArray(O.ATTRS)) { if (!isNil(O.ATTRS)) error("type::ATTRS"); } else if (!empty(O.ATTRS)) CONS.setAttrs(O.ATTRS); for (var N in O) if (N!="NAME" && N!="PARENT" && N!="JSPROTO" && N!="ATTRS") CONS[N]=O[N]; } delete CONS.name; if (!empty(CONS.ATTRS)) { setprop(CONS.JSPROTO,"init0",function () { for (var I=0;I")) this.setv(CONS.ATTRS[I].NAME,VAL0); else if (CONS.ATTRS[I].QUALIF.has("v")) this[CONS.ATTRS[I].NAME]=VAL0; } }, False,True); } setprop(CONS,"create",CREATE,False,True); return CONS; } var obj=type(function (VAL,CONT) { if (!isUndefined(VAL) && constructor(VAL)!=Object) { if (!isContainer(VAL)) { if (constructor(VAL)==Array && isDefined(tree)) return tree(VAL,CONT); } else { if (!isUndefined(CONT)) error("obj.cons"); CONT=VAL; VAL=Undefined; } } var RES=obj.create(CONT); if (isDefined(VAL)) Object.assign(RES,VAL); return RES; }, { "NAME":"obj", "PARENT":Nil, "JSPROTO":Object.prototype, "ATTRS":[] }); type=type(type, { "NAME":"type", "PARENT":obj, "ATTRS":[] }); setprop(type,"create",function () { error("type.create"); }); setprop(type,"getByName",function (NAME) { return TYPES[NAME]; }); function isType(O) { return isa(O,type); } setprop(TYPEPROTO,"setMethod",function (NAME,FUNC) { setprop(this.JSPROTO,NAME,FUNC,False,True); }, False,True); obj.setMethod("init",function () {}); type.setMethod("name",function () { return this.NAME; }); type.setMethod("parent",function () { return this.PARENT; }); type.setMethod("inherits",function (T) { var P=this.parent(); if (!isType(T) || P==Nil) return False; if (P==T) return True; else return P.inherits(T); }); type.setMethod("method",function (NAME) { var FUNC=this.JSPROTO[NAME]; return isFunction(FUNC)?FUNC:Undefined; }); type.setMethod("super",function (NAME) { return this.parent().method(NAME); }); obj.setMethod("super",function (NAME,...PARMS) { var M=typeOf(this).super(NAME); if (isNil(M)) error("super::method "+NAME+" doesn't exists in class "+typeOf(this).parent().name()); return M.apply(this,PARMS); }); var nil=type(function (VAL) { var RES=boxit(VAL); if (!isNil(RES.valueOf())) error("nil"); return RES; }, { "NAME":"nil", "PARENT":obj, "ATTRS":[] }); var BoxedNil=nil.create(),BoxedUndefined=nil.create(); nil.setMethod("valueOf",function () { if (this==BoxedUndefined) return Undefined; if (this==BoxedNil) return Nil; error("nil.valueOf"); }); function isUnboxed(O) { if (O==Nil) return True; return isAtom(O) && O.valueOf()===O; } function isBoxed(O) { if (O==Nil) return False; return !isUnboxed(O); } function boxed(O) { if (O==Nil) return boxit(O); if (isUnboxed(O)) return Object(O); return O; } function boxit(O) { if (isUndefined(O)) return BoxedUndefined; if (eqNil(O)) return BoxedNil; return O; } function typeOf(O) { O=boxit(O); if (!isFunction(O.typeOf)) return obj; return O.typeOf(); } var symb=type(function (S) { return Symbol(S); }, { "NAME":"symb", "PARENT":obj, "JSPROTO":Symbol.prototype, "ATTRS":[] }); var bool=type(function (B,CONT) { return bool.create(B,CONT); }, { "NAME":"bool", "PARENT":obj, "JSPROTO":Boolean.prototype, "ATTRS":[] }); var num=type(function (N,CONT) { return num.create(N,CONT); }, { "NAME":"num", "PARENT":obj, "JSPROTO":Number.prototype, "ATTRS":[] }); var str=type(function (S,CONT) { return str.create(S,CONT); }, { "NAME":"str", "PARENT":obj, "JSPROTO":String.prototype, "ATTRS":[] }); var array=type(function (VAL) { if (isString(VAL)) return explode(VAL); var RES=[]; if (isDefined(VAL)) Object.assign(RES,VAL); return RES; }, { "NAME":"array", "PARENT":obj, "JSPROTO":Array.prototype, "ATTRS":[] }); type.setMethod("isAtom",function (STRICT) { if (STRICT) return this==nil || this==symb || this==bool || this==num || this==str; else return this.isAtom(True) || this.inherits(nil) || this.inherits(symb) || this.inherits(bool) || this.inherits(num) || this.inherits(str); }); type.setMethod("root",function () { if (this.isAtom(True)) return this; else if (this.parent()==Nil) return obj; else return this.parent().root(); }); var set=type(function (VAL) { if (isUndefined(VAL)) VAL=[]; return set.create(implode(VAL)); }, { "NAME":"set", "PARENT":str, "ATTRS":[], "ELEMS":Undefined }); function isSet(O) { return isa(O,set); } set.setMethod("contains",function (ELTS) { if (!isString(ELTS)) error("set.contains"); ; for (var I=0;I", "l" ]); function isQualif(O) { return isa(O,qualif); } var addr=type(function (NAME,TYPE,QUALIF,VAL0) { if (isUndefined(TYPE)) return addr.obj(NAME); else { var RES=addr.create(); RES.init(NAME,TYPE,QUALIF,VAL0); return RES; } }, { "NAME":"addr", "PARENT":obj, "ATTRS":[] }); addr.setMethod("init",function (NAME,TYPE,QUALIF,VAL0) { if (isUndefined(TYPE)) TYPE=str; if (isString(QUALIF)) QUALIF=qualif(QUALIF); else if (!isQualif(QUALIF)) error("addr.init"); Object.assign(this,{ "NAME":NAME, "TYPE":TYPE, "QUALIF":QUALIF, "VAL0":VAL0 }); }); setprop(addr,"obj",function (S) { S=trim(S," ",True,True); var A=splitOnce(S," ",["v",Undefined]); var Q=qualif(A[0]); if (Q.inter("vci")=="") Q=Q.union("v"); A=splitOnce(A[1],"=",[Undefined,Undefined]); var VAL0=eval("(function () { return "+A[1]+"; })()"); A=splitOnce(A[0],":",[Undefined,"obj"]); var NAME=A[0],TYPE=type.getByName(A[1]); return addr(NAME,TYPE,Q,VAL0); }); function isAddr(O) { return isa(O,addr); } type.setMethod("attr",function (NAME) { return find(this.ATTRS,function (O) { return O.NAME==NAME; }); }); addr.setMethod("has",function (Q) { return this.QUALIF.has(Q); }); type.setMethod("attrHas",function (NAME,Q) { var A=this.attr(NAME); return isDefined(A) && A.has(Q); }); type.setMethod("setAttr",function (A) { if (isString(A)) A=addr(A); if (!isAddr(A)) error("setAttr"); if (!isNil(this.attr(A.NAME))) error("type.setAttr"); this.ATTRS.push(A); if (A.QUALIF.has("c")) { setprop(this.JSPROTO,A.NAME,A.VAL0,False,True); } }); type.setMethod("attrs",function () { return this.ATTRS; }); type.setMethod("setAttrs",function (L) { for (var I=0;I"); if (isBoxed(VAL) && MODE=="flat" && !PO) error("delete(!PO)::"+N); if (isBoxed(VAL) && (MODE=="full" || PO)) { VAL.delete(MODE); } } this.addFlags("d"); }); setprop(obj,"delete",function (O,MODE) { if (isUnboxed(O)) O.delete(MODE); }); function tree(A,CONT) { if (isAtom(A) || constructor(A)!=Array && !isTemplate(A) || length(A)<1 || !isType(A[0])) return A; var O=length(A)==1?{}:A[1]; if (constructor(O)!=Object) error("tree(1)"); O.$=[]; for (var I=2;I2) error("tree(2)"); return RES; } function range(O,MIN,MAX,LI,COL) { return { "OBJ":O,"MIN":MIN,"MAX":MAX,"NAT":Nil,"LI":LI,"COL":COL }; } function rangeBOF(RG) { return RG.MIN==0; } function rangeEOF(RG) { return RG.MIN>=length(RG.OBJ); } function rangeValue(RG) { return substring(RG.OBJ,RG.MIN,RG.MAX); } function lexerReadString(S,i,C) { while (i=length(S)) error("lexerReadString"); return i; } function lexerReadUntil(S,i,C1,C2,STRICT) { if (STRICT==Undefined) STRICT=True; while (i=length(S)) error("lexerReadUntil"); return i; } function lexerRead(S,i,N1,N2) { while (i=0 && (S[i]=='\"' || charIs("'",CharNatQuote) && S[i]=='\'')) { i0=i; i=lexerReadString(S,i+1,S[i]); BEG=i0,END=i+1; NAT=TokenNatStr; } else if (TOKENIZECOMMENTS && i>=0 && i+1=0 && i+1=length(S)?0:1); NAT=TokenNatComment; } else { var j; j=lexerRead(S,i,charnat(S[i]),charIs(S[i],CharNatAlf)?CharNatDigit:-1); BEG=i,END=j; NAT=charnatToToknat(charnat(S[i])); } if (BEG==-1) error("lexerNext"); RG.MIN=BEG; RG.MAX=END; } else { RG.MIN=RG.MAX=length(S); } RG.NAT=NAT; RG.LI=LI; RG.COL=COL; ERRLI=LI; ERRCOL=COL; S=rangeValue(RG); if (RG.NAT==TokenNatOpn) { var N=length(S),TOK=S; while (N>0) { TOK=substring(S,0,N); if (TOKOPS[TOK]!=Undefined) break; N--; } if (N>0 && N!=length(S)) RG.MAX=RG.MIN+N; } return NAT; } function lexerStart(TEXT) { ERRLI=ERRCOL=1; var RG=range(TEXT,0,0,1,1); lexerNext(RG); return RG; } function lexerEOF(RG) { return rangeEOF(RG); } function tokenize(SRC,KEEP) { var RES=[], RG=lexerStart(SRC); while (!lexerEOF(RG)) { if (KEEP || RG.NAT!=TokenNatSpc && RG.NAT!=TokenNatComment) RES.push(rangeValue(RG)); lexerNext(RG); } return RES; } var PRIOR={},POSTFIX={},MULTI={}; function tokenizeStart(TOKSPEC) { var T=splitTrim(TOKSPEC," "), P=-1; for (var I in T) { if (T[I]==";;") P--; else { var OP=T[I],POST=False; if (OP[length(OP)-1]=="_") POST=True,OP=substring(OP,0,length(OP)-1); var OP0=OP; if (OP[0]=="_") OP=substring(OP,1,length(OP)); TOKOPS[OP]=1; PRIOR[OP0]=P; POSTFIX[OP0]=POST; } } } function tokenizeInit() {} var _SERIALIZING=[], SERIALIZEINDENT=0, SERIALIZING=False; function prettyBis(O,MODE,SKIN,INDENT) { if (INDENT==Undefined) INDENT=False; var OSERIALIZING=SERIALIZING; if (isFunction(MODE)) return MODE(O); if (isType(O)) return O.NAME; if (isNil(O)) return "Nil"; if (isUndefined(O)) return "Undef"; if (isBoolean(O)) return O?"True":"False"; if (isNumber(O)) return O.toString(); if (isSymbol(O)) return isUndefined(sy(O))?O.toString():sy(O); if (isString(O)) return '"'+strEscape(O)+'"'; if (isFunction(O)) return ''; if (contains(_SERIALIZING,O)) { if (isFunction(O.getId)) return "@"+O.getId(); else return "@^^"; } SERIALIZING=True; var RES=""; if (MODE=="name") { if (isArray(O)) RES="[...]"; else { var NAME=O.NAME; if (!isUndefined(NAME)) RES=NAME; else RES="{...}"; } } else { function incIndent(N) { SERIALIZEINDENT+=N; OUTINDENT=SERIALIZEINDENT; } if (isArray(O)) { _SERIALIZING.push(O); RES+="["; if (INDENT) incIndent(2); for (var I=0;I0) RES+=","; if (INDENT) RES+="\n"+spc(SERIALIZEINDENT); RES+=prettyBis(O[I],MODE,SKIN); } if (INDENT) incIndent(-2); RES+="]"; } else { _SERIALIZING.push(O); var TYPE=typeOf(O),PATTERN=Nil; RES+=(TYPE==obj?"":TYPE.NAME)+"{"; if (SKIN!=Undefined) { var SKINT=SKIN[TYPE.NAME]; if (isUndefined(SKINT)) SKINT=SKIN["*"]; if (SKINT!=Undefined) { if (MODE==Undefined) MODE=SKINT["default"]; if (MODE!=Undefined) PATTERN=SKINT[MODE]; } } if (MODE==Undefined) MODE="short"; if (isNil(PATTERN)) PATTERN={"*":["av","full"]}; if (INDENT) incIndent(2); var FIRST=True; for (var NAME of Object.getOwnPropertyNames(O)) { var MODE2=Undefined; if (PATTERN.hasOwnProperty(NAME)) MODE2=PATTERN[NAME]; if (MODE2==Undefined) MODE2=PATTERN["*"]; if (MODE2!=Undefined && !contains(MODE2[0],"-")) { var SA=contains(MODE2[0],"a"), SV=contains(MODE2[0],"v"); if (!FIRST && (SA||SV)) RES+=","; if (SA||SV) if (INDENT) RES+="\n"+spc(SERIALIZEINDENT); if (SA||SV) FIRST=False; if (SA) RES+=isSymbol(NAME)?pretty(NAME):NAME; if (SA&&SV) RES+="="; if (SV) { var VAL; if (NAME=="caller" || NAME=="callee" || NAME=="arguments") VAL=""; else VAL=O[NAME]; RES+=prettyBis(VAL,MODE2[1],SKIN,contains(MODE2[0],"i")); } } } if (INDENT) incIndent(-2); RES+="}"; } } SERIALIZING=OSERIALIZING; return RES; } function pretty(O,MODE,SKIN) { if (!SERIALIZING) _SERIALIZING=[]; if (isUndefined(MODE)) MODE="short"; var RES=prettyBis(O,MODE,SKIN); if (!SERIALIZING) _SERIALIZING=[]; return RES; } var _SFID,_SFOBJ; function sfid(HIDDEN) { HIDDEN=isDefined(HIDDEN); return (HIDDEN?chr(1):chr(2))+_SFID++; } function sfisHiddenId(ID) { if (!isNumber(ID) && !isString(ID)) outd(ID),cr(),error("sfisHiddenId"); return ID[0]==chr(1); } function sfisLocId(ID) { if (!isNumber(ID) && !isString(ID)) error("sfisLocId"); return ID[0]==chr(1) || ID[0]==chr(2); } function sffetch(ID) { return _SFOBJ[ID]; } function sfstore(O,HIDDEN) { if (isUnboxed(O)) return; var ID=O[SymbolId]; if (isUndefined(ID)) ID=sfid(HIDDEN); else if (isDefined(sffetch(ID))) return; O[SymbolId]=ID; _SFOBJ[ID]=O; } function sfrelease() { for (N in _SFOBJ) { if (sfisLocId(N)) delete sffetch(N)[SymbolId]; } } function sfinit() { _SFID=0; _SFOBJ={}; _SFOUT=[]; _SFDONE={}; _SFFIRST=True; _SFINDENT=0; } var _SFSymbElt="ELT"+chr(2),_SFLANG; function parsefList(L,I,STOP,CONT) { var N=length(L),FOUND=False,TYPE=array,RES=[],VAR=Undefined,ELT=Nil,TYNAME; function omg(S) { if (S=="(") return _SFLANG=="lisp"?S:"{"; if (S==")") return _SFLANG=="lisp"?S:"}"; if (S=="=") return _SFLANG=="lisp"?S:":"; error("omg"); } if (STOP==omg(")")) { TYPE=obj; var OBJ0=False; if (_SFLANG=="json" && L[I]=="{") I++,OBJ0=True; else if (I=N || I+1"+I+" "+L[I]); if (_SFLANG=="json" && !OBJ0) if (L[I]!="{") error("parsefList(2)"); else I++; RES=obj({}); } function parseval(VAR,VAL,TYELT) { if (isUndefined(TYELT)) TYELT=obj; if (!empty(TYPE.attrs())) { var A=TYPE.attr(VAR); if (A!=Nil) TYELT=A.TYPE; } if (TYELT==obj) { if (length(VAL)>=2 && VAL[0]=='"' && VAL[length(VAL)-1]=='"') TYELT=str; else ; } if (TYELT==bool) { if (VAL=="True") VAL=True; else if (VAL=="False") VAL=False; else error("parseval(1)"); } else if (TYELT==num) { ; VAL=JSON.parse(VAL); } else if (TYELT==str) VAL=substring(VAL,1,length(VAL)-1); else ; return VAL; } function pushvar(VAL) { if (isString(VAR)) if (syExists(VAR)) VAR=sy(VAR); if (strIsOmg(VAR)) error("pushvar(0)-->"+VAR); if (strIsOmg(VAL)) error("pushvar(1)-->"+VAL); if (STOP==omg(")")) { if (VAR==_SFSymbElt) ELT.push(VAL); else { var TYELT; if (VAR==sy("+o")) TYELT=num; VAL=parseval(VAR,VAL,TYELT); if (VAR==sy("+o")) RES.setId(VAL); else RES[VAR]=VAL; } VAR=Undefined; } else RES.push(VAL); } var FIRST=True; while (I=N || L[I+1]!=omg("=")) { VAR=_SFSymbElt; if (ELT==Nil) ELT=[]; } else { VAR=L[I]; I+=2; if (I>=N || L[I]==omg(")") || L[I]=="]") error("parsefList::Nothing after '='"); } } if ((_SFLANG=="lisp" && L[I]==omg("(")) || (_SFLANG=="json" && L[I]==omg("(")) || (_SFLANG=="json" && L[I+1]==omg("(")) || L[I]=="[") { var A=parsefList(L,I+(_SFLANG=="lisp"?1:0),L[I]=="["?"]":omg(")"),CONT); pushvar(A[0]); I=A[1]; } else pushvar(L[I]),I++; } } if (ELT!=Nil) VAR="$",pushvar(ELT); if (STOP!=omg(")") && STOP!="]" && FOUND) error("parsefList::STOP(1)"); if ((STOP==omg(")") || STOP=="]") && !FOUND) error("parsefList::STOP(2)<"+STOP+">"); if (TYNAME=="type") RES.PARENT=type.getByName(RES.PARENT),RES=type(Nil,RES); else if (TYPE!=obj && TYPE!=array) { RES=TYPE(RES); if (!isNil(CONT)) CONT.store(RES,RES.getId()); } return [RES,I]; } function parsef(S,CONT,LANG) { if (isString(CONT)) LANG=CONT,CONT=Undefined; if (isUndefined(LANG)) LANG="json"; _SFLANG=LANG; if (LANG!="lisp" && LANG!="json") error("parsef(0)"); parsefStart(); var RES=parsefList(tokenize(S),0,"",CONT)[0]; RES=linkf(RES,CONT); return RES; } function parsefStart() { charsInit(); charnatSet("#",CharNatAlf); charnatSet("+",CharNatAlf); charnatSet("%",CharNatAlf); tokenizeStart("( ) [ ] { } = : ,"); } var _SFOUT,_SFDONE,_SFFIRST,_SFINDENT; function sfout(S) { _SFOUT.push(S); return S; } function sfresult() { return _SFOUT.join(""); } function sfattrs(O) { return RES=Object.getOwnPropertyNames(O).concat(Object.getOwnPropertySymbols(O)).filter(function (X) { return X!=SymbolUp && X!=SymbolCont && X!="TO" }); } function serializefBis(O,MODE,MODES) { var ISFIRST,SKIPSPC,SFSDONE; function sfslot(N,SMODE) { if (isUndefined(SMODE)) SMODE={}; if (O.hasOwnProperty(N) && !(N==sy("+o") && sfisHiddenId(O[N]))) { if (!SKIPSPC) { if (_SFLANG=="json" && !ISFIRST) sfout(","); if (isDefined(SMODE["nl"])) sfout("\n"+spc(_SFINDENT)); else if (_SFLANG=="lisp") sfout(" "); } SKIPSPC=False; sfout(isSymbol(N)?sy(N):N),sfout(_SFLANG=="lisp"?"=":":"); if (N==sy("+o")) sfout(O[N]); else serializefBis(O[N],MODE=="flat"?"symb":MODE,MODES); ISFIRST=False; SFSDONE[N]=1; } } if (isNil(O)) return sfout("Nil"); if (isUndefined(O)) return sfout("Undef"); if (isBoolean(O)) return sfout(O?"True":"False"); if (isNumber(O)) return sfout(O.toString()); if (isString(O)) return sfout('"'+strEscape(O)+'"'); if (isFunction(O)) return sfout(''); if (isArray(O)) { ISFIRST=True; sfout("["); for (var I=0;I<"+ REQ.ADDR.address+":"+REQ.ADDR.port+"::"+ REQ.IDCLI+" "+REQ.PATHNAME+" "+REQ.QUERY+">"); if (REQ.METHOD=="GET") out("[]"); else out(BODY.toString()); cr(),out("["+JSON.stringify(ERR)+"]=> "); if (REQ.METHOD=="GET") out("..."); else out(ANSW); cr(),cr(); } var THIS=this; function handler(REQ,ANSW) { var REQLOG=_REQLOG=req(REQ); _CURSRV=THIS; function ret(ERR,CTYPE,MSG,RES) { if (CTYPE=="application/json") RES=isUndefined(RES)?"null":JSON.stringify(RES); var SRES=RES; if (length(SRES)>80) SRES=substring(RES,0,80)+" ..."; log(REQNO++,REQLOG,MSG,ERR,SRES); ANSW.writeHead(ERR, {'Content-Type': CTYPE, 'Access-Control-Allow-Origin': '*' }); ANSW.write(RES); ANSW.end("\n"); _REQLOG=_CURSRV=Nil; } if (endsWith(REQLOG.PATHNAME,".jix")) { if (REQ.method=="POST") { var MSG="",ISOBJ=false; REQ.on('data', function (DATA) { if (ISOBJ) error("serverCreate(multipart obj)"); else { if (typeOf(DATA)==str) MSG+=DATA; else { MSG=DATA; ISOBJ=true; } } }); REQ.on('end',function () { if (ISOBJ) MSG=JSON.parse(MSG.toString()); var PARMS=JSON.parse(MSG); REQLOG.IDCLI=PARMS[1].shift(); var RES=THIS.call(PARMS[0],PARMS[1]); ret(200,"application/json",MSG,RES); }); } else if (REQ.method=="GET") { ret(200,"application/json","",{ _type:"error", MSG:"RPCs must be POST"}); } } else { fs.readFile(__dirname+'/'+REQLOG.PATHNAME,'utf-8',function(ERR,DATA) { ; if (ERR) { ret(404,"text/html","",'

Page Not Found

'); } else { ret(200,"text/html","",DATA); } }); } } if (!isNil(this._RUNNING)) error("server.start"); var SRV=http.createServer(handler); this._RUNNING=SRV; SRV.on('connection', function (SOCK) { SOCK.unref(); }); SRV.listen(this.PORT,"0.0.0.0"); }); server.setMethod("stop",function () { if (isNil(this._RUNNING)) error("server.stop"); this._RUNNING.close(); this._RUNNING=Nil; }); server.setMethod("attach",function (CONT) { if (!isContainer(CONT) || isDefined(CONT.SRV)) error("server.attach"); this.CONT[CONT.IDCONT]=CONT; CONT.SRV=this; }); server.setMethod("container",function (NAME,FOP) { if (FOP) { var CONT=this.container(NAME); if (isNil(CONT)) { CONT=container(NAME,this); } return CONT; } else return find(this.CONT,function (X) { return isDefined(X) && X.NAME==NAME }); }); function _fetchconts() { return RES=server.currentClient().containers(True).map(function (C) { return {"NAME":C.NAME}; }); } server.setMethod("containers",function (FETCH) { if (FETCH) { if (isLocal(this)) ; else if (isRemote(this)) { var L=this.call("_fetchconts",[]); for (var C of L) { this.container(C.NAME,True); } } else if (isClient(this)) { var SRV=server.getById(this.IDSRVPARENT); for (var C of SRV.containers()) { if (isString(C.NAME) && C.NAME!="") { this.container(C.NAME,True); } } } return this.containers(); } else return this.CONT.filter(function (X) { return isDefined(X); }); }); function _grep(NAME,Q) { var CONT=server.getById(server.currentClient().IDSRVPARENT).container(NAME); if (isNil(CONT)) error("_grep"); return serialize(CONT.query(Q),"flat*"); } function _syncobjs(NAME,S) { var CONT=server.getById(server.currentClient().IDSRVPARENT).container(NAME); if (isNil(CONT)) error("_syncobjs"); parse(S,CONT); return True; } function _srvls() { var T={ "l":"LOC", "r":"REM", "c":"CLI" }; function cls(CONT) { outd(CONT.IDCONT),out(" "); outd(CONT.SRV.IDSRV),out(" ["); outd(CONT.NAME),out(";"); outd(CONT.FNAME),out("]"); } function ls(SRV) { out(T[SRV.CATEG]), out(" "),outd(SRV.IDSRV); out(" "),outd(SRV.IDCLI); out(" "),outd(SRV.HREF); out(" "),outd(SRV.ADDR); out(" "),outd(SRV.PORT); for (var C of SRV.containers()) cr(),out(" "),cls(C); } for (var I in server.SRV) ls(server.SRV[I]),cr(); return Nil; } function serversInit() { if (SERVER) { http=require('http'); APIDefault={ "_connect": _connect, "_close": _close, "_srvls": _srvls, "_fetchconts": _fetchconts, "_grep": _grep, "_syncobjs": _syncobjs }; } } function csvparseObjVals(S) { var A=tokenize(S,True); if (length(A)==0) error("csvparseObjVals"); var EXP="v",I=0,RES=[]; while (I=length(A)) RES.push(""); } } return RES; } function csvparseObj(S,TYPE,SLOT,CONT) { var A=csvparseObjVals(S),O={}; if (length(A)!=length(SLOT)) out(display(A)),cr(),out(display(SLOT)),cr(),error("csvparse"); for (var I=0;I1 && VAL[0]=='"' && VAL[length(VAL)-1]=='"') VAL=trim(VAL,'"',True,True); O[SLOT[I]]=VAL; } return TYPE(O,CONT); } function csvparsef(S,CONT,TYPE) { csvparsefStart(); var A=splitTrim(S,"\n"),RES=[]; if (length(A)==0) error("csvparsef"); var SLOT=splitTrim(A[0],","), TYNAME; for (var I=0;I1) TYNAME=A2[0],SLOT[0]=A2[1]; } SLOT[I]=splitTrim(SLOT[I],":")[0]; } if (isType(CONT)) TYPE=CONT,CONT=Undefined; if (isDefined(TYNAME) && isUndefined(TYPE)) { TYPE=type(Nil,{ NAME:TYNAME, PARENT:obj, ATTRS:SLOT }); } if (isUndefined(TYPE)) error("csvparsef(2)"); for (var I=1;I")) return FULLREF?[UP2[0],UP2[1],UP[1]]:UP2[0]; } if (!FULLREF) return UP[0]; } return UP; }); obj.setMethod("upa",function () { var UP=this.up(True,True); if (isUndefined(UP)) return Undefined; var A=typeOf(UP[0]).attr(UP[1]); return A; }); obj.setMethod("multiA",function () { if (!isArray(this)) return Undefined; var A=this.upa(); return isDefined(A) && A.has("*")?A:Undefined; }); obj.setMethod("setUp",function (NEWUP,NAME) { if (!isUndefined(NEWUP) && !isObject(NEWUP)) error("setUp(1)"); var UP=this.up(True,True); if (!isUndefined(UP)) { if (UP[0][UP[1]]!=this) error("setUp(2)"); UP[0][UP[1]]=Undefined; } if (isUndefined(NEWUP)) this[SymbolUp]=Undefined; else this[SymbolUp]=[NEWUP,NAME]; }); obj.setMethod("detach",function () { this.setUp(Undefined); }); container.setMethod("newId",function () { return this.LASTID++; }); container.setMethod("store",function (O,ID,UP,UPNAME) { if (isUndefined(ID)) ID=this.newId(); O.setId(ID); O.setUp(UP,UPNAME); O.setContainerOf(this); }); obj.setMethod("getv",function (NAME) { return this[NAME]; }); obj.setMethod("setv",function (NAME,VAL) { if (!isString(NAME) && !isNumber(NAME)) error("setv::"+NAME); if (this[NAME]==VAL) return; var A=typeOf(this).attr(NAME), MA=this.multiA(), NUM=isNumStr(NAME), SAMECONT=isUnboxed(VAL) || this.containerOf()==VAL.containerOf(); if (NUM && isDefined(MA) && MA.has(">") || isDefined(A) && A.has(">")) { if (NUM && SAMECONT && isDefined(MA) && MA.has("!") || isDefined(A) && A.has("!")) { if (isBoxed(this[NAME])) this[NAME].detach(); } else { if (isBoxed(VAL) && (!SAMECONT || isDefined(VAL.up()))) VAL=copy(VAL,this.containerOf()); } if (isBoxed(VAL)) VAL.setUp(this,NAME); } this[NAME]=VAL; }); obj.setMethod("remove",function (NAME,N) { function rm(A,I) { var VAL=A[I]; if (isBoxed(VAL) && VAL.up(True)==A) VAL.detach(); } if (isArray(this) && isNumStr(NAME)) { if (isUndefined(N)) N=1; if (NAME<0 || NAME>=length(this) || NAME+N>length(this)) error("obj.remove"); var M=N; while (M--) { rm(this,NAME); this.splice0(NAME,1); } for (var I=NAME;I=length(this) || NAME+N>length(this)) error("obj.cut"); for (var I=NAME;I"); var VAL2=VAL; if (isBoxed(VAL) && MODE=="flat" && !PO) error("copy(!PO)::"+N); if (isBoxed(VAL) && (MODE=="full" || PO)) { VAL2=this.copy(VAL,MODE); if (isArray(VAL2) && PO) { for (var I=0;I=32) return CHAR; else return ASCII[SHIFT?1:0][KEY]; } function keyboardIsChar(KEY) { return KEY<0x1000; } function shift() { return _LASTEVENT.SHIFT; } function ctrl() { return _LASTEVENT.CTRL; } function alt() { return _LASTEVENT.ALT; } function mouseX() { return _LASTEVENT.X; } function mouseY() { return _LASTEVENT.Y; } function keyToStr(KEY) { if (isString(KEY)) return KEY; if (keyboardIsChar(KEY)) return chr(KEY); switch (KEY) { case KeyReturn: return "return"; case KeyLeft: return "left"; case KeyRight: return "right"; case KeyDown: return "down"; case KeyUp: return "up"; case KeyClick: return "click"; case KeyMove: return "move"; } return Nil; } function strToKey(S) { if (!isString(S)) error("strToKey"); if (length(S)==1) { var KEY=asc(S[0]); if (KEY==10) return KeyReturn; return KEY; } if (S=="return") return KeyReturn; if (S=="left") return KeyLeft; if (S=="right") return KeyRight; if (S=="down") return KeyDown; if (S=="up") return KeyUp; if (S=="click") return KeyClick; if (S=="move") return KeyMove; return Nil; } var ELEMENT_NODE=1, ATTRIBUTE_NODE=2, TEXT_NODE=3, CDATA_SECTION_NODE=4, ENTITY_REFERENCE_NODE=5, ENTITY_NODE=6, PROCESSING_INSTRUCTION_NODE=7, COMMENT_NODE=8, DOCUMENT_NODE=9, DOCUMENT_TYPE_NODE=10, DOCUMENT_FRAGMENT_NODE=11, NOTATION_NODE=12; var ERRO; var SymbolFrom=sy("<="), DomElement=prototype(prototype(prototype(prototype(document.createElement("div"))))).constructor; dom=type(function (O) { var DOM; if (isString(O)) DOM=document.createTextNode(O); else if (isa0(O,DomElement)) { DOM=O; if (DOM[SymbolFrom]) return DOM[SymbolFrom]; ; } else { if (!isType(O) || !O.inherits(html)) ERRO=O,error("dom.cons"); DOM=document.createElement(O.name()=="_input"?"input":O.name()); } var RES=dom.create(); RES.DOM=DOM; DOM[SymbolFrom]=RES; return RES; }, { "NAME":"dom", "PARENT":obj }); function isDom(O) { return isa(O,dom); } dom.setMethod("categ",function () { return this.DOM.nodeType; }); function isDomTextNode(O) { return isDom(O) && O.categ()==TEXT_NODE; } function isDomElement(O) { return isDom(O) && O.categ()==ELEMENT_NODE; } setprop(dom,"getById",function (ID) { var E=document.getElementById(ID); if (E) return dom(E); return Undefined; }); setprop(dom,"getByName",function (NAME,ALL) { var L=document.getElementsByTagName(NAME),RES=[]; for (var E of L) RES.push(dom(E)); return ALL?RES:RES[0]; }); dom.setMethod("tag",function () { return lcase(this.DOM.nodeName); }); dom.setMethod("from",function () { return this.FROM; }); dom.setMethod("setFrom",function (W) { if (!isHtml(W)) error("dom.setFrom"); this.FROM=W; }); dom.setMethod("getv",function (NAME) { if (isDomElement(this)) return this.DOM.getAttribute(NAME); return this[NAME]; }); dom.setMethod("setv",function (NAME,VAL) { if (isDomElement(this)) this.DOM.setAttribute(NAME,VAL); this[NAME]=VAL; }); var _DOMFOCUS=Nil; setprop(dom,"focussed",function () { return _DOMFOCUS; }); setprop(dom,"focus",function (E) { E.focus(); _DOMFOCUS=E; }); var _SHIFT=False,_CTRL=False,_ALT=False; setprop(dom,"event",function (EVT) { var TARGET=EVT.target; if (TARGET.nodeName.toLowerCase()=="html") TARGET=document.getElementsByTagName("body")[0]; var EVT2=new event(EVT.type,TARGET,EVT),EVT3=Nil; if (EVT.type=="keydown" || EVT.type=="keyup" || EVT.type=="keypress") { if (EVT.shiftKey!=Nil) _SHIFT=EVT.shiftKey; if (EVT.ctrlKey!=Nil) _CTRL=EVT.ctrlKey; if (EVT.altKey!=Nil) _ALT=EVT.altKey; EVT2.KEY=keyboardGetAscii(EVT.shiftKey,EVT.charCode,EVT.keyCode); EVT2.SCANCODE=EVT.keyCode; if (EVT.type=="keydown" && EVT2.KEY!=Nil && EVT.keyIdentifier!=Nil && EVT.keyIdentifier.substring(0,2)!="U+") { EVT3=new event("keypress",TARGET,EVT); EVT3.KEY=EVT2.KEY; EVT3.SCANCODE=EVT2.SCANCODE; EVT3.SHIFT=_SHIFT; EVT3.CTRL=_CTRL; EVT3.ALT=_ALT; } if (EVT2.KEY==Nil) EVT2.KEY=EVT2.SCANCODE; } if (EVT.type=="click" || EVT.type=="mousemove") { if (EVT.type=="click") EVT2.KEY=KeyClick; if (EVT.type=="move") EVT2.KEY=KeyMove; EVT2.X=0; EVT2.Y=0; } EVT2.SHIFT=_SHIFT; EVT2.CTRL=_CTRL; EVT2.ALT=_ALT; if (EVT3!=Nil) return EVT3; if (EVT2.TAG=="keyup" || EVT2.TAG=="keydown" && keyboardIsChar(EVT2.KEY)) return Nil; if (EVT2.TAG=="keydown") EVT2.TAG="keypress"; return EVT2; }); setprop(dom,"propagate",function (EVT) { EVT=dom.event(EVT); if (EVT!=Nil) { if (dom.focussed()!=Nil && (EVT.TAG=="keydown" || EVT.TAG=="keyup" || EVT.TAG=="keypress")) EVT.TARGET=dom.focussed(); var _E=EVT.TARGET; while (_E!=Nil) { if (!isUndefined(_E[SymbolFrom])) { var E=_E[SymbolFrom]; if (E!=Nil && E.from()!=Nil) { EVT.TARGET=E.from(); html.propagate(EVT); break; } } _E=_E.parentNode; } } }); document.addEventListener("keyup",dom.propagate,false); document.addEventListener("keydown",dom.propagate,false); document.addEventListener("keypress",dom.propagate,false); document.addEventListener("click",dom.propagate,false); var widget=type(function (O) { error("widget.cons"); }, { "NAME":"widget", "PARENT":obj, "ATTRS":["TAG", "FROM","TO", "!*> $"] }); widget.$=container(); setprop(widget,"getById",function (ID) { return widget.$.getbyId[ID]; }); setprop(widget,"create0",widget.create); setprop(widget,"create",function () { return this.create0(widget.$) }); function isWidget(O) { return isa(O,widget); } widget.setMethod("parent",function () { return this.up(); }); widget.setMethod("setParent",function (WUP) { error("widget.setParent(!Yet)"); }); function widgetType(NAME,PARENT) { var T=type(function (O) { var T=origin[NAME]; if (isContainer(O)) { if (O!=widget.$) error(T.name()+".cons(!widget.$)::"+O.NAME); O=Undefined; } if (isDom(O)) return T({ "TO":O }); else { var RES=T.create(); RES.init(O); return RES; } }, { "NAME":NAME, "PARENT":PARENT, "ATTRS":["TAG", "FROM","TO", "!*> $=[]"] }); setprop(T,"create0",widget.create0); setprop(T,"create",widget.create); origin[NAME]=T; return T; } var htmla=type(function () { return htmla.create(widget.$); }, { "NAME":"htmla", "PARENT":array }); htmla.setMethod("setv",function (I,VAL) { if (!isNumStr(I)) error("htmla.setv"); this.super("setv",I,VAL); var UP=this.up(); if (isUndefined(UP)) error("htmla.setv(2)"); if (isDomElement(UP.TO)) { var DOM=UP.TO.DOM; if (I<0 || I>=DOM.childNodes.length) error("htmla.setv(3)"); if (isString(VAL)) { DOM.replaceChild(document.createTextNode(VAL),DOM.childNodes[I]); } else if (isDom(VAL.TO)) { DOM.replaceChild(VAL.TO.DOM,DOM.childNodes[I]); } } }); htmla.setMethod("push",function (VAL) { if (isNumber(VAL)) VAL=VAL.toString(); if (!isHtml(VAL) && !isString(VAL)) error("htmla.push"); this.super("push",VAL); return VAL; }); htmla.setMethod("remove",function (I,N) { this.super("remove",I,N); var UP=this.up(); if (isUndefined(UP)) error("htmla.remove"); if (isDomElement(UP.TO)) { while (N--) UP.TO.DOM.removeChild(UP.TO.DOM.childNodes[I]); } ; }); htmla.setMethod("removeAll",function () { this.remove(0,length(this)); }); htmla.setMethod("insert",function (I,...VAL) { var UP=this.up(); if (isUndefined(UP)) error("htmla.insert(1)"); if (isDomElement(UP.TO)) { var DOM=UP.TO.DOM; if (I<0 || I>DOM.childNodes.length) error("htmla.insert(2)"); var N=length(VAL); while (N--) { DOM.insertBefore(document.createTextNode(""),DOM.childNodes[I]); } } this.super("insert",I,...VAL); }); var html=widgetType("html",widget); html.setMethod("init",function (O) { if (isUndefined(O)) O={}; if (constructor(O)!=Object) error("html.init(1)"); var TO=O.TO; if (isUndefined(TO)) TO=dom(typeOf(this)); else if (TO.tag()!=typeOf(this).name()) error("html.init(2)"); if (isDefined(TO.from())) error("html.init(3)"); TO.setFrom(this); this.TAG=typeOf(this).name(); this.TO=TO; this.$=htmla(); this.$.setUp(this,"$"); if (isDefined(this.TO)) html.fetchDomTree(this.$,TO); for (var N of ["events", "targets"]) { var VAL=this.TO.getv(N); if (!isNil(VAL)) { if (!isNil(O[VAL])) error("html.init("+N+")(1)"); this[N]=html[N=="events"?"parseLEvent":"parseLTarget"](VAL); } else this[N]=N=="events"?[]:{}; } for (var N in O) { var VAL=O[N]; if (N=="TO") ; else if (N=="TAG" && isDefined(VAL) && VAL!=typeOf(this).name()) error("html.init(4)"); else if (N=="$") for (var N2 in O.$) { var W=O.$[N2]; if (isJxmlPure(W)) W=W.TO; if (isDefined(W)) this.$.push(W); } else if (N=="events") this[N]=html.parseLEvent(VAL); else if (N=="targets") this[N]=html.parseLTarget(VAL); else { this[N]=VAL; this.TO.setv(N,VAL); } } }); var markup=tree; function isHtml(O) { return isa(O,html); } function isHtmlAtom(O) { return isHtml(O) && isDom(O.TO) && isDomTextNode(O.TO); } setprop(html,"getById",function (ID) { var D=dom.getById(ID); if (D) return D.FROM; return Undefined; }); setprop(html,"getByName",function (NAME,ALL) { var L=dom.getByName(NAME,ALL); if (!ALL) if (L) return L.FROM; else return L; else return L.filter(function (D) { return isDefined(D.FROM) }); }); setprop(html,"fetchDomTree",function (A,DOM) { var A2=DOM.DOM.childNodes; for (var I=0;I"); return [splitTrim(A[0],"|"),splitTrim(A[1],"&")]; }); setprop(html,"parseLEvent",function (L) { if (isString(L)) L=splitTrim(L,";"); if (!isArray(L)) error("html.parseLEvent"); return L.map(html.parseEvent); }); setprop(html,"eventMatch",function (E,KEY) { var LHS=E[0],S=keyToStr(KEY); for (var I in LHS) { if (LHS[I]=="alpha" && keyboardIsChar(KEY) && strIsAlpha(S)) return True; if (LHS[I]=="num" && keyboardIsChar(KEY) && strIsNum(S)) return True; if (LHS[I]==S) return True; } return False; }); setprop(html,"leventMatch",function (L,KEY) { for (var I in L) if (html.eventMatch(L[I],KEY)) return L[I]; return Nil; }); setprop(html,"parseTarget",function (L,T) { var A=splitTrim(T,":"); L[A[0]]=A[1]; }); setprop(html,"parseLTarget",function (L) { if (isString(L)) L=splitTrim(L,";"); if (!isArray(L)) return L; var RES={}; for (var T of L) html.parseTarget(RES,T); return RES; }); setprop(html,"evalTarget",function (TARGET,EXPR) { if (!isString(EXPR) || length(EXPR)==0) error("html.evalTarget"); var O=Nil; if (EXPR=="$") O=TARGET; else { if (EXPR[0]=="#") O=substring(EXPR,1,length(EXPR)); if (O!=Nil) O=html.getById(O); } return O; }); setprop(html,"defaultParm",function (ACTION) { switch (ACTION) { case "load": return "^"; case "mode": return "^"; case "save": return ""; case "focus": return "_^"; default: return "_^"; } }); setprop(html,"evalParm",function (ACTION,PARM,THIS,TARGET) { var A=ACTION.split("!"); ACTION=A[0]; if (length(A)>1) PARM=A[1]; if (PARM=="") PARM=html.defaultParm(ACTION); switch (PARM) { case "$": return THIS; case "*": return THIS.collect(); case "^": return TARGET.OBJ; case "_^": return TARGET; case "": return Nil; default: return PARM; } }); setprop(html,"propagate",function (EVT) { function fn(ACTION) { var A=ACTION.split("!"); return A[0]; } var TARGET=EVT.TARGET,ACTION=Nil; while (TARGET!=Nil) { ACTION=html.leventMatch(TARGET.events,EVT.KEY); if (ACTION!=Nil) break; TARGET=TARGET.parent(); } if (ACTION!=Nil) { _LASTEVENT=EVT; ACTION=ACTION[1]; TARGET=EVT.TARGET; while (TARGET!=Nil) { var TARGETA=TARGET.targets[fn(ACTION[0])]; if (!isUndefined(TARGETA)) { var A=splitTrim(TARGETA,"!"),PARM=""; TARGETA=A[0]; if (length(A)>1) PARM=A[1]; TARGETA=html.evalTarget(TARGET,TARGETA); if (TARGETA==Nil) error("html.propagate(1)"); for (var I in ACTION) { if (!isFunction(TARGETA[fn(ACTION[I])])) error("html.propagate(2)"); } for (var I in ACTION) TARGETA[fn(ACTION[I])](html.evalParm(ACTION[I],PARM,TARGET,EVT.TARGET)); break; } TARGET=TARGET.parent(); } } }); function out0(S) { if (isHtml(S)) { html.body().$.push(S);return; } if (OUTS!=Nil) { _out0(S);return; } if (!isString(S)) error("widgets.out0"); if (S=="
" || S=="\n") S=br(); if (S=="
") S=hr(); ; html.body().$.push(S); } function out(S) { out0(S); } var jxml=widgetType("jxml",html); jxml.setMethod("init",function (O) { if (isUndefined(O)) O={}; if (constructor(O)!=Object) error("jxml.init(1)"); this.TAG=typeOf(this).name(); this.$=array.create(widget.$); this.$.setUp(this,"$"); for (var N in O) { var VAL=O[N]; if (N=="TAG" && isDefined(VAL) && VAL!=typeOf(this).name()) error("jxml.init(2)"); else if (N=="$") for (var N2 in O.$) this.$.push(O.$[N2]); else if (N=="src") if (!isContainer(VAL)) error("jxml.init(src)"); else this[N]=VAL; else if (N=="value") this.value=VAL; else if (N=="skin") if (!isSkin(VAL)) error("jxml.init(skin)"); else this[N]=VAL; else { this[N]=VAL; } } this.expand(); for (var N of ["id", "style", "class", "events", "targets"]) { if (isDefined(this[N]) && isDefined(this.TO)) { if (N=="events") this.TO[N]=html.parseLEvent(this[N]); else if (N=="targets") this.TO[N]=html.parseLTarget(this[N]); else { this.TO[N]=this[N]; if (isDefined(this.TO.TO)) this.TO.TO.setv(N,this[N]); } } } }); function isJxml(O,STRICT) { return isa(O,jxml) && (!STRICT || isJxmlPure(O)); } function isHtmlPure(O) { return isa(O,html) && !isa(O,jxml); } jxml.setMethod("expand",function () { return Nil; }); var JXMLTAGS=[ "@", "skin","shape","view", "superpose", "lines", "columns", "splitv", "button","input" ]; for (var N of JXMLTAGS) widgetType(N,N=="columns"?lines:jxml); function isJxmlPure(O) { if (!isJxml(O)) return False; return contains(JXMLTAGS,typeOf(O).name()); } var JXMLREF=origin["@"]; var template=type(Nil, { NAME:"template", PARENT:array }); function isTemplate(O) { return isa(O,template); } template.setMethod("expand",function (PARMS) { function exp(A) { if (isString(A) && A[0]=="$") { var VAR=substring(A,1,length(A)); if (PARMS.hasOwnProperty(VAR)) return PARMS[VAR]; } if (isArray(A) && length(A)==0 && isDefined(PARMS[""])) return PARMS[""]; if (isArray(A) && length(A)>0 && !isType(A[0])) A.unshift(columns); if (isAtom(A) || constructor(A)!=Array && !isTemplate(A) || length(A)<1 || !isType(A[0])) return A; var O=length(A)==1?{}:A[1]; if (constructor(O)!=Object) error("template.expand(2)"); var RES=[]; RES[0]=A[0]; var O2={}; for (var N in O) O2[N]=exp(O[N]); RES[1]=O2; for (var I=2;I0) { if (length(this.$)!=1 || !isSkin(this.$[0])) error("lines.expand(skin !Yet)"); } this.load(this.value); } else { ; for (var I in this.$) { var W=this.$[I]; if (isHtmlPure(W) || isString(W) || isNumStr(W)) { var REF=JXMLREF(); W.detach(); this.display1(REF,W,1); this.$.setv(I,REF); } else if (isJxmlPure(W)) { this.display1(W,W.TO,1,0); } else error("lines.expand(2)"); } } }); columns.LB=template([table,{},[tr,{},"$"]]); columns.LBPATH=columns.LB.findVarPos("$"); columns.LBPATH.pop(); columns.LD=template([]); columns.LDPATH=[]; button.setMethod("expand",function () { if (!isNil(this.TO)) error("button.expand"); this.TO=markup([_input,{type:"button"}]); this.TO.FROM=this; if (isDefined(this.title)) { this.TO.title=this.title; this.TO.TO.setv("value",this.title); } }); input.setMethod("expand",function () { if (!isNil(this.TO)) error("input.expand"); this.TO=markup([_input,{type:"text"}]); this.TO.FROM=this; if (isDefined(this.name)) { this.TO.name=this.name; } if (isDefined(this.$[0])) { this.TO.value=this.$[0]; this.TO.TO.setv("value",this.$[0]); } }); splitv.setMethod("expand",function () { if (!isNil(this.TO)) error("splitv.expand"); if (!isDefined(this.$[0])) error("splitv.expand(2)"); var L=splitTrim(this.$[0],","); L.splice(0,0,lines,{}); this.TO=markup(L).TO; this.TO.FROM=this; }); html.setMethod("mode",function (MODE) { var CTX=this.CTX; CTX.MODE=MODE; this.redisplay(); }); html.setMethod("load",function (L) { if (isUndefined(this.FROM) || !isJxmlPure(this.FROM)) error("html.load(1)"); this.FROM.load(L); }); html.setMethod("collect",function () { var RES={},N=0; function traverse(W) { if (isAtom(W)) return; if (typeOf(W)==_input && W.type=="text") { var NAME=W.name,VALUE=W.TO.DOM.value; if (isUndefined(NAME)) NAME="in"+N,N++; if (isUndefined(VALUE)) VALUE=""; RES[NAME]=VALUE; } for (var I=0;I"); if (!contains(SELFCLOSE,W.TAG)) { if (length(W.$)>0) outIndentInc(+2); for (var I=0;I0) outIndentInc(-2),crIndent(),out(""); } } startOutS(); traverse(this); var RES=getOutS(); stopOutS(); return RES; }); function test1() { parsefStart(); var S="(56abcd1234 [befghij \"abcd\\\\\"])", RG=lexerStart(S); while (!lexerEOF(RG)) { out("<"+rangeValue(RG)+">"),cr(); out(display([RG.MIN,RG.MAX,RG.NAT,RG.LI,RG.COL])),cr(); lexerNext(RG); } out("---\n"); var A=tokenize(S); out(display(A)),cr(); out("---\n"); A=tokenize(S); var person=type(Nil,{ NAME:"person" }); var O=person({ "NAME":"Smith", "FNAME":"John", "AGE":43 }); out(pretty(O,"short")),cr(); out("---\n"); type(Nil,{ NAME:"range" }); var O=parsef('range{+o:"id1",A:1,B:2,C,D,E,F:{}}{Z:1}'); out(pretty(O)),cr(); out("---\n"); out(serializef(O,[["range","flat", [["ID"],["A"],["B"],["F"],["$",{"nl":1}]] ], ["*","full",[]]],"json")),out("_"),cr(); out("---\n"); out(pretty(O)),cr(); } function test2() { var C=container("C1"), person=type(Nil,{ NAME:"person", ATTRS:["NAME=''","FNAME","AGE=0","> YEARS=[]"] }), P=person({ NAME:"Smith", FNAME:"John", AGE:23, YEARS:[{ A:123 },{ B:456 }] }); out(pretty(P)),cr(); var P2=copy(P,C); out(pretty(P2)),cr(); out(pretty(P2.YEARS[0])),cr(); P2.delete(); out(pretty(P2)),cr(); } var SK={ "song":{ "short":{ "Title":["av",""], "Authors":["av",""], "Year":["av",""] } }, "*":{ "short":{ "+o":["av",""], "NAME":["av",""] } } }; function test3() { var C=container("C1"); C.load("./Songs","db"); SK["song"]["short"][SymbolCont]=["-",""]; SK["song"]["short"][SymbolId]=["av",""]; out(pretty(C.$[0],"short",SK)),cr(); } function test4() { var S=fileRead("./Songs.csv"), C=container("C1"); C.load("./Songs","csv"); out(pretty(C.$[0],"short",SK)),cr(); out("---\n"); var L=C.query({ Year:"*5" }); for (var I=0;I