From 1c6c0bf37b43de21ca695f293e94c42a696d8380 Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Tue, 30 Mar 2021 21:10:23 +0200 Subject: [PATCH] Scheme: Added bracket support (#2813) --- components/prism-racket.js | 49 +--- components/prism-racket.min.js | 2 +- components/prism-scheme.js | 24 +- components/prism-scheme.min.js | 2 +- tests/languages/scheme/builtin_feature.test | 10 +- tests/languages/scheme/comment_feature.test | 4 + tests/languages/scheme/function_feature.test | 94 ++++++- tests/languages/scheme/issue2811.test | 27 ++ tests/languages/scheme/keyword_feature.test | 249 ++++++++++++++---- .../scheme/lambda_parameter_feature.test | 12 + tests/languages/scheme/number_feature.test | 5 + tests/languages/scheme/operator_feature.test | 12 +- 12 files changed, 369 insertions(+), 121 deletions(-) create mode 100644 tests/languages/scheme/issue2811.test diff --git a/components/prism-racket.js b/components/prism-racket.js index f5eaac2b35..af3478060e 100644 --- a/components/prism-racket.js +++ b/components/prism-racket.js @@ -2,58 +2,11 @@ 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]+/, + 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 "(" -// and "["; Similar for ")". This is a bit tricky because "(" can be escaped or inside a character set. Both cases -// have to be handled differently and, of course, we don't want to destroy groups, so we can only replace literal "(" -// and ")". -// To do this, we use a regular expression which will parse any JS regular expression. It works because regexes are -// matches from left to right and already matched text cannot be matched again. We use this to first capture all -// escaped characters (not really, we don't get escape sequences but we don't need them). Because we already captured -// all escaped characters, we know that any "[" character is the start of a character set, so we match that character -// set whole. -// With the regex parsed, we only have to replace all escaped "(" (they cannot be unescaped outside of character sets) -// with /[([]/ and replace all "(" inside character sets. -// Note: This method does not work for "(" that are escaped like this /\x28/ or this /\u0028/. -Prism.languages.DFS(Prism.languages.racket, function (key, value) { - if (Prism.util.type(value) === 'RegExp') { - var source = value.source.replace(/\\(.)|\[\^?((?:\\.|[^\\\]])*)\]/g, function (m, g1, g2) { - if (g1) { - if (g1 === '(') { - // replace all '(' characters outside character sets - return '[([]'; - } - if (g1 === ')') { - // replace all ')' characters outside character sets - return '[)\\]]'; - } - } - if (g2) { - var prefix = m[1] === '^' ? '[^' : '['; - return prefix + g2.replace(/\\(.)|[()]/g, function (m, g1) { - if (m === '(' || g1 === '(') { - // replace all '(' characters inside character sets - return '(['; - } - if (m === ')' || g1 === ')') { - // replace all ')' characters inside character sets - return ')\\]'; - } - return m; - }) + ']'; - } - return m; - }); - - this[key] = RegExp(source, value.flags); - } -}); - Prism.languages.insertBefore('racket', 'string', { 'lang': { pattern: /^#lang.+/m, diff --git a/components/prism-racket.min.js b/components/prism-racket.min.js index 5a3e25e8ca..5f3c44d039 100644 --- a/components/prism-racket.min.js +++ b/components/prism-racket.min.js @@ -1 +1 @@ -Prism.languages.racket=Prism.languages.extend("scheme",{"lambda-parameter":{pattern:/(\(lambda\s+\()[^()'\s]+/,lookbehind:!0}}),Prism.languages.DFS(Prism.languages.racket,function(e,a){if("RegExp"===Prism.util.type(a)){var r=a.source.replace(/\\(.)|\[\^?((?:\\.|[^\\\]])*)\]/g,function(e,a,r){if(a){if("("===a)return"[([]";if(")"===a)return"[)\\]]"}return r?("^"===e[1]?"[^":"[")+r.replace(/\\(.)|[()]/g,function(e,a){return"("===e||"("===a?"([":")"===e||")"===a?")\\]":e})+"]":e});this[e]=RegExp(r,a.flags)}}),Prism.languages.insertBefore("racket","string",{lang:{pattern:/^#lang.+/m,greedy:!0,alias:"keyword"}}),Prism.languages.rkt=Prism.languages.racket; \ No newline at end of file +Prism.languages.racket=Prism.languages.extend("scheme",{"lambda-parameter":{pattern:/([(\[]lambda\s+[(\[])[^()\[\]'\s]+/,lookbehind:!0}}),Prism.languages.insertBefore("racket","string",{lang:{pattern:/^#lang.+/m,greedy:!0,alias:"keyword"}}),Prism.languages.rkt=Prism.languages.racket; \ No newline at end of file diff --git a/components/prism-scheme.js b/components/prism-scheme.js index 77a9255a72..a035d98a71 100644 --- a/components/prism-scheme.js +++ b/components/prism-scheme.js @@ -5,13 +5,13 @@ // and (potentially nested) multiline comments: // #| comment #| nested |# still comment |# // (only 1 level of nesting is supported) - 'comment': /;.*|#;\s*\((?:[^()]|\([^()]*\))*\)|#\|(?:[^#|]|#(?!\|)|\|(?!#)|#\|(?:[^#|]|#(?!\|)|\|(?!#))*\|#)*\|#/, + 'comment': /;.*|#;\s*(?:\((?:[^()]|\([^()]*\))*\)|\[(?:[^\[\]]|\[[^\[\]]*\])*\])|#\|(?:[^#|]|#(?!\|)|\|(?!#)|#\|(?:[^#|]|#(?!\|)|\|(?!#))*\|#)*\|#/, 'string': { pattern: /"(?:[^"\\]|\\.)*"/, greedy: true }, 'symbol': { - pattern: /'[^()#'\s]+/, + pattern: /'[^()\[\]#'\s]+/, greedy: true }, 'character': { @@ -22,25 +22,25 @@ 'lambda-parameter': [ // https://www.cs.cmu.edu/Groups/AI/html/r4rs/r4rs_6.html#SEC30 { - pattern: /((?:^|[^'`#])\(lambda\s+)(?:[^|()'\s]+|\|(?:[^\\|]|\\.)*\|)/, + pattern: /((?:^|[^'`#])[(\[]lambda\s+)(?:[^|()\[\]'\s]+|\|(?:[^\\|]|\\.)*\|)/, lookbehind: true }, { - pattern: /((?:^|[^'`#])\(lambda\s+\()[^()']+/, + pattern: /((?:^|[^'`#])[(\[]lambda\s+[(\[])[^()\[\]']+/, lookbehind: true } ], 'keyword': { - 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]|$)/, + 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]|$)/, lookbehind: true }, 'builtin': { // all functions of the base library of R7RS plus some of built-ins of R5Rs - 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]|$)/, + 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]|$)/, lookbehind: true }, 'operator': { - pattern: /((?:^|[^'`#])\()(?:[-+*%/]|[<>]=?|=>?)(?=[()\s]|$)/, + pattern: /((?:^|[^'`#])[(\[])(?:[-+*%/]|[<>]=?|=>?)(?=[()\[\]\s]|$)/, lookbehind: true }, 'number': { @@ -82,24 +82,24 @@ '': /(?:@|)?|/.source, '': /#[box](?:#[ei])?|(?:#[ei])?#[box]/.source, - '': /(^|[\s()])(?:|)(?=[()\s]|$)/.source, + '': /(^|[()\[\]\s])(?:|)(?=[()\[\]\s]|$)/.source, }), 'i'), lookbehind: true }, 'boolean': { - pattern: /(^|[\s()])#(?:[ft]|false|true)(?=[()\s]|$)/, + pattern: /(^|[()\[\]\s])#(?:[ft]|false|true)(?=[()\[\]\s]|$)/, lookbehind: true }, 'function': { - pattern: /((?:^|[^'`#])\()(?:[^|()'\s]+|\|(?:[^\\|]|\\.)*\|)(?=[()\s]|$)/, + pattern: /((?:^|[^'`#])[(\[])(?:[^|()\[\]'\s]+|\|(?:[^\\|]|\\.)*\|)(?=[()\[\]\s]|$)/, lookbehind: true }, 'identifier': { - pattern: /(^|[\s()])\|(?:[^\\|]|\\.)*\|(?=[()\s]|$)/, + pattern: /(^|[()\[\]\s])\|(?:[^\\|]|\\.)*\|(?=[()\[\]\s]|$)/, lookbehind: true, greedy: true }, - 'punctuation': /[()']/ + 'punctuation': /[()\[\]']/ }; /** diff --git a/components/prism-scheme.min.js b/components/prism-scheme.min.js index 4724e88fd3..8970718a18 100644 --- a/components/prism-scheme.min.js +++ b/components/prism-scheme.min.js @@ -1 +1 @@ -Prism.languages.scheme={comment:/;.*|#;\s*\((?:[^()]|\([^()]*\))*\)|#\|(?:[^#|]|#(?!\|)|\|(?!#)|#\|(?:[^#|]|#(?!\|)|\|(?!#))*\|#)*\|#/,string:{pattern:/"(?:[^"\\]|\\.)*"/,greedy:!0},symbol:{pattern:/'[^()#'\s]+/,greedy:!0},character:{pattern:/#\\(?:[ux][a-fA-F\d]+\b|[-a-zA-Z]+\b|[\uD800-\uDBFF][\uDC00-\uDFFF]|\S)/,greedy:!0,alias:"string"},"lambda-parameter":[{pattern:/((?:^|[^'`#])\(lambda\s+)(?:[^|()'\s]+|\|(?:[^\\|]|\\.)*\|)/,lookbehind:!0},{pattern:/((?:^|[^'`#])\(lambda\s+\()[^()']+/,lookbehind:!0}],keyword:{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]|$)/,lookbehind:!0},builtin:{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]|$)/,lookbehind:!0},operator:{pattern:/((?:^|[^'`#])\()(?:[-+*%/]|[<>]=?|=>?)(?=[()\s]|$)/,lookbehind:!0},number:{pattern:RegExp(function(r){for(var e in r)r[e]=r[e].replace(/<[\w\s]+>/g,function(e){return"(?:"+r[e].trim()+")"});return r[e]}({"":"\\d+(?:/\\d+)?|(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:e[+-]?\\d+)?","":"[+-]?|[+-](?:inf|nan)\\.0","":"[+-](?:|(?:inf|nan)\\.0)?i","":"(?:@|)?|","":"(?:#d(?:#[ei])?|#[ei](?:#d)?)?","":"[0-9a-f]+(?:/[0-9a-f]+)?","":"[+-]?|[+-](?:inf|nan)\\.0","":"[+-](?:|(?:inf|nan)\\.0)?i","":"(?:@|)?|","":"#[box](?:#[ei])?|(?:#[ei])?#[box]","":"(^|[\\s()])(?:|)(?=[()\\s]|$)"}),"i"),lookbehind:!0},boolean:{pattern:/(^|[\s()])#(?:[ft]|false|true)(?=[()\s]|$)/,lookbehind:!0},function:{pattern:/((?:^|[^'`#])\()(?:[^|()'\s]+|\|(?:[^\\|]|\\.)*\|)(?=[()\s]|$)/,lookbehind:!0},identifier:{pattern:/(^|[\s()])\|(?:[^\\|]|\\.)*\|(?=[()\s]|$)/,lookbehind:!0,greedy:!0},punctuation:/[()']/}; \ No newline at end of file +Prism.languages.scheme={comment:/;.*|#;\s*(?:\((?:[^()]|\([^()]*\))*\)|\[(?:[^\[\]]|\[[^\[\]]*\])*\])|#\|(?:[^#|]|#(?!\|)|\|(?!#)|#\|(?:[^#|]|#(?!\|)|\|(?!#))*\|#)*\|#/,string:{pattern:/"(?:[^"\\]|\\.)*"/,greedy:!0},symbol:{pattern:/'[^()\[\]#'\s]+/,greedy:!0},character:{pattern:/#\\(?:[ux][a-fA-F\d]+\b|[-a-zA-Z]+\b|[\uD800-\uDBFF][\uDC00-\uDFFF]|\S)/,greedy:!0,alias:"string"},"lambda-parameter":[{pattern:/((?:^|[^'`#])[(\[]lambda\s+)(?:[^|()\[\]'\s]+|\|(?:[^\\|]|\\.)*\|)/,lookbehind:!0},{pattern:/((?:^|[^'`#])[(\[]lambda\s+[(\[])[^()\[\]']+/,lookbehind:!0}],keyword:{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]|$)/,lookbehind:!0},builtin:{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]|$)/,lookbehind:!0},operator:{pattern:/((?:^|[^'`#])[(\[])(?:[-+*%/]|[<>]=?|=>?)(?=[()\[\]\s]|$)/,lookbehind:!0},number:{pattern:RegExp(function(r){for(var e in r)r[e]=r[e].replace(/<[\w\s]+>/g,function(e){return"(?:"+r[e].trim()+")"});return r[e]}({"":"\\d+(?:/\\d+)?|(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:e[+-]?\\d+)?","":"[+-]?|[+-](?:inf|nan)\\.0","":"[+-](?:|(?:inf|nan)\\.0)?i","":"(?:@|)?|","":"(?:#d(?:#[ei])?|#[ei](?:#d)?)?","":"[0-9a-f]+(?:/[0-9a-f]+)?","":"[+-]?|[+-](?:inf|nan)\\.0","":"[+-](?:|(?:inf|nan)\\.0)?i","":"(?:@|)?|","":"#[box](?:#[ei])?|(?:#[ei])?#[box]","":"(^|[()\\[\\]\\s])(?:|)(?=[()\\[\\]\\s]|$)"}),"i"),lookbehind:!0},boolean:{pattern:/(^|[()\[\]\s])#(?:[ft]|false|true)(?=[()\[\]\s]|$)/,lookbehind:!0},function:{pattern:/((?:^|[^'`#])[(\[])(?:[^|()\[\]'\s]+|\|(?:[^\\|]|\\.)*\|)(?=[()\[\]\s]|$)/,lookbehind:!0},identifier:{pattern:/(^|[()\[\]\s])\|(?:[^\\|]|\\.)*\|(?=[()\[\]\s]|$)/,lookbehind:!0,greedy:!0},punctuation:/[()\[\]']/}; \ No newline at end of file diff --git a/tests/languages/scheme/builtin_feature.test b/tests/languages/scheme/builtin_feature.test index 1a3706f4b4..72bda723e1 100644 --- a/tests/languages/scheme/builtin_feature.test +++ b/tests/languages/scheme/builtin_feature.test @@ -194,6 +194,10 @@ (write-u8 (zero? +; with brackets +[map +[max + ---------------------------------------------------- [ @@ -391,7 +395,11 @@ ["punctuation", "("], ["builtin", "write-char"], ["punctuation", "("], ["builtin", "write-string"], ["punctuation", "("], ["builtin", "write-u8"], - ["punctuation", "("], ["builtin", "zero?"] + ["punctuation", "("], ["builtin", "zero?"], + + ["comment", "; with brackets"], + ["punctuation", "["], ["builtin", "map"], + ["punctuation", "["], ["builtin", "max"] ] ---------------------------------------------------- diff --git a/tests/languages/scheme/comment_feature.test b/tests/languages/scheme/comment_feature.test index af9bef0320..90ae5e8f5d 100644 --- a/tests/languages/scheme/comment_feature.test +++ b/tests/languages/scheme/comment_feature.test @@ -3,6 +3,8 @@ #;(foo bar) #; (foo) +#;[foo bar] +#; [foo] #| comment @@ -17,6 +19,8 @@ ["comment", "#;(foo bar)"], ["comment", "#; (foo)"], + ["comment", "#;[foo bar]"], + ["comment", "#; [foo]"], ["comment", "#|\r\n comment\r\n #| nested comment |#\r\n|#"] ] diff --git a/tests/languages/scheme/function_feature.test b/tests/languages/scheme/function_feature.test index bbd3259920..cd470914ae 100644 --- a/tests/languages/scheme/function_feature.test +++ b/tests/languages/scheme/function_feature.test @@ -7,17 +7,95 @@ (defined foo) (|some name| foo) +[fl= 1 2] +[flmin 2 3] +[inexact->exact 3] +[!fact] +[** 10] +[** +[defined foo] +[|some name| foo] + ---------------------------------------------------- [ - ["punctuation", "("], ["function", "fl="], ["number", "1"], ["number", "2"], ["punctuation", ")"], - ["punctuation", "("], ["function", "flmin"], ["number", "2"], ["number", "3"], ["punctuation", ")"], - ["punctuation", "("], ["function", "inexact->exact"], ["number", "3"], ["punctuation", ")"], - ["punctuation", "("], ["function", "!fact"], ["punctuation", ")"], - ["punctuation", "("], ["function", "**"], ["number", "10"], ["punctuation", ")"], - ["punctuation", "("], ["function", "**"], - ["punctuation", "("], ["function", "defined"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["function", "|some name|"], " foo", ["punctuation", ")"] + ["punctuation", "("], + ["function", "fl="], + ["number", "1"], + ["number", "2"], + ["punctuation", ")"], + + ["punctuation", "("], + ["function", "flmin"], + ["number", "2"], + ["number", "3"], + ["punctuation", ")"], + + ["punctuation", "("], + ["function", "inexact->exact"], + ["number", "3"], + ["punctuation", ")"], + + ["punctuation", "("], + ["function", "!fact"], + ["punctuation", ")"], + + ["punctuation", "("], + ["function", "**"], + ["number", "10"], + ["punctuation", ")"], + + ["punctuation", "("], + ["function", "**"], + + ["punctuation", "("], + ["function", "defined"], + " foo", + ["punctuation", ")"], + + ["punctuation", "("], + ["function", "|some name|"], + " foo", + ["punctuation", ")"], + + ["punctuation", "["], + ["function", "fl="], + ["number", "1"], + ["number", "2"], + ["punctuation", "]"], + + ["punctuation", "["], + ["function", "flmin"], + ["number", "2"], + ["number", "3"], + ["punctuation", "]"], + + ["punctuation", "["], + ["function", "inexact->exact"], + ["number", "3"], + ["punctuation", "]"], + + ["punctuation", "["], + ["function", "!fact"], + ["punctuation", "]"], + + ["punctuation", "["], + ["function", "**"], + ["number", "10"], + ["punctuation", "]"], + + ["punctuation", "["], + ["function", "**"], + + ["punctuation", "["], + ["function", "defined"], + " foo", + ["punctuation", "]"], + + ["punctuation", "["], + ["function", "|some name|"], + " foo", + ["punctuation", "]"] ] ---------------------------------------------------- diff --git a/tests/languages/scheme/issue2811.test b/tests/languages/scheme/issue2811.test new file mode 100644 index 0000000000..16211fd696 --- /dev/null +++ b/tests/languages/scheme/issue2811.test @@ -0,0 +1,27 @@ +(let ([x 10] + [y 20]) + (+ x y)) + +---------------------------------------------------- + +[ + ["punctuation", "("], + ["keyword", "let"], + ["punctuation", "("], + ["punctuation", "["], + ["function", "x"], + ["number", "10"], + ["punctuation", "]"], + + ["punctuation", "["], + ["function", "y"], + ["number", "20"], + ["punctuation", "]"], + ["punctuation", ")"], + + ["punctuation", "("], + ["operator", "+"], + " x y", + ["punctuation", ")"], + ["punctuation", ")"] +] \ No newline at end of file diff --git a/tests/languages/scheme/keyword_feature.test b/tests/languages/scheme/keyword_feature.test index 2d6e82f5cf..25ffc29917 100644 --- a/tests/languages/scheme/keyword_feature.test +++ b/tests/languages/scheme/keyword_feature.test @@ -47,57 +47,210 @@ (unquote-splicing) (when) +; with brackets + +[if] +[when] + ---------------------------------------------------- [ - ["punctuation", "("], ["keyword", "begin"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "case"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "case-lambda"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "cond"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "cond-expand"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "define-library"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "define-macro"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "define-record-type"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "define-syntax"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "define-values"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "define"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "defmacro"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "delay-force"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "delay"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "do"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "else"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "export"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "except"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "guard"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "if"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "import"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "include"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "include-ci"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "include-library-declarations"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "lambda"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "let-syntax"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "let-values"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "let"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "let*-values"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "let*"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "letrec-syntax"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "letrec-values"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "letrec"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "letrec*"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "only"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "parameterize"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "prefix"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "quasi-quote"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "quasiquote"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "quote"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "rename"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "set!"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "syntax-case"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "syntax-rules"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "unless"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "unquote"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "unquote-splicing"], ["punctuation", ")"], - ["punctuation", "("], ["keyword", "when"], ["punctuation", ")"] + ["punctuation", "("], + ["keyword", "begin"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "case"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "case-lambda"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "cond"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "cond-expand"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "define-library"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "define-macro"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "define-record-type"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "define-syntax"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "define-values"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "define"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "defmacro"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "delay-force"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "delay"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "do"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "else"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "export"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "except"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "guard"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "if"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "import"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "include"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "include-ci"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "include-library-declarations"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "lambda"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "let-syntax"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "let-values"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "let"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "let*-values"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "let*"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "letrec-syntax"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "letrec-values"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "letrec"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "letrec*"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "only"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "parameterize"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "prefix"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "quasi-quote"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "quasiquote"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "quote"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "rename"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "set!"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "syntax-case"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "syntax-rules"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "unless"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "unquote"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "unquote-splicing"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "when"], + ["punctuation", ")"], + + ["comment", "; with brackets"], + + ["punctuation", "["], ["keyword", "if"], ["punctuation", "]"], + ["punctuation", "["], ["keyword", "when"], ["punctuation", "]"] ] ---------------------------------------------------- diff --git a/tests/languages/scheme/lambda_parameter_feature.test b/tests/languages/scheme/lambda_parameter_feature.test index bbc7a22ffa..2e56e03af1 100644 --- a/tests/languages/scheme/lambda_parameter_feature.test +++ b/tests/languages/scheme/lambda_parameter_feature.test @@ -5,6 +5,7 @@ (lambda (x) x) (lambda (foo bar) (concat foo bar)) +(lambda [foo bar] (concat foo bar)) ---------------------------------------------------- @@ -38,6 +39,17 @@ ["function", "concat"], " foo bar", ["punctuation", ")"], + ["punctuation", ")"], + + ["punctuation", "("], + ["keyword", "lambda"], + ["punctuation", "["], + ["lambda-parameter", "foo bar"], + ["punctuation", "]"], + ["punctuation", "("], + ["function", "concat"], + " foo bar", + ["punctuation", ")"], ["punctuation", ")"] ] diff --git a/tests/languages/scheme/number_feature.test b/tests/languages/scheme/number_feature.test index 2b00dc8492..0520d669c2 100644 --- a/tests/languages/scheme/number_feature.test +++ b/tests/languages/scheme/number_feature.test @@ -12,6 +12,8 @@ (list #xBAD #b1110011 #o777) (list #i#x10 #i#x10+10i #b10+10i) +[list 123] + 10+i 10+.1i 10+1.i @@ -93,11 +95,14 @@ ["number", "#b10+10i"], ["punctuation", ")"], + ["punctuation", "["], ["builtin", "list"], ["number", "123"], ["punctuation", "]"], + ["number", "10+i"], ["number", "10+.1i"], ["number", "10+1.i"], ["comment", "; not a number but a symbol"], + ["punctuation", "("], ["keyword", "define"], " 1+2 ", diff --git a/tests/languages/scheme/operator_feature.test b/tests/languages/scheme/operator_feature.test index 5904c1a3ed..245f0a2ac4 100644 --- a/tests/languages/scheme/operator_feature.test +++ b/tests/languages/scheme/operator_feature.test @@ -10,6 +10,10 @@ (= (=> +; with brackets +[= +[=> + ---------------------------------------------------- [ @@ -23,9 +27,13 @@ ["punctuation", "("], ["operator", ">"], ["punctuation", "("], ["operator", ">="], ["punctuation", "("], ["operator", "="], - ["punctuation", "("], ["operator", "=>"] + ["punctuation", "("], ["operator", "=>"], + + ["comment", "; with brackets"], + ["punctuation", "["], ["operator", "="], + ["punctuation", "["], ["operator", "=>"] ] ---------------------------------------------------- -Checks for operators. \ No newline at end of file +Checks for operators.