UNPKG

expexp

Version:

The express model io and express model and data representation.

137 lines (106 loc) 3.04 kB
import {traverse, isArrSem, path2str} from './tree.js' export function SlctEval(model, nttById, getRawData, getData, getNttValue, resOneStage) { const me = {} const vs = [[]] // stack of current value(s) // The first dim grows with argument lists, parenthesis. // The second dim grows and shrinks while evaluating term or simple_expression. // const ss = [] // scope stack (only grows with function calls or query expressions) const fs = [] // self stack (grows with scope quantifiers) const errors = [] // List of error reasons let ignore = false // If set, this references the json, that ends the ignore state. const setup = function() { // Do nothing. } me.eval = function(nttTok, json) { fs.push(nttTok) // initial SELF pushVal(nttTok) // const instInfo = getRawData(nttTok) // console.log('instInfo', instInfo) // ss.push(instInfo.scope) Actually should be lazy created. return nttEval(nttTok, json) } // Pushes / starts an empty new array on the value stack. const pushNewArr = function() { vs.push([]) } // Most of the time this should not be used directly. // It is more internal for the others stack operations. // But there are certain sensible exceptions: When a infrastructure array // becomes a data array may be, and others. const curArr = function() { return vs[vs.length-1] } const curVal = function(off = 0) { const curAr = curArr() return curAr[curAr.length-1+off] // most of the time curArr[0] } const pushVal = function(value) { curArr().push(value) } const chgVal = function(value) { const curAr = curArr() if (0 < curAr.length) { curAr[curAr.length-1] = value } else { curAr.push(value) } } const popVal = function() { return curArr().pop() // Is undefined if array is empty. } const popArr = function() { return vs.pop() } const popTransfer = function() { const actVal = curVal() vs.pop() pushVal(actVal) } function console_log() { if (true) { const json = arguments[0] const path = arguments[1] const ii = arguments[2] const remArgs = Array.prototype.slice.call(arguments, 3) console.log(path2str(ii, path, json), ...remArgs) } } const nttEval = function(tok, json) { // stack.length = 0 // reset // stack.push(tok) traverse(json, evAfter, evBefore) return true // TODO what? } const evBefore = function(json, path, ii) { if (ignore) return // console_log(json, path, ii, 'b') switch (json.t) { case 'any_ref': bAnyRef(json, path, ii) break } // TODO } const evAfter = function(json, path, ii) { if (ignore === json) { ignore = false console_log(json, path, ii, 'IGNORE END') return } else if (ignore) { return } // console_log(json, path, ii, 'a') switch (json.t) { case 'any_ref': aAnyRef(json, path, ii) break } // TODO } const bAnyRef = function(json, path, ii) { console_log(json, path, ii, 'bAnyRef') } const aAnyRef = function(json, path, ii) { console_log(json, path, ii, 'aAnyRef') } setup() return me }