all repos — NoPaste @ 29b774f090102303e43cf939b38ac2083e62d9f1

Resurrected - The PussTheCat.org fork of NoPaste

scripts/CodeMirror/mode/dylan/index.html (view raw)

  1<!doctype html>
  2
  3<title>CodeMirror: Dylan mode</title>
  4<meta charset="utf-8"/>
  5<link rel=stylesheet href="../../doc/docs.css">
  6
  7<link rel="stylesheet" href="../../lib/codemirror.css">
  8<script src="../../lib/codemirror.js"></script>
  9<script src="../../addon/edit/matchbrackets.js"></script>
 10<script src="../../addon/comment/continuecomment.js"></script>
 11<script src="../../addon/comment/comment.js"></script>
 12<script src="dylan.js"></script>
 13<style>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
 14<div id=nav>
 15  <a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></a>
 16
 17  <ul>
 18    <li><a href="../../index.html">Home</a>
 19    <li><a href="../../doc/manual.html">Manual</a>
 20    <li><a href="https://github.com/codemirror/codemirror">Code</a>
 21  </ul>
 22  <ul>
 23    <li><a href="../index.html">Language modes</a>
 24    <li><a class=active href="#">Dylan</a>
 25  </ul>
 26</div>
 27
 28<article>
 29<h2>Dylan mode</h2>
 30
 31
 32<div><textarea id="code" name="code">
 33Module:       locators-internals
 34Synopsis:     Abstract modeling of locations
 35Author:       Andy Armstrong
 36Copyright:    Original Code is Copyright (c) 1995-2004 Functional Objects, Inc.
 37              All rights reserved.
 38License:      See License.txt in this distribution for details.
 39Warranty:     Distributed WITHOUT WARRANTY OF ANY KIND
 40
 41define open generic locator-server
 42    (locator :: <locator>) => (server :: false-or(<server-locator>));
 43define open generic locator-host
 44    (locator :: <locator>) => (host :: false-or(<string>));
 45define open generic locator-volume
 46    (locator :: <locator>) => (volume :: false-or(<string>));
 47define open generic locator-directory
 48    (locator :: <locator>) => (directory :: false-or(<directory-locator>));
 49define open generic locator-relative?
 50    (locator :: <locator>) => (relative? :: <boolean>);
 51define open generic locator-path
 52    (locator :: <locator>) => (path :: <sequence>);
 53define open generic locator-base
 54    (locator :: <locator>) => (base :: false-or(<string>));
 55define open generic locator-extension
 56    (locator :: <locator>) => (extension :: false-or(<string>));
 57
 58/// Locator classes
 59
 60define open abstract class <directory-locator> (<physical-locator>)
 61end class <directory-locator>;
 62
 63define open abstract class <file-locator> (<physical-locator>)
 64end class <file-locator>;
 65
 66define method as
 67    (class == <directory-locator>, string :: <string>)
 68 => (locator :: <directory-locator>)
 69  as(<native-directory-locator>, string)
 70end method as;
 71
 72define method make
 73    (class == <directory-locator>,
 74     #key server :: false-or(<server-locator>) = #f,
 75          path :: <sequence> = #[],
 76          relative? :: <boolean> = #f,
 77          name :: false-or(<string>) = #f)
 78 => (locator :: <directory-locator>)
 79  make(<native-directory-locator>,
 80       server:    server,
 81       path:      path,
 82       relative?: relative?,
 83       name:      name)
 84end method make;
 85
 86define method as
 87    (class == <file-locator>, string :: <string>)
 88 => (locator :: <file-locator>)
 89  as(<native-file-locator>, string)
 90end method as;
 91
 92define method make
 93    (class == <file-locator>,
 94     #key directory :: false-or(<directory-locator>) = #f,
 95          base :: false-or(<string>) = #f,
 96          extension :: false-or(<string>) = #f,
 97          name :: false-or(<string>) = #f)
 98 => (locator :: <file-locator>)
 99  make(<native-file-locator>,
100       directory: directory,
101       base:      base,
102       extension: extension,
103       name:      name)
104end method make;
105
106/// Locator coercion
107
108//---*** andrewa: This caching scheme doesn't work yet, so disable it.
109define constant $cache-locators?        = #f;
110define constant $cache-locator-strings? = #f;
111
112define constant $locator-to-string-cache = make(<object-table>, weak: #"key");
113define constant $string-to-locator-cache = make(<string-table>, weak: #"value");
114
115define open generic locator-as-string
116    (class :: subclass(<string>), locator :: <locator>)
117 => (string :: <string>);
118
119define open generic string-as-locator
120    (class :: subclass(<locator>), string :: <string>)
121 => (locator :: <locator>);
122
123define sealed sideways method as
124    (class :: subclass(<string>), locator :: <locator>)
125 => (string :: <string>)
126  let string = element($locator-to-string-cache, locator, default: #f);
127  if (string)
128    as(class, string)
129  else
130    let string = locator-as-string(class, locator);
131    if ($cache-locator-strings?)
132      element($locator-to-string-cache, locator) := string;
133    else
134      string
135    end
136  end
137end method as;
138
139define sealed sideways method as
140    (class :: subclass(<locator>), string :: <string>)
141 => (locator :: <locator>)
142  let locator = element($string-to-locator-cache, string, default: #f);
143  if (instance?(locator, class))
144    locator
145  else
146    let locator = string-as-locator(class, string);
147    if ($cache-locators?)
148      element($string-to-locator-cache, string) := locator;
149    else
150      locator
151    end
152  end
153end method as;
154
155/// Locator conditions
156
157define class <locator-error> (<format-string-condition>, <error>)
158end class <locator-error>;
159
160define function locator-error
161    (format-string :: <string>, #rest format-arguments)
162  error(make(<locator-error>, 
163             format-string:    format-string,
164             format-arguments: format-arguments))
165end function locator-error;
166
167/// Useful locator protocols
168
169define open generic locator-test
170    (locator :: <directory-locator>) => (test :: <function>);
171
172define method locator-test
173    (locator :: <directory-locator>) => (test :: <function>)
174  \=
175end method locator-test;
176
177define open generic locator-might-have-links?
178    (locator :: <directory-locator>) => (links? :: <boolean>);
179
180define method locator-might-have-links?
181    (locator :: <directory-locator>) => (links? :: singleton(#f))
182  #f
183end method locator-might-have-links?;
184
185define method locator-relative?
186    (locator :: <file-locator>) => (relative? :: <boolean>)
187  let directory = locator.locator-directory;
188  ~directory | directory.locator-relative?
189end method locator-relative?;
190
191define method current-directory-locator?
192    (locator :: <directory-locator>) => (current-directory? :: <boolean>)
193  locator.locator-relative?
194    & locator.locator-path = #[#"self"]
195end method current-directory-locator?;
196
197define method locator-directory
198    (locator :: <directory-locator>) => (parent :: false-or(<directory-locator>))
199  let path = locator.locator-path;
200  unless (empty?(path))
201    make(object-class(locator),
202         server:    locator.locator-server,
203         path:      copy-sequence(path, end: path.size - 1),
204         relative?: locator.locator-relative?)
205  end
206end method locator-directory;
207
208/// Simplify locator
209
210define open generic simplify-locator
211    (locator :: <physical-locator>)
212 => (simplified-locator :: <physical-locator>);
213
214define method simplify-locator
215    (locator :: <directory-locator>)
216 => (simplified-locator :: <directory-locator>)
217  let path = locator.locator-path;
218  let relative? = locator.locator-relative?;
219  let resolve-parent? = ~locator.locator-might-have-links?;
220  let simplified-path
221    = simplify-path(path, 
222                    resolve-parent?: resolve-parent?,
223                    relative?: relative?);
224  if (path ~= simplified-path)
225    make(object-class(locator),
226         server:    locator.locator-server,
227         path:      simplified-path,
228         relative?: locator.locator-relative?)
229  else
230    locator
231  end
232end method simplify-locator;
233
234define method simplify-locator
235    (locator :: <file-locator>) => (simplified-locator :: <file-locator>)
236  let directory = locator.locator-directory;
237  let simplified-directory = directory & simplify-locator(directory);
238  if (directory ~= simplified-directory)
239    make(object-class(locator),
240         directory: simplified-directory,
241         base:      locator.locator-base,
242         extension: locator.locator-extension)
243  else
244    locator
245  end
246end method simplify-locator;
247
248/// Subdirectory locator
249
250define open generic subdirectory-locator
251    (locator :: <directory-locator>, #rest sub-path)
252 => (subdirectory :: <directory-locator>);
253
254define method subdirectory-locator
255    (locator :: <directory-locator>, #rest sub-path)
256 => (subdirectory :: <directory-locator>)
257  let old-path = locator.locator-path;
258  let new-path = concatenate-as(<simple-object-vector>, old-path, sub-path);
259  make(object-class(locator),
260       server:    locator.locator-server,
261       path:      new-path,
262       relative?: locator.locator-relative?)
263end method subdirectory-locator;
264
265/// Relative locator
266
267define open generic relative-locator
268    (locator :: <physical-locator>, from-locator :: <physical-locator>)
269 => (relative-locator :: <physical-locator>);
270
271define method relative-locator
272    (locator :: <directory-locator>, from-locator :: <directory-locator>)
273 => (relative-locator :: <directory-locator>)
274  let path = locator.locator-path;
275  let from-path = from-locator.locator-path;
276  case
277    ~locator.locator-relative? & from-locator.locator-relative? =>
278      locator-error
279        ("Cannot find relative path of absolute locator %= from relative locator %=",
280         locator, from-locator);
281    locator.locator-server ~= from-locator.locator-server =>
282      locator;
283    path = from-path =>
284      make(object-class(locator),
285           path: vector(#"self"),
286           relative?: #t);
287    otherwise =>
288      make(object-class(locator),
289           path: relative-path(path, from-path, test: locator.locator-test),
290           relative?: #t);
291  end
292end method relative-locator;
293
294define method relative-locator
295    (locator :: <file-locator>, from-directory :: <directory-locator>)
296 => (relative-locator :: <file-locator>)
297  let directory = locator.locator-directory;
298  let relative-directory = directory & relative-locator(directory, from-directory);
299  if (relative-directory ~= directory)
300    simplify-locator
301      (make(object-class(locator),
302            directory: relative-directory,
303            base:      locator.locator-base,
304            extension: locator.locator-extension))
305  else
306    locator
307  end
308end method relative-locator;
309
310define method relative-locator
311    (locator :: <physical-locator>, from-locator :: <file-locator>)
312 => (relative-locator :: <physical-locator>)
313  let from-directory = from-locator.locator-directory;
314  case
315    from-directory =>
316      relative-locator(locator, from-directory);
317    ~locator.locator-relative? =>
318      locator-error
319        ("Cannot find relative path of absolute locator %= from relative locator %=",
320         locator, from-locator);
321    otherwise =>
322      locator;
323  end
324end method relative-locator;
325
326/// Merge locators
327
328define open generic merge-locators
329    (locator :: <physical-locator>, from-locator :: <physical-locator>)
330 => (merged-locator :: <physical-locator>);
331
332/// Merge locators
333
334define method merge-locators
335    (locator :: <directory-locator>, from-locator :: <directory-locator>)
336 => (merged-locator :: <directory-locator>)
337  if (locator.locator-relative?)
338    let path = concatenate(from-locator.locator-path, locator.locator-path);
339    simplify-locator
340      (make(object-class(locator),
341            server:    from-locator.locator-server,
342            path:      path,
343            relative?: from-locator.locator-relative?))
344  else
345    locator
346  end
347end method merge-locators;
348
349define method merge-locators
350    (locator :: <file-locator>, from-locator :: <directory-locator>)
351 => (merged-locator :: <file-locator>)
352  let directory = locator.locator-directory;
353  let merged-directory 
354    = if (directory)
355        merge-locators(directory, from-locator)
356      else
357        simplify-locator(from-locator)
358      end;
359  if (merged-directory ~= directory)
360    make(object-class(locator),
361         directory: merged-directory,
362         base:      locator.locator-base,
363         extension: locator.locator-extension)
364  else
365    locator
366  end
367end method merge-locators;
368
369define method merge-locators
370    (locator :: <physical-locator>, from-locator :: <file-locator>)
371 => (merged-locator :: <physical-locator>)
372  let from-directory = from-locator.locator-directory;
373  if (from-directory)
374    merge-locators(locator, from-directory)
375  else
376    locator
377  end
378end method merge-locators;
379
380/// Locator protocols
381
382define sideways method supports-open-locator?
383    (locator :: <file-locator>) => (openable? :: <boolean>)
384  ~locator.locator-relative?
385end method supports-open-locator?;
386
387define sideways method open-locator
388    (locator :: <file-locator>, #rest keywords, #key, #all-keys)
389 => (stream :: <stream>)
390  apply(open-file-stream, locator, keywords)
391end method open-locator;
392</textarea></div>
393
394    <script>
395      var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
396        mode: "text/x-dylan",
397        lineNumbers: true,
398        matchBrackets: true,
399        continueComments: "Enter",
400        extraKeys: {"Ctrl-Q": "toggleComment"},
401        tabMode: "indent",
402        indentUnit: 2
403      });
404    </script>
405
406    <p><strong>MIME types defined:</strong> <code>text/x-dylan</code>.</p>
407</article>