Advertisement
rplantiko

oMeta Core for ABAP

Jan 24th, 2012
688
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ABAP 72.24 KB | None | 0 0
  1. program z_ometa_base.
  2.  
  3. * The core logic of the OMeta/JS 2.0 parser generator
  4. * Made available to ABAP using its built-in JS interpreter
  5.  
  6. * For oMeta, see
  7. * http://tinlizzie.org/ometa/ for oMeta
  8. * Also
  9. * http://ruediger-plantiko.blogspot.com/2010/11/eine-objektorientierte-metasprache.html
  10.  
  11. * I have chosen the report form for easy copy/paste
  12.  
  13. data: go_js type ref to cl_java_script,
  14.       begin of gs_translation,
  15.         source type string,
  16.       end of gs_translation.
  17.  
  18. load-of-program.
  19.   perform _do_on_load.
  20.  
  21. * --- API part ---------------------------------------------------------------------
  22.  
  23. * --- DO_IT
  24. * Execute any JS code with this JS instance
  25. form do_it using iv_source type string
  26.            changing ev_result type string
  27.                     ev_error_code type i.
  28.   ev_result = go_js->evaluate( iv_source ).
  29.   ev_error_code = go_js->last_condition_code.
  30. endform.                    "do_it
  31.  
  32. * --- MATCH
  33. * Matches code against a rule and returns the result
  34. form match using iv_grammar type string
  35.                  iv_rule type string
  36.                  iv_source type string
  37.            changing ev_result type string
  38.                     ev_error_code type i.
  39. * Leider funktionieren Referenzen auf den Stack nicht -> Muss kopieren
  40.   gs_translation-source = iv_source.
  41.  
  42.   perform _match using iv_grammar iv_rule 'trans.source'
  43.                  changing ev_result ev_error_code.
  44.  
  45. endform.                    "match
  46.  
  47. * --- MATCH_LAST_RESULT
  48. * For applying a chain of transformations
  49. form match_last_result using iv_grammar type string
  50.                  iv_rule type string
  51.            changing ev_result type string
  52.                     ev_error_code type i.
  53.  
  54.   perform _match using iv_grammar iv_rule 'transLastResult'
  55.                  changing ev_result ev_error_code.
  56.  
  57. endform.                    "match
  58.  
  59. * --- TRANSLATE
  60. * Build a parser for a given oMeta grammar
  61. form translate using iv_source type string
  62.                changing ev_result type string
  63.                         ev_error_code type i.
  64.   data: lv_result type string.
  65.  
  66.   gs_translation-source = iv_source.
  67.   perform do_it using 'translateCode( trans.source ) '
  68.                 changing ev_result ev_error_code.
  69.   if ev_error_code = 0.
  70. * Ignore the meaningless result which is of type '[Object object]'
  71.     perform do_it using ev_result
  72.                  changing lv_result ev_error_code.
  73.   endif.
  74.  
  75. endform.                    "translate
  76.  
  77. * --- GET_OMETA_JS
  78. * Give back an instance of the oMeta enabled JS interpreter
  79. * Not needed in simpler cases
  80. form get_ometa_js changing eo_js type ref to cl_java_script.
  81.   eo_js = go_js.
  82. endform.                    "get_ometa_js
  83.  
  84. * --- GET_LAST_ERROR
  85. form get_last_error changing ev_text type string.
  86.   ev_text = space.
  87.   if go_js->last_condition_code <> 0.
  88.     ev_text = go_js->last_error_message.
  89.   endif.
  90.  
  91. endform.                    "get_last_error
  92.  
  93.  
  94. * --- BIND (iv_name maybe compound, like 'abap.obj'
  95. form bind using iv_name type string
  96.                 cv_any  type any.
  97.  
  98.   data: lv_obj  type string,
  99.         lv_prop type string.
  100.  
  101.   if iv_name ca '.'.
  102.     split iv_name at '.' into lv_obj lv_prop.
  103.   else.
  104.     lv_prop = iv_name.
  105.   endif.
  106.  
  107.   go_js->bind( exporting name_obj = lv_obj
  108.                          name_prop = lv_prop
  109.                changing  data = cv_any ).
  110.  
  111. endform.                    "bind
  112.  
  113. * --- Private part -------------------------------------------------------
  114.  
  115. form _match using iv_grammar type string
  116.                   iv_rule type string
  117.                   iv_source_symbol type string
  118.            changing ev_result type string
  119.                     ev_error_code type i.
  120.  
  121.   data: lv_result type string,
  122.         lv_matcher type string value
  123.           'transLastResult = #Grammar.matchAll' &
  124.             '(#Source, "#Rule" );'.
  125.  
  126.   replace :
  127.     '#Grammar' in lv_matcher with iv_grammar,
  128.     '#Rule' in lv_matcher with iv_rule,
  129.     '#Source' in lv_matcher with iv_source_symbol.
  130.  
  131.   clear ev_result.
  132.  
  133.   perform do_it using lv_matcher
  134.                 changing ev_result ev_error_code.
  135.  
  136.  
  137. endform.                    "_match
  138.  
  139. *&---------------------------------------------------------------------*
  140. *&      Form  _do_on_load
  141. *&---------------------------------------------------------------------*
  142. *       text
  143. *----------------------------------------------------------------------*
  144. form _do_on_load.
  145.  
  146.   go_js = cl_java_script=>create( ).
  147.   perform bind using 'trans.source' gs_translation-source.
  148. * A global JS variable: the result of the last transformation as JS object
  149.   go_js->evaluate( `var transLastResult = null;` ).
  150.   perform _do_ometa_base.
  151.  
  152. endform.                    "_do_on_load
  153.  
  154. * ---
  155. form _do_ometa_base.
  156.   data: lv_base type string,
  157.         lv_result type string,
  158.         lv_error_code type i.
  159.  
  160.   perform _read_ometa_base changing lv_base.
  161.   perform do_it using lv_base
  162.           changing lv_result lv_error_code.
  163.  
  164. * oMeta base code corrupt?
  165.   assert lv_error_code = 0.
  166.  
  167. endform.                    "do_ometa_base
  168.  
  169. * ---
  170. form _read_ometa_base changing cv_base type string.
  171.   data: lt_code type stringtab,
  172.         lv_code type text72,
  173.         lv_tabix type i.
  174.  
  175.   field-symbols: <lv_code> type string.
  176.  
  177.   read report 'Z_OMETA_BASE' into lt_code.
  178.   find regex '<<<\s*ometa-base' in table lt_code match line lv_tabix.
  179.   assert sy-subrc eq 0.
  180.   add 1 to lv_tabix.
  181.   loop at lt_code into lv_code from lv_tabix.
  182.     concatenate cv_base lv_code+2 into cv_base respecting blanks.
  183.   endloop.
  184.  
  185.   replace all occurrences of '#CRLF#' in cv_base
  186.     with cl_abap_char_utilities=>cr_lf.
  187.  
  188.  
  189. endform.                    "read_ometa_base
  190.  
  191.  
  192. * oMeta-Base consists of these files:
  193. *    'lib.js',
  194. *    'ometa-base.js',
  195. *    'parser.js',
  196. *    'bs-js-compiler.js',
  197. *    'bs-ometa-compiler.js',
  198. *    'bs-ometa-optimizer.js',
  199. *    'bs-ometa-js-compiler.js'.
  200. *  + Definition von translateCode()
  201.  
  202.  
  203. * <<< ometa-base
  204. * #CRLF#// try to use StringBuffer instead of string concatenation to im
  205. * prove performance#CRLF##CRLF#function StringBuffer() {#CRLF#  this.str
  206. * ings = []#CRLF#  for (var idx = 0; idx < arguments.length; idx++)#CRLF
  207. * #    this.nextPutAll(arguments[idx])#CRLF#}#CRLF#StringBuffer.prototyp
  208. * e.nextPutAll = function(s) { this.strings.push(s) }#CRLF#StringBuffer.
  209. * prototype.contents   = function()  { return this.strings.join("") }#CR
  210. * LF#String.prototype.writeStream      = function() { return new StringB
  211. * uffer(this) }#CRLF##CRLF#// make Arrays print themselves sensibly#CRLF
  212. * ##CRLF#Object.prototype.printOn = function(ws) { ws.nextPutAll(this.to
  213. * String()) }#CRLF##CRLF#Array.prototype.toString = function() { var ws
  214. * = "".writeStream(); this.printOn(ws); return ws.contents() }#CRLF#Arra
  215. * y.prototype.printOn = function(ws) {#CRLF#  ws.nextPutAll("[")#CRLF#
  216. * for (var idx = 0; idx < this.length; idx++) {#CRLF#    if (idx > 0)#CR
  217. * LF#      ws.nextPutAll(", ")#CRLF#    this[idx].printOn(ws)#CRLF#  }#C
  218. * RLF#  ws.nextPutAll("]")#CRLF#}#CRLF##CRLF#// delegation#CRLF##CRLF#Ob
  219. * ject.prototype.delegated = function(props) {#CRLF#  var f = function()
  220. *  { }#CRLF#  f.prototype = this#CRLF#  var r = new f()#CRLF#  for (var
  221. * p in props)#CRLF#    if (props.hasOwnProperty(p))#CRLF#      r[p] = pr
  222. * ops[p]#CRLF#  return r#CRLF#}#CRLF##CRLF#// some reflective stuff#CRLF
  223. * ##CRLF#Object.prototype.ownPropertyNames = function() {#CRLF#  var r =
  224. *  []#CRLF#  for (name in this)#CRLF#    if (this.hasOwnProperty(name))#
  225. * CRLF#      r.push(name)#CRLF#  return r#CRLF#}#CRLF##CRLF#Object.proto
  226. * type.hasProperty = function(p) { return this[p] != undefined }#CRLF##C
  227. * RLF#Object.prototype.isNumber    = function() { return false }#CRLF#Nu
  228. * mber.prototype.isNumber    = function() { return true }#CRLF##CRLF#Obj
  229. * ect.prototype.isString    = function() { return false }#CRLF#String.pr
  230. * ototype.isString    = function() { return true }#CRLF##CRLF#Object.pro
  231. * totype.isCharacter = function() { return false }#CRLF##CRLF#String.pro
  232. * totype.isCharacter = function() { return this.length == 1 }#CRLF#Strin
  233. * g.prototype.isSpace     = function() { return this.isCharacter() && th
  234. * is.charCodeAt(0) <= 32   }#CRLF#String.prototype.isDigit     = functio
  235. * n() { return this.isCharacter() && this >= "0" && this <= "9" }#CRLF#S
  236. * tring.prototype.isLower     = function() { return this.isCharacter() &
  237. * & this >= "a" && this <= "z" }#CRLF#String.prototype.isUpper     = fun
  238. * ction() { return this.isCharacter() && this >= "A" && this <= "Z" }#CR
  239. * LF##CRLF#String.prototype.digitValue  = function() { return this.charC
  240. * odeAt(0) - "0".charCodeAt(0) }#CRLF##CRLF#Object.prototype.isSequencea
  241. * ble = false#CRLF#Array.prototype.isSequenceable  = true#CRLF#String.pr
  242. * ototype.isSequenceable = true#CRLF##CRLF#// some functional programmin
  243. * g stuff#CRLF##CRLF#Array.prototype.map = function(f) {#CRLF#  var r =
  244. * []#CRLF#  for (var idx = 0; idx < this.length; idx++)#CRLF#    r[idx]
  245. * = f(this[idx])#CRLF#  return r#CRLF#}#CRLF##CRLF#Array.prototype.reduc
  246. * e = function(f, z) {#CRLF#  var r = z#CRLF#  for (var idx = 0; idx < t
  247. * his.length; idx++)#CRLF#    r = f(r, this[idx])#CRLF#  return r#CRLF#}
  248. * #CRLF##CRLF#Array.prototype.delimWith = function(d) {#CRLF#  return th
  249. * is.reduce(#CRLF#    function(xs, x) {#CRLF#      if (xs.length > 0)#CR
  250. * LF#        xs.push(d)#CRLF#      xs.push(x)#CRLF#      return xs#CRLF#
  251. *     },#CRLF#   [])#CRLF#}#CRLF##CRLF#// Squeak's ReadStream, kind of#C
  252. * RLF##CRLF#function ReadStream(anArrayOrString) {#CRLF#  this.src = anA
  253. * rrayOrString#CRLF#  this.pos = 0#CRLF#}#CRLF#ReadStream.prototype.atEn
  254. * d = function() { return this.pos >= this.src.length }#CRLF#ReadStream.
  255. * prototype.next  = function() { return this.src.at(this.pos++) }#CRLF##
  256. * CRLF#// escape characters#CRLF##CRLF#escapeStringFor = new Object()#CR
  257. * LF#for (var c = 0; c < 256; c++)#CRLF#  escapeStringFor[c] = String.fr
  258. * omCharCode(c)#CRLF#escapeStringFor["\\".charCodeAt(0)] = "\\\\"#CRLF#e
  259. * scapeStringFor['"'.charCodeAt(0)]  = '\\"'#CRLF#escapeStringFor["'".ch
  260. * arCodeAt(0)]  = "\\'"#CRLF#escapeStringFor["\r".charCodeAt(0)] = "\\r"
  261. * #CRLF#escapeStringFor["\n".charCodeAt(0)] = "\\n"#CRLF#escapeStringFor
  262. * ["\t".charCodeAt(0)] = "\\t"#CRLF#escapeChar = function(c) {#CRLF#  va
  263. * r charCode = c.charCodeAt(0)#CRLF#  return charCode > 255 ? String.fro
  264. * mCharCode(charCode) : escapeStringFor[charCode]#CRLF#}#CRLF##CRLF#func
  265. * tion unescape(s) {#CRLF#  if (s[0] == '\\')#CRLF#    switch (s[1]) {#C
  266. * RLF#      case '\\': return '\\'#CRLF#      case 'r':  return '\r'#CRL
  267. * F#      case 'n':  return '\n'#CRLF#      case 't':  return '\t'#CRLF#
  268. *       default:   return s[1]#CRLF#    }#CRLF#  else#CRLF#    return s#
  269. * CRLF#}#CRLF##CRLF#String.prototype.toProgramString = function() {#CRLF
  270. * #  var ws = "\"".writeStream()#CRLF#  for (var idx = 0; idx < this.len
  271. * gth; idx++)#CRLF#    ws.nextPutAll(escapeChar(this[idx]))#CRLF#  ws.ne
  272. * xtPutAll("\"")#CRLF#  return ws.contents()#CRLF#}#CRLF##CRLF#// C-styl
  273. * e tempnam function#CRLF##CRLF#function tempnam(s) { return (s ? s : "_
  274. * tmpnam_") + tempnam.n++ }#CRLF#tempnam.n = 0#CRLF##CRLF##CRLF#// Copyr
  275. * ight (c) 2007, 2008 Alessandro Warth <awarth@cs.ucla.edu>#CRLF##CRLF#/
  276. * *#CRLF#  new syntax:#CRLF#    #foo  match the string object 'foo' (shou
  277. * ld also be accepted in JS)#CRLF#    'abc' match the string object 'abc
  278. * '#CRLF#    'c'    match the string object 'c'#CRLF#    ``abc''  match the
  279. *  sequence of string objects 'a', 'b', 'c'#CRLF#    "abc"  token('abc')#
  280. * CRLF#    [1 2 3]  match the array object [1, 2, 3]#CRLF#    foo(bar)  ap
  281. * ply rule foo with argument bar#CRLF#    -> ...  do semantic actions in
  282. * JS (no more ST). allow multiple statements, but no declarations#CRLF#
  283. *   probably don't even need {}s, because newlines can terminate it!#CRLF
  284. * #*/#CRLF##CRLF#/*#CRLF#// ometa M {#CRLF#//   number = number:n digit:
  285. * d -> { n * 10 + d.digitValue() }#CRLF#//          | digit:d          -
  286. * > { d.digitValue() }.#CRLF#// }#CRLF##CRLF#try {#CRLF#  M = OMeta.dele
  287. * gated({#CRLF#    number: function() {#CRLF#      var $elf = this#CRLF#
  288. *       return $elf._or(#CRLF#        function() {#CRLF#          var n,
  289. *  d#CRLF#          n = $elf._apply("number")#CRLF#          d = $elf._a
  290. * pply("digit")#CRLF#          return n * 10 + d.digitValue()#CRLF#
  291. *    },#CRLF#        function() {#CRLF#          var d#CRLF#          d
  292. * = $elf._apply("digit")#CRLF#          return d.digitValue()#CRLF#
  293. *    }#CRLF#      )#CRLF#    }#CRLF#  })#CRLF#  M.matchAll("123456789",
  294. * "number")#CRLF#} catch (f) { alert(f) }#CRLF#*/#CRLF##CRLF#// the fail
  295. * ure exception#CRLF##CRLF#fail = { toString: function() { return "match
  296. *  failed" } }#CRLF##CRLF#// streams and memoization#CRLF##CRLF#function
  297. *  OMInputStream(hd, tl) {#CRLF#  this.memo = { }#CRLF#  this.hd   = hd#
  298. * CRLF#  this.tl   = tl#CRLF#}#CRLF#OMInputStream.prototype.head = funct
  299. * ion() { return this.hd }#CRLF#OMInputStream.prototype.tail = function(
  300. * ) { return this.tl }#CRLF##CRLF#function OMInputStreamEnd() { this.mem
  301. * o = { } }#CRLF#OMInputStreamEnd.prototype.head = function() { throw fa
  302. * il }#CRLF#OMInputStreamEnd.prototype.tail = function() { throw fail }#
  303. * CRLF##CRLF#Array.prototype.toOMInputStream  = function() { return make
  304. * ArrayOMInputStream(this, 0) }#CRLF#//String.prototype.toOMInputStream
  305. * = Array.prototype.toOMInputStream#CRLF#String.prototype.toOMInputStrea
  306. * m = ("x"[0] == 'x') ? Array.prototype.toOMInputStream : function() { r
  307. * eturn makeArrayOMInputStream(this.split(''), 0)  }#CRLF##CRLF#function
  308. *  makeArrayOMInputStream(arr, idx) { return idx < arr.length ? new Arra
  309. * yOMInputStream(arr, idx) : new OMInputStreamEnd() }#CRLF##CRLF#functio
  310. * n ArrayOMInputStream(arr, idx) {#CRLF#  this.memo = { }#CRLF#  this.ar
  311. * r  = arr#CRLF#  this.idx  = idx#CRLF#  this.hd   = arr[idx]#CRLF#}#CRL
  312. * F#ArrayOMInputStream.prototype.head = function() { return this.hd }#CR
  313. * LF#ArrayOMInputStream.prototype.tail = function() {#CRLF#  if (this.tl
  314. *  == undefined)#CRLF#    this.tl = makeArrayOMInputStream(this.arr, thi
  315. * s.idx + 1)#CRLF#  return this.tl#CRLF#}#CRLF##CRLF#function makeOMInpu
  316. * tStreamProxy(target) {#CRLF#  return target.delegated({#CRLF#    memo:
  317. *    { },#CRLF#    target: target,#CRLF#    tail:   function() { return
  318. * makeOMInputStreamProxy(target.tail()) }#CRLF#  })#CRLF#}#CRLF##CRLF#//
  319. *  Failer (i.e., that which makes things fail) is used to detect (direct
  320. * ) left recursion and memoize failures#CRLF##CRLF#function Failer() { }
  321. * #CRLF#Failer.prototype.used = false#CRLF##CRLF#// the OMeta "class" an
  322. * d basic functionality#CRLF##CRLF#OMeta = {#CRLF#  _apply: function(rul
  323. * e) {#CRLF#    var memoRec = this.input.memo[rule]#CRLF#    if (memoRec
  324. *  == undefined) {#CRLF#      var origInput = this.input,#CRLF#
  325. *  failer    = new Failer()#CRLF#      this.input.memo[rule] = failer#CR
  326. * LF#      this.input.memo[rule] = memoRec = {ans: this[rule].apply(this
  327. * ), nextInput: this.input}#CRLF#      if (failer.used) {#CRLF#        v
  328. * ar sentinel = this.input#CRLF#        while (true) {#CRLF#          tr
  329. * y {#CRLF#            this.input = origInput#CRLF#            var ans =
  330. *  this[rule].apply(this)#CRLF#            if (this.input == sentinel)#C
  331. * RLF#              throw fail#CRLF#            memoRec.ans       = ans#
  332. * CRLF#            memoRec.nextInput = this.input#CRLF#          }#CRLF#
  333. *           catch (f) {#CRLF#            if (f != fail)#CRLF#
  334. *    throw f#CRLF#            break#CRLF#          }#CRLF#        }#CRLF
  335. * #      }#CRLF#    }#CRLF#    else if (memoRec instanceof Failer) {#CRL
  336. * F#      memoRec.used = true#CRLF#      throw fail#CRLF#    }#CRLF#
  337. * this.input = memoRec.nextInput#CRLF#    return memoRec.ans#CRLF#  },#C
  338. * RLF##CRLF#  // note: _applyWithArgs and _superApplyWithArgs are not me
  339. * moized, so they can't be left-recursive#CRLF#  _applyWithArgs: functio
  340. * n(rule) {#CRLF#    for (var idx = arguments.length - 1; idx > 0; idx--
  341. * )#CRLF#      this.input = new OMInputStream(arguments[idx], this.input
  342. * )#CRLF#    return this[rule].apply(this)#CRLF#  },#CRLF#  _superApplyW
  343. * ithArgs: function($elf, rule) {#CRLF#    for (var idx = arguments.leng
  344. * th - 1; idx > 1; idx--)#CRLF#      $elf.input = new OMInputStream(argu
  345. * ments[idx], $elf.input)#CRLF#    return this[rule].apply($elf)#CRLF#
  346. * },#CRLF#  _pred: function(b) {#CRLF#    if (b)#CRLF#      return true#
  347. * CRLF#    throw fail#CRLF#  },#CRLF#  _not: function(x) {#CRLF#    var
  348. * origInput = this.input#CRLF#    try { x() }#CRLF#    catch (f) {#CRLF#
  349. *       if (f != fail)#CRLF#        throw f#CRLF#      this.input = orig
  350. * Input#CRLF#      return true#CRLF#    }#CRLF#    throw fail#CRLF#  },#
  351. * CRLF#  _lookahead: function(x) {#CRLF#    var origInput = this.input,#
  352. * CRLF#        r        = x()#CRLF#    this.input = origInput#CRLF#    r
  353. * eturn r#CRLF#  },#CRLF#  _or: function() {#CRLF#    var origInput = th
  354. * is.input#CRLF#    for (var idx = 0; idx < arguments.length; idx++)#CRL
  355. * F#      try { this.input = origInput; return arguments[idx]() }#CRLF#
  356. *      catch (f) {#CRLF#        if (f != fail)#CRLF#          throw f#CR
  357. * LF#      }#CRLF#    throw fail#CRLF#  },#CRLF#  _many: function(x) {#C
  358. * RLF#    var ans = arguments[1] != undefined ? [arguments[1]] : []#CRLF
  359. * #    while (true) {#CRLF#      var origInput = this.input#CRLF#      t
  360. * ry { ans.push(x()) }#CRLF#      catch (f) {#CRLF#        if (f != fail
  361. * )#CRLF#          throw f#CRLF#        this.input = origInput#CRLF#
  362. *     break#CRLF#      }#CRLF#    }#CRLF#    return ans#CRLF#  },#CRLF#
  363. *  _many1: function(x) { return this._many(x, x()) },#CRLF#  _form: func
  364. * tion(x) {#CRLF#    var v = this._apply("anything")#CRLF#    if (!v.isS
  365. * equenceable)#CRLF#      throw fail#CRLF#    var origInput = this.input
  366. * #CRLF#    this.input = makeArrayOMInputStream(v, 0)#CRLF#    var r = x
  367. * ()#CRLF#    this._apply("end")#CRLF#    this.input = origInput#CRLF#
  368. *   return v#CRLF#  },#CRLF##CRLF#  // some basic rules#CRLF#  anything:
  369. *  function() {#CRLF#    var r = this.input.head()#CRLF#    this.input =
  370. *  this.input.tail()#CRLF#    return r#CRLF#  },#CRLF#  end: function()
  371. * {#CRLF#    var $elf = this#CRLF#    return this._not(function() { retu
  372. * rn $elf._apply("anything") })#CRLF#  },#CRLF#  pos: function() {#CRLF#
  373. *     return this.input.idx#CRLF#  },#CRLF#  empty: function() { return
  374. * true },#CRLF#  apply: function() {#CRLF#    var r = this._apply("anyth
  375. * ing")#CRLF#    return this._apply(r)#CRLF#  },#CRLF#  foreign: functio
  376. * n() {#CRLF#    var g   = this._apply("anything"),#CRLF#        r   = t
  377. * his._apply("anything"),#CRLF#        gi  = g.delegated({input: makeOMI
  378. * nputStreamProxy(this.input)})#CRLF#    var ans = gi._apply(r)#CRLF#
  379. *  this.input = gi.input.target#CRLF#    return ans#CRLF#  },#CRLF##CRLF
  380. * #  //  some useful "derived" rules#CRLF#  exactly: function() {#CRLF#
  381. *    var wanted = this._apply("anything")#CRLF#    if (wanted === this._
  382. * apply("anything"))#CRLF#      return wanted#CRLF#    throw fail#CRLF#
  383. *  },#CRLF#  "true": function() {#CRLF#    var r = this._apply("anything
  384. * ")#CRLF#    this._pred(r == true)#CRLF#    return r#CRLF#  },#CRLF#  "
  385. * false": function() {#CRLF#    var r = this._apply("anything")#CRLF#
  386. *  this._pred(r == false)#CRLF#    return r#CRLF#  },#CRLF#  "undefined"
  387. * : function() {#CRLF#    var r = this._apply("anything")#CRLF#    this.
  388. * _pred(r == undefined)#CRLF#    return r#CRLF#  },#CRLF#  number: funct
  389. * ion() {#CRLF#    var r = this._apply("anything")#CRLF#    this._pred(r
  390. * .isNumber())#CRLF#    return r#CRLF#  },#CRLF#  string: function() {#C
  391. * RLF#    var r = this._apply("anything")#CRLF#    this._pred(r.isString
  392. * ())#CRLF#    return r#CRLF#  },#CRLF#  "char": function() {#CRLF#    v
  393. * ar r = this._apply("anything")#CRLF#    this._pred(r.isCharacter())#CR
  394. * LF#    return r#CRLF#  },#CRLF#  space: function() {#CRLF#    var r =
  395. * this._apply("char")#CRLF#    this._pred(r.charCodeAt(0) <= 32)#CRLF#
  396. *   return r#CRLF#  },#CRLF#  spaces: function() {#CRLF#    var $elf = t
  397. * his#CRLF#    return this._many(function() { return $elf._apply("space"
  398. * ) })#CRLF#  },#CRLF#  digit: function() {#CRLF#    var r = this._apply
  399. * ("char")#CRLF#    this._pred(r.isDigit())#CRLF#    return r#CRLF#  },#
  400. * CRLF#  lower: function() {#CRLF#    var r = this._apply("char")#CRLF#
  401. *    this._pred(r.isLower())#CRLF#    return r#CRLF#  },#CRLF#  upper: f
  402. * unction() {#CRLF#    var r = this._apply("char")#CRLF#    this._pred(r
  403. * .isUpper())#CRLF#    return r#CRLF#  },#CRLF#  letter: function() {#CR
  404. * LF#    var $elf = this#CRLF#    return this._or(function() { return $e
  405. * lf._apply("lower") },#CRLF#                    function() { return $el
  406. * f._apply("upper") })#CRLF#  },#CRLF#  letterOrDigit: function() {#CRLF
  407. * #    var $elf = this#CRLF#    return this._or(function() { return $elf
  408. * ._apply("letter") },#CRLF#                    function() { return $elf
  409. * ._apply("digit")  })#CRLF#  },#CRLF#  firstAndRest: function()  {#CRLF
  410. * #    var $elf  = this,#CRLF#        first = this._apply("anything"),#C
  411. * RLF#        rest  = this._apply("anything")#CRLF#     return this._man
  412. * y(function() { return $elf._apply(rest) }, this._apply(first))#CRLF#
  413. * },#CRLF#  seq: function() {#CRLF#    var xs = this._apply("anything")#
  414. * CRLF#    for (var idx = 0; idx < xs.length; idx++)#CRLF#      this._ap
  415. * plyWithArgs("exactly", xs[idx])#CRLF#    return xs#CRLF#  },#CRLF#  no
  416. * tLast: function() {#CRLF#    var $elf = this,#CRLF#        rule = this
  417. * ._apply("anything"),#CRLF#        r    = this._apply(rule)#CRLF#    th
  418. * is._lookahead(function() { return $elf._apply(rule) })#CRLF#    return
  419. *  r#CRLF#  },#CRLF##CRLF#  initialize: function() { },#CRLF#  // match
  420. * and matchAll are a grammar's "public interface"#CRLF#  _genericMatch:
  421. * function(input, rule, args, matchFailed) {#CRLF#    if (args == undefi
  422. * ned)#CRLF#      args = []#CRLF#    var realArgs = [rule]#CRLF#    for
  423. * (var idx = 0; idx < args.length; idx++)#CRLF#      realArgs.push(args[
  424. * idx])#CRLF#    var m = this.delegated({input: input})#CRLF#    m.initi
  425. * alize()#CRLF#    try { return realArgs.length == 1 ? m._apply.call(m,
  426. * realArgs[0]) : m._applyWithArgs.apply(m, realArgs) }#CRLF#    catch (f
  427. * ) {#CRLF#      if (f == fail && matchFailed != undefined) {#CRLF#
  428. *    var input = m.input#CRLF#        if (input.idx != undefined) {#CRLF
  429. * #          while (input.tl != undefined && input.tl.idx != undefined)#
  430. * CRLF#            input = input.tl#CRLF#          input.idx--#CRLF#
  431. *     }#CRLF#        return matchFailed(m, input.idx)#CRLF#      }#CRLF#
  432. *       throw f#CRLF#    }#CRLF#  },#CRLF#  match: function(obj, rule, a
  433. * rgs, matchFailed) {#CRLF#    return this._genericMatch([obj].toOMInput
  434. * Stream(),    rule, args, matchFailed)#CRLF#  },#CRLF#  matchAll: funct
  435. * ion(listyObj, rule, args, matchFailed) {#CRLF#    return this._generic
  436. * Match(listyObj.toOMInputStream(), rule, args, matchFailed)#CRLF#  }#CR
  437. * LF#}#CRLF##CRLF##CRLF#// Copyright (c) 2007, 2008 Alessandro Warth <aw
  438. * arth@cs.ucla.edu>#CRLF#Parser = OMeta.delegated({#CRLF#  listOf: funct
  439. * ion() {#CRLF#    var $elf  = this,#CRLF#        rule  = this._apply("a
  440. * nything"),#CRLF#        delim = this._apply("anything")#CRLF#    retur
  441. * n this._or(function() {#CRLF#                      var r = $elf._apply
  442. * (rule)#CRLF#                      return $elf._many(function() {#CRLF#
  443. *                                           $elf._applyWithArgs("token",
  444. *  delim)#CRLF#                                          return $elf._ap
  445. * ply(rule)#CRLF#                                        },#CRLF#
  446. *                                  r)#CRLF#                    },#CRLF#
  447. *                    function() { return [] })#CRLF#  },#CRLF#  token: f
  448. * unction() {#CRLF#    var cs = this._apply("anything")#CRLF#    this._a
  449. * pply("spaces")#CRLF#    return this._applyWithArgs("seq", cs)#CRLF#  }
  450. * #CRLF#})#CRLF##CRLF##CRLF#{BSJSParser=Parser.delegated({"fromTo":funct
  451. * ion(){var $elf=this,x,y;return (function(){x=$elf._apply("anything");y
  452. * =$elf._apply("anything");$elf._applyWithArgs("seq",x);#CRLF#$elf._many
  453. * (function(){#CRLF#return (function(){$elf._not(function(){#CRLF#return
  454. *  $elf._applyWithArgs("seq",y)});return $elf._apply("char")})()});retur
  455. * n $elf._applyWithArgs("seq",y)})()},"space":function(){var $elf=this;r
  456. * eturn $elf._or((function(){#CRLF#return Parser._superApplyWithArgs($el
  457. * f,"space")}),(function(){#CRLF#return $elf._applyWithArgs("fromTo","//
  458. * ","\n")}),(function(){#CRLF#return $elf._applyWithArgs("fromTo","/*","
  459. * */")}))},"nameFirst":function(){var $elf=this;return $elf._or((functio
  460. * n(){#CRLF#return $elf._apply("letter")}),(function(){#CRLF#return $elf
  461. * ._applyWithArgs("exactly","$")}),(function(){#CRLF#return $elf._applyW
  462. * ithArgs("exactly","_")}))},"nameRest":function(){var $elf=this;return
  463. * $elf._or((function(){#CRLF#return $elf._apply("nameFirst")}),(function
  464. * (){#CRLF#return $elf._apply("digit")}))},"iName":function(){var $elf=t
  465. * his,r;#CRLF#          return (function(){r=$elf._applyWithArgs("firstA
  466. * ndRest","nameFirst","nameRest");return r.join("")})()},"isKeyword":fun
  467. * ction(){var $elf=this,x;return (function(){x=$elf._apply("anything");r
  468. * eturn $elf._pred(BSJSParser._isKeyword(x))})()},"name":function(){var
  469. * $elf=this,n;return (function(){n=$elf._apply("iName");$elf._not(functi
  470. * on(){#CRLF#return $elf._applyWithArgs("isKeyword",n)});return ["name",
  471. * ((n == "self")?"$elf":n)]})()},"keyword":function(){var $elf=this,k;re
  472. * turn (function(){k=$elf._apply("iName");$elf._applyWithArgs("isKeyword
  473. * ",k);return [k,k]})()},"number":function(){var $elf=this,ws,fs;return
  474. * (function(){ws=$elf._many1(function(){#CRLF#return $elf._apply("digit"
  475. * )});fs=$elf._or((function(){#CRLF#return (function(){$elf._applyWithAr
  476. * gs("exactly",".");return $elf._many1(function(){#CRLF#return $elf._app
  477. * ly("digit")})})()}),(function(){#CRLF#return (function(){$elf._apply("
  478. * empty");return []})()}));return ["number",parseFloat(((ws.join("") + "
  479. * .") + fs.join("")))]})()},"escapeChar":function(){var $elf=this,c;retu
  480. * rn (function(){$elf._applyWithArgs("exactly","\\");c=$elf._apply("char
  481. * ");return unescape(("\\" + c))})()},"str":function(){var $elf=this,cs,
  482. * cs,cs,n;return $elf._or((function(){#CRLF#                    return (
  483. * function(){$elf._applyWithArgs("seq","\"\"\"");cs=$elf._many(function(
  484. * ){#CRLF#return $elf._or((function(){#CRLF#return $elf._apply("escapeCh
  485. * ar")}),(function(){#CRLF#return (function(){$elf._not(function(){#CRLF
  486. * #return $elf._applyWithArgs("seq","\"\"\"")});return $elf._apply("char
  487. * ")})()}))});$elf._applyWithArgs("seq","\"\"\"");return ["string",cs.jo
  488. * in("")]})()}),(function(){#CRLF#return (function(){$elf._applyWithArgs
  489. * ("exactly","\'");cs=$elf._many(function(){#CRLF#return $elf._or((funct
  490. * ion(){#CRLF#return $elf._apply("escapeChar")}),(function(){#CRLF#retur
  491. * n (function(){$elf._not(function(){#CRLF#return $elf._applyWithArgs("e
  492. * xactly","\'")});return $elf._apply("char")})()}))});$elf._applyWithArg
  493. * s("exactly","\'");return ["string",cs.join("")]})()}),(function(){#CRL
  494. * F#return (function(){$elf._applyWithArgs("exactly","\"");cs=$elf._many
  495. * (function(){#CRLF#return $elf._or((function(){#CRLF#return $elf._apply
  496. * ("escapeChar")}),(function(){#CRLF#return (function(){$elf._not(functi
  497. * on(){#CRLF#return $elf._applyWithArgs("exactly","\"")});return $elf._a
  498. * pply("char")})()}))});$elf._applyWithArgs("exactly","\"");return ["str
  499. * ing",cs.join("")]})()}),(function(){#CRLF#return (function(){$elf._or(
  500. * (function(){#CRLF#return $elf._applyWithArgs("exactly","#")}),(functio
  501. * n(){#CRLF#return $elf._applyWithArgs("exactly","`")}));n=$elf._apply("
  502. * iName");return ["string",n]})()}))},"special":function(){var $elf=this
  503. * ,s;return (function(){s=$elf._or((function(){#CRLF#return $elf._applyW
  504. * ithArgs("exactly","(")}),(function(){#CRLF#return $elf._applyWithArgs(
  505. * "exactly",")")}),(function(){#CRLF#return $elf._applyWithArgs("exactly
  506. * ","{")}),(function(){#CRLF#return $elf._applyWithArgs("exactly","}")})
  507. * ,(function(){#CRLF#return $elf._applyWithArgs("exactly","[")}),(functi
  508. * on(){#CRLF#return $elf._applyWithArgs("exactly","]")}),(function(){#CR
  509. * LF#return $elf._applyWithArgs("exactly",",")}),(function(){#CRLF#retur
  510. * n $elf._applyWithArgs("exactly",";")}),(function(){#CRLF#return $elf._
  511. * applyWithArgs("exactly","?")}),(function(){#CRLF#return $elf._applyWit
  512. * hArgs("exactly",":")}),(function(){#CRLF#return $elf._applyWithArgs("s
  513. * eq","!==")}),(function(){#CRLF#return $elf._applyWithArgs("seq","!=")}
  514. * ),(function(){#CRLF#return $elf._applyWithArgs("seq","===")}),(functio
  515. * n(){#CRLF#return $elf._applyWithArgs("seq","==")}),(function(){#CRLF#r
  516. * eturn $elf._applyWithArgs("seq","=")}),(function(){#CRLF#return $elf._
  517. * applyWithArgs("seq",">=")}),(function(){#CRLF#return $elf._applyWithAr
  518. * gs("exactly",">")}),(function(){#CRLF#return $elf._applyWithArgs("seq"
  519. * ,"<=")}),(function(){#CRLF#return $elf._applyWithArgs("exactly","<")})
  520. * ,(function(){#CRLF#return $elf._applyWithArgs("seq","++")}),(function(
  521. * ){#CRLF#return $elf._applyWithArgs("seq","+=")}),(function(){#CRLF#ret
  522. * urn $elf._applyWithArgs("exactly","+")}),(function(){#CRLF#return $elf
  523. * ._applyWithArgs("seq","--")}),(function(){#CRLF#return $elf._applyWith
  524. * Args("seq","-=")}),(function(){#CRLF#return $elf._applyWithArgs("exact
  525. * ly","-")}),(function(){#CRLF#return $elf._applyWithArgs("seq","*=")}),
  526. * (function(){#CRLF#return $elf._applyWithArgs("exactly","*")}),(functio
  527. * n(){#CRLF#return $elf._applyWithArgs("seq","/=")}),(function(){#CRLF#r
  528. * eturn $elf._applyWithArgs("exactly","/")}),(function(){#CRLF#return $e
  529. * lf._applyWithArgs("seq","%=")}),(function(){#CRLF#return $elf._applyWi
  530. * thArgs("exactly","%")}),(function(){#CRLF#return $elf._applyWithArgs("
  531. * seq","&&=")}),(function(){#CRLF#return $elf._applyWithArgs("seq","&&")
  532. * }),(function(){#CRLF#return $elf._applyWithArgs("seq","||=")}),(functi
  533. * on(){#CRLF#return $elf._applyWithArgs("seq","||")}),(function(){#CRLF#
  534. * return $elf._applyWithArgs("exactly",".")}),(function(){#CRLF#return $
  535. * elf._applyWithArgs("exactly","!")}));#CRLF#                    return
  536. * [s,s]})()},"tok":function(){var $elf=this;return (function(){$elf._app
  537. * ly("spaces");return $elf._or((function(){#CRLF#return $elf._apply("nam
  538. * e")}),(function(){#CRLF#return $elf._apply("keyword")}),(function(){#C
  539. * RLF#return $elf._apply("number")}),(function(){#CRLF#return $elf._appl
  540. * y("str")}),(function(){#CRLF#return $elf._apply("special")}))})()},"to
  541. * ks":function(){var $elf=this,ts;return (function(){ts=$elf._many(funct
  542. * ion(){#CRLF#return $elf._apply("token")});$elf._apply("spaces");$elf._
  543. * apply("end");return ts})()},"token":function(){var $elf=this,tt,t;retu
  544. * rn (function(){tt=$elf._apply("anything");t=$elf._apply("tok");$elf._p
  545. * red((t[(0)] == tt));return t[(1)]})()},"spacesNoNl":function(){var $el
  546. * f=this;return $elf._many(function(){#CRLF#return (function(){$elf._not
  547. * (function(){#CRLF#return $elf._applyWithArgs("exactly","\n")});return
  548. * $elf._apply("space")})()})},"expr":function(){var $elf=this,e,t,f,rhs,
  549. * rhs,rhs,rhs,rhs,rhs,rhs,rhs;return (function(){e=$elf._apply("orExpr")
  550. * ;return $elf._or((function(){#CRLF#return (function(){$elf._applyWithA
  551. * rgs("token","?");t=$elf._apply("expr");$elf._applyWithArgs("token",":"
  552. * );f=$elf._apply("expr");return ["condExpr",e,t,f]})()}),(function(){#C
  553. * RLF#return (function(){$elf._applyWithArgs("token","=");rhs=$elf._appl
  554. * y("expr");return ["set",e,rhs]})()}),(function(){#CRLF#return (functio
  555. * n(){$elf._applyWithArgs("token","+=");rhs=$elf._apply("expr");return [
  556. * "mset",e,"+",rhs]})()}),(function(){#CRLF#return (function(){$elf._app
  557. * lyWithArgs("token","-=");rhs=$elf._apply("expr");return ["mset",e,"-",
  558. * rhs]})()}),(function(){#CRLF#return (function(){$elf._applyWithArgs("t
  559. * oken","*=");rhs=$elf._apply("expr");return ["mset",e,"*",rhs]})()}),(f
  560. * unction(){#CRLF#return (function(){$elf._applyWithArgs("token","/=");r
  561. * hs=$elf._apply("expr");return ["mset",e,"/",rhs]})()}),(function(){#CR
  562. * LF#return (function(){$elf._applyWithArgs("token","%=");rhs=$elf._appl
  563. * y("expr");return ["mset",e,"%",rhs]})()}),(function(){#CRLF#return (fu
  564. * nction(){$elf._applyWithArgs("token","&&=");rhs=$elf._apply("expr");re
  565. * turn ["mset",e,"&&",rhs]})()}),(function(){#CRLF#return (function(){$e
  566. * lf._applyWithArgs("token","||=");rhs=$elf._apply("expr");return ["mset
  567. * ",e,"||",rhs]})()}),(function(){#CRLF#return (function(){$elf._apply("
  568. * empty");return e})()}))})()},"orExpr":function(){var $elf=this,x,y;ret
  569. * urn $elf._or((function(){#CRLF#return (function(){x=$elf._apply("orExp
  570. * r");$elf._applyWithArgs("token","||");y=$elf._apply("andExpr");return
  571. * ["binop","||",x,y]})()}),(function(){#CRLF#return $elf._apply("andExpr
  572. * ")}))},"andExpr":function(){var $elf=this,x,y;return $elf._or((functio
  573. * n(){#CRLF#                    return (function(){x=$elf._apply("andExp
  574. * r");$elf._applyWithArgs("token","&&");y=$elf._apply("eqExpr");return [
  575. * "binop","&&",x,y]})()}),(function(){#CRLF#return $elf._apply("eqExpr")
  576. * }))},"eqExpr":function(){var $elf=this,x,y,y,y,y;return $elf._or((func
  577. * tion(){#CRLF#return (function(){x=$elf._apply("eqExpr");return $elf._o
  578. * r((function(){#CRLF#return (function(){$elf._applyWithArgs("token","==
  579. * ");y=$elf._apply("relExpr");return ["binop","==",x,y]})()}),(function(
  580. * ){#CRLF#return (function(){$elf._applyWithArgs("token","!=");y=$elf._a
  581. * pply("relExpr");return ["binop","!=",x,y]})()}),(function(){#CRLF#retu
  582. * rn (function(){$elf._applyWithArgs("token","===");y=$elf._apply("relEx
  583. * pr");return ["binop","===",x,y]})()}),(function(){#CRLF#return (functi
  584. * on(){$elf._applyWithArgs("token","!==");y=$elf._apply("relExpr");retur
  585. * n ["binop","!==",x,y]})()}))})()}),(function(){#CRLF#return $elf._appl
  586. * y("relExpr")}))},"relExpr":function(){var $elf=this,x,y,y,y,y,y;return
  587. *  $elf._or((function(){#CRLF#return (function(){x=$elf._apply("relExpr"
  588. * );return $elf._or((function(){#CRLF#return (function(){$elf._applyWith
  589. * Args("token",">");y=$elf._apply("addExpr");return ["binop",">",x,y]})(
  590. * )}),(function(){#CRLF#return (function(){$elf._applyWithArgs("token","
  591. * >=");y=$elf._apply("addExpr");return ["binop",">=",x,y]})()}),(functio
  592. * n(){#CRLF#return (function(){$elf._applyWithArgs("token","<");y=$elf._
  593. * apply("addExpr");return ["binop","<",x,y]})()}),(function(){#CRLF#retu
  594. * rn (function(){$elf._applyWithArgs("token","<=");y=$elf._apply("addExp
  595. * r");return ["binop","<=",x,y]})()}),(function(){#CRLF#return (function
  596. * (){$elf._applyWithArgs("token","instanceof");y=$elf._apply("addExpr");
  597. * return ["binop","instanceof",x,y]})()}))})()}),(function(){#CRLF#retur
  598. * n $elf._apply("addExpr")}))},"addExpr":function(){var $elf=this,x,y,x,
  599. * y;return $elf._or((function(){#CRLF#return (function(){x=$elf._apply("
  600. * addExpr");$elf._applyWithArgs("token","+");y=$elf._apply("mulExpr");re
  601. * turn ["binop","+",x,y]})()}),(function(){#CRLF#return (function(){x=$e
  602. * lf._apply("addExpr");$elf._applyWithArgs("token","-");y=$elf._apply("m
  603. * ulExpr");return ["binop","-",x,y]})()}),(function(){#CRLF#return $elf.
  604. * _apply("mulExpr")}))},"mulExpr":function(){var $elf=this,x,y,x,y,x,y;r
  605. * eturn $elf._or((function(){#CRLF#return (function(){x=$elf._apply("mul
  606. * Expr");$elf._applyWithArgs("token","*");y=$elf._apply("unary");return
  607. * ["binop","*",x,y]})()}),(function(){#CRLF#return (function(){x=$elf._a
  608. * pply("mulExpr");$elf._applyWithArgs("token","/");y=$elf._apply("unary"
  609. * );return ["binop","/",x,y]})()}),(function(){#CRLF#return (function(){
  610. * x=$elf._apply("mulExpr");$elf._applyWithArgs("token","%");y=$elf._appl
  611. * y("unary");return ["binop","%",x,y]})()}),(function(){#CRLF#return $el
  612. * f._apply("unary")}))},"unary":function(){var $elf=this,p,p,p,p,p;retur
  613. * n $elf._or((function(){#CRLF#return (function(){$elf._applyWithArgs("t
  614. * oken","-");p=$elf._apply("postfix");return ["unop","-",p]})()}),(funct
  615. * ion(){#CRLF#return (function(){$elf._applyWithArgs("token","+");p=$elf
  616. * ._apply("postfix");return p})()}),(function(){#CRLF#return (function()
  617. * {$elf._applyWithArgs("token","++");p=$elf._apply("postfix");return ["p
  618. * reop","++",p]})()}),(function(){#CRLF#return (function(){$elf._applyWi
  619. * thArgs("token","--");p=$elf._apply("postfix");return ["preop","--",p]}
  620. * )()}),(function(){#CRLF#return (function(){$elf._applyWithArgs("token"
  621. * ,"!");p=$elf._apply("unary");return ["unop","!",p]})()}),(function(){#
  622. * CRLF#return $elf._apply("postfix")}))},"postfix":function(){var $elf=t
  623. * his,p;return (function(){p=$elf._apply("primExpr");return $elf._or((fu
  624. * nction(){#CRLF#return (function(){$elf._apply("spacesNoNl");$elf._appl
  625. * yWithArgs("token","++");return ["postop","++",p]})()}),(function(){#CR
  626. * LF#return (function(){$elf._apply("spacesNoNl");$elf._applyWithArgs("t
  627. * oken","--");return ["postop","--",p]})()}),(function(){#CRLF#return (f
  628. * unction(){$elf._apply("empty");return p})()}))})()},"primExpr":functio
  629. * n(){var $elf=this,p,i,m,as,f,as;return $elf._or((function(){#CRLF#retu
  630. * rn (function(){p=$elf._apply("primExpr");return $elf._or((function(){#
  631. * CRLF#return (function(){$elf._applyWithArgs("token","[");i=$elf._apply
  632. * ("expr");$elf._applyWithArgs("token","]");return ["getp",i,p]})()}),(f
  633. * unction(){#CRLF#return (function(){$elf._applyWithArgs("token",".");m=
  634. * $elf._applyWithArgs("token","name");$elf._applyWithArgs("token","(");a
  635. * s=$elf._applyWithArgs("listOf","expr",",");$elf._applyWithArgs("token"
  636. * ,")");return ["send",m,p].concat(as)})()}),(function(){#CRLF#return (f
  637. * unction(){$elf._applyWithArgs("token",".");f=$elf._applyWithArgs("toke
  638. * n","name");return ["getp",["string",f],p]})()}),(function(){#CRLF#retu
  639. * rn (function(){$elf._applyWithArgs("token","(");as=$elf._applyWithArgs
  640. * ("listOf","expr",",");$elf._applyWithArgs("token",")");return ["call",
  641. * p].concat(as)})()}))})()}),(function(){#CRLF#return $elf._apply("primE
  642. * xprHd")}))},"primExprHd":function(){var $elf=this,e,n,n,s,n,as,es;retu
  643. * rn $elf._or((function(){#CRLF#return (function(){$elf._applyWithArgs("
  644. * token","(");e=$elf._apply("expr");$elf._applyWithArgs("token",")");ret
  645. * urn e})()}),(function(){#CRLF#return (function(){$elf._applyWithArgs("
  646. * token","this");return ["this"]})()}),(function(){#CRLF#return (functio
  647. * n(){n=$elf._applyWithArgs("token","name");return ["get",n]})()}),(func
  648. * tion(){#CRLF#return (function(){n=$elf._applyWithArgs("token","number"
  649. * );return ["number",n]})()}),(function(){#CRLF#return (function(){s=$el
  650. * f._applyWithArgs("token","string");return ["string",s]})()}),(function
  651. * (){#CRLF#return (function(){$elf._applyWithArgs("token","function");re
  652. * turn $elf._apply("funcRest")})()}),(function(){#CRLF#return (function(
  653. * ){$elf._applyWithArgs("token","new");n=$elf._applyWithArgs("token","na
  654. * me");$elf._applyWithArgs("token","(");as=$elf._applyWithArgs("listOf",
  655. * "expr",",");$elf._applyWithArgs("token",")");return ["new",n].concat(a
  656. * s)})()}),(function(){#CRLF#return (function(){$elf._applyWithArgs("tok
  657. * en","[");es=$elf._applyWithArgs("listOf","expr",",");$elf._applyWithAr
  658. * gs("token","]");return ["arr"].concat(es)})()}),(function(){#CRLF#retu
  659. * rn $elf._apply("json")}))},"json":function(){var $elf=this,bs;return (
  660. * function(){$elf._applyWithArgs("token","{");bs=$elf._applyWithArgs("li
  661. * stOf","jsonBinding",",");$elf._applyWithArgs("token","}");return ["jso
  662. * n"].concat(bs)})()},"jsonBinding":function(){var $elf=this,n,v;return
  663. * (function(){n=$elf._apply("jsonPropName");$elf._applyWithArgs("token",
  664. * ":");v=$elf._apply("expr");return ["binding",n,v]})()},"jsonPropName":
  665. * function(){var $elf=this;return $elf._or((function(){#CRLF#return $elf
  666. * ._applyWithArgs("token","name")}),(function(){#CRLF#return $elf._apply
  667. * WithArgs("token","number")}),(function(){#CRLF#return $elf._applyWithA
  668. * rgs("token","string")}))},"formal":function(){var $elf=this;return (fu
  669. * nction(){$elf._apply("spaces");return $elf._applyWithArgs("token","nam
  670. * e")})()},"funcRest":function(){var $elf=this,fs,body;return (function(
  671. * ){$elf._applyWithArgs("token","(");fs=$elf._applyWithArgs("listOf","fo
  672. * rmal",",");$elf._applyWithArgs("token",")");$elf._applyWithArgs("token
  673. * ","{");body=$elf._apply("srcElems");$elf._applyWithArgs("token","}");r
  674. * eturn ["func",fs,body]})()},"sc":function(){var $elf=this;return $elf.
  675. * _or((function(){#CRLF#return (function(){$elf._apply("spacesNoNl");ret
  676. * urn $elf._or((function(){#CRLF#return $elf._applyWithArgs("exactly","\
  677. * n")}),(function(){#CRLF#return $elf._lookahead(function(){#CRLF#return
  678. *  $elf._applyWithArgs("exactly","}")})}),(function(){#CRLF#return $elf.
  679. * _apply("end")}))})()}),(function(){#CRLF#return $elf._applyWithArgs("t
  680. * oken",";")}))},"binding":function(){var $elf=this,n,v;return (function
  681. * (){n=$elf._applyWithArgs("token","name");v=$elf._or((function(){#CRLF#
  682. * return (function(){$elf._applyWithArgs("token","=");return $elf._apply
  683. * ("expr")})()}),(function(){#CRLF#return (function(){$elf._apply("empty
  684. * ");return ["get","undefined"]})()}));return ["var",n,v]})()},"block":f
  685. * unction(){var $elf=this,ss;return (function(){$elf._applyWithArgs("tok
  686. * en","{");ss=$elf._apply("srcElems");$elf._applyWithArgs("token","}");r
  687. * eturn ss})()},"stmt":function(){var $elf=this,bs,c,t,f,c,s,s,c,i,c,u,s
  688. * ,n,v,e,s,e,c,cs,cs,cs,e,t,e,c,f,e,x,s,e;return $elf._or((function(){#C
  689. * RLF#return $elf._apply("block")}),(function(){#CRLF#return (function()
  690. * {$elf._applyWithArgs("token","var");bs=$elf._applyWithArgs("listOf","b
  691. * inding",",");$elf._apply("sc");return ["begin"].concat(bs)})()}),(func
  692. * tion(){#CRLF#return (function(){$elf._applyWithArgs("token","if");$elf
  693. * ._applyWithArgs("token","(");c=$elf._apply("expr");$elf._applyWithArgs
  694. * ("token",")");t=$elf._apply("stmt");f=$elf._or((function(){#CRLF#retur
  695. * n (function(){$elf._applyWithArgs("token","else");return $elf._apply("
  696. * stmt")})()}),(function(){#CRLF#return (function(){$elf._apply("empty")
  697. * ;return ["get","undefined"]})()}));return ["if",c,t,f]})()}),(function
  698. * (){#CRLF#return (function(){$elf._applyWithArgs("token","while");$elf.
  699. * _applyWithArgs("token","(");c=$elf._apply("expr");$elf._applyWithArgs(
  700. * "token",")");s=$elf._apply("stmt");return ["while",c,s]})()}),(functio
  701. * n(){#CRLF#return (function(){$elf._applyWithArgs("token","do");s=$elf.
  702. * _apply("stmt");$elf._applyWithArgs("token","while");$elf._applyWithArg
  703. * s("token","(");c=$elf._apply("expr");$elf._applyWithArgs("token",")");
  704. * $elf._apply("sc");return ["doWhile",s,c]})()}),(function(){#CRLF#retur
  705. * n (function(){$elf._applyWithArgs("token","for");$elf._applyWithArgs("
  706. * token","(");i=$elf._or((function(){#CRLF#return (function(){$elf._appl
  707. * yWithArgs("token","var");return $elf._apply("binding")})()}),(function
  708. * (){#CRLF#return $elf._apply("expr")}),(function(){#CRLF#return (functi
  709. * on(){$elf._apply("empty");return ["get","undefined"]})()}));$elf._appl
  710. * yWithArgs("token",";");c=$elf._or((function(){#CRLF#return $elf._apply
  711. * ("expr")}),(function(){#CRLF#return (function(){$elf._apply("empty");r
  712. * eturn ["get","true"]})()}));$elf._applyWithArgs("token",";");u=$elf._o
  713. * r((function(){#CRLF#return $elf._apply("expr")}),(function(){#CRLF#ret
  714. * urn (function(){$elf._apply("empty");return ["get","undefined"]})()}))
  715. * ;$elf._applyWithArgs("token",")");s=$elf._apply("stmt");return ["for",
  716. * i,c,u,s]})()}),(function(){#CRLF#return (function(){$elf._applyWithArg
  717. * s("token","for");$elf._applyWithArgs("token","(");v=$elf._or((function
  718. * (){#CRLF#return (function(){$elf._applyWithArgs("token","var");n=$elf.
  719. * _applyWithArgs("token","name");return ["var",n,["get","undefined"]]})(
  720. * )}),(function(){#CRLF#return $elf._apply("expr")}));$elf._applyWithArg
  721. * s("token","in");e=$elf._apply("expr");$elf._applyWithArgs("token",")")
  722. * ;s=$elf._apply("stmt");return ["forIn",v,e,s]})()}),(function(){#CRLF#
  723. * return (function(){$elf._applyWithArgs("token","switch");$elf._applyWi
  724. * thArgs("token","(");e=$elf._apply("expr");$elf._applyWithArgs("token",
  725. * ")");$elf._applyWithArgs("token","{");cs=$elf._many(function(){#CRLF#r
  726. * eturn $elf._or((function(){#CRLF#return (function(){$elf._applyWithArg
  727. * s("token","case");c=$elf._apply("expr");$elf._applyWithArgs("token",":
  728. * ");cs=$elf._apply("srcElems");return ["case",c,cs]})()}),(function(){#
  729. * CRLF#return (function(){$elf._applyWithArgs("token","default");$elf._a
  730. * pplyWithArgs("token",":");cs=$elf._apply("srcElems");return ["default"
  731. * ,cs]})()}))});$elf._applyWithArgs("token","}");return ["switch",e].con
  732. * cat(cs)})()}),(function(){#CRLF#return (function(){$elf._applyWithArgs
  733. * ("token","break");$elf._apply("sc");return ["break"]})()}),(function()
  734. * {#CRLF#return (function(){$elf._applyWithArgs("token","continue");$elf
  735. * ._apply("sc");#CRLF#return ["continue"]})()}),(function(){#CRLF#return
  736. *  (function(){$elf._applyWithArgs("token","throw");$elf._apply("spacesN
  737. * oNl");e=$elf._apply("expr");$elf._apply("sc");return ["throw",e]})()})
  738. * ,(function(){#CRLF#return (function(){$elf._applyWithArgs("token","try
  739. * ");t=$elf._apply("block");$elf._applyWithArgs("token","catch");$elf._a
  740. * pplyWithArgs("token","(");e=$elf._applyWithArgs("token","name");$elf._
  741. * applyWithArgs("token",")");c=$elf._apply("block");f=$elf._or((function
  742. * (){#CRLF#return (function(){$elf._applyWithArgs("token","finally");ret
  743. * urn $elf._apply("block")})()}),(function(){#CRLF#return (function(){$e
  744. * lf._apply("empty");return ["get","undefined"]})()}));return ["try",t,e
  745. * ,c,f]})()}),(function(){#CRLF#return (function(){$elf._applyWithArgs("
  746. * token","return");e=$elf._or((function(){#CRLF#return $elf._apply("expr
  747. * ")}),(function(){#CRLF#return (function(){$elf._apply("empty");return
  748. * ["get","undefined"]})()}));$elf._apply("sc");return ["return",e]})()})
  749. * ,(function(){#CRLF#return (function(){$elf._applyWithArgs("token","wit
  750. * h");$elf._applyWithArgs("token","(");x=$elf._apply("expr");$elf._apply
  751. * WithArgs("token",")");s=$elf._apply("stmt");return ["with",x,s]})()}),
  752. * (function(){#CRLF#return (function(){e=$elf._apply("expr");$elf._apply
  753. * ("sc");return e})()}),(function(){#CRLF#return (function(){$elf._apply
  754. * WithArgs("token",";");return ["get","undefined"]})()}))},"srcElem":fun
  755. * ction(){var $elf=this,n,f;return $elf._or((function(){#CRLF#return (fu
  756. * nction(){$elf._applyWithArgs("token","function");n=$elf._applyWithArgs
  757. * ("token","name");f=$elf._apply("funcRest");return ["var",n,f]})()}),(f
  758. * unction(){#CRLF#return $elf._apply("stmt")}))},"srcElems":function(){v
  759. * ar $elf=this,ss;return (function(){ss=$elf._many(function(){#CRLF#retu
  760. * rn $elf._apply("srcElem")});return ["begin"].concat(ss)})()},"topLevel
  761. * ":function(){var $elf=this,r;return (function(){r=$elf._apply("srcElem
  762. * s");$elf._apply("spaces");$elf._apply("end");return r})()},"curlySemAc
  763. * tion":function(){var $elf=this,s,ss,r,r;return $elf._or((function(){#C
  764. * RLF#return (function(){$elf._applyWithArgs("token","{");ss=$elf._many1
  765. * (function(){#CRLF#return (function(){s=$elf._apply("srcElem");$elf._lo
  766. * okahead(function(){#CRLF#return $elf._apply("srcElem")});return s})()}
  767. * );r=$elf._apply("expr");$elf._apply("sc");$elf._applyWithArgs("token",
  768. * "}");$elf._apply("spaces");return (function (){ss.push(["return",r]);r
  769. * eturn ["call",["func",[],["begin"].concat(ss)]]})()})()}),(function(){
  770. * #CRLF#return (function(){$elf._applyWithArgs("token","{");r=$elf._appl
  771. * y("expr");$elf._applyWithArgs("token","}");$elf._apply("spaces");retur
  772. * n r})()}))},"semAction":function(){var $elf=this,r;return $elf._or((fu
  773. * nction(){#CRLF#return $elf._apply("curlySemAction")}),(function(){#CRL
  774. * F#return (function(){r=$elf._apply("primExpr");$elf._apply("spaces");r
  775. * eturn r})()}))}});BSJSParser["keywords"]=({});keywords=["break","case"
  776. * ,"catch","continue","default","delete","do","else","finally","for","fu
  777. * nction","if","in","instanceof","new","return","switch","this","throw",
  778. * "try","typeof","var","void","while","with","ometa"];for(var idx=(0);(i
  779. * dx < keywords["length"]);idx++){BSJSParser["keywords"][keywords[idx]]=
  780. * true}BSJSParser["_isKeyword"]=(function (k){#CRLF#return (this["keywor
  781. * ds"].hasProperty(k) && (!Object["prototype"].hasProperty(k)))});BSJSTr
  782. * anslator=OMeta.delegated({"trans":function(){var $elf=this,t,ans;retur
  783. * n (function(){$elf._form(function(){#CRLF#return (function(){t=$elf._a
  784. * pply("anything");return ans=$elf._applyWithArgs("apply",t)})()});retur
  785. * n ans})()},"curlyTrans":function(){var $elf=this,r,rs,r;return $elf._o
  786. * r((function(){#CRLF#return (function(){$elf._form(function(){#CRLF#ret
  787. * urn (function(){$elf._applyWithArgs("exactly","begin");return r=$elf._
  788. * apply("curlyTrans")})()});return r})()}),(function(){#CRLF#return (fun
  789. * ction(){$elf._form(function(){#CRLF#return (function(){$elf._applyWith
  790. * Args("exactly","begin");return rs=$elf._many(function(){#CRLF#return $
  791. * elf._apply("trans")})})()});return (("{" + rs.join(";")) + "}")})()}),
  792. * (function(){#CRLF#return (function(){r=$elf._apply("trans");return (("
  793. * {" + r) + "}")})()}))},"this":function(){var $elf=this;return "this"},
  794. * "break":function(){var $elf=this;return "break"},"continue":function()
  795. * {var $elf=this;return "continue"},"number":function(){var $elf=this,n;
  796. * return (function(){n=$elf._apply("anything");return (("(" + n) + ")")}
  797. * )()},"string":function(){var $elf=this,s;return (function(){s=$elf._ap
  798. * ply("anything");return s.toProgramString()})()},"arr":function(){var $
  799. * elf=this,xs;return (function(){xs=$elf._many(function(){#CRLF#return $
  800. * elf._apply("trans")});return (("[" + xs.join(",")) + "]")})()},"unop":
  801. * function(){var $elf=this,op,x;return (function(){op=$elf._apply("anyth
  802. * ing");x=$elf._apply("trans");return ((("(" + op) + x) + ")")})()},"get
  803. * p":function(){var $elf=this,fd,x;return (function(){fd=$elf._apply("tr
  804. * ans");x=$elf._apply("trans");return (((x + "[") + fd) + "]")})()},"get
  805. * ":function(){var $elf=this,x;return (function(){x=$elf._apply("anythin
  806. * g");return x})()},"set":function(){var $elf=this,lhs,rhs;return (funct
  807. * ion(){lhs=$elf._apply("trans");rhs=$elf._apply("trans");return ((lhs +
  808. *  "=") + rhs)})()},"mset":function(){var $elf=this,lhs,op,rhs;return (f
  809. * unction(){lhs=$elf._apply("trans");op=$elf._apply("anything");rhs=$elf
  810. * ._apply("trans");return (((lhs + op) + "=") + rhs)})()},"binop":functi
  811. * on(){var $elf=this,op,x,y;return (function(){op=$elf._apply("anything"
  812. * );x=$elf._apply("trans");y=$elf._apply("trans");return (((((("(" + x)
  813. * + " ") + op) + " ") + y) + ")")})()},"preop":function(){var $elf=this,
  814. * op,x;return (function(){op=$elf._apply("anything");x=$elf._apply("tran
  815. * s");return (op + x)})()},"postop":function(){var $elf=this,op,x;return
  816. *  (function(){op=$elf._apply("anything");x=$elf._apply("trans");return
  817. * (x + op)})()},"return":function(){var $elf=this,x;return (function(){x
  818. * =$elf._apply("trans");return ("return " + x)})()},"with":function(){va
  819. * r $elf=this,x,s;return (function(){x=$elf._apply("trans");s=$elf._appl
  820. * y("curlyTrans");return ((("with(" + x) + ")") + s)})()},"if":function(
  821. * ){var $elf=this,cond,t,e;return (function(){cond=$elf._apply("trans");
  822. * t=$elf._apply("curlyTrans");e=$elf._apply("curlyTrans");return ((((("i
  823. * f(" + cond) + ")") + t) + "else") + e)})()},"condExpr":function(){var
  824. * $elf=this,cond,t,e;return (function(){cond=$elf._apply("trans");t=$elf
  825. * ._apply("trans");e=$elf._apply("trans");return (((((("(" + cond) + "?"
  826. * ) + t) + ":") + e) + ")")})()},"while":function(){var $elf=this,cond,b
  827. * ody;return (function(){cond=$elf._apply("trans");body=$elf._apply("cur
  828. * lyTrans");return ((("while(" + cond) + ")") + body)})()},"doWhile":fun
  829. * ction(){var $elf=this,body,cond;return (function(){body=$elf._apply("c
  830. * urlyTrans");cond=$elf._apply("trans");return (((("do" + body) + "while
  831. * (") + cond) + ")")})()},"for":function(){var $elf=this,init,cond,upd,b
  832. * ody;return (function(){init=$elf._apply("trans");cond=$elf._apply("tra
  833. * ns");upd=$elf._apply("trans");body=$elf._apply("curlyTrans");return ((
  834. * ((((("for(" + init) + ";") + cond) + ";") + upd) + ")") + body)})()},"
  835. * forIn":function(){var $elf=this,x,arr,body;return (function(){x=$elf._
  836. * apply("trans");arr=$elf._apply("trans");body=$elf._apply("curlyTrans")
  837. * ;return ((((("for(" + x) + " in ") + arr) + ")") + body)})()},"begin":
  838. * function(){var $elf=this,x,x,xs;return $elf._or((function(){#CRLF#retu
  839. * rn (function(){x=$elf._apply("trans");$elf._apply("end");return x})()}
  840. * ),(function(){#CRLF#return (function(){xs=$elf._many(function(){#CRLF#
  841. * return (function(){x=$elf._apply("trans");return $elf._or((function(){
  842. * #CRLF#return (function(){$elf._or((function(){#CRLF#return $elf._pred(
  843. * (x[(x["length"] - (1))] == "}"))}),(function(){#CRLF#return $elf._appl
  844. * y("end")}));return x})()}),(function(){#CRLF#return (function(){$elf._
  845. * apply("empty");return (x + ";")})()}))})()});return (("{" + xs.join(""
  846. * )) + "}")})()}))},"func":function(){var $elf=this,args,body;return (fu
  847. * nction(){args=$elf._apply("anything");body=$elf._apply("curlyTrans");r
  848. * eturn (((("(function (" + args.join(",")) + ")") + body) + ")")})()},"
  849. * call":function(){var $elf=this,fn,args;return (function(){fn=$elf._app
  850. * ly("trans");args=$elf._many(function(){#CRLF#return $elf._apply("trans
  851. * ")});return (((fn + "(") + args.join(",")) + ")")})()},"send":function
  852. * (){var $elf=this,msg,recv,args;return (function(){msg=$elf._apply("any
  853. * thing");recv=$elf._apply("trans");args=$elf._many(function(){#CRLF#ret
  854. * urn $elf._apply("trans")});return (((((recv + ".") + msg) + "(") + arg
  855. * s.join(",")) + ")")})()},"new":function(){var $elf=this,cls,args;retur
  856. * n (function(){cls=$elf._apply("anything");args=$elf._many(function(){#
  857. * CRLF#return $elf._apply("trans")});return (((("new " + cls) + "(") + a
  858. * rgs.join(",")) + ")")})()},"var":function(){var $elf=this,name,val;ret
  859. * urn (function(){name=$elf._apply("anything");val=$elf._apply("trans");
  860. * return ((("var " + name) + "=") + val)})()},"throw":function(){var $el
  861. * f=this,x;return (function(){x=$elf._apply("trans");return ("throw " +
  862. * x)})()},"try":function(){var $elf=this,x,name,c,f;return (function(){x
  863. * =$elf._apply("curlyTrans");name=$elf._apply("anything");c=$elf._apply(
  864. * "curlyTrans");f=$elf._apply("curlyTrans");return ((((((("try " + x) +
  865. * "catch(") + name) + ")") + c) + "finally") + f)})()},"json":function()
  866. * {var $elf=this,props;return (function(){props=$elf._many(function(){#C
  867. * RLF#return $elf._apply("trans")});return (("({" + props.join(",")) + "
  868. * })")})()},"binding":function(){var $elf=this,name,val;return (function
  869. * (){name=$elf._apply("anything");val=$elf._apply("trans");return ((name
  870. * .toProgramString() + ": ") + val)})()},"switch":function(){var $elf=th
  871. * is,x,cases;return (function(){x=$elf._apply("trans");cases=$elf._many(
  872. * function(){#CRLF#return $elf._apply("trans")});return (((("switch(" +
  873. * x) + "){") + cases.join(";")) + "}")})()},"case":function(){var $elf=t
  874. * his,x,y;return (function(){x=$elf._apply("trans");y=$elf._apply("trans
  875. * ");return ((("case " + x) + ": ") + y)})()},"default":function(){var $
  876. * elf=this,y;return (function(){y=$elf._apply("trans");return ("default:
  877. *  " + y)})()}})}#CRLF##CRLF#{BSOMetaParser=Parser.delegated({"fromTo":f
  878. * unction(){var $elf=this,x,y;return (function(){x=$elf._apply("anything
  879. * ");y=$elf._apply("anything");$elf._applyWithArgs("seq",x);$elf._many(f
  880. * unction(){return (function(){$elf._not(function(){return $elf._applyWi
  881. * thArgs("seq",y)});return $elf._apply("char")})()});return $elf._applyW
  882. * ithArgs("seq",y)})()},"space":function(){var $elf=this;return $elf._or
  883. * ((function(){return Parser._superApplyWithArgs($elf,"space")}),(functi
  884. * on(){return $elf._applyWithArgs("fromTo","//","\n")}),(function(){retu
  885. * rn $elf._applyWithArgs("fromTo","/*","*/")}))},"nameFirst":function(){
  886. * var $elf=this;return $elf._or((function(){return $elf._applyWithArgs("
  887. * exactly","_")}),(function(){return $elf._applyWithArgs("exactly","$")}
  888. * ),(function(){return $elf._apply("letter")}))},"nameRest":function(){v
  889. * ar $elf=this;return $elf._or((function(){return $elf._apply("nameFirst
  890. * ")}),(function(){return $elf._apply("digit")}))},"tsName":function(){v
  891. * ar $elf=this,xs;return (function(){xs=$elf._applyWithArgs("firstAndRes
  892. * t","nameFirst","nameRest");return xs.join("")})()},"name":function(){v
  893. * ar $elf=this;return (function(){$elf._apply("spaces");return $elf._app
  894. * ly("tsName")})()},"eChar":function(){var $elf=this,c;return $elf._or((
  895. * function(){return (function(){$elf._applyWithArgs("exactly","\\");c=$e
  896. * lf._apply("char");return unescape(("\\" + c))})()}),(function(){return
  897. *  $elf._apply("char")}))},"tsString":function(){var $elf=this,xs;return
  898. *  (function(){$elf._applyWithArgs("exactly","\'");xs=$elf._many(functio
  899. * n(){return (function(){$elf._not(function(){return $elf._applyWithArgs
  900. * ("exactly","\'")});return $elf._apply("eChar")})()});$elf._applyWithAr
  901. * gs("exactly","\'");return xs.join("")})()},"characters":function(){var
  902. *  $elf=this,xs;return (function(){$elf._applyWithArgs("exactly","`");$e
  903. * lf._applyWithArgs("exactly","`");xs=$elf._many(function(){return (func
  904. * tion(){$elf._not(function(){return (function(){$elf._applyWithArgs("ex
  905. * actly","\'");return $elf._applyWithArgs("exactly","\'")})()});return $
  906. * elf._apply("eChar")})()});$elf._applyWithArgs("exactly","\'");$elf._ap
  907. * plyWithArgs("exactly","\'");return ["App","seq",xs.join("").toProgramS
  908. * tring()]})()},"sCharacters":function(){var $elf=this,xs;return (functi
  909. * on(){$elf._applyWithArgs("exactly","\"");xs=$elf._many(function(){retu
  910. * rn (function(){$elf._not(function(){return $elf._applyWithArgs("exactl
  911. * y","\"")});return $elf._apply("eChar")})()});$elf._applyWithArgs("exac
  912. * tly","\"");return ["App","token",xs.join("").toProgramString()]})()},"
  913. * string":function(){var $elf=this,xs;return (function(){xs=$elf._or((fu
  914. * nction(){return (function(){$elf._or((function(){return $elf._applyWit
  915. * hArgs("exactly","#")}),(function(){return $elf._applyWithArgs("exactly
  916. * ","`")}));return $elf._apply("tsName")})()}),(function(){return $elf._
  917. * apply("tsString")}));return ["App","exactly",xs.toProgramString()]})()
  918. * },"number":function(){var $elf=this,sign,ds;return (function(){sign=$e
  919. * lf._or((function(){return $elf._applyWithArgs("exactly","-")}),(functi
  920. * on(){return (function(){$elf._apply("empty");return ""})()}));ds=$elf.
  921. * _many1(function(){return $elf._apply("digit")});return ["App","exactly
  922. * ",(sign + ds.join(""))]})()},"keyword":function(){var $elf=this,xs;ret
  923. * urn (function(){xs=$elf._apply("anything");$elf._applyWithArgs("token"
  924. * ,xs);$elf._not(function(){return $elf._apply("letterOrDigit")});return
  925. *  xs})()},"args":function(){var $elf=this,xs;return $elf._or((function(
  926. * ){return (function(){$elf._applyWithArgs("exactly","(");xs=$elf._apply
  927. * WithArgs("listOf","hostExpr",",");$elf._applyWithArgs("token",")");ret
  928. * urn xs})()}),(function(){return (function(){$elf._apply("empty");retur
  929. * n []})()}))},"application":function(){var $elf=this,rule,as,rule,as;re
  930. * turn $elf._or((function(){return (function(){$elf._applyWithArgs("toke
  931. * n","^");rule=$elf._apply("name");as=$elf._apply("args");return ["App",
  932. * "super",(("\'" + rule) + "\'")].concat(as)})()}),(function(){return (f
  933. * unction(){rule=$elf._apply("name");as=$elf._apply("args");return ["App
  934. * ",rule].concat(as)})()}))},"hostExpr":function(){var $elf=this,r;retur
  935. * n (function(){r=$elf._applyWithArgs("foreign",BSJSParser,"expr");retur
  936. * n $elf._applyWithArgs("foreign",BSJSTranslator,"trans",r)})()},"atomic
  937. * HostExpr":function(){var $elf=this,r;return (function(){r=$elf._applyW
  938. * ithArgs("foreign",BSJSParser,"semAction");return $elf._applyWithArgs("
  939. * foreign",BSJSTranslator,"trans",r)})()},"curlyHostExpr":function(){var
  940. *  $elf=this,r;return (function(){r=$elf._applyWithArgs("foreign",BSJSPa
  941. * rser,"curlySemAction");return $elf._applyWithArgs("foreign",BSJSTransl
  942. * ator,"trans",r)})()},"semAction":function(){var $elf=this,x,x;return $
  943. * elf._or((function(){return (function(){$elf._or((function(){return $el
  944. * f._applyWithArgs("token","!")}),(function(){return $elf._applyWithArgs
  945. * ("token","->")}));x=$elf._apply("atomicHostExpr");return ["Act",x]})()
  946. * }),(function(){return (function(){x=$elf._apply("curlyHostExpr");retur
  947. * n ["Act",x]})()}))},"semPred":function(){var $elf=this,x;return (funct
  948. * ion(){$elf._applyWithArgs("token","?");x=$elf._apply("atomicHostExpr")
  949. * ;return ["Pred",x]})()},"expr":function(){var $elf=this,xs;return (fun
  950. * ction(){xs=$elf._applyWithArgs("listOf","expr4","|");return ["Or"].con
  951. * cat(xs)})()},"expr4":function(){var $elf=this,xs;return (function(){xs
  952. * =$elf._many(function(){return $elf._apply("expr3")});return ["And"].co
  953. * ncat(xs)})()},"optIter":function(){var $elf=this,x;return (function(){
  954. * x=$elf._apply("anything");return $elf._or((function(){return (function
  955. * (){$elf._applyWithArgs("token","*");return ["Many",x]})()}),(function(
  956. * ){return (function(){$elf._applyWithArgs("token","+");return ["Many1",
  957. * x]})()}),(function(){return (function(){$elf._apply("empty");return x}
  958. * )()}))})()},"expr3":function(){var $elf=this,x,x,n,n;return $elf._or((
  959. * function(){return (function(){x=$elf._apply("expr2");x=$elf._applyWith
  960. * Args("optIter",x);return $elf._or((function(){return (function(){$elf.
  961. * _applyWithArgs("exactly",":");n=$elf._apply("name");return (function (
  962. * ){$elf["locals"].push(n);return ["Set",n,x]})()})()}),(function(){retu
  963. * rn (function(){$elf._apply("empty");return x})()}))})()}),(function(){
  964. * return (function(){$elf._applyWithArgs("token",":");n=$elf._apply("nam
  965. * e");return (function (){$elf["locals"].push(n);return ["Set",n,["App",
  966. * "anything"]]})()})()}))},"expr2":function(){var $elf=this,x,x;return $
  967. * elf._or((function(){return (function(){$elf._applyWithArgs("token","~"
  968. * );x=$elf._apply("expr2");return ["Not",x]})()}),(function(){return (fu
  969. * nction(){$elf._applyWithArgs("token","&");x=$elf._apply("expr1");retur
  970. * n ["Lookahead",x]})()}),(function(){return $elf._apply("expr1")}))},"e
  971. * xpr1":function(){var $elf=this,x,x,x;return $elf._or((function(){retur
  972. * n $elf._apply("application")}),(function(){return $elf._apply("semActi
  973. * on")}),(function(){return $elf._apply("semPred")}),(function(){return
  974. * (function(){x=$elf._or((function(){return $elf._applyWithArgs("keyword
  975. * ","undefined")}),(function(){return $elf._applyWithArgs("keyword","nil
  976. * ")}),(function(){return $elf._applyWithArgs("keyword","true")}),(funct
  977. * ion(){return $elf._applyWithArgs("keyword","false")}));return ["App","
  978. * exactly",x]})()}),(function(){return (function(){$elf._apply("spaces")
  979. * ;return $elf._or((function(){return $elf._apply("characters")}),(funct
  980. * ion(){return $elf._apply("sCharacters")}),(function(){return $elf._app
  981. * ly("string")}),(function(){return $elf._apply("number")}))})()}),(func
  982. * tion(){return (function(){$elf._applyWithArgs("token","[");x=$elf._app
  983. * ly("expr");$elf._applyWithArgs("token","]");return ["Form",x]})()}),(f
  984. * unction(){return (function(){$elf._applyWithArgs("token","(");x=$elf._
  985. * apply("expr");$elf._applyWithArgs("token",")");return x})()}))},"ruleN
  986. * ame":function(){var $elf=this;return $elf._or((function(){return $elf.
  987. * _apply("name")}),(function(){return (function(){$elf._apply("spaces");
  988. * return $elf._apply("tsString")})()}))},"rule":function(){var $elf=this
  989. * ,n,x,xs;return (function(){$elf._lookahead(function(){return n=$elf._a
  990. * pply("ruleName")});$elf["locals"]=["$elf=this"];x=$elf._applyWithArgs(
  991. * "rulePart",n);xs=$elf._many(function(){return (function(){$elf._applyW
  992. * ithArgs("token",",");return $elf._applyWithArgs("rulePart",n)})()});re
  993. * turn ["Rule",n,$elf["locals"],["Or",x].concat(xs)]})()},"rulePart":fun
  994. * ction(){var $elf=this,rn,n,b1,b2;return (function(){rn=$elf._apply("an
  995. * ything");n=$elf._apply("ruleName");$elf._pred((n == rn));b1=$elf._appl
  996. * y("expr4");return $elf._or((function(){return (function(){$elf._applyW
  997. * ithArgs("token","=");b2=$elf._apply("expr");return ["And",b1,b2]})()})
  998. * ,(function(){return (function(){$elf._apply("empty");return b1})()}))}
  999. * )()},"grammar":function(){var $elf=this,n,sn,rs;return (function(){$el
  1000. * f._applyWithArgs("keyword","ometa");n=$elf._apply("name");sn=$elf._or(
  1001. * (function(){return (function(){$elf._applyWithArgs("token","<:");retur
  1002. * n $elf._apply("name")})()}),(function(){return (function(){$elf._apply
  1003. * ("empty");return "OMeta"})()}));$elf._applyWithArgs("token","{");rs=$e
  1004. * lf._applyWithArgs("listOf","rule",",");$elf._applyWithArgs("token","}"
  1005. * );return $elf._applyWithArgs("foreign",BSOMetaOptimizer,"optimizeGramm
  1006. * ar",["Grammar",n,sn].concat(rs))})()}});BSOMetaTranslator=OMeta.delega
  1007. * ted({"trans":function(){var $elf=this,t,ans;return (function(){$elf._f
  1008. * orm(function(){return (function(){t=$elf._apply("anything");return ans
  1009. * =$elf._applyWithArgs("apply",t)})()});return ans})()},"App":function()
  1010. * {var $elf=this,args,rule,args,rule;return $elf._or((function(){return
  1011. * (function(){$elf._applyWithArgs("exactly","super");args=$elf._many1(fu
  1012. * nction(){return $elf._apply("anything")});return [$elf["sName"],"._sup
  1013. * erApplyWithArgs($elf,",args.join(","),")"].join("")})()}),(function(){
  1014. * return (function(){rule=$elf._apply("anything");args=$elf._many1(funct
  1015. * ion(){return $elf._apply("anything")});return ["$elf._applyWithArgs(\"
  1016. * ",rule,"\",",args.join(","),")"].join("")})()}),(function(){return (fu
  1017. * nction(){rule=$elf._apply("anything");return ["$elf._apply(\"",rule,"\
  1018. * ")"].join("")})()}))},"Act":function(){var $elf=this,expr;return (func
  1019. * tion(){expr=$elf._apply("anything");return expr})()},"Pred":function()
  1020. * {var $elf=this,expr;return (function(){expr=$elf._apply("anything");re
  1021. * turn ["$elf._pred(",expr,")"].join("")})()},"Or":function(){var $elf=t
  1022. * his,xs;return (function(){xs=$elf._many(function(){return $elf._apply(
  1023. * "transFn")});return ["$elf._or(",xs.join(","),")"].join("")})()},"And"
  1024. * :function(){var $elf=this,xs,y;return $elf._or((function(){return (fun
  1025. * ction(){xs=$elf._many(function(){return $elf._applyWithArgs("notLast",
  1026. * "trans")});y=$elf._apply("trans");return (function (){xs.push(("return
  1027. *  " + y));return ["(function(){",xs.join(";"),"})()"].join("")})()})()}
  1028. * ),(function(){return "(function(){})"}))},"Many":function(){var $elf=t
  1029. * his,x;return (function(){x=$elf._apply("trans");return ["$elf._many(fu
  1030. * nction(){return ",x,"})"].join("")})()},"Many1":function(){var $elf=th
  1031. * is,x;return (function(){x=$elf._apply("trans");return ["$elf._many1(fu
  1032. * nction(){return ",x,"})"].join("")})()},"Set":function(){var $elf=this
  1033. * ,n,v;return (function(){n=$elf._apply("anything");v=$elf._apply("trans
  1034. * ");return [n,"=",v].join("")})()},"Not":function(){var $elf=this,x;ret
  1035. * urn (function(){x=$elf._apply("trans");return ["$elf._not(function(){r
  1036. * eturn ",x,"})"].join("")})()},"Lookahead":function(){var $elf=this,x;r
  1037. * eturn (function(){x=$elf._apply("trans");return ["$elf._lookahead(func
  1038. * tion(){return ",x,"})"].join("")})()},"Form":function(){var $elf=this,
  1039. * x;return (function(){x=$elf._apply("trans");return ["$elf._form(functi
  1040. * on(){return ",x,"})"].join("")})()},"Rule":function(){var $elf=this,na
  1041. * me,ls,body;return (function(){name=$elf._apply("anything");ls=$elf._ap
  1042. * ply("locals");body=$elf._apply("trans");return ["\"",name,"\":function
  1043. * (){",ls,"return ",body,"}"].join("")})()},"Grammar":function(){var $el
  1044. * f=this,name,sName,rules;return (function(){name=$elf._apply("anything"
  1045. * );sName=$elf._apply("anything");$elf["sName"]=sName;rules=$elf._many(f
  1046. * unction(){return $elf._apply("trans")});return [name,"=",sName,".deleg
  1047. * ated({",rules.join(","),"})"].join("")})()},"locals":function(){var $e
  1048. * lf=this,vs;return $elf._or((function(){return (function(){$elf._form(f
  1049. * unction(){return vs=$elf._many1(function(){return $elf._apply("string"
  1050. * )})});return ["var ",vs.join(","),";"].join("")})()}),(function(){retu
  1051. * rn (function(){$elf._form(function(){return (function(){})});return ""
  1052. * })()}))},"transFn":function(){var $elf=this,x;return (function(){x=$el
  1053. * f._apply("trans");return ["(function(){return ",x,"})"].join("")})()}}
  1054. * )}#CRLF##CRLF#{BSNullOptimization=OMeta.delegated();BSNullOptimization
  1055. * ['setHelped']=function() {var $elf=this;return $elf["_didSomething"]=t
  1056. * rue};BSNullOptimization['helped']=function() {var $elf=this;return $el
  1057. * f._pred($elf["_didSomething"])};BSNullOptimization['trans']=function()
  1058. *  {var $elf=this,t,ans;return $elf._or((function(){return (function(){$
  1059. * elf._form(function(){return (function(){t=$elf._apply("anything");$elf
  1060. * ._pred($elf.hasProperty(t));return ans=$elf._applyWithArgs("apply", t)
  1061. * })()});return ans})()}),(function(){return $elf._apply("anything")}))}
  1062. * ;BSNullOptimization['optimize']=function() {var $elf=this,x;return (fu
  1063. * nction(){x=$elf._apply("trans");$elf._apply("helped");return x})()};BS
  1064. * NullOptimization['Or']=function() {var $elf=this,xs;return (function()
  1065. * {xs=$elf._many(function(){return $elf._apply("trans")});return ["Or"].
  1066. * concat(xs)})()};BSNullOptimization['And']=function() {var $elf=this,xs
  1067. * ;return (function(){xs=$elf._many(function(){return $elf._apply("trans
  1068. * ")});return ["And"].concat(xs)})()};BSNullOptimization['Many']=functio
  1069. * n() {var $elf=this,x;return (function(){x=$elf._apply("trans");return
  1070. * ["Many",x]})()};BSNullOptimization['Many1']=function() {var $elf=this,
  1071. * x;return (function(){x=$elf._apply("trans");return ["Many1",x]})()};BS
  1072. * NullOptimization['Set']=function() {var $elf=this,n,v;return (function
  1073. * (){n=$elf._apply("anything");v=$elf._apply("trans");return ["Set",n,v]
  1074. * })()};BSNullOptimization['Not']=function() {var $elf=this,x;return (fu
  1075. * nction(){x=$elf._apply("trans");return ["Not",x]})()};BSNullOptimizati
  1076. * on['Lookahead']=function() {var $elf=this,x;return (function(){x=$elf.
  1077. * _apply("trans");return ["Lookahead",x]})()};BSNullOptimization['Form']
  1078. * =function() {var $elf=this,x;return (function(){x=$elf._apply("trans")
  1079. * ;return ["Form",x]})()};BSNullOptimization['Rule']=function() {var $el
  1080. * f=this,name,ls,body;return (function(){name=$elf._apply("anything");ls
  1081. * =$elf._apply("anything");body=$elf._apply("trans");return ["Rule",name
  1082. * ,ls,body]})()};BSNullOptimization.prototype=BSNullOptimization;;BSNull
  1083. * Optimization["initialize"]=(function () {this["_didSomething"]=false})
  1084. * ;BSAndOrOptimization=BSNullOptimization.delegated();BSAndOrOptimizatio
  1085. * n['And']=function() {var $elf=this,x,xs;return $elf._or((function(){re
  1086. * turn (function(){x=$elf._apply("trans");$elf._apply("end");$elf._apply
  1087. * ("setHelped");return x})()}),(function(){return (function(){xs=$elf._a
  1088. * pplyWithArgs("transInside", "And");return ["And"].concat(xs)})()}))};B
  1089. * SAndOrOptimization['Or']=function() {var $elf=this,x,xs;return $elf._o
  1090. * r((function(){return (function(){x=$elf._apply("trans");$elf._apply("e
  1091. * nd");$elf._apply("setHelped");return x})()}),(function(){return (funct
  1092. * ion(){xs=$elf._applyWithArgs("transInside", "Or");return ["Or"].concat
  1093. * (xs)})()}))};BSAndOrOptimization['transInside']=function() {var $elf=t
  1094. * his,t,xs,ys,x,xs;return (function(){t=$elf._apply("anything");return $
  1095. * elf._or((function(){return (function(){$elf._form(function(){return (f
  1096. * unction(){$elf._applyWithArgs("exactly", t);return xs=$elf._applyWithA
  1097. * rgs("transInside", t)})()});ys=$elf._applyWithArgs("transInside", t);$
  1098. * elf._apply("setHelped");return xs.concat(ys)})()}),(function(){return
  1099. * (function(){x=$elf._apply("trans");xs=$elf._applyWithArgs("transInside
  1100. * ", t);return [x].concat(xs)})()}),(function(){return []}))})()};BSAndO
  1101. * rOptimization.prototype=BSAndOrOptimization;;BSOMetaOptimizer=OMeta.de
  1102. * legated();BSOMetaOptimizer['optimizeGrammar']=function() {var $elf=thi
  1103. * s,n,sn,rs;return (function(){$elf._form(function(){return (function(){
  1104. * $elf._applyWithArgs("exactly", "Grammar");n=$elf._apply("anything");sn
  1105. * =$elf._apply("anything");return rs=$elf._many(function(){return $elf._
  1106. * apply("optimizeRule")})})()});return ["Grammar",n,sn].concat(rs)})()};
  1107. * BSOMetaOptimizer['optimizeRule']=function() {var $elf=this,r,r;return
  1108. * (function(){r=$elf._apply("anything");$elf._many(function(){return r=$
  1109. * elf._applyWithArgs("foreign", BSAndOrOptimization, "optimize", r)});re
  1110. * turn r})()};BSOMetaOptimizer.prototype=BSOMetaOptimizer;}#CRLF##CRLF#{
  1111. * BSOMetaJSParser=BSJSParser.delegated();BSOMetaJSParser['srcElem']=func
  1112. * tion() {var $elf=this,r;return $elf._or((function(){return (function()
  1113. * {$elf._apply("spaces");r=$elf._applyWithArgs("foreign", BSOMetaParser,
  1114. *  "grammar");$elf._apply("sc");return r})()}),(function(){return BSJSPa
  1115. * rser._superApplyWithArgs($elf,"srcElem")}))};BSOMetaJSParser.prototype
  1116. * =BSOMetaJSParser;;BSOMetaJSTranslator=BSJSTranslator.delegated();BSOMe
  1117. * taJSTranslator['Grammar']=function() {var $elf=this;return $elf._apply
  1118. * WithArgs("foreign", BSOMetaTranslator, "Grammar")};BSOMetaJSTranslator
  1119. * .prototype=BSOMetaJSTranslator;}#CRLF#
  1120. * function translateCode(s) {
  1121. * var translationError = function(m, i) { throw fail };
  1122. * var tree = BSOMetaJSParser.matchAll(s, "topLevel", undefined, function
  1123. * (m, i) { throw fail.delegated({errorPos: i}) });
  1124. * return BSOMetaJSTranslator.match(tree, "trans", undefined, translation
  1125. * Error) }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement