diff options
author | Nivesh Rajbhandari | 2012-05-03 17:09:07 -0700 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-05-03 17:09:07 -0700 |
commit | 8be6e94b57f4bd6e28754a6113b4d6a401365e13 (patch) | |
tree | 19f48f969ab872b9ef46cc4e7d6c2b9d2544cd4d /imports/codemirror/mode/xquery/index.html | |
parent | c14b8d9fd1acde98ffc427b0bbdba7d1442c39a4 (diff) | |
parent | fec9ccee11ea21ffc95edce6e89d0d302b63e3d8 (diff) | |
download | ninja-8be6e94b57f4bd6e28754a6113b4d6a401365e13.tar.gz |
Merge branch 'refs/heads/ninja-internal' into WebGLFixes
Diffstat (limited to 'imports/codemirror/mode/xquery/index.html')
-rw-r--r-- | imports/codemirror/mode/xquery/index.html | 222 |
1 files changed, 222 insertions, 0 deletions
diff --git a/imports/codemirror/mode/xquery/index.html b/imports/codemirror/mode/xquery/index.html new file mode 100644 index 00000000..82f00d24 --- /dev/null +++ b/imports/codemirror/mode/xquery/index.html | |||
@@ -0,0 +1,222 @@ | |||
1 | <!doctype html> | ||
2 | <html> | ||
3 | <!-- | ||
4 | /* | ||
5 | Copyright (C) 2011 by MarkLogic Corporation | ||
6 | Author: Mike Brevoort <mike@brevoort.com> | ||
7 | |||
8 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
9 | of this software and associated documentation files (the "Software"), to deal | ||
10 | in the Software without restriction, including without limitation the rights | ||
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
12 | copies of the Software, and to permit persons to whom the Software is | ||
13 | furnished to do so, subject to the following conditions: | ||
14 | |||
15 | The above copyright notice and this permission notice shall be included in | ||
16 | all copies or substantial portions of the Software. | ||
17 | |||
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
24 | THE SOFTWARE. | ||
25 | */ | ||
26 | --> | ||
27 | <head> | ||
28 | <title>CodeMirror 2: JavaScript mode</title> | ||
29 | <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
30 | <script src="http://codemirror.net/lib/codemirror.js"></script> | ||
31 | <script src="xquery.js"></script> | ||
32 | <link rel="stylesheet" href="../../doc/docs.css"> | ||
33 | <link rel="stylesheet" href="../../theme/xq-dark.css"> | ||
34 | <style type="text/css"> | ||
35 | .CodeMirror { | ||
36 | border-top: 1px solid black; border-bottom: 1px solid black; | ||
37 | } | ||
38 | .CodeMirror-scroll { | ||
39 | height:400px; | ||
40 | } | ||
41 | </style> | ||
42 | </head> | ||
43 | <body> | ||
44 | <h1>CodeMirror 2: XQuery mode</h1> | ||
45 | |||
46 | <div class="cm-s-default"> | ||
47 | <textarea id="code" name="code"> | ||
48 | xquery version "1.0-ml"; | ||
49 | (: this is | ||
50 | : a | ||
51 | "comment" :) | ||
52 | let $let := <x attr="value">"test"<func>function() $var {function()} {$var}</func></x> | ||
53 | let $joe:=1 | ||
54 | return element element { | ||
55 | attribute attribute { 1 }, | ||
56 | element test { 'a' }, | ||
57 | attribute foo { "bar" }, | ||
58 | fn:doc()[ foo/@bar eq $let ], | ||
59 | //x } | ||
60 | |||
61 | (: a more 'evil' test :) | ||
62 | (: Modified Blakeley example (: with nested comment :) ... :) | ||
63 | declare private function local:declare() {()}; | ||
64 | declare private function local:private() {()}; | ||
65 | declare private function local:function() {()}; | ||
66 | declare private function local:local() {()}; | ||
67 | let $let := <let>let $let := "let"</let> | ||
68 | return element element { | ||
69 | attribute attribute { try { xdmp:version() } catch($e) { xdmp:log($e) } }, | ||
70 | attribute fn:doc { "bar" castable as xs:string }, | ||
71 | element text { text { "text" } }, | ||
72 | fn:doc()[ child::eq/(@bar | attribute::attribute) eq $let ], | ||
73 | //fn:doc | ||
74 | } | ||
75 | |||
76 | |||
77 | |||
78 | xquery version "1.0-ml"; | ||
79 | |||
80 | (: Copyright 2006-2010 Mark Logic Corporation. :) | ||
81 | |||
82 | (: | ||
83 | : Licensed under the Apache License, Version 2.0 (the "License"); | ||
84 | : you may not use this file except in compliance with the License. | ||
85 | : You may obtain a copy of the License at | ||
86 | : | ||
87 | : http://www.apache.org/licenses/LICENSE-2.0 | ||
88 | : | ||
89 | : Unless required by applicable law or agreed to in writing, software | ||
90 | : distributed under the License is distributed on an "AS IS" BASIS, | ||
91 | : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
92 | : See the License for the specific language governing permissions and | ||
93 | : limitations under the License. | ||
94 | :) | ||
95 | |||
96 | module namespace json = "http://marklogic.com/json"; | ||
97 | declare default function namespace "http://www.w3.org/2005/xpath-functions"; | ||
98 | |||
99 | (: Need to backslash escape any double quotes, backslashes, and newlines :) | ||
100 | declare function json:escape($s as xs:string) as xs:string { | ||
101 | let $s := replace($s, "\\", "\\\\") | ||
102 | let $s := replace($s, """", "\\""") | ||
103 | let $s := replace($s, codepoints-to-string((13, 10)), "\\n") | ||
104 | let $s := replace($s, codepoints-to-string(13), "\\n") | ||
105 | let $s := replace($s, codepoints-to-string(10), "\\n") | ||
106 | return $s | ||
107 | }; | ||
108 | |||
109 | declare function json:atomize($x as element()) as xs:string { | ||
110 | if (count($x/node()) = 0) then 'null' | ||
111 | else if ($x/@type = "number") then | ||
112 | let $castable := $x castable as xs:float or | ||
113 | $x castable as xs:double or | ||
114 | $x castable as xs:decimal | ||
115 | return | ||
116 | if ($castable) then xs:string($x) | ||
117 | else error(concat("Not a number: ", xdmp:describe($x))) | ||
118 | else if ($x/@type = "boolean") then | ||
119 | let $castable := $x castable as xs:boolean | ||
120 | return | ||
121 | if ($castable) then xs:string(xs:boolean($x)) | ||
122 | else error(concat("Not a boolean: ", xdmp:describe($x))) | ||
123 | else concat('"', json:escape($x), '"') | ||
124 | }; | ||
125 | |||
126 | (: Print the thing that comes after the colon :) | ||
127 | declare function json:print-value($x as element()) as xs:string { | ||
128 | if (count($x/*) = 0) then | ||
129 | json:atomize($x) | ||
130 | else if ($x/@quote = "true") then | ||
131 | concat('"', json:escape(xdmp:quote($x/node())), '"') | ||
132 | else | ||
133 | string-join(('{', | ||
134 | string-join(for $i in $x/* return json:print-name-value($i), ","), | ||
135 | '}'), "") | ||
136 | }; | ||
137 | |||
138 | (: Print the name and value both :) | ||
139 | declare function json:print-name-value($x as element()) as xs:string? { | ||
140 | let $name := name($x) | ||
141 | let $first-in-array := | ||
142 | count($x/preceding-sibling::*[name(.) = $name]) = 0 and | ||
143 | (count($x/following-sibling::*[name(.) = $name]) > 0 or $x/@array = "true") | ||
144 | let $later-in-array := count($x/preceding-sibling::*[name(.) = $name]) > 0 | ||
145 | return | ||
146 | |||
147 | if ($later-in-array) then | ||
148 | () (: I was handled previously :) | ||
149 | else if ($first-in-array) then | ||
150 | string-join(('"', json:escape($name), '":[', | ||
151 | string-join((for $i in ($x, $x/following-sibling::*[name(.) = $name]) return json:print-value($i)), ","), | ||
152 | ']'), "") | ||
153 | else | ||
154 | string-join(('"', json:escape($name), '":', json:print-value($x)), "") | ||
155 | }; | ||
156 | |||
157 | (:~ | ||
158 | Transforms an XML element into a JSON string representation. See http://json.org. | ||
159 | <p/> | ||
160 | Sample usage: | ||
161 | <pre> | ||
162 | xquery version "1.0-ml"; | ||
163 | import module namespace json="http://marklogic.com/json" at "json.xqy"; | ||
164 | json:serialize(&lt;foo&gt;&lt;bar&gt;kid&lt;/bar&gt;&lt;/foo&gt;) | ||
165 | </pre> | ||
166 | Sample transformations: | ||
167 | <pre> | ||
168 | &lt;e/&gt; becomes {"e":null} | ||
169 | &lt;e&gt;text&lt;/e&gt; becomes {"e":"text"} | ||
170 | &lt;e&gt;quote " escaping&lt;/e&gt; becomes {"e":"quote \" escaping"} | ||
171 | &lt;e&gt;backslash \ escaping&lt;/e&gt; becomes {"e":"backslash \\ escaping"} | ||
172 | &lt;e&gt;&lt;a&gt;text1&lt;/a&gt;&lt;b&gt;text2&lt;/b&gt;&lt;/e&gt; becomes {"e":{"a":"text1","b":"text2"}} | ||
173 | &lt;e&gt;&lt;a&gt;text1&lt;/a&gt;&lt;a&gt;text2&lt;/a&gt;&lt;/e&gt; becomes {"e":{"a":["text1","text2"]}} | ||
174 | &lt;e&gt;&lt;a array="true"&gt;text1&lt;/a&gt;&lt;/e&gt; becomes {"e":{"a":["text1"]}} | ||
175 | &lt;e&gt;&lt;a type="boolean"&gt;false&lt;/a&gt;&lt;/e&gt; becomes {"e":{"a":false}} | ||
176 | &lt;e&gt;&lt;a type="number"&gt;123.5&lt;/a&gt;&lt;/e&gt; becomes {"e":{"a":123.5}} | ||
177 | &lt;e quote="true"&gt;&lt;div attrib="value"/&gt;&lt;/e&gt; becomes {"e":"&lt;div attrib=\"value\"/&gt;"} | ||
178 | </pre> | ||
179 | <p/> | ||
180 | Namespace URIs are ignored. Namespace prefixes are included in the JSON name. | ||
181 | <p/> | ||
182 | Attributes are ignored, except for the special attribute @array="true" that | ||
183 | indicates the JSON serialization should write the node, even if single, as an | ||
184 | array, and the attribute @type that can be set to "boolean" or "number" to | ||
185 | dictate the value should be written as that type (unquoted). There's also | ||
186 | an @quote attribute that when set to true writes the inner content as text | ||
187 | rather than as structured JSON, useful for sending some XHTML over the | ||
188 | wire. | ||
189 | <p/> | ||
190 | Text nodes within mixed content are ignored. | ||
191 | |||
192 | @param $x Element node to convert | ||
193 | @return String holding JSON serialized representation of $x | ||
194 | |||
195 | @author Jason Hunter | ||
196 | @version 1.0.1 | ||
197 | |||
198 | Ported to xquery 1.0-ml; double escaped backslashes in json:escape | ||
199 | :) | ||
200 | declare function json:serialize($x as element()) as xs:string { | ||
201 | string-join(('{', json:print-name-value($x), '}'), "") | ||
202 | }; | ||
203 | </textarea> | ||
204 | </div> | ||
205 | |||
206 | <script> | ||
207 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | ||
208 | lineNumbers: true, | ||
209 | matchBrackets: true, | ||