index.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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="http://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. def initialize(@foo); end
  43. abstract def abstract_method : String
  44. @[AlwaysInline]
  45. def with_foofoo
  46. with Foo.new(self) yield
  47. end
  48. struct Foo
  49. def initialize(@foo); 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)
  59. super(@bar.not_nil! + 100)
  60. end
  61. macro alias_method(name, method)
  62. def {{ name }}(*args)
  63. {{ method }}(*args)
  64. end
  65. end
  66. def a_method
  67. "Hello, World"
  68. end
  69. alias_method abstract_method, a_method
  70. macro def show_instance_vars : Nil
  71. {% for var in @type.instance_vars %}
  72. puts "@{{ var }} = #{ @{{ var }} }"
  73. {% end %}
  74. nil
  75. end
  76. end
  77. class Baz &lt; Bar; end
  78. lib LibC
  79. fun c_puts = "puts"(str : Char*) : Int
  80. end
  81. $baz = Baz.new(100)
  82. $baz.show_instance_vars
  83. $baz.with_foofoo do
  84. LibC.c_puts hello_world
  85. end
  86. </textarea></form>
  87. <script>
  88. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  89. mode: "text/x-crystal",
  90. matchBrackets: true,
  91. indentUnit: 2
  92. });
  93. </script>
  94. <p><strong>MIME types defined:</strong> <code>text/x-crystal</code>.</p>
  95. </article>