Skip to content

Commit 1946918

Browse files
authoredMay 13, 2020
Scheme: Improved lambda parameter (#2346)
1 parent 194c542 commit 1946918

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed
 

‎components/prism-racket.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
Prism.languages.racket = Prism.languages.extend('scheme', {});
1+
Prism.languages.racket = Prism.languages.extend('scheme', {
2+
'lambda-parameter': {
3+
// the racket lambda syntax is a lot more complex, so we won't even attempt to capture it.
4+
// this will just prevent false positives of the `function` pattern
5+
pattern: /(\(lambda\s+\()[^()'\s]+/,
6+
lookbehind: true
7+
}
8+
});
29

310
// Add brackets to racket
411
// The basic idea here is to go through all pattens of Scheme and replace all occurrences of "(" with the union of "("

‎components/prism-racket.min.js

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

‎components/prism-scheme.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,17 @@ Prism.languages.scheme = {
1313
greedy: true,
1414
alias: 'string'
1515
},
16-
'lambda-parameter': {
17-
pattern: /(\(lambda\s+\()[^()'\s]+/,
18-
lookbehind: true
19-
},
16+
'lambda-parameter': [
17+
// https://www.cs.cmu.edu/Groups/AI/html/r4rs/r4rs_6.html#SEC30
18+
{
19+
pattern: /(\(lambda\s+)[^()'\s]+/,
20+
lookbehind: true
21+
},
22+
{
23+
pattern: /(\(lambda\s+\()[^()']+/,
24+
lookbehind: true
25+
}
26+
],
2027
'keyword': {
2128
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]|$)/,
2229
lookbehind: true

‎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/scheme/lambda_parameter_feature.test

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
1+
(lambda x x)
2+
(lambda (x) x)
13
(lambda (foo bar) (concat foo bar))
24

35
----------------------------------------------------
46

57
[
8+
["punctuation", "("],
9+
["keyword", "lambda"],
10+
["lambda-parameter", "x"],
11+
" x",
12+
["punctuation", ")"],
13+
["punctuation", "("],
14+
["keyword", "lambda"],
15+
["punctuation", "("],
16+
["lambda-parameter", "x"],
17+
["punctuation", ")"],
18+
" x",
19+
["punctuation", ")"],
620
["punctuation", "("],
721
["keyword", "lambda"],
822
["punctuation", "("],
9-
["lambda-parameter", "foo"],
10-
" bar",
23+
["lambda-parameter", "foo bar"],
1124
["punctuation", ")"],
1225
["punctuation", "("],
1326
["function", "concat"],

0 commit comments

Comments
 (0)
Please sign in to comment.