index.html 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>CodeMirror: PEG.js Mode</title>
  5. <meta charset="utf-8"/>
  6. <link rel=stylesheet href="../../doc/docs.css">
  7. <link rel="stylesheet" href="../../lib/codemirror.css">
  8. <script src="../../lib/codemirror.js"></script>
  9. <script src="../javascript/javascript.js"></script>
  10. <script src="pegjs.js"></script>
  11. <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
  12. </head>
  13. <body>
  14. <div id=nav>
  15. <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
  16. <ul>
  17. <li><a href="../../index.html">Home</a>
  18. <li><a href="../../doc/manual.html">Manual</a>
  19. <li><a href="https://github.com/codemirror/codemirror">Code</a>
  20. </ul>
  21. <ul>
  22. <li><a href="../index.html">Language modes</a>
  23. <li><a class=active href="#">PEG.js Mode</a>
  24. </ul>
  25. </div>
  26. <article>
  27. <h2>PEG.js Mode</h2>
  28. <form><textarea id="code" name="code">
  29. /*
  30. * Classic example grammar, which recognizes simple arithmetic expressions like
  31. * "2*(3+4)". The parser generated from this grammar then computes their value.
  32. */
  33. start
  34. = additive
  35. additive
  36. = left:multiplicative "+" right:additive { return left + right; }
  37. / multiplicative
  38. multiplicative
  39. = left:primary "*" right:multiplicative { return left * right; }
  40. / primary
  41. primary
  42. = integer
  43. / "(" additive:additive ")" { return additive; }
  44. integer "integer"
  45. = digits:[0-9]+ { return parseInt(digits.join(""), 10); }
  46. letter = [a-z]+</textarea></form>
  47. <script>
  48. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  49. mode: {name: "pegjs"},
  50. lineNumbers: true
  51. });
  52. </script>
  53. <h3>The PEG.js Mode</h3>
  54. <p> Created by Forbes Lindesay.</p>
  55. </article>
  56. </body>
  57. </html>