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