index.html 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <!doctype html>
  2. <title>CodeMirror: Scheme 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="scheme.js"></script>
  8. <style>.CodeMirror {background: #f8f8f8;}</style>
  9. <div id=nav>
  10. <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
  11. <ul>
  12. <li><a href="../../index.html">Home</a>
  13. <li><a href="../../doc/manual.html">Manual</a>
  14. <li><a href="https://github.com/codemirror/codemirror">Code</a>
  15. </ul>
  16. <ul>
  17. <li><a href="../index.html">Language modes</a>
  18. <li><a class=active href="#">Scheme</a>
  19. </ul>
  20. </div>
  21. <article>
  22. <h2>Scheme mode</h2>
  23. <form><textarea id="code" name="code">
  24. ; See if the input starts with a given symbol.
  25. (define (match-symbol input pattern)
  26. (cond ((null? (remain input)) #f)
  27. ((eqv? (car (remain input)) pattern) (r-cdr input))
  28. (else #f)))
  29. ; Allow the input to start with one of a list of patterns.
  30. (define (match-or input pattern)
  31. (cond ((null? pattern) #f)
  32. ((match-pattern input (car pattern)))
  33. (else (match-or input (cdr pattern)))))
  34. ; Allow a sequence of patterns.
  35. (define (match-seq input pattern)
  36. (if (null? pattern)
  37. input
  38. (let ((match (match-pattern input (car pattern))))
  39. (if match (match-seq match (cdr pattern)) #f))))
  40. ; Match with the pattern but no problem if it does not match.
  41. (define (match-opt input pattern)
  42. (let ((match (match-pattern input (car pattern))))
  43. (if match match input)))
  44. ; Match anything (other than '()), until pattern is found. The rather
  45. ; clumsy form of requiring an ending pattern is needed to decide where
  46. ; the end of the match is. If none is given, this will match the rest
  47. ; of the sentence.
  48. (define (match-any input pattern)
  49. (cond ((null? (remain input)) #f)
  50. ((null? pattern) (f-cons (remain input) (clear-remain input)))
  51. (else
  52. (let ((accum-any (collector)))
  53. (define (match-pattern-any input pattern)
  54. (cond ((null? (remain input)) #f)
  55. (else (accum-any (car (remain input)))
  56. (cond ((match-pattern (r-cdr input) pattern))
  57. (else (match-pattern-any (r-cdr input) pattern))))))
  58. (let ((retval (match-pattern-any input (car pattern))))
  59. (if retval
  60. (f-cons (accum-any) retval)
  61. #f))))))
  62. </textarea></form>
  63. <script>
  64. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
  65. </script>
  66. <p><strong>MIME types defined:</strong> <code>text/x-scheme</code>.</p>
  67. </article>