PageRenderTime 1324ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/system/thirdparty/codemirror/contrib/ometa/index.html

https://gitlab.com/srueegger/1zu12bB
HTML | 77 lines | 68 code | 9 blank | 0 comment | 0 complexity | fa2d31219eb47b6a20bc5ecc223e3773 MD5 | raw file
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head>
  3. <script src="../../js/codemirror.js" type="text/javascript"></script>
  4. <title>CodeMirror: OmetaJS demonstration</title>
  5. <link rel="stylesheet" type="text/css" href="../../css/docs.css"/>
  6. </head>
  7. <body style="padding: 20px;">
  8. <p>This page demonstrates <a href="../../index.html">CodeMirror</a>'s <a
  9. href="http://www.tinlizzie.org/ometa">OmetaJS</a> parser.</p>
  10. <p>Adapted from the official Javascript parser by Eric KEDJI
  11. &lt;<a href="mailto:eric.kedji@gmail.com">eric.kedji@gmail.com</a>&gt;.</p>
  12. <div style="border-top: 1px solid black; border-bottom: 1px solid black;">
  13. <textarea id="code" cols="120" rows="30">
  14. // Source: http://www.tinlizzie.org/ometa-js/#Lisp
  15. // Inspired by McCarthy's meta-circular lisp
  16. ometa Lisp {
  17. ev = string:a -> self.env[a]
  18. | [#lambda :fs :body] -> [#lambda, fs, body]
  19. | [#quote :ans] -> ans
  20. | [#cond evCond:ans] -> ans
  21. | [ev:f ev*:xs] app(f, xs):ans -> ans,
  22. evCond = condF* condT:ans anything* -> x,
  23. condT = [ev:x ?x ev:ans] -> ans,
  24. condF = ~condT anything,
  25. app = #car [[:hd anything*]] -> hd
  26. | #cdr [[:hd anything*:tl]] -> tl
  27. | #cons [:hd :tl] -> [hd].concat(tl)
  28. | #atom [:x] -> (!(x instanceof Array))
  29. | #eq [:x :y] -> (x == y)
  30. | [#lambda :fs :body] :args
  31. enter bind(fs, args) ev(body):ans leave -> ans,
  32. enter = -> (self.env = self.env.delegated({_p: self.env})),
  33. bind = [] []
  34. | [:f anything*:fs] [:a anything*:as] bind(fs, as) -> (self.env[f] = a),
  35. leave = -> (self.env = self.env._p)
  36. }
  37. Lisp.initialize = function() { this.env = {car: "car", cdr: "cdr", cons: "cons", atom: "atom", eq: "eq", nil: null, T: "T"} }
  38. lispEval = function(x) { return Lisp.match(x, "ev") }
  39. lispEval([`quote, [1, 2, 3]])
  40. lispEval([`car, [`quote, [1, 2, 3]]])
  41. lispEval([`cdr, [`quote, [1, 2, 3]]])
  42. lispEval([`cons, [`quote, `x], [`quote, `y]])
  43. lispEval([`eq, [`quote, `x], [`quote, `x]])
  44. lispEval([[`lambda, [`x], [`cons, `x, `x]], [`quote, `boo]])
  45. </textarea>
  46. </div>
  47. <script type="text/javascript">
  48. /* var textarea = document.getElementById('code');
  49. var editor = new MirrorFrame(CodeMirror.replace(textarea), {
  50. height: "350px",
  51. content: textarea.value,
  52. parserfile: ["tokenizeometa.js", "parseometa.js"],
  53. stylesheet: "css/ometacolors.css",
  54. path: "js/",
  55. autoMatchParens: true
  56. });
  57. */
  58. var editor = CodeMirror.fromTextArea('code', {
  59. height: "450px",
  60. parserfile: ["../contrib/ometa/js/tokenizeometa.js",
  61. "../contrib/ometa/js/parseometa.js"],
  62. stylesheet: "css/ometacolors.css",
  63. path: "../../js/",
  64. textWrapping: false
  65. });
  66. </script>
  67. </body>
  68. </html>