prism-scheme.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. Prism.languages.scheme = {
  2. // this supports "normal" single-line comments:
  3. // ; comment
  4. // and (potentially nested) multiline comments:
  5. // #| comment #| nested |# still comment |#
  6. // (only 1 level of nesting is supported)
  7. 'comment': /;.*|#;\s*\((?:[^()]|\([^()]*\))*\)|#\|(?:[^#|]|#(?!\|)|\|(?!#)|#\|(?:[^#|]|#(?!\|)|\|(?!#))*\|#)*\|#/,
  8. 'string': {
  9. pattern: /"(?:[^"\\]|\\.)*"/,
  10. greedy: true
  11. },
  12. 'symbol': {
  13. pattern: /'[^()#'\s]+/,
  14. greedy: true
  15. },
  16. 'character': {
  17. pattern: /#\\(?:[ux][a-fA-F\d]+\b|[-a-zA-Z]+\b|\S)/,
  18. greedy: true,
  19. alias: 'string'
  20. },
  21. 'lambda-parameter': [
  22. // https://www.cs.cmu.edu/Groups/AI/html/r4rs/r4rs_6.html#SEC30
  23. {
  24. pattern: /(\(lambda\s+)(?:[^|()'\s]+|\|(?:[^\\|]|\\.)*\|)/,
  25. lookbehind: true
  26. },
  27. {
  28. pattern: /(\(lambda\s+\()[^()']+/,
  29. lookbehind: true
  30. }
  31. ],
  32. 'keyword': {
  33. pattern: /(\()(?:begin|case(?:-lambda)?|cond(?:-expand)?|define(?:-library|-macro|-record-type|-syntax|-values)?|defmacro|delay(?:-force)?|do|else|export|except|guard|if|import|include(?:-ci|-library-declarations)?|lambda|let(?:rec)?(?:-syntax|-values|\*)?|let\*-values|only|parameterize|prefix|(?:quasi-?)?quote|rename|set!|syntax-(?:case|rules)|unless|unquote(?:-splicing)?|when)(?=[()\s]|$)/,
  34. lookbehind: true
  35. },
  36. 'builtin': {
  37. // all functions of the base library of R7RS plus some of built-ins of R5Rs
  38. pattern: /(\()(?:abs|and|append|apply|assoc|ass[qv]|binary-port\?|boolean=?\?|bytevector(?:-append|-copy|-copy!|-length|-u8-ref|-u8-set!|\?)?|caar|cadr|call-with-(?:current-continuation|port|values)|call\/cc|car|cdar|cddr|cdr|ceiling|char(?:->integer|-ready\?|\?|<\?|<=\?|=\?|>\?|>=\?)|close-(?:input-port|output-port|port)|complex\?|cons|current-(?:error|input|output)-port|denominator|dynamic-wind|eof-object\??|eq\?|equal\?|eqv\?|error|error-object(?:-irritants|-message|\?)|eval|even\?|exact(?:-integer-sqrt|-integer\?|\?)?|expt|features|file-error\?|floor(?:-quotient|-remainder|\/)?|flush-output-port|for-each|gcd|get-output-(?:bytevector|string)|inexact\??|input-port(?:-open\?|\?)|integer(?:->char|\?)|lcm|length|list(?:->string|->vector|-copy|-ref|-set!|-tail|\?)?|make-(?:bytevector|list|parameter|string|vector)|map|max|member|memq|memv|min|modulo|negative\?|newline|not|null\?|number(?:->string|\?)|numerator|odd\?|open-(?:input|output)-(?:bytevector|string)|or|output-port(?:-open\?|\?)|pair\?|peek-char|peek-u8|port\?|positive\?|procedure\?|quotient|raise|raise-continuable|rational\?|rationalize|read-(?:bytevector|bytevector!|char|error\?|line|string|u8)|real\?|remainder|reverse|round|set-c[ad]r!|square|string(?:->list|->number|->symbol|->utf8|->vector|-append|-copy|-copy!|-fill!|-for-each|-length|-map|-ref|-set!|\?|<\?|<=\?|=\?|>\?|>=\?)?|substring|symbol(?:->string|\?|=\?)|syntax-error|textual-port\?|truncate(?:-quotient|-remainder|\/)?|u8-ready\?|utf8->string|values|vector(?:->list|->string|-append|-copy|-copy!|-fill!|-for-each|-length|-map|-ref|-set!|\?)?|with-exception-handler|write-(?:bytevector|char|string|u8)|zero\?)(?=[()\s]|$)/,
  39. lookbehind: true
  40. },
  41. 'operator': {
  42. pattern: /(\()(?:[-+*%/]|[<>]=?|=>?)(?=[()\s]|$)/,
  43. lookbehind: true
  44. },
  45. 'number': {
  46. // This pattern (apart from the lookarounds) works like this:
  47. //
  48. // Decimal numbers
  49. // <dec real> := \d*\.?\d+(?:[eE][+-]?\d+)?|\d+\/\d+
  50. // <dec complex> := <dec real>(?:[+-]<dec real>i)?|<dec real>i
  51. // <dec prefix> := (?:#d(?:#[ei])?|#[ei](?:#d)?)?
  52. // <dec number> := <dec prefix>[+-]?<complex>
  53. //
  54. // Binary, octal, and hexadecimal numbers
  55. // <b.o.x. real> := [\da-fA-F]+(?:\/[\da-fA-F]+)?
  56. // <b.o.x. complex> := <b.o.x. real>(?:[+-]<b.o.x. real>i)?|<b.o.x. real>i
  57. // <b.o.x. prefix> := #[box](?:#[ei])?|#[ei](?:#[box])?
  58. // <b.o.x. number> := <b.o.x. prefix>[+-]?<b.o.x. complex>
  59. //
  60. // <number> := <dec number>|<b.o.x. number>
  61. pattern: /(^|[\s()])(?:(?:#d(?:#[ei])?|#[ei](?:#d)?)?[+-]?(?:(?:\d*\.?\d+(?:[eE][+-]?\d+)?|\d+\/\d+)(?:[+-](?:\d*\.?\d+(?:[eE][+-]?\d+)?|\d+\/\d+)i)?|(?:\d*\.?\d+(?:[eE][+-]?\d+)?|\d+\/\d+)i)|(?:#[box](?:#[ei])?|#[ei](?:#[box])?)[+-]?(?:[\da-fA-F]+(?:\/[\da-fA-F]+)?(?:[+-][\da-fA-F]+(?:\/[\da-fA-F]+)?i)?|[\da-fA-F]+(?:\/[\da-fA-F]+)?i))(?=[()\s]|$)/,
  62. lookbehind: true
  63. },
  64. 'boolean': {
  65. pattern: /(^|[\s()])#(?:[ft]|false|true)(?=[()\s]|$)/,
  66. lookbehind: true
  67. },
  68. 'function': {
  69. pattern: /(\()(?:[^|()'\s]+|\|(?:[^\\|]|\\.)*\|)(?=[()\s]|$)/,
  70. lookbehind: true
  71. },
  72. 'identifier': {
  73. pattern: /(^|[\s()])\|(?:[^\\|]|\\.)*\|(?=[()\s]|$)/,
  74. lookbehind: true,
  75. greedy: true
  76. },
  77. 'punctuation': /[()']/
  78. };