index.html 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>CodeMirror 2: Scheme mode</title>
  5. <link rel="stylesheet" href="../../lib/codemirror.css">
  6. <script src="../../lib/codemirror.js"></script>
  7. <script src="scheme.js"></script>
  8. <link rel="stylesheet" href="../../theme/default.css">
  9. <style>.CodeMirror {background: #f8f8f8;}</style>
  10. <link rel="stylesheet" href="../../css/docs.css">
  11. </head>
  12. <body>
  13. <h1>CodeMirror 2: Scheme mode</h1>
  14. <form><textarea id="code" name="code">
  15. ; See if the input starts with a given symbol.
  16. (define (match-symbol input pattern)
  17. (cond ((null? (remain input)) #f)
  18. ((eqv? (car (remain input)) pattern) (r-cdr input))
  19. (else #f)))
  20. ; Allow the input to start with one of a list of patterns.
  21. (define (match-or input pattern)
  22. (cond ((null? pattern) #f)
  23. ((match-pattern input (car pattern)))
  24. (else (match-or input (cdr pattern)))))
  25. ; Allow a sequence of patterns.
  26. (define (match-seq input pattern)
  27. (if (null? pattern)
  28. input
  29. (let ((match (match-pattern input (car pattern))))
  30. (if match (match-seq match (cdr pattern)) #f))))
  31. ; Match with the pattern but no problem if it does not match.
  32. (define (match-opt input pattern)
  33. (let ((match (match-pattern input (car pattern))))
  34. (if match match input)))
  35. ; Match anything (other than '()), until pattern is found. The rather
  36. ; clumsy form of requiring an ending pattern is needed to decide where
  37. ; the end of the match is. If none is given, this will match the rest
  38. ; of the sentence.
  39. (define (match-any input pattern)
  40. (cond ((null? (remain input)) #f)
  41. ((null? pattern) (f-cons (remain input) (clear-remain input)))
  42. (else
  43. (let ((accum-any (collector)))
  44. (define (match-pattern-any input pattern)
  45. (cond ((null? (remain input)) #f)
  46. (else (accum-any (car (remain input)))
  47. (cond ((match-pattern (r-cdr input) pattern))
  48. (else (match-pattern-any (r-cdr input) pattern))))))
  49. (let ((retval (match-pattern-any input (car pattern))))
  50. (if retval
  51. (f-cons (accum-any) retval)
  52. #f))))))
  53. </textarea></form>
  54. <script>
  55. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
  56. </script>
  57. <p><strong>MIME types defined:</strong> <code>text/x-scheme</code>.</p>
  58. </body>
  59. </html>