Fix: merge conflict
[myslice.git] / to-be-integrated / third-party / codemirror-3.15 / mode / groovy / index.html
1 <!doctype html>
2 <html>
3   <head>
4     <meta charset="utf-8">
5     <title>CodeMirror: Groovy mode</title>
6     <link rel="stylesheet" href="../../lib/codemirror.css">
7     <script src="../../lib/codemirror.js"></script>
8     <script src="../../addon/edit/matchbrackets.js"></script>
9     <script src="groovy.js"></script>
10     <link rel="stylesheet" href="../../doc/docs.css">
11     <style>.CodeMirror {border-top: 1px solid #500; border-bottom: 1px solid #500;}</style>
12   </head>
13   <body>
14     <h1>CodeMirror: Groovy mode</h1>
15
16 <form><textarea id="code" name="code">
17 //Pattern for groovy script
18 def p = ~/.*\.groovy/
19 new File( 'd:\\scripts' ).eachFileMatch(p) {f ->
20   // imports list
21   def imports = []
22   f.eachLine {
23     // condition to detect an import instruction
24     ln -> if ( ln =~ '^import .*' ) {
25       imports << "${ln - 'import '}"
26     }
27   }
28   // print thmen
29   if ( ! imports.empty ) {
30     println f
31     imports.each{ println "   $it" }
32   }
33 }
34
35 /* Coin changer demo code from http://groovy.codehaus.org */
36
37 enum UsCoin {
38   quarter(25), dime(10), nickel(5), penny(1)
39   UsCoin(v) { value = v }
40   final value
41 }
42
43 enum OzzieCoin {
44   fifty(50), twenty(20), ten(10), five(5)
45   OzzieCoin(v) { value = v }
46   final value
47 }
48
49 def plural(word, count) {
50   if (count == 1) return word
51   word[-1] == 'y' ? word[0..-2] + "ies" : word + "s"
52 }
53
54 def change(currency, amount) {
55   currency.values().inject([]){ list, coin ->
56      int count = amount / coin.value
57      amount = amount % coin.value
58      list += "$count ${plural(coin.toString(), count)}"
59   }
60 }
61 </textarea></form>
62
63     <script>
64       var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
65         lineNumbers: true,
66         matchBrackets: true,
67         mode: "text/x-groovy"
68       });
69     </script>
70
71     <p><strong>MIME types defined:</strong> <code>text/x-groovy</code></p>
72   </body>
73 </html>