mirror of
https://github.com/cheat/cheat.git
synced 2024-11-23 06:21:35 +01:00
103 lines
51 KiB
Go
103 lines
51 KiB
Go
|
package r
|
|||
|
|
|||
|
import (
|
|||
|
. "github.com/alecthomas/chroma" // nolint
|
|||
|
"github.com/alecthomas/chroma/lexers/internal"
|
|||
|
)
|
|||
|
|
|||
|
// Racket lexer.
|
|||
|
var Racket = internal.Register(MustNewLexer(
|
|||
|
&Config{
|
|||
|
Name: "Racket",
|
|||
|
Aliases: []string{"racket", "rkt"},
|
|||
|
Filenames: []string{"*.rkt", "*.rktd", "*.rktl"},
|
|||
|
MimeTypes: []string{"text/x-racket", "application/x-racket"},
|
|||
|
},
|
|||
|
Rules{
|
|||
|
"root": {
|
|||
|
{`[)\]}]`, Error, nil},
|
|||
|
{`(?!\Z)`, Text, Push("unquoted-datum")},
|
|||
|
},
|
|||
|
"datum": {
|
|||
|
{`(?s)#;|#![ /]([^\\\n]|\\.)*`, Comment, nil},
|
|||
|
{`;[^\n\r
]*`, CommentSingle, nil},
|
|||
|
{`#\|`, CommentMultiline, Push("block-comment")},
|
|||
|
{`\s+`, Text, nil},
|
|||
|
{"(?i)(?:#e)?(?:#d)?(?:#e)?[-+]?\\d+(?=[()[\\]{}\",\\'`;\\s])", LiteralNumberInteger, Pop(1)},
|
|||
|
{"(?i)(?:#e)?(?:#d)?(?:#e)?[-+]?(\\d+(\\.\\d*)?|\\.\\d+)([deflst][-+]?\\d+)?(?=[()[\\]{}\",\\'`;\\s])", LiteralNumberFloat, Pop(1)},
|
|||
|
{"(?i)(?:#e)?(?:#d)?(?:#e)?[-+]?((?:(?:\\d+(?:/\\d+|\\.\\d*)?|\\.\\d+)(?:[defls][-+]?\\d+)?)([-+](?:(?:\\d+(?:/\\d+|\\.\\d*)?|\\.\\d+)(?:[defls][-+]?\\d+)?)?i)?|[-+](?:(?:\\d+(?:/\\d+|\\.\\d*)?|\\.\\d+)(?:[defls][-+]?\\d+)?)?i)(?=[()[\\]{}\",\\'`;\\s])",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ralNumberFloat, Pop(1)},
|
|||
|
{"(?i)(#[ei])?#b(?:\\|[^|]*\\||\\\\[\\w\\W]|[^|\\\\()[\\]{}\",\\'`;\\s]+)+", LiteralNumberBin, Pop(1)},
|
|||
|
{"(?i)(#[ei])?#o(?:\\|[^|]*\\||\\\\[\\w\\W]|[^|\\\\()[\\]{}\",\\'`;\\s]+)+", LiteralNumberOct, Pop(1)},
|
|||
|
{"(?i)(#[ei])?#x(?:\\|[^|]*\\||\\\\[\\w\\W]|[^|\\\\()[\\]{}\",\\'`;\\s]+)+", LiteralNumberHex, Pop(1)},
|
|||
|
{"(?i)(#d)?#i(?:\\|[^|]*\\||\\\\[\\w\\W]|[^|\\\\()[\\]{}\",\\'`;\\s]+)+", LiteralNumberFloat, Pop(1)},
|
|||
|
{`#?"`, LiteralStringDouble, Push("#pop", "string")},
|
|||
|
{`#<<(.+)\n(^(?!\1$).*$\n)*^\1$`, LiteralStringHeredoc, Pop(1)},
|
|||
|
{`#\\(u[\da-fA-F]{1,4}|U[\da-fA-F]{1,8})`, LiteralStringChar, Pop(1)},
|
|||
|
{`(?is)#\\([0-7]{3}|[a-z]+|.)`, LiteralStringChar, Pop(1)},
|
|||
|
{`(?s)#[pr]x#?"(\\?.)*?"`, LiteralStringRegex, Pop(1)},
|
|||
|
{`#(true|false|[tTfF])`, NameConstant, Pop(1)},
|
|||
|
{"#:(?:\\|[^|]*\\||\\\\[\\w\\W]|[^|\\\\()[\\]{}\",\\'`;\\s]+)+", KeywordDeclaration, Pop(1)},
|
|||
|
{`(#lang |#!)(\S+)`, ByGroups(KeywordNamespace, NameNamespace), nil},
|
|||
|
{`#reader`, KeywordNamespace, Push("quoted-datum")},
|
|||
|
{"(?i)\\.(?=[()[\\]{}\",\\'`;\\s])|#c[is]|#['`]|#,@?", Operator, nil},
|
|||
|
{`'|#[s&]|#hash(eqv?)?|#\d*(?=[([{])`, Operator, Push("#pop", "quoted-datum")},
|
|||
|
},
|
|||
|
"datum*": {
|
|||
|
{"`|,@?", Operator, nil},
|
|||
|
{"(?:\\|[^|]*\\||\\\\[\\w\\W]|[^|\\\\()[\\]{}\",\\'`;\\s]+)+", LiteralStringSymbol, Pop(1)},
|
|||
|
{`[|\\]`, Error, nil},
|
|||
|
Default(Pop(1)),
|
|||
|
},
|
|||
|
"list": {
|
|||
|
{`[)\]}]`, Punctuation, Pop(1)},
|
|||
|
},
|
|||
|
"unquoted-datum": {
|
|||
|
Include("datum"),
|
|||
|
{"quote(?=[()[\\]{}\",\\'`;\\s])", Keyword, Push("#pop", "quoted-datum")},
|
|||
|
{"`", Operator, Push("#pop", "quasiquoted-datum")},
|
|||
|
{"quasiquote(?=[()[\\]{}\",\\'`;\\s])", Keyword, Push("#pop", "quasiquoted-datum")},
|
|||
|
{`[([{]`, Punctuation, Push("#pop", "unquoted-list")},
|
|||
|
{Words(``, "(?=[()[\\]{}\",\\'`;\\s])", `#%app`, `#%datum`, `#%declare`, `#%expression`, `#%module-begin`, `#%plain-app`, `#%plain-lambda`, `#%plain-module-begin`, `#%printing-module-begin`, `#%provide`, `#%require`, `#%stratified-body`, `#%top`, `#%top-interaction`, `#%variable-reference`, `->`, `->*`, `->*m`, `->d`, `->dm`, `->i`, `->m`, `...`, `:do-in`, `==`, `=>`, `_`, `absent`, `abstract`, `all-defined-out`, `all-from-out`, `and`, `any`, `augment`, `augment*`, `augment-final`, `augment-final*`, `augride`, `augride*`, `begin`, `begin-for-syntax`, `begin0`, `case`, `case->`, `case->m`, `case-lambda`, `class`, `class*`, `class-field-accessor`, `class-field-mutator`, `class/c`, `class/derived`, `combine-in`, `combine-out`, `command-line`, `compound-unit`, `compound-unit/infer`, `cond`, `cons/dc`, `contract`, `contract-out`, `contract-struct`, `contracted`, `define`, `define-compound-unit`, `define-compound-unit/infer`, `define-contract-struct`, `define-custom-hash-types`, `define-custom-set-types`, `define-for-syntax`, `define-local-member-name`, `define-logger`, `define-match-expander`, `define-member-name`, `define-module-boundary-contract`, `define-namespace-anchor`, `define-opt/c`, `define-sequence-syntax`, `define-serializable-class`, `define-serializable-class*`, `define-signature`, `define-signature-form`, `define-struct`, `define-struct/contract`, `define-struct/derived`, `define-syntax`, `define-syntax-rule`, `define-syntaxes`, `define-unit`, `define-unit-binding`, `define-unit-from-context`, `define-unit/contract`, `define-unit/new-import-export`, `define-unit/s`, `define-values`, `define-values-for-export`, `define-values-for-syntax`, `define-values/invoke-unit`, `define-values/invoke-unit/infer`, `define/augment`, `define/augment-final`, `define/augride`, `define/contract`, `define/final-prop`, `define/match`, `define/overment`, `define/override`, `define/override-final`, `define/private`, `define/public`, `define/public-final`, `define/pubment`, `define/subexpression-pos-prop`, `define/subexpression-pos-prop/name`, `delay`, `delay/idle`, `delay/name`, `delay/strict`, `delay/sync`, `delay/thread`, `do`, `else`, `except`, `except-in`, `except-out`, `export`, `extends`, `failure-cont`, `false`, `false/c`, `field`, `field-bound?`, `file`, `flat-murec-contract`, `flat-rec-contract`, `for`, `for*`, `for*/and`, `for*/async`, `for*/first`, `for*/fold`, `for*/fold/derived`, `for*/hash`, `for*/hasheq`, `for*/hasheqv`, `for*/last`, `for*/list`, `for*/lists`, `for*/mutable-set`, `for*/mutable-seteq`, `for*/mutable-seteqv`, `for*/or`, `for*/product`, `for*/set`, `for*/seteq`, `for*/seteqv`, `for*/stream`, `for*/sum`, `for*/vector`, `for*/weak-set`, `for*/weak-seteq`, `for*/weak-seteqv`, `for-label`, `for-meta`, `for-syntax`, `for-template`, `for/and`, `for/async`, `for/first`, `for/fold`, `for/fold/derived`, `for/hash`, `for/hasheq`, `for/hasheqv`, `for/last`, `for/list`, `for/lists`, `for/mutable-set`, `for/mutable-seteq`, `for/mutable-seteqv`, `for/or`, `for/product`, `for/set`, `for/seteq`, `for/seteqv`, `for/stream`, `for/sum`, `for/vector`, `for/weak-set`, `for/weak-seteq`, `for/weak-seteqv`, `gen:custom-write`, `gen:dict`, `gen:equal+hash`, `gen:set`, `gen:stream`, `generic`, `get-field`, `hash/dc`, `if`, `implies`, `import`, `include`, `include-at/relative-to`, `include-at/relative-to/reader`, `include/reader`, `inherit`, `inherit-field`, `inherit/inner`, `inherit/super`, `init`, `init-depend`, `init-field`, `init-rest`, `inner`, `inspect`, `instantiate`, `interface`, `interface*`, `invariant-assertion`, `invoke-unit`, `invoke-unit/infer`, `lambda`, `lazy`, `let`, `let*`, `let*-values`, `let-syntax`, `let-syntaxes`, `let-values`, `let/cc`, `let/ec`, `letrec`, `letrec-syntax`, `letrec-syntaxes`, `letrec-syntaxes+values`, `letrec-values`, `lib`, `link`, `local`, `local-require`, `log-debug`, `log-error`, `log-fatal`, `log-info`, `log-warning`, `match`, `match*`, `match*/derived`, `match-define`, `match-define-values`, `match-lambda`, `match-lambda*`, `match-lambda**`, `match-let`, `match-let*`, `match-let*-valu
|
|||
|
{Words(``, "(?=[()[\\]{}\",\\'`;\\s])", `*`, `*list/c`, `+`, `-`, `/`, `<`, `</c`, `<=`, `<=/c`, `=`, `=/c`, `>`, `>/c`, `>=`, `>=/c`, `abort-current-continuation`, `abs`, `absolute-path?`, `acos`, `add-between`, `add1`, `alarm-evt`, `always-evt`, `and/c`, `andmap`, `angle`, `any/c`, `append`, `append*`, `append-map`, `apply`, `argmax`, `argmin`, `arithmetic-shift`, `arity-at-least`, `arity-at-least-value`, `arity-at-least?`, `arity-checking-wrapper`, `arity-includes?`, `arity=?`, `arrow-contract-info`, `arrow-contract-info-accepts-arglist`, `arrow-contract-info-chaperone-procedure`, `arrow-contract-info-check-first-order`, `arrow-contract-info?`, `asin`, `assf`, `assoc`, `assq`, `assv`, `atan`, `bad-number-of-results`, `banner`, `base->-doms/c`, `base->-rngs/c`, `base->?`, `between/c`, `bitwise-and`, `bitwise-bit-field`, `bitwise-bit-set?`, `bitwise-ior`, `bitwise-not`, `bitwise-xor`, `blame-add-car-context`, `blame-add-cdr-context`, `blame-add-context`, `blame-add-missing-party`, `blame-add-nth-arg-context`, `blame-add-range-context`, `blame-add-unknown-context`, `blame-context`, `blame-contract`, `blame-fmt->-string`, `blame-missing-party?`, `blame-negative`, `blame-original?`, `blame-positive`, `blame-replace-negative`, `blame-source`, `blame-swap`, `blame-swapped?`, `blame-update`, `blame-value`, `blame?`, `boolean=?`, `boolean?`, `bound-identifier=?`, `box`, `box-cas!`, `box-immutable`, `box-immutable/c`, `box/c`, `box?`, `break-enabled`, `break-parameterization?`, `break-thread`, `build-chaperone-contract-property`, `build-compound-type-name`, `build-contract-property`, `build-flat-contract-property`, `build-list`, `build-path`, `build-path/convention-type`, `build-string`, `build-vector`, `byte-pregexp`, `byte-pregexp?`, `byte-ready?`, `byte-regexp`, `byte-regexp?`, `byte?`, `bytes`, `bytes->immutable-bytes`, `bytes->list`, `bytes->path`, `bytes->path-element`, `bytes->string/latin-1`, `bytes->string/locale`, `bytes->string/utf-8`, `bytes-append`, `bytes-append*`, `bytes-close-converter`, `bytes-convert`, `bytes-convert-end`, `bytes-converter?`, `bytes-copy`, `bytes-copy!`, `bytes-environment-variable-name?`, `bytes-fill!`, `bytes-join`, `bytes-length`, `bytes-no-nuls?`, `bytes-open-converter`, `bytes-ref`, `bytes-set!`, `bytes-utf-8-index`, `bytes-utf-8-length`, `bytes-utf-8-ref`, `bytes<?`, `bytes=?`, `bytes>?`, `bytes?`, `caaaar`, `caaadr`, `caaar`, `caadar`, `caaddr`, `caadr`, `caar`, `cadaar`, `cadadr`, `cadar`, `caddar`, `cadddr`, `caddr`, `cadr`, `call-in-nested-thread`, `call-with-atomic-output-file`, `call-with-break-parameterization`, `call-with-composable-continuation`, `call-with-continuation-barrier`, `call-with-continuation-prompt`, `call-with-current-continuation`, `call-with-default-reading-parameterization`, `call-with-escape-continuation`, `call-with-exception-handler`, `call-with-file-lock/timeout`, `call-with-immediate-continuation-mark`, `call-with-input-bytes`, `call-with-input-file`, `call-with-input-file*`, `call-with-input-string`, `call-with-output-bytes`, `call-with-output-file`, `call-with-output-file*`, `call-with-output-string`, `call-with-parameterization`, `call-with-semaphore`, `call-with-semaphore/enable-break`, `call-with-values`, `call/cc`, `call/ec`, `car`, `cartesian-product`, `cdaaar`, `cdaadr`, `cdaar`, `cdadar`, `cdaddr`, `cdadr`, `cdar`, `cddaar`, `cddadr`, `cddar`, `cdddar`, `cddddr`, `cdddr`, `cddr`, `cdr`, `ceiling`, `channel-get`, `channel-put`, `channel-put-evt`, `channel-put-evt?`, `channel-try-get`, `channel/c`, `channel?`, `chaperone-box`, `chaperone-channel`, `chaperone-continuation-mark-key`, `chaperone-contract-property?`, `chaperone-contract?`, `chaperone-evt`, `chaperone-hash`, `chaperone-hash-set`, `chaperone-of?`, `chaperone-procedure`, `chaperone-procedure*`, `chaperone-prompt-tag`, `chaperone-struct`, `chaperone-struct-type`, `chaperone-vector`, `chaperone?`, `char->integer`, `char-alphabetic?`, `char-blank?`, `char-ci<=?`, `char-ci<?`, `char-ci=?`, `char-ci>=?`, `char-ci>?`, `char-downcase`, `char-foldcase`, `char-general-category`, `char-graphic?`,
|
|||
|
{"(?:\\|[^|]*\\||\\\\[\\w\\W]|[^|\\\\()[\\]{}\",\\'`;\\s]+)+", Name, Pop(1)},
|
|||
|
Include("datum*"),
|
|||
|
},
|
|||
|
"unquoted-list": {
|
|||
|
Include("list"),
|
|||
|
{`(?!\Z)`, Text, Push("unquoted-datum")},
|
|||
|
},
|
|||
|
"quasiquoted-datum": {
|
|||
|
Include("datum"),
|
|||
|
{`,@?`, Operator, Push("#pop", "unquoted-datum")},
|
|||
|
{"unquote(-splicing)?(?=[()[\\]{}\",\\'`;\\s])", Keyword, Push("#pop", "unquoted-datum")},
|
|||
|
{`[([{]`, Punctuation, Push("#pop", "quasiquoted-list")},
|
|||
|
Include("datum*"),
|
|||
|
},
|
|||
|
"quasiquoted-list": {
|
|||
|
Include("list"),
|
|||
|
{`(?!\Z)`, Text, Push("quasiquoted-datum")},
|
|||
|
},
|
|||
|
"quoted-datum": {
|
|||
|
Include("datum"),
|
|||
|
{`[([{]`, Punctuation, Push("#pop", "quoted-list")},
|
|||
|
Include("datum*"),
|
|||
|
},
|
|||
|
"quoted-list": {
|
|||
|
Include("list"),
|
|||
|
{`(?!\Z)`, Text, Push("quoted-datum")},
|
|||
|
},
|
|||
|
"block-comment": {
|
|||
|
{`#\|`, CommentMultiline, Push()},
|
|||
|
{`\|#`, CommentMultiline, Pop(1)},
|
|||
|
{`[^#|]+|.`, CommentMultiline, nil},
|
|||
|
},
|
|||
|
"string": {
|
|||
|
{`"`, LiteralStringDouble, Pop(1)},
|
|||
|
{`(?s)\\([0-7]{1,3}|x[\da-fA-F]{1,2}|u[\da-fA-F]{1,4}|U[\da-fA-F]{1,8}|.)`, LiteralStringEscape, nil},
|
|||
|
{`[^\\"]+`, LiteralStringDouble, nil},
|
|||
|
},
|
|||
|
},
|
|||
|
))
|