## load the definition factory by pasting in the whole of the script ## initially - having first extended the lexer via the console ## script is then the first item in the history /* ## inspect this at the console: tabs.children[4].children[0] */ ## assign the text content of this to the JS-EDEN observable testhistory: ${{ (root.lookup("testhistory")).assign((tabs.children[4]).children[0].textContent, this).value(); }}$; ## introduce the following function to extract specific patterns from the script func findpatt { ${{ var th = arguments[0]; var repatt = arguments[1]; var reattr = arguments[2]; return th.match(RegExp(repatt, reattr)); }}$; } ## reattr i - case insensitive, g - global, m - multiline ## as an illustrative example: ## finding number of observables with 'is' defns ## assuming that such definitions start at the beginning of a line matchth is findpatt(testhistory, "^[^\\s]*\\s+is", "gm"); ## use the following action to display the results of the match: proc wmatchth : matchth { writeln(matchth); writeln(matchth#); } ## extend the find function to an action that makes a substitution for a pattern: func substpatt { ${{ var th = arguments[0]; var repatt = arguments[1]; var reattr = arguments[2]; var repstr = arguments[3]; return th.replace(RegExp(repatt, reattr), repstr); }}$; } ## replace all ## commented lines by blank lines: newfilteredth is substpatt(testhistory, "\#\#.*$", "gm", ""); ## eliminating ## comments and multiple new lines: compactth is substpatt(newfilteredth, "\n+", "gm", "\n"); ## now make a sequence of tidying up commands, and ## place an html version of the script on the Model Readme tab ## don't want to lose the ${{ preface to pure JavaScript code in script - resolve by replacing $ by $ ## also would like to deal more satisfactorily with management commands: showObservables, writeln, forget ## do this by sequence of preliminary substitutions to create dummy definitions ## _σ = showObservables("currsc|patt|subststr|segcol|γ|astr|seg|scrip|mat|α|β|γ|δ"); ## _ω = writeln("hello"); ## _φ = forget("α"); scompactth is substpatt(compactth, "^showObservables", "gm", "_σ = $&"); wcompactth is substpatt(scompactth, "writeln", "gm", "_ω = $&"); fcompactth is substpatt(wcompactth, "forget", "gm", "_φ = $&"); dcompactth is substpatt(fcompactth, "\${", "gm", "${"); qcompactth is substpatt(dcompactth, "\"", "gm", """); ltqcompactth is substpatt(qcompactth, "<", "gm", "<"); fltqcompactth is substpatt(ltqcompactth, "func\ ([^\\s]*)", "gm", "\n
\n$&");

pfltqcompactth is substpatt(fltqcompactth, "proc\ ([^\\s]*)", "gm", "
\n
\n$&");

dpfltqcompactth is substpatt(pfltqcompactth, "^([^\\s]*)\\s+is\\s+.*$", "gm", "
\n
\n$&"); 

adpfltqcompactth is substpatt(dpfltqcompactth, "^([^\\s]*)\\s+=\\s+.*$", "gm", "
\n
\n$&"); 

badpfltqcompactth is substpatt(adpfltqcompactth, "\\/\\*", "gm", ""); 



html("
" // kbadpfltqcompactth // "
"); ## at this point, some JScript has been eliminated within HTML comments /**************************************** ## we can locate the JS code in this script thus: matchth is findpatt(kbadpfltqcompactth, "\\$\\{\\{", "gm"); matchth is findpatt(kbadpfltqcompactth, "\\}\\}\\$;", "gm"); ## and comment out JSscript thus: nobjskbadpfltqcompactth is substpatt(kbadpfltqcompactth, "\\$\\{\\{", "gm", ""); html("
" // nojskbadpfltqcompactth // "
"); ## BUT there is an interference problem - JScript within a EDEN multi-line comment context ## gets to be processed, creating nested HTML comments ***************************************/ ## so in order to remove JScript, we should deal with the transformed version ## of the history that is currently being displayed in the Model Readme ## this is stored in the JScript variable: tabs.children[3].textContent ## assign the text content of this to the JS-EDEN observable testhistory2: ${{ (root.lookup("testhistory2")).assign((tabs.children[3]).textContent, this).value(); }}$; ## now - where necessary e.g. no need to remove comments, as there are none ## - repeat the sequence of tidying up commands, and ## place an html version of the script on the Model Readme tab ## eliminating multiple new lines: compactth2 is substpatt(testhistory2, "\n+", "gm", "\n"); dcompactth2 is substpatt(compactth2, "\${", "gm", "${"); qcompactth2 is substpatt(dcompactth2, "\"", "gm", """); ltqcompactth2 is substpatt(qcompactth2, "<", "gm", "<"); fltqcompactth2 is substpatt(ltqcompactth2, "func\ ([^\\s]*)", "gm", "
\n
\n$&");

pfltqcompactth2 is substpatt(fltqcompactth2, "proc\ ([^\\s]*)", "gm", "
\n
\n$&");

dpfltqcompactth2 is substpatt(pfltqcompactth2, "^([^\\s]*)\\s+is\\s+.*$", "gm", "
\n
\n$&"); 

adpfltqcompactth2 is substpatt(dpfltqcompactth2, "^([^\\s]*)\\s+=\\s+.*$", "gm", "
\n
\n$&");



nobjsth2 is substpatt(adpfltqcompactth2, "\\$\\{\\{", "gm", "");



html("
" // nojsth2 // "
"); ## internal representation of EDEN-only script is then the HTML collection ${{ tabs.children[3].children }}$; ## in this script, commented extracts and JScript segments ## are preserved as HTML comments ## can use this test to determine (roughly!) whether a definition is of a Div ${{ /is Div/.test(tabs.children[3].children[0].textContent) }}$; func mktextseg { ${{ var segindex = arguments[0]; return tabs.children[3].children[segindex-1].textContent; }}$; } segix = 3; textsegix is mktextseg(segix); func mktextrange { ${{ var segindex1 = arguments[0]; var segindex2 = arguments[1]; var construaltxt = document.createRange(); construaltxt.setStartBefore(tabs.children[3].children[segindex1]); construaltxt.setEndAfter(tabs.children[3].children[segindex2]); return construaltxt.toString(); }}$; } writeln(mktextrange(4,7)); func lastdefnobsix { ${{ var ix = arguments[0]; var symtable = tabs.children[3].children; var obsix = symtable.namedItem(symtable[ix].getAttribute("id")); return ((obsix[0]!==undefined) ? obsix[obsix.length - 1] : obsix).textContent; }}$; } for (i=1; i<=145; i++) writeln(lastdefnobsix(i)); ## can now display the HTML elements associated with funcs, procs, defns, and asgns /* tabs.children[3].children.namedItem("func") tabs.children[3].children.namedItem("proc") tabs.children[3].children.namedItem("defn") tabs.children[3].children.namedItem("asgn") */ proc maketext { ${{ var kind = arguments[0]; var result = ""; var subsymtable = tabs.children[3].children.namedItem(kind); for (var i=0; i" // kbadpfltqcompactth // "
"); ## gives full details of functions, including JScript components html("
" // nojsth2 // "
"); ## gives only headers for functions, omitting JScript elements ## want to omit definitions that take the form "is Div" ## thought is to make result acceptable to DMT proc maketextomitobs { ${{ var kind = arguments[0]; var omitobs = arguments[1]; var result = ""; var subsymtable = tabs.children[3].children.namedItem(kind); for (var i=0; i