Scheme improvements (#1556)

1. `)` is part for symbols (strings).
2. Function names which have a keyword/builtin as a prefix are not matched correctly.
3. Zero-length function names.
4. `'` is highlighted as `string` even if it marks a list.

Also add support for Scheme characters.
This commit is contained in:
Michael Schmidt 2018-11-29 14:07:27 +01:00 committed by James DiGioia
parent 5db04656da
commit 225dd3f731
8 changed files with 143 additions and 116 deletions

View File

@ -1,29 +1,33 @@
Prism.languages.scheme = {
'comment' : /;.*/,
'string' : {
pattern: /"(?:[^"\\\r\n]|\\.)*"|'[^('\s]*/,
'comment': /;.*/,
'string': {
pattern: /"(?:[^"\\\r\n]|\\.)*"|'[^()#'\s]+/,
greedy: true
},
'keyword' : {
pattern : /(\()(?:define(?:-syntax|-library|-values)?|(?:case-)?lambda|let(?:\*|rec)?(?:-values)?|else|if|cond|begin|delay(?:-force)?|parameterize|guard|set!|(?:quasi-)?quote|syntax-rules)/,
lookbehind : true
'character': {
pattern: /#\\(?:u[a-fA-F\d]{4}|[a-zA-Z]+|\S)/,
alias: 'string'
},
'builtin' : {
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\?)/,
lookbehind : true
'keyword': {
pattern: /(\()(?:define(?:-syntax|-library|-values)?|(?:case-)?lambda|let(?:\*|rec)?(?:-values)?|else|if|cond|begin|delay(?:-force)?|parameterize|guard|set!|(?:quasi-)?quote|syntax-rules)(?=[()\s])/,
lookbehind: true
},
'number' : {
'builtin': {
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])/,
lookbehind: true
},
'number': {
pattern: /(\s|[()])[-+]?\d*\.?\d+(?:\s*[-+]\s*\d*\.?\d+i)?\b/,
lookbehind: true
},
'boolean' : /#[tf]/,
'boolean': /#[tf]/,
'operator': {
pattern: /(\()(?:[-+*%\/]|[<>]=?|=>?)/,
lookbehind: true
},
'function' : {
pattern : /(\()[^\s()]*(?=[\s)])/,
lookbehind : true
'function': {
pattern: /(\()[^()#'\s]+(?=[()\s)])/,
lookbehind: true
},
'punctuation' : /[()]/
};
'punctuation': /[()']/
};

View File

@ -1 +1 @@
Prism.languages.scheme={comment:/;.*/,string:{pattern:/"(?:[^"\\\r\n]|\\.)*"|'[^('\s]*/,greedy:!0},keyword:{pattern:/(\()(?:define(?:-syntax|-library|-values)?|(?:case-)?lambda|let(?:\*|rec)?(?:-values)?|else|if|cond|begin|delay(?:-force)?|parameterize|guard|set!|(?:quasi-)?quote|syntax-rules)/,lookbehind:!0},builtin:{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\?)/,lookbehind:!0},number:{pattern:/(\s|[()])[-+]?\d*\.?\d+(?:\s*[-+]\s*\d*\.?\d+i)?\b/,lookbehind:!0},"boolean":/#[tf]/,operator:{pattern:/(\()(?:[-+*%\/]|[<>]=?|=>?)/,lookbehind:!0},"function":{pattern:/(\()[^\s()]*(?=[\s)])/,lookbehind:!0},punctuation:/[()]/};
Prism.languages.scheme={comment:/;.*/,string:{pattern:/"(?:[^"\\\r\n]|\\.)*"|'[^()#'\s]+/,greedy:!0},character:{pattern:/#\\(?:u[a-fA-F\d]{4}|[a-zA-Z]+|\S)/,alias:"string"},keyword:{pattern:/(\()(?:define(?:-syntax|-library|-values)?|(?:case-)?lambda|let(?:\*|rec)?(?:-values)?|else|if|cond|begin|delay(?:-force)?|parameterize|guard|set!|(?:quasi-)?quote|syntax-rules)(?=[()\s])/,lookbehind:!0},builtin:{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])/,lookbehind:!0},number:{pattern:/(\s|[()])[-+]?\d*\.?\d+(?:\s*[-+]\s*\d*\.?\d+i)?\b/,lookbehind:!0},"boolean":/#[tf]/,operator:{pattern:/(\()(?:[-+*%\/]|[<>]=?|=>?)/,lookbehind:!0},"function":{pattern:/(\()[^()#'\s]+(?=[()\s)])/,lookbehind:!0},punctuation:/[()']/};

View File

@ -1,53 +1,53 @@
(cons
(car
(cdr
(null?
(pair?
(boolean?
(eof-object?
(char?
(procedure?
(number?
(port?
(string?
(vector?
(symbol?
(bytevector?
(list
(call-with-current-continuation
(call/cc
(append
(abs
(apply
(eval
(cons)
(car)
(cdr)
(null?)
(pair?)
(boolean?)
(eof-object?)
(char?)
(procedure?)
(number?)
(port?)
(string?)
(vector?)
(symbol?)
(bytevector?)
(list)
(call-with-current-continuation)
(call/cc)
(append)
(abs)
(apply)
(eval)
----------------------------------------------------
[
["punctuation", "("], ["builtin", "cons"],
["punctuation", "("], ["builtin", "car"],
["punctuation", "("], ["builtin", "cdr"],
["punctuation", "("], ["builtin", "null?"],
["punctuation", "("], ["builtin", "pair?"],
["punctuation", "("], ["builtin", "boolean?"],
["punctuation", "("], ["builtin", "eof-object?"],
["punctuation", "("], ["builtin", "char?"],
["punctuation", "("], ["builtin", "procedure?"],
["punctuation", "("], ["builtin", "number?"],
["punctuation", "("], ["builtin", "port?"],
["punctuation", "("], ["builtin", "string?"],
["punctuation", "("], ["builtin", "vector?"],
["punctuation", "("], ["builtin", "symbol?"],
["punctuation", "("], ["builtin", "bytevector?"],
["punctuation", "("], ["builtin", "list"],
["punctuation", "("], ["builtin", "call-with-current-continuation"],
["punctuation", "("], ["builtin", "call/cc"],
["punctuation", "("], ["builtin", "append"],
["punctuation", "("], ["builtin", "abs"],
["punctuation", "("], ["builtin", "apply"],
["punctuation", "("], ["builtin", "eval"]
["punctuation", "("], ["builtin", "cons"], ["punctuation", ")"],
["punctuation", "("], ["builtin", "car"], ["punctuation", ")"],
["punctuation", "("], ["builtin", "cdr"], ["punctuation", ")"],
["punctuation", "("], ["builtin", "null?"], ["punctuation", ")"],
["punctuation", "("], ["builtin", "pair?"], ["punctuation", ")"],
["punctuation", "("], ["builtin", "boolean?"], ["punctuation", ")"],
["punctuation", "("], ["builtin", "eof-object?"], ["punctuation", ")"],
["punctuation", "("], ["builtin", "char?"], ["punctuation", ")"],
["punctuation", "("], ["builtin", "procedure?"], ["punctuation", ")"],
["punctuation", "("], ["builtin", "number?"], ["punctuation", ")"],
["punctuation", "("], ["builtin", "port?"], ["punctuation", ")"],
["punctuation", "("], ["builtin", "string?"], ["punctuation", ")"],
["punctuation", "("], ["builtin", "vector?"], ["punctuation", ")"],
["punctuation", "("], ["builtin", "symbol?"], ["punctuation", ")"],
["punctuation", "("], ["builtin", "bytevector?"], ["punctuation", ")"],
["punctuation", "("], ["builtin", "list"], ["punctuation", ")"],
["punctuation", "("], ["builtin", "call-with-current-continuation"], ["punctuation", ")"],
["punctuation", "("], ["builtin", "call/cc"], ["punctuation", ")"],
["punctuation", "("], ["builtin", "append"], ["punctuation", ")"],
["punctuation", "("], ["builtin", "abs"], ["punctuation", ")"],
["punctuation", "("], ["builtin", "apply"], ["punctuation", ")"],
["punctuation", "("], ["builtin", "eval"], ["punctuation", ")"]
]
----------------------------------------------------
Checks for builtins.
Checks for builtins.

View File

@ -0,0 +1,19 @@
#\a
#\space
#\u0041
#\λ
#\)
----------------------------------------------------
[
["character", "#\\a"],
["character", "#\\space"],
["character", "#\\u0041"],
["character", "#\\λ"],
["character", "#\\)"]
]
----------------------------------------------------
Checks for character literals.

View File

@ -3,6 +3,7 @@
(exact? 2)
(inexact->exact 3)
(!fact)
(defined foo)
----------------------------------------------------
@ -11,7 +12,8 @@
["punctuation", "("], ["function", "flmin"], ["number", "2"], ["number", "3"], ["punctuation", ")"],
["punctuation", "("], ["function", "exact?"], ["number", "2"], ["punctuation", ")"],
["punctuation", "("], ["function", "inexact->exact"], ["number", "3"], ["punctuation", ")"],
["punctuation", "("], ["function", "!fact"], ["punctuation", ")"]
["punctuation", "("], ["function", "!fact"], ["punctuation", ")"],
["punctuation", "("], ["function", "defined"], " foo", ["punctuation", ")"]
]
----------------------------------------------------

View File

@ -4,9 +4,9 @@
[
["punctuation", "("], ["builtin", "pair?"],
["string", "'"], ["punctuation", "("], ["number", "1"], ["number", "2"], ["punctuation", ")"], ["punctuation", ")"]
["punctuation", "'"], ["punctuation", "("], ["number", "1"], ["number", "2"], ["punctuation", ")"], ["punctuation", ")"]
]
----------------------------------------------------
Tests that first number of a list is not highlighted as a function. See #1331
Tests that first number of a list is not highlighted as a function. See #1331

View File

@ -1,57 +1,57 @@
(define
(define-syntax
(define-library
(define-values
(case-lambda
(lambda
(let
(let*
(letrec
(let-values
(let*-values
(letrec-values
(else
(if
(cond
(begin
(delay
(delay-force
(parameterize
(guard
(set!
(quasi-quote
(quote
(syntax-rules
(define)
(define-syntax)
(define-library)
(define-values)
(case-lambda)
(lambda)
(let)
(let*)
(letrec)
(let-values)
(let*-values)
(letrec-values)
(else)
(if)
(cond)
(begin)
(delay)
(delay-force)
(parameterize)
(guard)
(set!)
(quasi-quote)
(quote)
(syntax-rules)
----------------------------------------------------
[
["punctuation", "("], ["keyword", "define"],
["punctuation", "("], ["keyword", "define-syntax"],
["punctuation", "("], ["keyword", "define-library"],
["punctuation", "("], ["keyword", "define-values"],
["punctuation", "("], ["keyword", "case-lambda"],
["punctuation", "("], ["keyword", "lambda"],
["punctuation", "("], ["keyword", "let"],
["punctuation", "("], ["keyword", "let*"],
["punctuation", "("], ["keyword", "letrec"],
["punctuation", "("], ["keyword", "let-values"],
["punctuation", "("], ["keyword", "let*-values"],
["punctuation", "("], ["keyword", "letrec-values"],
["punctuation", "("], ["keyword", "else"],
["punctuation", "("], ["keyword", "if"],
["punctuation", "("], ["keyword", "cond"],
["punctuation", "("], ["keyword", "begin"],
["punctuation", "("], ["keyword", "delay"],
["punctuation", "("], ["keyword", "delay-force"],
["punctuation", "("], ["keyword", "parameterize"],
["punctuation", "("], ["keyword", "guard"],
["punctuation", "("], ["keyword", "set!"],
["punctuation", "("], ["keyword", "quasi-quote"],
["punctuation", "("], ["keyword", "quote"],
["punctuation", "("], ["keyword", "syntax-rules"]
["punctuation", "("], ["keyword", "define"], ["punctuation", ")"],
["punctuation", "("], ["keyword", "define-syntax"], ["punctuation", ")"],
["punctuation", "("], ["keyword", "define-library"], ["punctuation", ")"],
["punctuation", "("], ["keyword", "define-values"], ["punctuation", ")"],
["punctuation", "("], ["keyword", "case-lambda"], ["punctuation", ")"],
["punctuation", "("], ["keyword", "lambda"], ["punctuation", ")"],
["punctuation", "("], ["keyword", "let"], ["punctuation", ")"],
["punctuation", "("], ["keyword", "let*"], ["punctuation", ")"],
["punctuation", "("], ["keyword", "letrec"], ["punctuation", ")"],
["punctuation", "("], ["keyword", "let-values"], ["punctuation", ")"],
["punctuation", "("], ["keyword", "let*-values"], ["punctuation", ")"],
["punctuation", "("], ["keyword", "letrec-values"], ["punctuation", ")"],
["punctuation", "("], ["keyword", "else"], ["punctuation", ")"],
["punctuation", "("], ["keyword", "if"], ["punctuation", ")"],
["punctuation", "("], ["keyword", "cond"], ["punctuation", ")"],
["punctuation", "("], ["keyword", "begin"], ["punctuation", ")"],
["punctuation", "("], ["keyword", "delay"], ["punctuation", ")"],
["punctuation", "("], ["keyword", "delay-force"], ["punctuation", ")"],
["punctuation", "("], ["keyword", "parameterize"], ["punctuation", ")"],
["punctuation", "("], ["keyword", "guard"], ["punctuation", ")"],
["punctuation", "("], ["keyword", "set!"], ["punctuation", ")"],
["punctuation", "("], ["keyword", "quasi-quote"], ["punctuation", ")"],
["punctuation", "("], ["keyword", "quote"], ["punctuation", ")"],
["punctuation", "("], ["keyword", "syntax-rules"], ["punctuation", ")"]
]
----------------------------------------------------
Checks for keywords.
Checks for keywords.

View File

@ -1,15 +1,17 @@
""
"fo\"obar"
'turkey
(define a 'foo)
----------------------------------------------------
[
["string", "\"\""],
["string", "\"fo\\\"obar\""],
["string", "'turkey"]
["string", "'turkey"],
["punctuation", "("], ["keyword", "define"], " a ", ["string","'foo"], ["punctuation",")"]
]
----------------------------------------------------
Checks for strings and symbols.
Checks for strings and symbols.