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