index.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <!doctype html>
  2. <title>CodeMirror: Crystal 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="../../addon/edit/matchbrackets.js"></script>
  8. <script src="crystal.js"></script>
  9. <style>
  10. .CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
  11. .cm-s-default span.cm-arrow { color: red; }
  12. </style>
  13. <div id=nav>
  14. <a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
  15. <ul>
  16. <li><a href="../../index.html">Home</a>
  17. <li><a href="../../doc/manual.html">Manual</a>
  18. <li><a href="https://github.com/codemirror/codemirror">Code</a>
  19. </ul>
  20. <ul>
  21. <li><a href="../index.html">Language modes</a>
  22. <li><a class=active href="#">Crystal</a>
  23. </ul>
  24. </div>
  25. <article>
  26. <h2>Crystal mode</h2>
  27. <form><textarea id="code" name="code">
  28. # Features of Crystal
  29. # - Ruby-inspired syntax.
  30. # - Statically type-checked but without having to specify the type of variables or method arguments.
  31. # - Be able to call C code by writing bindings to it in Crystal.
  32. # - Have compile-time evaluation and generation of code, to avoid boilerplate code.
  33. # - Compile to efficient native code.
  34. # A very basic HTTP server
  35. require "http/server"
  36. server = HTTP::Server.new(8080) do |request|
  37. HTTP::Response.ok "text/plain", "Hello world, got #{request.path}!"
  38. end
  39. puts "Listening on http://0.0.0.0:8080"
  40. server.listen
  41. module Foo
  42. abstract def abstract_method : String
  43. @[AlwaysInline]
  44. def with_foofoo
  45. with Foo.new(self) yield
  46. end
  47. struct Foo
  48. def initialize(@foo : ::Foo)
  49. end
  50. def hello_world
  51. @foo.abstract_method
  52. end
  53. end
  54. end
  55. class Bar
  56. include Foo
  57. @@foobar = 12345
  58. def initialize(@bar : Int32)
  59. end
  60. macro alias_method(name, method)
  61. def {{ name }}(*args)
  62. {{ method }}(*args)
  63. end
  64. end
  65. def a_method
  66. "Hello, World"
  67. end
  68. alias_method abstract_method, a_method
  69. def show_instance_vars : Nil
  70. {% for var in @type.instance_vars %}
  71. puts "@{{ var }} = #{ @{{ var }} }"
  72. {% end %}
  73. end
  74. end
  75. class Baz &lt; Bar; end
  76. lib LibC
  77. fun c_puts = "puts"(str : Char*) : Int
  78. end
  79. baz = Baz.new(100)
  80. baz.show_instance_vars
  81. baz.with_foofoo do
  82. LibC.c_puts hello_world
  83. end
  84. </textarea></form>
  85. <script>
  86. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  87. mode: "text/x-crystal",
  88. matchBrackets: true,
  89. indentUnit: 2
  90. });
  91. </script>
  92. <p><strong>MIME types defined:</strong> <code>text/x-crystal</code>.</p>
  93. </article>