Skip to content

Commit e4f6cca

Browse files
Scheme: Added support for R7RS syntax (#2525)
1 parent fa2225f commit e4f6cca

10 files changed

+523
-108
lines changed

components/prism-scheme.js

+22-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
Prism.languages.scheme = {
2-
'comment': /;.*/,
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*\((?:[^()]|\([^()]*\))*\)|#\|(?:[^#|]|#(?!\|)|\|(?!#)|#\|(?:[^#|]|#(?!\|)|\|(?!#))*\|#)*\|#/,
38
'string': {
49
pattern: /"(?:[^"\\]|\\.)*"/,
510
greedy: true
@@ -9,14 +14,14 @@ Prism.languages.scheme = {
914
greedy: true
1015
},
1116
'character': {
12-
pattern: /#\\(?:[ux][a-fA-F\d]+|[-a-zA-Z]+|\S)/,
17+
pattern: /#\\(?:[ux][a-fA-F\d]+\b|[-a-zA-Z]+\b|\S)/,
1318
greedy: true,
1419
alias: 'string'
1520
},
1621
'lambda-parameter': [
1722
// https://www.cs.cmu.edu/Groups/AI/html/r4rs/r4rs_6.html#SEC30
1823
{
19-
pattern: /(\(lambda\s+)[^()'\s]+/,
24+
pattern: /(\(lambda\s+)(?:[^|()'\s]+|\|(?:[^\\|]|\\.)*\|)/,
2025
lookbehind: true
2126
},
2227
{
@@ -25,11 +30,16 @@ Prism.languages.scheme = {
2530
}
2631
],
2732
'keyword': {
28-
pattern: /(\()(?:define(?:-library|-macro|-syntax|-values)?|defmacro|(?:case-)?lambda|let(?:(?:\*|rec)?(?:-values)?|-syntax|rec-syntax)|else|if|cond|begin|delay(?:-force)?|parameterize|guard|set!|(?:quasi-)?quote|syntax-(?:case|rules))(?=[()\s]|$)/,
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]|$)/,
2934
lookbehind: true
3035
},
3136
'builtin': {
32-
pattern: /(\()(?:(?:cons|car|cdr|list|call-with-current-continuation|call\/cc|append|abs|apply|eval)\b|null\?|pair\?|boolean\?|eof-object\?|char\?|procedure\?|number\?|port\?|string\?|vector\?|symbol\?|bytevector\?)(?=[()\s]|$)/,
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]|$)/,
3343
lookbehind: true
3444
},
3545
'number': {
@@ -52,16 +62,17 @@ Prism.languages.scheme = {
5262
lookbehind: true
5363
},
5464
'boolean': {
55-
pattern: /(^|[\s()])#[ft](?=[()\s]|$)/,
56-
lookbehind: true
57-
},
58-
'operator': {
59-
pattern: /(\()(?:[-+*%\/]|[<>]=?|=>?)(?=[()\s]|$)/,
65+
pattern: /(^|[\s()])#(?:[ft]|false|true)(?=[()\s]|$)/,
6066
lookbehind: true
6167
},
6268
'function': {
63-
pattern: /(\()[^()'\s]+(?=[()\s]|$)/,
69+
pattern: /(\()(?:[^|()'\s]+|\|(?:[^\\|]|\\.)*\|)(?=[()\s]|$)/,
6470
lookbehind: true
6571
},
72+
'identifier': {
73+
pattern: /(^|[\s()])\|(?:[^\\|]|\\.)*\|(?=[()\s]|$)/,
74+
lookbehind: true,
75+
greedy: true
76+
},
6677
'punctuation': /[()']/
6778
};

components/prism-scheme.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/languages/racket/function_feature.test

-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
(fl= 1 2)
22
(flmin 2 3)
3-
(exact? 2)
43
(inexact->exact 3)
54
(!fact)
65
(** 10)
7-
(exact?
86
(**
97
(defined foo)
108

119
[fl= 1 2]
1210
[flmin 2 3]
13-
[exact? 2]
1411
[inexact->exact 3]
1512
[!fact]
1613
[** 10]
17-
[exact?
1814
[**
1915
[defined foo]
2016

@@ -23,21 +19,17 @@
2319
[
2420
["punctuation", "("], ["function", "fl="], ["number", "1"], ["number", "2"], ["punctuation", ")"],
2521
["punctuation", "("], ["function", "flmin"], ["number", "2"], ["number", "3"], ["punctuation", ")"],
26-
["punctuation", "("], ["function", "exact?"], ["number", "2"], ["punctuation", ")"],
2722
["punctuation", "("], ["function", "inexact->exact"], ["number", "3"], ["punctuation", ")"],
2823
["punctuation", "("], ["function", "!fact"], ["punctuation", ")"],
2924
["punctuation", "("], ["function", "**"], ["number", "10"], ["punctuation", ")"],
30-
["punctuation", "("], ["function", "exact?"],
3125
["punctuation", "("], ["function", "**"],
3226
["punctuation", "("], ["function", "defined"], " foo", ["punctuation", ")"],
3327

3428
["punctuation", "["], ["function", "fl="], ["number", "1"], ["number", "2"], ["punctuation", "]"],
3529
["punctuation", "["], ["function", "flmin"], ["number", "2"], ["number", "3"], ["punctuation", "]"],
36-
["punctuation", "["], ["function", "exact?"], ["number", "2"], ["punctuation", "]"],
3730
["punctuation", "["], ["function", "inexact->exact"], ["number", "3"], ["punctuation", "]"],
3831
["punctuation", "["], ["function", "!fact"], ["punctuation", "]"],
3932
["punctuation", "["], ["function", "**"], ["number", "10"], ["punctuation", "]"],
40-
["punctuation", "["], ["function", "exact?"],
4133
["punctuation", "["], ["function", "**"],
4234
["punctuation", "["], ["function", "defined"], " foo", ["punctuation", "]"]
4335
]

tests/languages/scheme/boolean_feature.test

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
#t
22
#f
3-
4-
; not a boolean
53
#true
4+
#false
65

76
----------------------------------------------------
87

98
[
109
["boolean", "#t"],
1110
["boolean", "#f"],
12-
13-
["comment", "; not a boolean"],
14-
"\r\n#true"
11+
["boolean", "#true"],
12+
["boolean", "#false"]
1513
]
1614

1715
----------------------------------------------------

0 commit comments

Comments
 (0)