diff options
Diffstat (limited to 'imports/codemirror/mode/go/index.html')
-rw-r--r-- | imports/codemirror/mode/go/index.html | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/imports/codemirror/mode/go/index.html b/imports/codemirror/mode/go/index.html new file mode 100644 index 00000000..9cdad1ad --- /dev/null +++ b/imports/codemirror/mode/go/index.html | |||
@@ -0,0 +1,72 @@ | |||
1 | <!doctype html> | ||
2 | <html> | ||
3 | <head> | ||
4 | <title>CodeMirror: Go mode</title> | ||
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
6 | <link rel="stylesheet" href="../../theme/elegant.css"> | ||
7 | <script src="../../lib/codemirror.js"></script> | ||
8 | <script src="go.js"></script> | ||
9 | <link rel="stylesheet" href="../../doc/docs.css"> | ||
10 | <style>.CodeMirror {border:1px solid #999; background:#ffc}</style> | ||
11 | </head> | ||
12 | <body> | ||
13 | <h1>CodeMirror: Go mode</h1> | ||
14 | |||
15 | <form><textarea id="code" name="code"> | ||
16 | // Prime Sieve in Go. | ||
17 | // Taken from the Go specification. | ||
18 | // Copyright © The Go Authors. | ||
19 | |||
20 | package main | ||
21 | |||
22 | import "fmt" | ||
23 | |||
24 | // Send the sequence 2, 3, 4, ... to channel 'ch'. | ||
25 | func generate(ch chan<- int) { | ||
26 | for i := 2; ; i++ { | ||
27 | ch <- i // Send 'i' to channel 'ch' | ||
28 | } | ||
29 | } | ||
30 | |||
31 | // Copy the values from channel 'src' to channel 'dst', | ||
32 | // removing those divisible by 'prime'. | ||
33 | func filter(src <-chan int, dst chan<- int, prime int) { | ||
34 | for i := range src { // Loop over values received from 'src'. | ||
35 | if i%prime != 0 { | ||
36 | dst <- i // Send 'i' to channel 'dst'. | ||
37 | } | ||
38 | } | ||
39 | } | ||
40 | |||
41 | // The prime sieve: Daisy-chain filter processes together. | ||
42 | func sieve() { | ||
43 | ch := make(chan int) // Create a new channel. | ||
44 | go generate(ch) // Start generate() as a subprocess. | ||
45 | for { | ||
46 | prime := <-ch | ||
47 | fmt.Print(prime, "\n") | ||
48 | ch1 := make(chan int) | ||
49 | go filter(ch, ch1, prime) | ||
50 | ch = ch1 | ||
51 | } | ||
52 | } | ||
53 | |||
54 | func main() { | ||
55 | sieve() | ||
56 | } | ||
57 | </textarea></form> | ||
58 | |||
59 | <script> | ||
60 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | ||
61 | theme: "elegant", | ||
62 | matchBrackets: true, | ||
63 | indentUnit: 8, | ||
64 | tabSize: 8, | ||
65 | indentWithTabs: true, | ||
66 | mode: "text/x-go" | ||
67 | }); | ||
68 | </script> | ||
69 | |||
70 | <p><strong>MIME type:</strong> <code>text/x-go</code></p> | ||
71 | </body> | ||
72 | </html> | ||