aboutsummaryrefslogtreecommitdiff
path: root/imports/codemirror/mode/xquery/index.html
diff options
context:
space:
mode:
authorJon Reid2012-05-04 14:56:24 -0700
committerJon Reid2012-05-04 14:56:24 -0700
commita6dd2917edcfeca1be7553e03281ddd538422ae1 (patch)
treee6846626bf1e967e80bcd652f6a76bb97abb1789 /imports/codemirror/mode/xquery/index.html
parent7fc185cc08b2ba912dbc7bce96f6a465c1dd6dbf (diff)
parent8964e070fa760d23c2de272ca36b8d9beba6007d (diff)
downloadninja-a6dd2917edcfeca1be7553e03281ddd538422ae1.tar.gz
Merge remote-tracking branch 'ninja-jduran/TimelineUber' into timeline-local
Diffstat (limited to 'imports/codemirror/mode/xquery/index.html')
-rw-r--r--imports/codemirror/mode/xquery/index.html222
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/*
5Copyright (C) 2011 by MarkLogic Corporation
6Author: Mike Brevoort <mike@brevoort.com>
7
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this software and associated documentation files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in
16all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24THE 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">
48xquery version &quot;1.0-ml&quot;;
49(: this is
50 : a
51 "comment" :)
52let $let := &lt;x attr=&quot;value&quot;&gt;&quot;test&quot;&lt;func&gt;function() $var {function()} {$var}&lt;/func&gt;&lt;/x&gt;
53let $joe:=1
54return element element {
55 attribute attribute { 1 },
56 element test { &#39;a&#39; },
57 attribute foo { &quot;bar&quot; },
58 fn:doc()[ foo/@bar eq $let ],
59 //x }
60
61(: a more 'evil' test :)
62(: Modified Blakeley example (: with nested comment :) ... :)
63declare private function local:declare() {()};
64declare private function local:private() {()};
65declare private function local:function() {()};
66declare private function local:local() {()};
67let $let := &lt;let&gt;let $let := &quot;let&quot;&lt;/let&gt;
68return element element {
69 attribute attribute { try { xdmp:version() } catch($e) { xdmp:log($e) } },
70 attribute fn:doc { &quot;bar&quot; castable as xs:string },
71 element text { text { &quot;text&quot; } },
72 fn:doc()[ child::eq/(@bar | attribute::attribute) eq $let ],
73 //fn:doc
74}
75
76
77
78xquery version &quot;1.0-ml&quot;;
79
80(: Copyright 2006-2010 Mark Logic Corporation. :)
81
82(:
83 : Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
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 &quot;AS IS&quot; 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
96module namespace json = &quot;http://marklogic.com/json&quot;;
97declare default function namespace &quot;http://www.w3.org/2005/xpath-functions&quot;;
98
99(: Need to backslash escape any double quotes, backslashes, and newlines :)
100declare function json:escape($s as xs:string) as xs:string {
101 let $s := replace($s, &quot;\\&quot;, &quot;\\\\&quot;)
102 let $s := replace($s, &quot;&quot;&quot;&quot;, &quot;\\&quot;&quot;&quot;)
103 let $s := replace($s, codepoints-to-string((13, 10)), &quot;\\n&quot;)
104 let $s := replace($s, codepoints-to-string(13), &quot;\\n&quot;)
105 let $s := replace($s, codepoints-to-string(10), &quot;\\n&quot;)
106 return $s
107};
108
109declare function json:atomize($x as element()) as xs:string {
110 if (count($x/node()) = 0) then 'null'
111 else if ($x/@type = &quot;number&quot;) 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(&quot;Not a number: &quot;, xdmp:describe($x)))
118 else if ($x/@type = &quot;boolean&quot;) then
119 let $castable := $x castable as xs:boolean
120 return
121 if ($castable) then xs:string(xs:boolean($x))
122 else error(concat(&quot;Not a boolean: &quot;, xdmp:describe($x)))
123 else concat('&quot;', json:escape($x), '&quot;')
124};
125
126(: Print the thing that comes after the colon :)
127declare 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 = &quot;true&quot;) then
131 concat('&quot;', json:escape(xdmp:quote($x/node())), '&quot;')
132 else
133 string-join(('{',
134 string-join(for $i in $x/* return json:print-name-value($i), &quot;,&quot;),
135 '}'), &quot;&quot;)
136};
137
138(: Print the name and value both :)
139declare 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]) &gt; 0 or $x/@array = &quot;true&quot;)
144 let $later-in-array := count($x/preceding-sibling::*[name(.) = $name]) &gt; 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(('&quot;', json:escape($name), '&quot;:[',
151 string-join((for $i in ($x, $x/following-sibling::*[name(.) = $name]) return json:print-value($i)), &quot;,&quot;),
152 ']'), &quot;&quot;)
153 else
154 string-join(('&quot;', json:escape($name), '&quot;:', json:print-value($x)), &quot;&quot;)
155};
156
157(:~
158 Transforms an XML element into a JSON string representation. See http://json.org.
159 &lt;p/&gt;
160 Sample usage:
161 &lt;pre&gt;
162 xquery version &quot;1.0-ml&quot;;
163 import module namespace json=&quot;http://marklogic.com/json&quot; at &quot;json.xqy&quot;;
164 json:serialize(&amp;lt;foo&amp;gt;&amp;lt;bar&amp;gt;kid&amp;lt;/bar&amp;gt;&amp;lt;/foo&amp;gt;)
165 &lt;/pre&gt;
166 Sample transformations:
167 &lt;pre&gt;
168 &amp;lt;e/&amp;gt; becomes {&quot;e&quot;:null}
169 &amp;lt;e&amp;gt;text&amp;lt;/e&amp;gt; becomes {&quot;e&quot;:&quot;text&quot;}
170 &amp;lt;e&amp;gt;quote &quot; escaping&amp;lt;/e&amp;gt; becomes {&quot;e&quot;:&quot;quote \&quot; escaping&quot;}
171 &amp;lt;e&amp;gt;backslash \ escaping&amp;lt;/e&amp;gt; becomes {&quot;e&quot;:&quot;backslash \\ escaping&quot;}
172 &amp;lt;e&amp;gt;&amp;lt;a&amp;gt;text1&amp;lt;/a&amp;gt;&amp;lt;b&amp;gt;text2&amp;lt;/b&amp;gt;&amp;lt;/e&amp;gt; becomes {&quot;e&quot;:{&quot;a&quot;:&quot;text1&quot;,&quot;b&quot;:&quot;text2&quot;}}
173 &amp;lt;e&amp;gt;&amp;lt;a&amp;gt;text1&amp;lt;/a&amp;gt;&amp;lt;a&amp;gt;text2&amp;lt;/a&amp;gt;&amp;lt;/e&amp;gt; becomes {&quot;e&quot;:{&quot;a&quot;:[&quot;text1&quot;,&quot;text2&quot;]}}
174 &amp;lt;e&amp;gt;&amp;lt;a array=&quot;true&quot;&amp;gt;text1&amp;lt;/a&amp;gt;&amp;lt;/e&amp;gt; becomes {&quot;e&quot;:{&quot;a&quot;:[&quot;text1&quot;]}}
175 &amp;lt;e&amp;gt;&amp;lt;a type=&quot;boolean&quot;&amp;gt;false&amp;lt;/a&amp;gt;&amp;lt;/e&amp;gt; becomes {&quot;e&quot;:{&quot;a&quot;:false}}
176 &amp;lt;e&amp;gt;&amp;lt;a type=&quot;number&quot;&amp;gt;123.5&amp;lt;/a&amp;gt;&amp;lt;/e&amp;gt; becomes {&quot;e&quot;:{&quot;a&quot;:123.5}}
177 &amp;lt;e quote=&quot;true&quot;&amp;gt;&amp;lt;div attrib=&quot;value&quot;/&amp;gt;&amp;lt;/e&amp;gt; becomes {&quot;e&quot;:&quot;&amp;lt;div attrib=\&quot;value\&quot;/&amp;gt;&quot;}
178 &lt;/pre&gt;
179 &lt;p/&gt;
180 Namespace URIs are ignored. Namespace prefixes are included in the JSON name.
181 &lt;p/&gt;
182 Attributes are ignored, except for the special attribute @array=&quot;true&quot; 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 &quot;boolean&quot; or &quot;number&quot; 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 &lt;p/&gt;
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:)
200declare function json:serialize($x as element()) as xs:string {
201 string-join(('{', json:print-name-value($x), '}'), &quot;&quot;)
202};
203 </textarea>
204</div>
205
206 <script>
207 var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
208 lineNumbers: true,
209