本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.8KB

  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>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
  12. </head>
  13. <body>
  14. <div id=nav>
  15. <a href="https://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>
上海开阖软件有限公司 沪ICP备12045867号-1