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.

71 lines
1.6 KiB

7 months ago
  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="https://codemirror.net/5"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></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/codemirror5">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(Die(n: 12).roll());
  29. }
  30. // Define a class.
  31. class Die {
  32. // Define a class variable.
  33. static final Random shaker = Random();
  34. // Define instance variables.
  35. final int sides;
  36. int? lastRoll;
  37. // Define a constructor.
  38. Die({int n = 6}) : sides = n {
  39. if (4 > n || n > 20) {
  40. // Support for errors and exceptions.
  41. throw ArgumentError(/* */);
  42. }
  43. }
  44. // Define a method using shorthand syntax.
  45. @override
  46. String toString() => '$lastRoll';
  47. // Define an instance method.
  48. int roll() {
  49. return lastRoll = 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>