Theme Inspinia
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

index.html 13KB

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