index.html 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <!doctype html>
  2. <title>CodeMirror: Dart mode</title>
  3. <meta charset="utf-8"/>
  4. <link rel=stylesheet href="../../doc/docs.css">
  5. <link rel="stylesheet" href="../../lib/codemirror.css">
  6. <script src="../../lib/codemirror.js"></script>
  7. <script src="../clike/clike.js"></script>
  8. <script src="dart.js"></script>
  9. <style>.CodeMirror {border: 1px solid #dee;}</style>
  10. <div id=nav>
  11. <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
  12. <ul>
  13. <li><a href="../../index.html">Home</a>
  14. <li><a href="../../doc/manual.html">Manual</a>
  15. <li><a href="https://github.com/codemirror/codemirror">Code</a>
  16. </ul>
  17. <ul>
  18. <li><a href="../index.html">Language modes</a>
  19. <li><a class=active href="#">Dart</a>
  20. </ul>
  21. </div>
  22. <article>
  23. <h2>Dart mode</h2>
  24. <form>
  25. <textarea id="code" name="code">
  26. import 'dart:math' show Random;
  27. void main() {
  28. print(new Die(n: 12).roll());
  29. }
  30. // Define a class.
  31. class Die {
  32. // Define a class variable.
  33. static Random shaker = new Random();
  34. // Define instance variables.
  35. int sides, value;
  36. // Define a method using shorthand syntax.
  37. String toString() => '$value';
  38. // Define a constructor.
  39. Die({int n: 6}) {
  40. if (4 <= n && n <= 20) {
  41. sides = n;
  42. } else {
  43. // Support for errors and exceptions.
  44. throw new ArgumentError(/* */);
  45. }
  46. }
  47. // Define an instance method.
  48. int roll() {
  49. return value = shaker.nextInt(sides) + 1;
  50. }
  51. }
  52. </textarea>
  53. </form>
  54. <script>
  55. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  56. lineNumbers: true,
  57. mode: "application/dart"
  58. });
  59. </script>
  60. </article>