...

Source file src/github.com/alecthomas/chroma/lexers/c/cl.go

Documentation: github.com/alecthomas/chroma/lexers/c

     1  package c
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  var (
     9  	clBuiltinFunctions = []string{
    10  		"<", "<=", "=", ">", ">=", "-", "/", "/=", "*", "+", "1-", "1+",
    11  		"abort", "abs", "acons", "acos", "acosh", "add-method", "adjoin",
    12  		"adjustable-array-p", "adjust-array", "allocate-instance",
    13  		"alpha-char-p", "alphanumericp", "append", "apply", "apropos",
    14  		"apropos-list", "aref", "arithmetic-error-operands",
    15  		"arithmetic-error-operation", "array-dimension", "array-dimensions",
    16  		"array-displacement", "array-element-type", "array-has-fill-pointer-p",
    17  		"array-in-bounds-p", "arrayp", "array-rank", "array-row-major-index",
    18  		"array-total-size", "ash", "asin", "asinh", "assoc", "assoc-if",
    19  		"assoc-if-not", "atan", "atanh", "atom", "bit", "bit-and", "bit-andc1",
    20  		"bit-andc2", "bit-eqv", "bit-ior", "bit-nand", "bit-nor", "bit-not",
    21  		"bit-orc1", "bit-orc2", "bit-vector-p", "bit-xor", "boole",
    22  		"both-case-p", "boundp", "break", "broadcast-stream-streams",
    23  		"butlast", "byte", "byte-position", "byte-size", "caaaar", "caaadr",
    24  		"caaar", "caadar", "caaddr", "caadr", "caar", "cadaar", "cadadr",
    25  		"cadar", "caddar", "cadddr", "caddr", "cadr", "call-next-method", "car",
    26  		"cdaaar", "cdaadr", "cdaar", "cdadar", "cdaddr", "cdadr", "cdar",
    27  		"cddaar", "cddadr", "cddar", "cdddar", "cddddr", "cdddr", "cddr", "cdr",
    28  		"ceiling", "cell-error-name", "cerror", "change-class", "char", "char<",
    29  		"char<=", "char=", "char>", "char>=", "char/=", "character",
    30  		"characterp", "char-code", "char-downcase", "char-equal",
    31  		"char-greaterp", "char-int", "char-lessp", "char-name",
    32  		"char-not-equal", "char-not-greaterp", "char-not-lessp", "char-upcase",
    33  		"cis", "class-name", "class-of", "clear-input", "clear-output",
    34  		"close", "clrhash", "code-char", "coerce", "compile",
    35  		"compiled-function-p", "compile-file", "compile-file-pathname",
    36  		"compiler-macro-function", "complement", "complex", "complexp",
    37  		"compute-applicable-methods", "compute-restarts", "concatenate",
    38  		"concatenated-stream-streams", "conjugate", "cons", "consp",
    39  		"constantly", "constantp", "continue", "copy-alist", "copy-list",
    40  		"copy-pprint-dispatch", "copy-readtable", "copy-seq", "copy-structure",
    41  		"copy-symbol", "copy-tree", "cos", "cosh", "count", "count-if",
    42  		"count-if-not", "decode-float", "decode-universal-time", "delete",
    43  		"delete-duplicates", "delete-file", "delete-if", "delete-if-not",
    44  		"delete-package", "denominator", "deposit-field", "describe",
    45  		"describe-object", "digit-char", "digit-char-p", "directory",
    46  		"directory-namestring", "disassemble", "documentation", "dpb",
    47  		"dribble", "echo-stream-input-stream", "echo-stream-output-stream",
    48  		"ed", "eighth", "elt", "encode-universal-time", "endp",
    49  		"enough-namestring", "ensure-directories-exist",
    50  		"ensure-generic-function", "eq", "eql", "equal", "equalp", "error",
    51  		"eval", "evenp", "every", "exp", "export", "expt", "fboundp",
    52  		"fceiling", "fdefinition", "ffloor", "fifth", "file-author",
    53  		"file-error-pathname", "file-length", "file-namestring",
    54  		"file-position", "file-string-length", "file-write-date",
    55  		"fill", "fill-pointer", "find", "find-all-symbols", "find-class",
    56  		"find-if", "find-if-not", "find-method", "find-package", "find-restart",
    57  		"find-symbol", "finish-output", "first", "float", "float-digits",
    58  		"floatp", "float-precision", "float-radix", "float-sign", "floor",
    59  		"fmakunbound", "force-output", "format", "fourth", "fresh-line",
    60  		"fround", "ftruncate", "funcall", "function-keywords",
    61  		"function-lambda-expression", "functionp", "gcd", "gensym", "gentemp",
    62  		"get", "get-decoded-time", "get-dispatch-macro-character", "getf",
    63  		"gethash", "get-internal-real-time", "get-internal-run-time",
    64  		"get-macro-character", "get-output-stream-string", "get-properties",
    65  		"get-setf-expansion", "get-universal-time", "graphic-char-p",
    66  		"hash-table-count", "hash-table-p", "hash-table-rehash-size",
    67  		"hash-table-rehash-threshold", "hash-table-size", "hash-table-test",
    68  		"host-namestring", "identity", "imagpart", "import",
    69  		"initialize-instance", "input-stream-p", "inspect",
    70  		"integer-decode-float", "integer-length", "integerp",
    71  		"interactive-stream-p", "intern", "intersection",
    72  		"invalid-method-error", "invoke-debugger", "invoke-restart",
    73  		"invoke-restart-interactively", "isqrt", "keywordp", "last", "lcm",
    74  		"ldb", "ldb-test", "ldiff", "length", "lisp-implementation-type",
    75  		"lisp-implementation-version", "list", "list*", "list-all-packages",
    76  		"listen", "list-length", "listp", "load",
    77  		"load-logical-pathname-translations", "log", "logand", "logandc1",
    78  		"logandc2", "logbitp", "logcount", "logeqv", "logical-pathname",
    79  		"logical-pathname-translations", "logior", "lognand", "lognor",
    80  		"lognot", "logorc1", "logorc2", "logtest", "logxor", "long-site-name",
    81  		"lower-case-p", "machine-instance", "machine-type", "machine-version",
    82  		"macroexpand", "macroexpand-1", "macro-function", "make-array",
    83  		"make-broadcast-stream", "make-concatenated-stream", "make-condition",
    84  		"make-dispatch-macro-character", "make-echo-stream", "make-hash-table",
    85  		"make-instance", "make-instances-obsolete", "make-list",
    86  		"make-load-form", "make-load-form-saving-slots", "make-package",
    87  		"make-pathname", "make-random-state", "make-sequence", "make-string",
    88  		"make-string-input-stream", "make-string-output-stream", "make-symbol",
    89  		"make-synonym-stream", "make-two-way-stream", "makunbound", "map",
    90  		"mapc", "mapcan", "mapcar", "mapcon", "maphash", "map-into", "mapl",
    91  		"maplist", "mask-field", "max", "member", "member-if", "member-if-not",
    92  		"merge", "merge-pathnames", "method-combination-error",
    93  		"method-qualifiers", "min", "minusp", "mismatch", "mod",
    94  		"muffle-warning", "name-char", "namestring", "nbutlast", "nconc",
    95  		"next-method-p", "nintersection", "ninth", "no-applicable-method",
    96  		"no-next-method", "not", "notany", "notevery", "nreconc", "nreverse",
    97  		"nset-difference", "nset-exclusive-or", "nstring-capitalize",
    98  		"nstring-downcase", "nstring-upcase", "nsublis", "nsubst", "nsubst-if",
    99  		"nsubst-if-not", "nsubstitute", "nsubstitute-if", "nsubstitute-if-not",
   100  		"nth", "nthcdr", "null", "numberp", "numerator", "nunion", "oddp",
   101  		"open", "open-stream-p", "output-stream-p", "package-error-package",
   102  		"package-name", "package-nicknames", "packagep",
   103  		"package-shadowing-symbols", "package-used-by-list", "package-use-list",
   104  		"pairlis", "parse-integer", "parse-namestring", "pathname",
   105  		"pathname-device", "pathname-directory", "pathname-host",
   106  		"pathname-match-p", "pathname-name", "pathnamep", "pathname-type",
   107  		"pathname-version", "peek-char", "phase", "plusp", "position",
   108  		"position-if", "position-if-not", "pprint", "pprint-dispatch",
   109  		"pprint-fill", "pprint-indent", "pprint-linear", "pprint-newline",
   110  		"pprint-tab", "pprint-tabular", "prin1", "prin1-to-string", "princ",
   111  		"princ-to-string", "print", "print-object", "probe-file", "proclaim",
   112  		"provide", "random", "random-state-p", "rassoc", "rassoc-if",
   113  		"rassoc-if-not", "rational", "rationalize", "rationalp", "read",
   114  		"read-byte", "read-char", "read-char-no-hang", "read-delimited-list",
   115  		"read-from-string", "read-line", "read-preserving-whitespace",
   116  		"read-sequence", "readtable-case", "readtablep", "realp", "realpart",
   117  		"reduce", "reinitialize-instance", "rem", "remhash", "remove",
   118  		"remove-duplicates", "remove-if", "remove-if-not", "remove-method",
   119  		"remprop", "rename-file", "rename-package", "replace", "require",
   120  		"rest", "restart-name", "revappend", "reverse", "room", "round",
   121  		"row-major-aref", "rplaca", "rplacd", "sbit", "scale-float", "schar",
   122  		"search", "second", "set", "set-difference",
   123  		"set-dispatch-macro-character", "set-exclusive-or",
   124  		"set-macro-character", "set-pprint-dispatch", "set-syntax-from-char",
   125  		"seventh", "shadow", "shadowing-import", "shared-initialize",
   126  		"short-site-name", "signal", "signum", "simple-bit-vector-p",
   127  		"simple-condition-format-arguments", "simple-condition-format-control",
   128  		"simple-string-p", "simple-vector-p", "sin", "sinh", "sixth", "sleep",
   129  		"slot-boundp", "slot-exists-p", "slot-makunbound", "slot-missing",
   130  		"slot-unbound", "slot-value", "software-type", "software-version",
   131  		"some", "sort", "special-operator-p", "sqrt", "stable-sort",
   132  		"standard-char-p", "store-value", "stream-element-type",
   133  		"stream-error-stream", "stream-external-format", "streamp", "string",
   134  		"string<", "string<=", "string=", "string>", "string>=", "string/=",
   135  		"string-capitalize", "string-downcase", "string-equal",
   136  		"string-greaterp", "string-left-trim", "string-lessp",
   137  		"string-not-equal", "string-not-greaterp", "string-not-lessp",
   138  		"stringp", "string-right-trim", "string-trim", "string-upcase",
   139  		"sublis", "subseq", "subsetp", "subst", "subst-if", "subst-if-not",
   140  		"substitute", "substitute-if", "substitute-if-not", "subtypep", "svref",
   141  		"sxhash", "symbol-function", "symbol-name", "symbolp", "symbol-package",
   142  		"symbol-plist", "symbol-value", "synonym-stream-symbol", "syntax:",
   143  		"tailp", "tan", "tanh", "tenth", "terpri", "third",
   144  		"translate-logical-pathname", "translate-pathname", "tree-equal",
   145  		"truename", "truncate", "two-way-stream-input-stream",
   146  		"two-way-stream-output-stream", "type-error-datum",
   147  		"type-error-expected-type", "type-of", "typep", "unbound-slot-instance",
   148  		"unexport", "unintern", "union", "unread-char", "unuse-package",
   149  		"update-instance-for-different-class",
   150  		"update-instance-for-redefined-class", "upgraded-array-element-type",
   151  		"upgraded-complex-part-type", "upper-case-p", "use-package",
   152  		"user-homedir-pathname", "use-value", "values", "values-list", "vector",
   153  		"vectorp", "vector-pop", "vector-push", "vector-push-extend", "warn",
   154  		"wild-pathname-p", "write", "write-byte", "write-char", "write-line",
   155  		"write-sequence", "write-string", "write-to-string", "yes-or-no-p",
   156  		"y-or-n-p", "zerop",
   157  	}
   158  
   159  	clSpecialForms = []string{
   160  		"block", "catch", "declare", "eval-when", "flet", "function", "go", "if",
   161  		"labels", "lambda", "let", "let*", "load-time-value", "locally", "macrolet",
   162  		"multiple-value-call", "multiple-value-prog1", "progn", "progv", "quote",
   163  		"return-from", "setq", "symbol-macrolet", "tagbody", "the", "throw",
   164  		"unwind-protect",
   165  	}
   166  
   167  	clMacros = []string{
   168  		"and", "assert", "call-method", "case", "ccase", "check-type", "cond",
   169  		"ctypecase", "decf", "declaim", "defclass", "defconstant", "defgeneric",
   170  		"define-compiler-macro", "define-condition", "define-method-combination",
   171  		"define-modify-macro", "define-setf-expander", "define-symbol-macro",
   172  		"defmacro", "defmethod", "defpackage", "defparameter", "defsetf",
   173  		"defstruct", "deftype", "defun", "defvar", "destructuring-bind", "do",
   174  		"do*", "do-all-symbols", "do-external-symbols", "dolist", "do-symbols",
   175  		"dotimes", "ecase", "etypecase", "formatter", "handler-bind",
   176  		"handler-case", "ignore-errors", "incf", "in-package", "lambda", "loop",
   177  		"loop-finish", "make-method", "multiple-value-bind", "multiple-value-list",
   178  		"multiple-value-setq", "nth-value", "or", "pop",
   179  		"pprint-exit-if-list-exhausted", "pprint-logical-block", "pprint-pop",
   180  		"print-unreadable-object", "prog", "prog*", "prog1", "prog2", "psetf",
   181  		"psetq", "push", "pushnew", "remf", "restart-bind", "restart-case",
   182  		"return", "rotatef", "setf", "shiftf", "step", "time", "trace", "typecase",
   183  		"unless", "untrace", "when", "with-accessors", "with-compilation-unit",
   184  		"with-condition-restarts", "with-hash-table-iterator",
   185  		"with-input-from-string", "with-open-file", "with-open-stream",
   186  		"with-output-to-string", "with-package-iterator", "with-simple-restart",
   187  		"with-slots", "with-standard-io-syntax",
   188  	}
   189  
   190  	clLambdaListKeywords = []string{
   191  		"&allow-other-keys", "&aux", "&body", "&environment", "&key", "&optional",
   192  		"&rest", "&whole",
   193  	}
   194  
   195  	clDeclarations = []string{
   196  		"dynamic-extent", "ignore", "optimize", "ftype", "inline", "special",
   197  		"ignorable", "notinline", "type",
   198  	}
   199  
   200  	clBuiltinTypes = []string{
   201  		"atom", "boolean", "base-char", "base-string", "bignum", "bit",
   202  		"compiled-function", "extended-char", "fixnum", "keyword", "nil",
   203  		"signed-byte", "short-float", "single-float", "double-float", "long-float",
   204  		"simple-array", "simple-base-string", "simple-bit-vector", "simple-string",
   205  		"simple-vector", "standard-char", "unsigned-byte",
   206  
   207  		// Condition Types
   208  		"arithmetic-error", "cell-error", "condition", "control-error",
   209  		"division-by-zero", "end-of-file", "error", "file-error",
   210  		"floating-point-inexact", "floating-point-overflow",
   211  		"floating-point-underflow", "floating-point-invalid-operation",
   212  		"parse-error", "package-error", "print-not-readable", "program-error",
   213  		"reader-error", "serious-condition", "simple-condition", "simple-error",
   214  		"simple-type-error", "simple-warning", "stream-error", "storage-condition",
   215  		"style-warning", "type-error", "unbound-variable", "unbound-slot",
   216  		"undefined-function", "warning",
   217  	}
   218  
   219  	clBuiltinClasses = []string{
   220  		"array", "broadcast-stream", "bit-vector", "built-in-class", "character",
   221  		"class", "complex", "concatenated-stream", "cons", "echo-stream",
   222  		"file-stream", "float", "function", "generic-function", "hash-table",
   223  		"integer", "list", "logical-pathname", "method-combination", "method",
   224  		"null", "number", "package", "pathname", "ratio", "rational", "readtable",
   225  		"real", "random-state", "restart", "sequence", "standard-class",
   226  		"standard-generic-function", "standard-method", "standard-object",
   227  		"string-stream", "stream", "string", "structure-class", "structure-object",
   228  		"symbol", "synonym-stream", "t", "two-way-stream", "vector",
   229  	}
   230  )
   231  
   232  // Common Lisp lexer.
   233  var CommonLisp = internal.Register(TypeRemappingLexer(MustNewLazyLexer(
   234  	&Config{
   235  		Name:            "Common Lisp",
   236  		Aliases:         []string{"common-lisp", "cl", "lisp"},
   237  		Filenames:       []string{"*.cl", "*.lisp"},
   238  		MimeTypes:       []string{"text/x-common-lisp"},
   239  		CaseInsensitive: true,
   240  	},
   241  	commonLispRules,
   242  ), TypeMapping{
   243  	{NameVariable, NameFunction, clBuiltinFunctions},
   244  	{NameVariable, Keyword, clSpecialForms},
   245  	{NameVariable, NameBuiltin, clMacros},
   246  	{NameVariable, Keyword, clLambdaListKeywords},
   247  	{NameVariable, Keyword, clDeclarations},
   248  	{NameVariable, KeywordType, clBuiltinTypes},
   249  	{NameVariable, NameClass, clBuiltinClasses},
   250  }))
   251  
   252  func commonLispRules() Rules {
   253  	return Rules{
   254  		"root": {
   255  			Default(Push("body")),
   256  		},
   257  		"multiline-comment": {
   258  			{`#\|`, CommentMultiline, Push()},
   259  			{`\|#`, CommentMultiline, Pop(1)},
   260  			{`[^|#]+`, CommentMultiline, nil},
   261  			{`[|#]`, CommentMultiline, nil},
   262  		},
   263  		"commented-form": {
   264  			{`\(`, CommentPreproc, Push()},
   265  			{`\)`, CommentPreproc, Pop(1)},
   266  			{`[^()]+`, CommentPreproc, nil},
   267  		},
   268  		"body": {
   269  			{`\s+`, Text, nil},
   270  			{`;.*$`, CommentSingle, nil},
   271  			{`#\|`, CommentMultiline, Push("multiline-comment")},
   272  			{`#\d*Y.*$`, CommentSpecial, nil},
   273  			{`"(\\.|\\\n|[^"\\])*"`, LiteralString, nil},
   274  			{`:(\|[^|]+\||(?:\\.|[\w!$%&*+-/<=>?@\[\]^{}~])(?:\\.|[\w!$%&*+-/<=>?@\[\]^{}~]|[#.:])*)`, LiteralStringSymbol, nil},
   275  			{`::(\|[^|]+\||(?:\\.|[\w!$%&*+-/<=>?@\[\]^{}~])(?:\\.|[\w!$%&*+-/<=>?@\[\]^{}~]|[#.:])*)`, LiteralStringSymbol, nil},
   276  			{`:#(\|[^|]+\||(?:\\.|[\w!$%&*+-/<=>?@\[\]^{}~])(?:\\.|[\w!$%&*+-/<=>?@\[\]^{}~]|[#.:])*)`, LiteralStringSymbol, nil},
   277  			{`'(\|[^|]+\||(?:\\.|[\w!$%&*+-/<=>?@\[\]^{}~])(?:\\.|[\w!$%&*+-/<=>?@\[\]^{}~]|[#.:])*)`, LiteralStringSymbol, nil},
   278  			{`'`, Operator, nil},
   279  			{"`", Operator, nil},
   280  			{"[-+]?\\d+\\.?(?=[ \"()\\'\\n,;`])", LiteralNumberInteger, nil},
   281  			{"[-+]?\\d+/\\d+(?=[ \"()\\'\\n,;`])", LiteralNumber, nil},
   282  			{"[-+]?(\\d*\\.\\d+([defls][-+]?\\d+)?|\\d+(\\.\\d*)?[defls][-+]?\\d+)(?=[ \"()\\'\\n,;`])", LiteralNumberFloat, nil},
   283  			{"#\\\\.(?=[ \"()\\'\\n,;`])", LiteralStringChar, nil},
   284  			{`#\\(\|[^|]+\||(?:\\.|[\w!$%&*+-/<=>?@\[\]^{}~])(?:\\.|[\w!$%&*+-/<=>?@\[\]^{}~]|[#.:])*)`, LiteralStringChar, nil},
   285  			{`#\(`, Operator, Push("body")},
   286  			{`#\d*\*[01]*`, LiteralOther, nil},
   287  			{`#:(\|[^|]+\||(?:\\.|[\w!$%&*+-/<=>?@\[\]^{}~])(?:\\.|[\w!$%&*+-/<=>?@\[\]^{}~]|[#.:])*)`, LiteralStringSymbol, nil},
   288  			{`#[.,]`, Operator, nil},
   289  			{`#\'`, NameFunction, nil},
   290  			{`#b[+-]?[01]+(/[01]+)?`, LiteralNumberBin, nil},
   291  			{`#o[+-]?[0-7]+(/[0-7]+)?`, LiteralNumberOct, nil},
   292  			{`#x[+-]?[0-9a-f]+(/[0-9a-f]+)?`, LiteralNumberHex, nil},
   293  			{`#\d+r[+-]?[0-9a-z]+(/[0-9a-z]+)?`, LiteralNumber, nil},
   294  			{`(#c)(\()`, ByGroups(LiteralNumber, Punctuation), Push("body")},
   295  			{`(#\d+a)(\()`, ByGroups(LiteralOther, Punctuation), Push("body")},
   296  			{`(#s)(\()`, ByGroups(LiteralOther, Punctuation), Push("body")},
   297  			{`#p?"(\\.|[^"])*"`, LiteralOther, nil},
   298  			{`#\d+=`, Operator, nil},
   299  			{`#\d+#`, Operator, nil},
   300  			{"#+nil(?=[ \"()\\'\\n,;`])\\s*\\(", CommentPreproc, Push("commented-form")},
   301  			{`#[+-]`, Operator, nil},
   302  			{`(,@|,|\.)`, Operator, nil},
   303  			{"(t|nil)(?=[ \"()\\'\\n,;`])", NameConstant, nil},
   304  			{`\*(\|[^|]+\||(?:\\.|[\w!$%&*+-/<=>?@\[\]^{}~])(?:\\.|[\w!$%&*+-/<=>?@\[\]^{}~]|[#.:])*)\*`, NameVariableGlobal, nil},
   305  			{`(\|[^|]+\||(?:\\.|[\w!$%&*+-/<=>?@\[\]^{}~])(?:\\.|[\w!$%&*+-/<=>?@\[\]^{}~]|[#.:])*)`, NameVariable, nil},
   306  			{`\(`, Punctuation, Push("body")},
   307  			{`\)`, Punctuation, Pop(1)},
   308  		},
   309  	}
   310  }
   311  

View as plain text