Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheme: Improved lambda parameter #2346

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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