File modules/editor/codemirror/mode/clike/index.html

Last commit: Sun Dec 17 01:14:09 2017 +0100	Jan Dankert	Integration eines weiteren Code-Editors: Codemirror. Demnächst müssen wir hier mal aufräumen und andere Editoren rauswerfen.
1 <!doctype html> 2 3 <title>CodeMirror: C-like 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 <link rel="stylesheet" href="../../addon/hint/show-hint.css"> 11 <script src="../../addon/hint/show-hint.js"></script> 12 <script src="clike.js"></script> 13 <style>.CodeMirror {border: 2px inset #dee;}</style> 14 <div id=nav> 15 <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a> 16 17 <ul> 18 <li><a href="../../index.html">Home</a> 19 <li><a href="../../doc/manual.html">Manual</a> 20 <li><a href="https://github.com/codemirror/codemirror">Code</a> 21 </ul> 22 <ul> 23 <li><a href="../index.html">Language modes</a> 24 <li><a class=active href="#">C-like</a> 25 </ul> 26 </div> 27 28 <article> 29 <h2>C-like mode</h2> 30 31 <div><textarea id="c-code"> 32 /* C demo code */ 33 34 #include <zmq.h> 35 #include <pthread.h> 36 #include <semaphore.h> 37 #include <time.h> 38 #include <stdio.h> 39 #include <fcntl.h> 40 #include <malloc.h> 41 42 typedef struct { 43 void* arg_socket; 44 zmq_msg_t* arg_msg; 45 char* arg_string; 46 unsigned long arg_len; 47 int arg_int, arg_command; 48 49 int signal_fd; 50 int pad; 51 void* context; 52 sem_t sem; 53 } acl_zmq_context; 54 55 #define p(X) (context->arg_##X) 56 57 void* zmq_thread(void* context_pointer) { 58 acl_zmq_context* context = (acl_zmq_context*)context_pointer; 59 char ok = 'K', err = 'X'; 60 int res; 61 62 while (1) { 63 while ((res = sem_wait(&amp;context->sem)) == EINTR); 64 if (res) {write(context->signal_fd, &amp;err, 1); goto cleanup;} 65 switch(p(command)) { 66 case 0: goto cleanup; 67 case 1: p(socket) = zmq_socket(context->context, p(int)); break; 68 case 2: p(int) = zmq_close(p(socket)); break; 69 case 3: p(int) = zmq_bind(p(socket), p(string)); break; 70 case 4: p(int) = zmq_connect(p(socket), p(string)); break; 71 case 5: p(int) = zmq_getsockopt(p(socket), p(int), (void*)p(string), &amp;p(len)); break; 72 case 6: p(int) = zmq_setsockopt(p(socket), p(int), (void*)p(string), p(len)); break; 73 case 7: p(int) = zmq_send(p(socket), p(msg), p(int)); break; 74 case 8: p(int) = zmq_recv(p(socket), p(msg), p(int)); break; 75 case 9: p(int) = zmq_poll(p(socket), p(int), p(len)); break; 76 } 77 p(command) = errno; 78 write(context->signal_fd, &amp;ok, 1); 79 } 80 cleanup: 81 close(context->signal_fd); 82 free(context_pointer); 83 return 0; 84 } 85 86 void* zmq_thread_init(void* zmq_context, int signal_fd) { 87 acl_zmq_context* context = malloc(sizeof(acl_zmq_context)); 88 pthread_t thread; 89 90 context->context = zmq_context; 91 context->signal_fd = signal_fd; 92 sem_init(&amp;context->sem, 1, 0); 93 pthread_create(&amp;thread, 0, &amp;zmq_thread, context); 94 pthread_detach(thread); 95 return context; 96 } 97 </textarea></div> 98 99 <h2>C++ example</h2> 100 101 <div><textarea id="cpp-code"> 102 #include <iostream> 103 #include "mystuff/util.h" 104 105 namespace { 106 enum Enum { 107 VAL1, VAL2, VAL3 108 }; 109 110 char32_t unicode_string = U"\U0010FFFF"; 111 string raw_string = R"delim(anything 112 you 113 want)delim"; 114 115 int Helper(const MyType& param) { 116 return 0; 117 } 118 } // namespace 119 120 class ForwardDec; 121 122 template <class T, class V> 123 class Class : public BaseClass { 124 const MyType<T, V> member_; 125 126 public: 127 const MyType<T, V>& Method() const { 128 return member_; 129 } 130 131 void Method2(MyType<T, V>* value); 132 } 133 134 template <class T, class V> 135 void Class::Method2(MyType<T, V>* value) { 136 std::out << 1 >> method(); 137 value->Method3(member_); 138 member_ = value; 139 } 140 </textarea></div> 141 142 <h2>Objective-C example</h2> 143 144 <div><textarea id="objectivec-code"> 145 /* 146 This is a longer comment 147 That spans two lines 148 */ 149 150 #import <Test/Test.h> 151 @implementation YourAppDelegate 152 153 // This is a one-line comment 154 155 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ 156 char myString[] = "This is a C character array"; 157 int test = 5; 158 return YES; 159 } 160 </textarea></div> 161 162 <h2>Java example</h2> 163 164 <div><textarea id="java-code"> 165 import com.demo.util.MyType; 166 import com.demo.util.MyInterface; 167 168 public enum Enum { 169 VAL1, VAL2, VAL3 170 } 171 172 public class Class<T, V> implements MyInterface { 173 public static final MyType<T, V> member; 174 175 private class InnerClass { 176 public int zero() { 177 return 0; 178 } 179 } 180 181 @Override 182 public MyType method() { 183 return member; 184 } 185 186 public void method2(MyType<T, V> value) { 187 method(); 188 value.method3(); 189 member = value; 190 } 191 } 192 </textarea></div> 193 194 <h2>Scala example</h2> 195 196 <div><textarea id="scala-code"> 197 object FilterTest extends App { 198 def filter(xs: List[Int], threshold: Int) = { 199 def process(ys: List[Int]): List[Int] = 200 if (ys.isEmpty) ys 201 else if (ys.head < threshold) ys.head :: process(ys.tail) 202 else process(ys.tail) 203 process(xs) 204 } 205 println(filter(List(1, 9, 2, 8, 3, 7, 4), 5)) 206 } 207 </textarea></div> 208 209 <h2>Kotlin mode</h2> 210 211 <div><textarea id="kotlin-code"> 212 package org.wasabi.http 213 214 import java.util.concurrent.Executors 215 import java.net.InetSocketAddress 216 import org.wasabi.app.AppConfiguration 217 import io.netty.bootstrap.ServerBootstrap 218 import io.netty.channel.nio.NioEventLoopGroup 219 import io.netty.channel.socket.nio.NioServerSocketChannel 220 import org.wasabi.app.AppServer 221 222 public class HttpServer(private val appServer: AppServer) { 223 224 val bootstrap: ServerBootstrap 225 val primaryGroup: NioEventLoopGroup 226 val workerGroup: NioEventLoopGroup 227 228 init { 229 // Define worker groups 230 primaryGroup = NioEventLoopGroup() 231 workerGroup = NioEventLoopGroup() 232 233 // Initialize bootstrap of server 234 bootstrap = ServerBootstrap() 235 236 bootstrap.group(primaryGroup, workerGroup) 237 bootstrap.channel(javaClass<NioServerSocketChannel>()) 238 bootstrap.childHandler(NettyPipelineInitializer(appServer)) 239 } 240 241 public fun start(wait: Boolean = true) { 242 val channel = bootstrap.bind(appServer.configuration.port)?.sync()?.channel() 243 244 if (wait) { 245 channel?.closeFuture()?.sync() 246 } 247 } 248 249 public fun stop() { 250 // Shutdown all event loops 251 primaryGroup.shutdownGracefully() 252 workerGroup.shutdownGracefully() 253 254 // Wait till all threads are terminated 255 primaryGroup.terminationFuture().sync() 256 workerGroup.terminationFuture().sync() 257 } 258 } 259 </textarea></div> 260 261 <h2>Ceylon mode</h2> 262 263 <div><textarea id="ceylon-code"> 264 "Produces the [[stream|Iterable]] that results from repeated 265 application of the given [[function|next]] to the given 266 [[first]] element of the stream, until the function first 267 returns [[finished]]. If the given function never returns 268 `finished`, the resulting stream is infinite. 269 270 For example: 271 272 loop(0)(2.plus).takeWhile(10.largerThan) 273 274 produces the stream `{ 0, 2, 4, 6, 8 }`." 275 tagged("Streams") 276 shared {Element+} loop&lt;Element&gt;( 277 "The first element of the resulting stream." 278 Element first)( 279 "The function that produces the next element of the 280 stream, given the current element. The function may 281 return [[finished]] to indicate the end of the 282 stream." 283 Element|Finished next(Element element)) 284 =&gt; let (start = first) 285 object satisfies {Element+} { 286 first =&gt; start; 287 empty =&gt; false; 288 function nextElement(Element element) 289 =&gt; next(element); 290 iterator() 291 =&gt; object satisfies Iterator&lt;Element&gt; { 292 variable Element|Finished current = start; 293 shared actual Element|Finished next() { 294 if (!is Finished result = current) { 295 current = nextElement(result); 296 return result; 297 } 298 else { 299 return finished; 300 } 301 } 302 }; 303 }; 304 </textarea></div> 305 306 <script> 307 var cEditor = CodeMirror.fromTextArea(document.getElementById("c-code"), { 308 lineNumbers: true, 309 matchBrackets: true, 310 mode: "text/x-csrc" 311 }); 312 var cppEditor = CodeMirror.fromTextArea(document.getElementById("cpp-code"), { 313 lineNumbers: true, 314 matchBrackets: true, 315 mode: "text/x-c++src" 316 }); 317 var javaEditor = CodeMirror.fromTextArea(document.getElementById("java-code"), { 318 lineNumbers: true, 319 matchBrackets: true, 320 mode: "text/x-java" 321 }); 322 var objectivecEditor = CodeMirror.fromTextArea(document.getElementById("objectivec-code"), { 323 lineNumbers: true, 324 matchBrackets: true, 325 mode: "text/x-objectivec" 326 }); 327 var scalaEditor = CodeMirror.fromTextArea(document.getElementById("scala-code"), { 328 lineNumbers: true, 329 matchBrackets: true, 330 mode: "text/x-scala" 331 }); 332 var kotlinEditor = CodeMirror.fromTextArea(document.getElementById("kotlin-code"), { 333 lineNumbers: true, 334 matchBrackets: true, 335 mode: "text/x-kotlin" 336 }); 337 var ceylonEditor = CodeMirror.fromTextArea(document.getElementById("ceylon-code"), { 338 lineNumbers: true, 339 matchBrackets: true, 340 mode: "text/x-ceylon" 341 }); 342 var mac = CodeMirror.keyMap.default == CodeMirror.keyMap.macDefault; 343 CodeMirror.keyMap.default[(mac ? "Cmd" : "Ctrl") + "-Space"] = "autocomplete"; 344 </script> 345 346 <p>Simple mode that tries to handle C-like languages as well as it 347 can. Takes two configuration parameters: <code>keywords</code>, an 348 object whose property names are the keywords in the language, 349 and <code>useCPP</code>, which determines whether C preprocessor 350 directives are recognized.</p> 351 352 <p><strong>MIME types defined:</strong> <code>text/x-csrc</code> 353 (C), <code>text/x-c++src</code> (C++), <code>text/x-java</code> 354 (Java), <code>text/x-csharp</code> (C#), 355 <code>text/x-objectivec</code> (Objective-C), 356 <code>text/x-scala</code> (Scala), <code>text/x-vertex</code> 357 <code>x-shader/x-fragment</code> (shader programs), 358 <code>text/x-squirrel</code> (Squirrel) and 359 <code>text/x-ceylon</code> (Ceylon)</p> 360 </article>
Download modules/editor/codemirror/mode/clike/index.html
History Sun, 17 Dec 2017 01:14:09 +0100 Jan Dankert Integration eines weiteren Code-Editors: Codemirror. Demnächst müssen wir hier mal aufräumen und andere Editoren rauswerfen.