Skip to content

Commit

Permalink
Scheme: Improved lambda parameter (PrismJS#2346)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored and quentinvernot committed Sep 11, 2020
1 parent dd9382a commit a9fbc10
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
9 changes: 8 additions & 1 deletion components/prism-racket.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
Prism.languages.racket = Prism.languages.extend('scheme', {});
Prism.languages.racket = Prism.languages.extend('scheme', {
'lambda-parameter': {
// the racket lambda syntax is a lot more complex, so we won't even attempt to capture it.
// this will just prevent false positives of the `function` pattern
pattern: /(\(lambda\s+\()[^()'\s]+/,
lookbehind: true
}
});

// Add brackets to racket
// The basic idea here is to go through all pattens of Scheme and replace all occurrences of "(" with the union of "("
Expand Down
2 changes: 1 addition & 1 deletion components/prism-racket.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions components/prism-scheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ Prism.languages.scheme = {
greedy: true,
alias: 'string'
},
'lambda-parameter': {
pattern: /(\(lambda\s+\()[^()'\s]+/,
lookbehind: true
},
'lambda-parameter': [
// https://www.cs.cmu.edu/Groups/AI/html/r4rs/r4rs_6.html#SEC30
{
pattern: /(\(lambda\s+)[^()'\s]+/,
lookbehind: true
},
{
pattern: /(\(lambda\s+\()[^()']+/,
lookbehind: true
}
],
'keyword': {
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]|$)/,
lookbehind: true
Expand Down
2 changes: 1 addition & 1 deletion components/prism-scheme.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions tests/languages/scheme/lambda_parameter_feature.test
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
(lambda x x)
(lambda (x) x)
(lambda (foo bar) (concat foo bar))

----------------------------------------------------

[
["punctuation", "("],
["keyword", "lambda"],
["lambda-parameter", "x"],
" x",
["punctuation", ")"],
["punctuation", "("],
["keyword", "lambda"],
["punctuation", "("],
["lambda-parameter", "x"],
["punctuation", ")"],
" x",
["punctuation", ")"],
["punctuation", "("],
["keyword", "lambda"],
["punctuation", "("],
["lambda-parameter", "foo"],
" bar",
["lambda-parameter", "foo bar"],
["punctuation", ")"],
["punctuation", "("],
["function", "concat"],
Expand Down

0 comments on commit a9fbc10

Please sign in to comment.