lisp.py 140 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694
  1. # -*- coding: utf-8 -*-
  2. """
  3. pygments.lexers.lisp
  4. ~~~~~~~~~~~~~~~~~~~~
  5. Lexers for Lispy languages.
  6. :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
  7. :license: BSD, see LICENSE for details.
  8. """
  9. import re
  10. from pygments.lexer import RegexLexer, include, bygroups, words, default
  11. from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
  12. Number, Punctuation, Literal, Error
  13. from pygments.lexers.python import PythonLexer
  14. __all__ = ['SchemeLexer', 'CommonLispLexer', 'HyLexer', 'RacketLexer',
  15. 'NewLispLexer', 'EmacsLispLexer', 'ShenLexer', 'CPSALexer',
  16. 'XtlangLexer', 'FennelLexer']
  17. class SchemeLexer(RegexLexer):
  18. """
  19. A Scheme lexer, parsing a stream and outputting the tokens
  20. needed to highlight scheme code.
  21. This lexer could be most probably easily subclassed to parse
  22. other LISP-Dialects like Common Lisp, Emacs Lisp or AutoLisp.
  23. This parser is checked with pastes from the LISP pastebin
  24. at http://paste.lisp.org/ to cover as much syntax as possible.
  25. It supports the full Scheme syntax as defined in R5RS.
  26. .. versionadded:: 0.6
  27. """
  28. name = 'Scheme'
  29. aliases = ['scheme', 'scm']
  30. filenames = ['*.scm', '*.ss']
  31. mimetypes = ['text/x-scheme', 'application/x-scheme']
  32. # list of known keywords and builtins taken form vim 6.4 scheme.vim
  33. # syntax file.
  34. keywords = (
  35. 'lambda', 'define', 'if', 'else', 'cond', 'and', 'or', 'case', 'let',
  36. 'let*', 'letrec', 'begin', 'do', 'delay', 'set!', '=>', 'quote',
  37. 'quasiquote', 'unquote', 'unquote-splicing', 'define-syntax',
  38. 'let-syntax', 'letrec-syntax', 'syntax-rules'
  39. )
  40. builtins = (
  41. '*', '+', '-', '/', '<', '<=', '=', '>', '>=', 'abs', 'acos', 'angle',
  42. 'append', 'apply', 'asin', 'assoc', 'assq', 'assv', 'atan',
  43. 'boolean?', 'caaaar', 'caaadr', 'caaar', 'caadar', 'caaddr', 'caadr',
  44. 'caar', 'cadaar', 'cadadr', 'cadar', 'caddar', 'cadddr', 'caddr',
  45. 'cadr', 'call-with-current-continuation', 'call-with-input-file',
  46. 'call-with-output-file', 'call-with-values', 'call/cc', 'car',
  47. 'cdaaar', 'cdaadr', 'cdaar', 'cdadar', 'cdaddr', 'cdadr', 'cdar',
  48. 'cddaar', 'cddadr', 'cddar', 'cdddar', 'cddddr', 'cdddr', 'cddr',
  49. 'cdr', 'ceiling', 'char->integer', 'char-alphabetic?', 'char-ci<=?',
  50. 'char-ci<?', 'char-ci=?', 'char-ci>=?', 'char-ci>?', 'char-downcase',
  51. 'char-lower-case?', 'char-numeric?', 'char-ready?', 'char-upcase',
  52. 'char-upper-case?', 'char-whitespace?', 'char<=?', 'char<?', 'char=?',
  53. 'char>=?', 'char>?', 'char?', 'close-input-port', 'close-output-port',
  54. 'complex?', 'cons', 'cos', 'current-input-port', 'current-output-port',
  55. 'denominator', 'display', 'dynamic-wind', 'eof-object?', 'eq?',
  56. 'equal?', 'eqv?', 'eval', 'even?', 'exact->inexact', 'exact?', 'exp',
  57. 'expt', 'floor', 'for-each', 'force', 'gcd', 'imag-part',
  58. 'inexact->exact', 'inexact?', 'input-port?', 'integer->char',
  59. 'integer?', 'interaction-environment', 'lcm', 'length', 'list',
  60. 'list->string', 'list->vector', 'list-ref', 'list-tail', 'list?',
  61. 'load', 'log', 'magnitude', 'make-polar', 'make-rectangular',
  62. 'make-string', 'make-vector', 'map', 'max', 'member', 'memq', 'memv',
  63. 'min', 'modulo', 'negative?', 'newline', 'not', 'null-environment',
  64. 'null?', 'number->string', 'number?', 'numerator', 'odd?',
  65. 'open-input-file', 'open-output-file', 'output-port?', 'pair?',
  66. 'peek-char', 'port?', 'positive?', 'procedure?', 'quotient',
  67. 'rational?', 'rationalize', 'read', 'read-char', 'real-part', 'real?',
  68. 'remainder', 'reverse', 'round', 'scheme-report-environment',
  69. 'set-car!', 'set-cdr!', 'sin', 'sqrt', 'string', 'string->list',
  70. 'string->number', 'string->symbol', 'string-append', 'string-ci<=?',
  71. 'string-ci<?', 'string-ci=?', 'string-ci>=?', 'string-ci>?',
  72. 'string-copy', 'string-fill!', 'string-length', 'string-ref',
  73. 'string-set!', 'string<=?', 'string<?', 'string=?', 'string>=?',
  74. 'string>?', 'string?', 'substring', 'symbol->string', 'symbol?',
  75. 'tan', 'transcript-off', 'transcript-on', 'truncate', 'values',
  76. 'vector', 'vector->list', 'vector-fill!', 'vector-length',
  77. 'vector-ref', 'vector-set!', 'vector?', 'with-input-from-file',
  78. 'with-output-to-file', 'write', 'write-char', 'zero?'
  79. )
  80. # valid names for identifiers
  81. # well, names can only not consist fully of numbers
  82. # but this should be good enough for now
  83. valid_name = r'[\w!$%&*+,/:<=>?@^~|-]+'
  84. tokens = {
  85. 'root': [
  86. # the comments
  87. # and going to the end of the line
  88. (r';.*$', Comment.Single),
  89. # multi-line comment
  90. (r'#\|', Comment.Multiline, 'multiline-comment'),
  91. # commented form (entire sexpr folliwng)
  92. (r'#;\s*\(', Comment, 'commented-form'),
  93. # signifies that the program text that follows is written with the
  94. # lexical and datum syntax described in r6rs
  95. (r'#!r6rs', Comment),
  96. # whitespaces - usually not relevant
  97. (r'\s+', Text),
  98. # numbers
  99. (r'-?\d+\.\d+', Number.Float),
  100. (r'-?\d+', Number.Integer),
  101. # support for uncommon kinds of numbers -
  102. # have to figure out what the characters mean
  103. # (r'(#e|#i|#b|#o|#d|#x)[\d.]+', Number),
  104. # strings, symbols and characters
  105. (r'"(\\\\|\\"|[^"])*"', String),
  106. (r"'" + valid_name, String.Symbol),
  107. (r"#\\([()/'\"._!§$%& ?=+-]|[a-zA-Z0-9]+)", String.Char),
  108. # constants
  109. (r'(#t|#f)', Name.Constant),
  110. # special operators
  111. (r"('|#|`|,@|,|\.)", Operator),
  112. # highlight the keywords
  113. ('(%s)' % '|'.join(re.escape(entry) + ' ' for entry in keywords),
  114. Keyword),
  115. # first variable in a quoted string like
  116. # '(this is syntactic sugar)
  117. (r"(?<='\()" + valid_name, Name.Variable),
  118. (r"(?<=#\()" + valid_name, Name.Variable),
  119. # highlight the builtins
  120. (r"(?<=\()(%s)" % '|'.join(re.escape(entry) + ' ' for entry in builtins),
  121. Name.Builtin),
  122. # the remaining functions
  123. (r'(?<=\()' + valid_name, Name.Function),
  124. # find the remaining variables
  125. (valid_name, Name.Variable),
  126. # the famous parentheses!
  127. (r'(\(|\))', Punctuation),
  128. (r'(\[|\])', Punctuation),
  129. ],
  130. 'multiline-comment': [
  131. (r'#\|', Comment.Multiline, '#push'),
  132. (r'\|#', Comment.Multiline, '#pop'),
  133. (r'[^|#]+', Comment.Multiline),
  134. (r'[|#]', Comment.Multiline),
  135. ],
  136. 'commented-form': [
  137. (r'\(', Comment, '#push'),
  138. (r'\)', Comment, '#pop'),
  139. (r'[^()]+', Comment),
  140. ],
  141. }
  142. class CommonLispLexer(RegexLexer):
  143. """
  144. A Common Lisp lexer.
  145. .. versionadded:: 0.9
  146. """
  147. name = 'Common Lisp'
  148. aliases = ['common-lisp', 'cl', 'lisp']
  149. filenames = ['*.cl', '*.lisp']
  150. mimetypes = ['text/x-common-lisp']
  151. flags = re.IGNORECASE | re.MULTILINE
  152. # couple of useful regexes
  153. # characters that are not macro-characters and can be used to begin a symbol
  154. nonmacro = r'\\.|[\w!$%&*+-/<=>?@\[\]^{}~]'
  155. constituent = nonmacro + '|[#.:]'
  156. terminated = r'(?=[ "()\'\n,;`])' # whitespace or terminating macro characters
  157. # symbol token, reverse-engineered from hyperspec
  158. # Take a deep breath...
  159. symbol = r'(\|[^|]+\||(?:%s)(?:%s)*)' % (nonmacro, constituent)
  160. def __init__(self, **options):
  161. from pygments.lexers._cl_builtins import BUILTIN_FUNCTIONS, \
  162. SPECIAL_FORMS, MACROS, LAMBDA_LIST_KEYWORDS, DECLARATIONS, \
  163. BUILTIN_TYPES, BUILTIN_CLASSES
  164. self.builtin_function = BUILTIN_FUNCTIONS
  165. self.special_forms = SPECIAL_FORMS
  166. self.macros = MACROS
  167. self.lambda_list_keywords = LAMBDA_LIST_KEYWORDS
  168. self.declarations = DECLARATIONS
  169. self.builtin_types = BUILTIN_TYPES
  170. self.builtin_classes = BUILTIN_CLASSES
  171. RegexLexer.__init__(self, **options)
  172. def get_tokens_unprocessed(self, text):
  173. stack = ['root']
  174. for index, token, value in RegexLexer.get_tokens_unprocessed(self, text, stack):
  175. if token is Name.Variable:
  176. if value in self.builtin_function:
  177. yield index, Name.Builtin, value
  178. continue
  179. if value in self.special_forms:
  180. yield index, Keyword, value
  181. continue
  182. if value in self.macros:
  183. yield index, Name.Builtin, value
  184. continue
  185. if value in self.lambda_list_keywords:
  186. yield index, Keyword, value
  187. continue
  188. if value in self.declarations:
  189. yield index, Keyword, value
  190. continue
  191. if value in self.builtin_types:
  192. yield index, Keyword.Type, value
  193. continue
  194. if value in self.builtin_classes:
  195. yield index, Name.Class, value
  196. continue
  197. yield index, token, value
  198. tokens = {
  199. 'root': [
  200. default('body'),
  201. ],
  202. 'multiline-comment': [
  203. (r'#\|', Comment.Multiline, '#push'), # (cf. Hyperspec 2.4.8.19)
  204. (r'\|#', Comment.Multiline, '#pop'),
  205. (r'[^|#]+', Comment.Multiline),
  206. (r'[|#]', Comment.Multiline),
  207. ],
  208. 'commented-form': [
  209. (r'\(', Comment.Preproc, '#push'),
  210. (r'\)', Comment.Preproc, '#pop'),
  211. (r'[^()]+', Comment.Preproc),
  212. ],
  213. 'body': [
  214. # whitespace
  215. (r'\s+', Text),
  216. # single-line comment
  217. (r';.*$', Comment.Single),
  218. # multi-line comment
  219. (r'#\|', Comment.Multiline, 'multiline-comment'),
  220. # encoding comment (?)
  221. (r'#\d*Y.*$', Comment.Special),
  222. # strings and characters
  223. (r'"(\\.|\\\n|[^"\\])*"', String),
  224. # quoting
  225. (r":" + symbol, String.Symbol),
  226. (r"::" + symbol, String.Symbol),
  227. (r":#" + symbol, String.Symbol),
  228. (r"'" + symbol, String.Symbol),
  229. (r"'", Operator),
  230. (r"`", Operator),
  231. # decimal numbers
  232. (r'[-+]?\d+\.?' + terminated, Number.Integer),
  233. (r'[-+]?\d+/\d+' + terminated, Number),
  234. (r'[-+]?(\d*\.\d+([defls][-+]?\d+)?|\d+(\.\d*)?[defls][-+]?\d+)' +
  235. terminated, Number.Float),
  236. # sharpsign strings and characters
  237. (r"#\\." + terminated, String.Char),
  238. (r"#\\" + symbol, String.Char),
  239. # vector
  240. (r'#\(', Operator, 'body'),
  241. # bitstring
  242. (r'#\d*\*[01]*', Literal.Other),
  243. # uninterned symbol
  244. (r'#:' + symbol, String.Symbol),
  245. # read-time and load-time evaluation
  246. (r'#[.,]', Operator),
  247. # function shorthand
  248. (r'#\'', Name.Function),
  249. # binary rational
  250. (r'#b[+-]?[01]+(/[01]+)?', Number.Bin),
  251. # octal rational
  252. (r'#o[+-]?[0-7]+(/[0-7]+)?', Number.Oct),
  253. # hex rational
  254. (r'#x[+-]?[0-9a-f]+(/[0-9a-f]+)?', Number.Hex),
  255. # radix rational
  256. (r'#\d+r[+-]?[0-9a-z]+(/[0-9a-z]+)?', Number),
  257. # complex
  258. (r'(#c)(\()', bygroups(Number, Punctuation), 'body'),
  259. # array
  260. (r'(#\d+a)(\()', bygroups(Literal.Other, Punctuation), 'body'),
  261. # structure
  262. (r'(#s)(\()', bygroups(Literal.Other, Punctuation), 'body'),
  263. # path
  264. (r'#p?"(\\.|[^"])*"', Literal.Other),
  265. # reference
  266. (r'#\d+=', Operator),
  267. (r'#\d+#', Operator),
  268. # read-time comment
  269. (r'#+nil' + terminated + r'\s*\(', Comment.Preproc, 'commented-form'),
  270. # read-time conditional
  271. (r'#[+-]', Operator),
  272. # special operators that should have been parsed already
  273. (r'(,@|,|\.)', Operator),
  274. # special constants
  275. (r'(t|nil)' + terminated, Name.Constant),
  276. # functions and variables
  277. (r'\*' + symbol + r'\*', Name.Variable.Global),
  278. (symbol, Name.Variable),
  279. # parentheses
  280. (r'\(', Punctuation, 'body'),
  281. (r'\)', Punctuation, '#pop'),
  282. ],
  283. }
  284. class HyLexer(RegexLexer):
  285. """
  286. Lexer for `Hy <http://hylang.org/>`_ source code.
  287. .. versionadded:: 2.0
  288. """
  289. name = 'Hy'
  290. aliases = ['hylang']
  291. filenames = ['*.hy']
  292. mimetypes = ['text/x-hy', 'application/x-hy']
  293. special_forms = (
  294. 'cond', 'for', '->', '->>', 'car',
  295. 'cdr', 'first', 'rest', 'let', 'when', 'unless',
  296. 'import', 'do', 'progn', 'get', 'slice', 'assoc', 'with-decorator',
  297. ',', 'list_comp', 'kwapply', '~', 'is', 'in', 'is-not', 'not-in',
  298. 'quasiquote', 'unquote', 'unquote-splice', 'quote', '|', '<<=', '>>=',
  299. 'foreach', 'while',
  300. 'eval-and-compile', 'eval-when-compile'
  301. )
  302. declarations = (
  303. 'def', 'defn', 'defun', 'defmacro', 'defclass', 'lambda', 'fn', 'setv'
  304. )
  305. hy_builtins = ()
  306. hy_core = (
  307. 'cycle', 'dec', 'distinct', 'drop', 'even?', 'filter', 'inc',
  308. 'instance?', 'iterable?', 'iterate', 'iterator?', 'neg?',
  309. 'none?', 'nth', 'numeric?', 'odd?', 'pos?', 'remove', 'repeat',
  310. 'repeatedly', 'take', 'take_nth', 'take_while', 'zero?'
  311. )
  312. builtins = hy_builtins + hy_core
  313. # valid names for identifiers
  314. # well, names can only not consist fully of numbers
  315. # but this should be good enough for now
  316. valid_name = r'(?!#)[\w!$%*+<=>?/.#-:]+'
  317. def _multi_escape(entries):
  318. return words(entries, suffix=' ')
  319. tokens = {
  320. 'root': [
  321. # the comments - always starting with semicolon
  322. # and going to the end of the line
  323. (r';.*$', Comment.Single),
  324. # whitespaces - usually not relevant
  325. (r'[,\s]+', Text),
  326. # numbers
  327. (r'-?\d+\.\d+', Number.Float),
  328. (r'-?\d+', Number.Integer),
  329. (r'0[0-7]+j?', Number.Oct),
  330. (r'0[xX][a-fA-F0-9]+', Number.Hex),
  331. # strings, symbols and characters
  332. (r'"(\\\\|\\"|[^"])*"', String),
  333. (r"'" + valid_name, String.Symbol),
  334. (r"\\(.|[a-z]+)", String.Char),
  335. (r'^(\s*)([rRuU]{,2}"""(?:.|\n)*?""")', bygroups(Text, String.Doc)),
  336. (r"^(\s*)([rRuU]{,2}'''(?:.|\n)*?''')", bygroups(Text, String.Doc)),
  337. # keywords
  338. (r'::?' + valid_name, String.Symbol),
  339. # special operators
  340. (r'~@|[`\'#^~&@]', Operator),
  341. include('py-keywords'),
  342. include('py-builtins'),
  343. # highlight the special forms
  344. (_multi_escape(special_forms), Keyword),
  345. # Technically, only the special forms are 'keywords'. The problem
  346. # is that only treating them as keywords means that things like
  347. # 'defn' and 'ns' need to be highlighted as builtins. This is ugly
  348. # and weird for most styles. So, as a compromise we're going to
  349. # highlight them as Keyword.Declarations.
  350. (_multi_escape(declarations), Keyword.Declaration),
  351. # highlight the builtins
  352. (_multi_escape(builtins), Name.Builtin),
  353. # the remaining functions
  354. (r'(?<=\()' + valid_name, Name.Function),
  355. # find the remaining variables
  356. (valid_name, Name.Variable),
  357. # Hy accepts vector notation
  358. (r'(\[|\])', Punctuation),
  359. # Hy accepts map notation
  360. (r'(\{|\})', Punctuation),
  361. # the famous parentheses!
  362. (r'(\(|\))', Punctuation),
  363. ],
  364. 'py-keywords': PythonLexer.tokens['keywords'],
  365. 'py-builtins': PythonLexer.tokens['builtins'],
  366. }
  367. def analyse_text(text):
  368. if '(import ' in text or '(defn ' in text:
  369. return 0.9
  370. class RacketLexer(RegexLexer):
  371. """
  372. Lexer for `Racket <http://racket-lang.org/>`_ source code (formerly
  373. known as PLT Scheme).
  374. .. versionadded:: 1.6
  375. """
  376. name = 'Racket'
  377. aliases = ['racket', 'rkt']
  378. filenames = ['*.rkt', '*.rktd', '*.rktl']
  379. mimetypes = ['text/x-racket', 'application/x-racket']
  380. # Generated by example.rkt
  381. _keywords = (
  382. u'#%app', u'#%datum', u'#%declare', u'#%expression', u'#%module-begin',
  383. u'#%plain-app', u'#%plain-lambda', u'#%plain-module-begin',
  384. u'#%printing-module-begin', u'#%provide', u'#%require',
  385. u'#%stratified-body', u'#%top', u'#%top-interaction',
  386. u'#%variable-reference', u'->', u'->*', u'->*m', u'->d', u'->dm', u'->i',
  387. u'->m', u'...', u':do-in', u'==', u'=>', u'_', u'absent', u'abstract',
  388. u'all-defined-out', u'all-from-out', u'and', u'any', u'augment', u'augment*',
  389. u'augment-final', u'augment-final*', u'augride', u'augride*', u'begin',
  390. u'begin-for-syntax', u'begin0', u'case', u'case->', u'case->m',
  391. u'case-lambda', u'class', u'class*', u'class-field-accessor',
  392. u'class-field-mutator', u'class/c', u'class/derived', u'combine-in',
  393. u'combine-out', u'command-line', u'compound-unit', u'compound-unit/infer',
  394. u'cond', u'cons/dc', u'contract', u'contract-out', u'contract-struct',
  395. u'contracted', u'define', u'define-compound-unit',
  396. u'define-compound-unit/infer', u'define-contract-struct',
  397. u'define-custom-hash-types', u'define-custom-set-types',
  398. u'define-for-syntax', u'define-local-member-name', u'define-logger',
  399. u'define-match-expander', u'define-member-name',
  400. u'define-module-boundary-contract', u'define-namespace-anchor',
  401. u'define-opt/c', u'define-sequence-syntax', u'define-serializable-class',
  402. u'define-serializable-class*', u'define-signature',
  403. u'define-signature-form', u'define-struct', u'define-struct/contract',
  404. u'define-struct/derived', u'define-syntax', u'define-syntax-rule',
  405. u'define-syntaxes', u'define-unit', u'define-unit-binding',
  406. u'define-unit-from-context', u'define-unit/contract',
  407. u'define-unit/new-import-export', u'define-unit/s', u'define-values',
  408. u'define-values-for-export', u'define-values-for-syntax',
  409. u'define-values/invoke-unit', u'define-values/invoke-unit/infer',
  410. u'define/augment', u'define/augment-final', u'define/augride',
  411. u'define/contract', u'define/final-prop', u'define/match',
  412. u'define/overment', u'define/override', u'define/override-final',
  413. u'define/private', u'define/public', u'define/public-final',
  414. u'define/pubment', u'define/subexpression-pos-prop',
  415. u'define/subexpression-pos-prop/name', u'delay', u'delay/idle',
  416. u'delay/name', u'delay/strict', u'delay/sync', u'delay/thread', u'do',
  417. u'else', u'except', u'except-in', u'except-out', u'export', u'extends',
  418. u'failure-cont', u'false', u'false/c', u'field', u'field-bound?', u'file',
  419. u'flat-murec-contract', u'flat-rec-contract', u'for', u'for*', u'for*/and',
  420. u'for*/async', u'for*/first', u'for*/fold', u'for*/fold/derived',
  421. u'for*/hash', u'for*/hasheq', u'for*/hasheqv', u'for*/last', u'for*/list',
  422. u'for*/lists', u'for*/mutable-set', u'for*/mutable-seteq',
  423. u'for*/mutable-seteqv', u'for*/or', u'for*/product', u'for*/set',
  424. u'for*/seteq', u'for*/seteqv', u'for*/stream', u'for*/sum', u'for*/vector',
  425. u'for*/weak-set', u'for*/weak-seteq', u'for*/weak-seteqv', u'for-label',
  426. u'for-meta', u'for-syntax', u'for-template', u'for/and', u'for/async',
  427. u'for/first', u'for/fold', u'for/fold/derived', u'for/hash', u'for/hasheq',
  428. u'for/hasheqv', u'for/last', u'for/list', u'for/lists', u'for/mutable-set',
  429. u'for/mutable-seteq', u'for/mutable-seteqv', u'for/or', u'for/product',
  430. u'for/set', u'for/seteq', u'for/seteqv', u'for/stream', u'for/sum',
  431. u'for/vector', u'for/weak-set', u'for/weak-seteq', u'for/weak-seteqv',
  432. u'gen:custom-write', u'gen:dict', u'gen:equal+hash', u'gen:set',
  433. u'gen:stream', u'generic', u'get-field', u'hash/dc', u'if', u'implies',
  434. u'import', u'include', u'include-at/relative-to',
  435. u'include-at/relative-to/reader', u'include/reader', u'inherit',
  436. u'inherit-field', u'inherit/inner', u'inherit/super', u'init',
  437. u'init-depend', u'init-field', u'init-rest', u'inner', u'inspect',
  438. u'instantiate', u'interface', u'interface*', u'invariant-assertion',
  439. u'invoke-unit', u'invoke-unit/infer', u'lambda', u'lazy', u'let', u'let*',
  440. u'let*-values', u'let-syntax', u'let-syntaxes', u'let-values', u'let/cc',
  441. u'let/ec', u'letrec', u'letrec-syntax', u'letrec-syntaxes',
  442. u'letrec-syntaxes+values', u'letrec-values', u'lib', u'link', u'local',
  443. u'local-require', u'log-debug', u'log-error', u'log-fatal', u'log-info',
  444. u'log-warning', u'match', u'match*', u'match*/derived', u'match-define',
  445. u'match-define-values', u'match-lambda', u'match-lambda*',
  446. u'match-lambda**', u'match-let', u'match-let*', u'match-let*-values',
  447. u'match-let-values', u'match-letrec', u'match-letrec-values',
  448. u'match/derived', u'match/values', u'member-name-key', u'mixin', u'module',
  449. u'module*', u'module+', u'nand', u'new', u'nor', u'object-contract',
  450. u'object/c', u'only', u'only-in', u'only-meta-in', u'open', u'opt/c', u'or',
  451. u'overment', u'overment*', u'override', u'override*', u'override-final',
  452. u'override-final*', u'parameterize', u'parameterize*',
  453. u'parameterize-break', u'parametric->/c', u'place', u'place*',
  454. u'place/context', u'planet', u'prefix', u'prefix-in', u'prefix-out',
  455. u'private', u'private*', u'prompt-tag/c', u'protect-out', u'provide',
  456. u'provide-signature-elements', u'provide/contract', u'public', u'public*',
  457. u'public-final', u'public-final*', u'pubment', u'pubment*', u'quasiquote',
  458. u'quasisyntax', u'quasisyntax/loc', u'quote', u'quote-syntax',
  459. u'quote-syntax/prune', u'recontract-out', u'recursive-contract',
  460. u'relative-in', u'rename', u'rename-in', u'rename-inner', u'rename-out',
  461. u'rename-super', u'require', u'send', u'send*', u'send+', u'send-generic',
  462. u'send/apply', u'send/keyword-apply', u'set!', u'set!-values',
  463. u'set-field!', u'shared', u'stream', u'stream*', u'stream-cons', u'struct',
  464. u'struct*', u'struct-copy', u'struct-field-index', u'struct-out',
  465. u'struct/c', u'struct/ctc', u'struct/dc', u'submod', u'super',
  466. u'super-instantiate', u'super-make-object', u'super-new', u'syntax',
  467. u'syntax-case', u'syntax-case*', u'syntax-id-rules', u'syntax-rules',
  468. u'syntax/loc', u'tag', u'this', u'this%', u'thunk', u'thunk*', u'time',
  469. u'unconstrained-domain->', u'unit', u'unit-from-context', u'unit/c',
  470. u'unit/new-import-export', u'unit/s', u'unless', u'unquote',
  471. u'unquote-splicing', u'unsyntax', u'unsyntax-splicing', u'values/drop',
  472. u'when', u'with-continuation-mark', u'with-contract',
  473. u'with-contract-continuation-mark', u'with-handlers', u'with-handlers*',
  474. u'with-method', u'with-syntax', u'λ'
  475. )
  476. # Generated by example.rkt
  477. _builtins = (
  478. u'*', u'*list/c', u'+', u'-', u'/', u'<', u'</c', u'<=', u'<=/c', u'=', u'=/c',
  479. u'>', u'>/c', u'>=', u'>=/c', u'abort-current-continuation', u'abs',
  480. u'absolute-path?', u'acos', u'add-between', u'add1', u'alarm-evt',
  481. u'always-evt', u'and/c', u'andmap', u'angle', u'any/c', u'append', u'append*',
  482. u'append-map', u'apply', u'argmax', u'argmin', u'arithmetic-shift',
  483. u'arity-at-least', u'arity-at-least-value', u'arity-at-least?',
  484. u'arity-checking-wrapper', u'arity-includes?', u'arity=?',
  485. u'arrow-contract-info', u'arrow-contract-info-accepts-arglist',
  486. u'arrow-contract-info-chaperone-procedure',
  487. u'arrow-contract-info-check-first-order', u'arrow-contract-info?',
  488. u'asin', u'assf', u'assoc', u'assq', u'assv', u'atan',
  489. u'bad-number-of-results', u'banner', u'base->-doms/c', u'base->-rngs/c',
  490. u'base->?', u'between/c', u'bitwise-and', u'bitwise-bit-field',
  491. u'bitwise-bit-set?', u'bitwise-ior', u'bitwise-not', u'bitwise-xor',
  492. u'blame-add-car-context', u'blame-add-cdr-context', u'blame-add-context',
  493. u'blame-add-missing-party', u'blame-add-nth-arg-context',
  494. u'blame-add-range-context', u'blame-add-unknown-context',
  495. u'blame-context', u'blame-contract', u'blame-fmt->-string',
  496. u'blame-missing-party?', u'blame-negative', u'blame-original?',
  497. u'blame-positive', u'blame-replace-negative', u'blame-source',
  498. u'blame-swap', u'blame-swapped?', u'blame-update', u'blame-value',
  499. u'blame?', u'boolean=?', u'boolean?', u'bound-identifier=?', u'box',
  500. u'box-cas!', u'box-immutable', u'box-immutable/c', u'box/c', u'box?',
  501. u'break-enabled', u'break-parameterization?', u'break-thread',
  502. u'build-chaperone-contract-property', u'build-compound-type-name',
  503. u'build-contract-property', u'build-flat-contract-property',
  504. u'build-list', u'build-path', u'build-path/convention-type',
  505. u'build-string', u'build-vector', u'byte-pregexp', u'byte-pregexp?',
  506. u'byte-ready?', u'byte-regexp', u'byte-regexp?', u'byte?', u'bytes',
  507. u'bytes->immutable-bytes', u'bytes->list', u'bytes->path',
  508. u'bytes->path-element', u'bytes->string/latin-1', u'bytes->string/locale',
  509. u'bytes->string/utf-8', u'bytes-append', u'bytes-append*',
  510. u'bytes-close-converter', u'bytes-convert', u'bytes-convert-end',
  511. u'bytes-converter?', u'bytes-copy', u'bytes-copy!',
  512. u'bytes-environment-variable-name?', u'bytes-fill!', u'bytes-join',
  513. u'bytes-length', u'bytes-no-nuls?', u'bytes-open-converter', u'bytes-ref',
  514. u'bytes-set!', u'bytes-utf-8-index', u'bytes-utf-8-length',
  515. u'bytes-utf-8-ref', u'bytes<?', u'bytes=?', u'bytes>?', u'bytes?', u'caaaar',
  516. u'caaadr', u'caaar', u'caadar', u'caaddr', u'caadr', u'caar', u'cadaar',
  517. u'cadadr', u'cadar', u'caddar', u'cadddr', u'caddr', u'cadr',
  518. u'call-in-nested-thread', u'call-with-atomic-output-file',
  519. u'call-with-break-parameterization',
  520. u'call-with-composable-continuation', u'call-with-continuation-barrier',
  521. u'call-with-continuation-prompt', u'call-with-current-continuation',
  522. u'call-with-default-reading-parameterization',
  523. u'call-with-escape-continuation', u'call-with-exception-handler',
  524. u'call-with-file-lock/timeout', u'call-with-immediate-continuation-mark',
  525. u'call-with-input-bytes', u'call-with-input-file',
  526. u'call-with-input-file*', u'call-with-input-string',
  527. u'call-with-output-bytes', u'call-with-output-file',
  528. u'call-with-output-file*', u'call-with-output-string',
  529. u'call-with-parameterization', u'call-with-semaphore',
  530. u'call-with-semaphore/enable-break', u'call-with-values', u'call/cc',
  531. u'call/ec', u'car', u'cartesian-product', u'cdaaar', u'cdaadr', u'cdaar',
  532. u'cdadar', u'cdaddr', u'cdadr', u'cdar', u'cddaar', u'cddadr', u'cddar',
  533. u'cdddar', u'cddddr', u'cdddr', u'cddr', u'cdr', u'ceiling', u'channel-get',
  534. u'channel-put', u'channel-put-evt', u'channel-put-evt?',
  535. u'channel-try-get', u'channel/c', u'channel?', u'chaperone-box',
  536. u'chaperone-channel', u'chaperone-continuation-mark-key',
  537. u'chaperone-contract-property?', u'chaperone-contract?', u'chaperone-evt',
  538. u'chaperone-hash', u'chaperone-hash-set', u'chaperone-of?',
  539. u'chaperone-procedure', u'chaperone-procedure*', u'chaperone-prompt-tag',
  540. u'chaperone-struct', u'chaperone-struct-type', u'chaperone-vector',
  541. u'chaperone?', u'char->integer', u'char-alphabetic?', u'char-blank?',
  542. u'char-ci<=?', u'char-ci<?', u'char-ci=?', u'char-ci>=?', u'char-ci>?',
  543. u'char-downcase', u'char-foldcase', u'char-general-category',
  544. u'char-graphic?', u'char-in', u'char-in/c', u'char-iso-control?',
  545. u'char-lower-case?', u'char-numeric?', u'char-punctuation?',
  546. u'char-ready?', u'char-symbolic?', u'char-title-case?', u'char-titlecase',
  547. u'char-upcase', u'char-upper-case?', u'char-utf-8-length',
  548. u'char-whitespace?', u'char<=?', u'char<?', u'char=?', u'char>=?', u'char>?',
  549. u'char?', u'check-duplicate-identifier', u'check-duplicates',
  550. u'checked-procedure-check-and-extract', u'choice-evt',
  551. u'class->interface', u'class-info', u'class-seal', u'class-unseal',
  552. u'class?', u'cleanse-path', u'close-input-port', u'close-output-port',
  553. u'coerce-chaperone-contract', u'coerce-chaperone-contracts',
  554. u'coerce-contract', u'coerce-contract/f', u'coerce-contracts',
  555. u'coerce-flat-contract', u'coerce-flat-contracts', u'collect-garbage',
  556. u'collection-file-path', u'collection-path', u'combinations', u'compile',
  557. u'compile-allow-set!-undefined', u'compile-context-preservation-enabled',
  558. u'compile-enforce-module-constants', u'compile-syntax',
  559. u'compiled-expression-recompile', u'compiled-expression?',
  560. u'compiled-module-expression?', u'complete-path?', u'complex?', u'compose',
  561. u'compose1', u'conjoin', u'conjugate', u'cons', u'cons/c', u'cons?', u'const',
  562. u'continuation-mark-key/c', u'continuation-mark-key?',
  563. u'continuation-mark-set->context', u'continuation-mark-set->list',
  564. u'continuation-mark-set->list*', u'continuation-mark-set-first',
  565. u'continuation-mark-set?', u'continuation-marks',
  566. u'continuation-prompt-available?', u'continuation-prompt-tag?',
  567. u'continuation?', u'contract-continuation-mark-key',
  568. u'contract-custom-write-property-proc', u'contract-exercise',
  569. u'contract-first-order', u'contract-first-order-passes?',
  570. u'contract-late-neg-projection', u'contract-name', u'contract-proc',
  571. u'contract-projection', u'contract-property?',
  572. u'contract-random-generate', u'contract-random-generate-fail',
  573. u'contract-random-generate-fail?',
  574. u'contract-random-generate-get-current-environment',
  575. u'contract-random-generate-stash', u'contract-random-generate/choose',
  576. u'contract-stronger?', u'contract-struct-exercise',
  577. u'contract-struct-generate', u'contract-struct-late-neg-projection',
  578. u'contract-struct-list-contract?', u'contract-val-first-projection',
  579. u'contract?', u'convert-stream', u'copy-directory/files', u'copy-file',
  580. u'copy-port', u'cos', u'cosh', u'count', u'current-blame-format',
  581. u'current-break-parameterization', u'current-code-inspector',
  582. u'current-command-line-arguments', u'current-compile',
  583. u'current-compiled-file-roots', u'current-continuation-marks',
  584. u'current-contract-region', u'current-custodian', u'current-directory',
  585. u'current-directory-for-user', u'current-drive',
  586. u'current-environment-variables', u'current-error-port', u'current-eval',
  587. u'current-evt-pseudo-random-generator',
  588. u'current-force-delete-permissions', u'current-future',
  589. u'current-gc-milliseconds', u'current-get-interaction-input-port',
  590. u'current-inexact-milliseconds', u'current-input-port',
  591. u'current-inspector', u'current-library-collection-links',
  592. u'current-library-collection-paths', u'current-load',
  593. u'current-load-extension', u'current-load-relative-directory',
  594. u'current-load/use-compiled', u'current-locale', u'current-logger',
  595. u'current-memory-use', u'current-milliseconds',
  596. u'current-module-declare-name', u'current-module-declare-source',
  597. u'current-module-name-resolver', u'current-module-path-for-load',
  598. u'current-namespace', u'current-output-port', u'current-parameterization',
  599. u'current-plumber', u'current-preserved-thread-cell-values',
  600. u'current-print', u'current-process-milliseconds', u'current-prompt-read',
  601. u'current-pseudo-random-generator', u'current-read-interaction',
  602. u'current-reader-guard', u'current-readtable', u'current-seconds',
  603. u'current-security-guard', u'current-subprocess-custodian-mode',
  604. u'current-thread', u'current-thread-group',
  605. u'current-thread-initial-stack-size',
  606. u'current-write-relative-directory', u'curry', u'curryr',
  607. u'custodian-box-value', u'custodian-box?', u'custodian-limit-memory',
  608. u'custodian-managed-list', u'custodian-memory-accounting-available?',
  609. u'custodian-require-memory', u'custodian-shutdown-all', u'custodian?',
  610. u'custom-print-quotable-accessor', u'custom-print-quotable?',
  611. u'custom-write-accessor', u'custom-write-property-proc', u'custom-write?',
  612. u'date', u'date*', u'date*-nanosecond', u'date*-time-zone-name', u'date*?',
  613. u'date-day', u'date-dst?', u'date-hour', u'date-minute', u'date-month',
  614. u'date-second', u'date-time-zone-offset', u'date-week-day', u'date-year',
  615. u'date-year-day', u'date?', u'datum->syntax', u'datum-intern-literal',
  616. u'default-continuation-prompt-tag', u'degrees->radians',
  617. u'delete-directory', u'delete-directory/files', u'delete-file',
  618. u'denominator', u'dict->list', u'dict-can-functional-set?',
  619. u'dict-can-remove-keys?', u'dict-clear', u'dict-clear!', u'dict-copy',
  620. u'dict-count', u'dict-empty?', u'dict-for-each', u'dict-has-key?',
  621. u'dict-implements/c', u'dict-implements?', u'dict-iter-contract',
  622. u'dict-iterate-first', u'dict-iterate-key', u'dict-iterate-next',
  623. u'dict-iterate-value', u'dict-key-contract', u'dict-keys', u'dict-map',
  624. u'dict-mutable?', u'dict-ref', u'dict-ref!', u'dict-remove',
  625. u'dict-remove!', u'dict-set', u'dict-set!', u'dict-set*', u'dict-set*!',
  626. u'dict-update', u'dict-update!', u'dict-value-contract', u'dict-values',
  627. u'dict?', u'directory-exists?', u'directory-list', u'disjoin', u'display',
  628. u'display-lines', u'display-lines-to-file', u'display-to-file',
  629. u'displayln', u'double-flonum?', u'drop', u'drop-common-prefix',
  630. u'drop-right', u'dropf', u'dropf-right', u'dump-memory-stats',
  631. u'dup-input-port', u'dup-output-port', u'dynamic->*', u'dynamic-get-field',
  632. u'dynamic-object/c', u'dynamic-place', u'dynamic-place*',
  633. u'dynamic-require', u'dynamic-require-for-syntax', u'dynamic-send',
  634. u'dynamic-set-field!', u'dynamic-wind', u'eighth', u'empty',
  635. u'empty-sequence', u'empty-stream', u'empty?',
  636. u'environment-variables-copy', u'environment-variables-names',
  637. u'environment-variables-ref', u'environment-variables-set!',
  638. u'environment-variables?', u'eof', u'eof-evt', u'eof-object?',
  639. u'ephemeron-value', u'ephemeron?', u'eprintf', u'eq-contract-val',
  640. u'eq-contract?', u'eq-hash-code', u'eq?', u'equal-contract-val',
  641. u'equal-contract?', u'equal-hash-code', u'equal-secondary-hash-code',
  642. u'equal<%>', u'equal?', u'equal?/recur', u'eqv-hash-code', u'eqv?', u'error',
  643. u'error-display-handler', u'error-escape-handler',
  644. u'error-print-context-length', u'error-print-source-location',
  645. u'error-print-width', u'error-value->string-handler', u'eval',
  646. u'eval-jit-enabled', u'eval-syntax', u'even?', u'evt/c', u'evt?',
  647. u'exact->inexact', u'exact-ceiling', u'exact-floor', u'exact-integer?',
  648. u'exact-nonnegative-integer?', u'exact-positive-integer?', u'exact-round',
  649. u'exact-truncate', u'exact?', u'executable-yield-handler', u'exit',
  650. u'exit-handler', u'exn', u'exn-continuation-marks', u'exn-message',
  651. u'exn:break', u'exn:break-continuation', u'exn:break:hang-up',
  652. u'exn:break:hang-up?', u'exn:break:terminate', u'exn:break:terminate?',
  653. u'exn:break?', u'exn:fail', u'exn:fail:contract',
  654. u'exn:fail:contract:arity', u'exn:fail:contract:arity?',
  655. u'exn:fail:contract:blame', u'exn:fail:contract:blame-object',
  656. u'exn:fail:contract:blame?', u'exn:fail:contract:continuation',
  657. u'exn:fail:contract:continuation?', u'exn:fail:contract:divide-by-zero',
  658. u'exn:fail:contract:divide-by-zero?',
  659. u'exn:fail:contract:non-fixnum-result',
  660. u'exn:fail:contract:non-fixnum-result?', u'exn:fail:contract:variable',
  661. u'exn:fail:contract:variable-id', u'exn:fail:contract:variable?',
  662. u'exn:fail:contract?', u'exn:fail:filesystem',
  663. u'exn:fail:filesystem:errno', u'exn:fail:filesystem:errno-errno',
  664. u'exn:fail:filesystem:errno?', u'exn:fail:filesystem:exists',
  665. u'exn:fail:filesystem:exists?', u'exn:fail:filesystem:missing-module',
  666. u'exn:fail:filesystem:missing-module-path',
  667. u'exn:fail:filesystem:missing-module?', u'exn:fail:filesystem:version',
  668. u'exn:fail:filesystem:version?', u'exn:fail:filesystem?',
  669. u'exn:fail:network', u'exn:fail:network:errno',
  670. u'exn:fail:network:errno-errno', u'exn:fail:network:errno?',
  671. u'exn:fail:network?', u'exn:fail:object', u'exn:fail:object?',
  672. u'exn:fail:out-of-memory', u'exn:fail:out-of-memory?', u'exn:fail:read',
  673. u'exn:fail:read-srclocs', u'exn:fail:read:eof', u'exn:fail:read:eof?',
  674. u'exn:fail:read:non-char', u'exn:fail:read:non-char?', u'exn:fail:read?',
  675. u'exn:fail:syntax', u'exn:fail:syntax-exprs',
  676. u'exn:fail:syntax:missing-module',
  677. u'exn:fail:syntax:missing-module-path',
  678. u'exn:fail:syntax:missing-module?', u'exn:fail:syntax:unbound',
  679. u'exn:fail:syntax:unbound?', u'exn:fail:syntax?', u'exn:fail:unsupported',
  680. u'exn:fail:unsupported?', u'exn:fail:user', u'exn:fail:user?',
  681. u'exn:fail?', u'exn:misc:match?', u'exn:missing-module-accessor',
  682. u'exn:missing-module?', u'exn:srclocs-accessor', u'exn:srclocs?', u'exn?',
  683. u'exp', u'expand', u'expand-once', u'expand-syntax', u'expand-syntax-once',
  684. u'expand-syntax-to-top-form', u'expand-to-top-form', u'expand-user-path',
  685. u'explode-path', u'expt', u'externalizable<%>', u'failure-result/c',
  686. u'false?', u'field-names', u'fifth', u'file->bytes', u'file->bytes-lines',
  687. u'file->lines', u'file->list', u'file->string', u'file->value',
  688. u'file-exists?', u'file-name-from-path', u'file-or-directory-identity',
  689. u'file-or-directory-modify-seconds', u'file-or-directory-permissions',
  690. u'file-position', u'file-position*', u'file-size',
  691. u'file-stream-buffer-mode', u'file-stream-port?', u'file-truncate',
  692. u'filename-extension', u'filesystem-change-evt',
  693. u'filesystem-change-evt-cancel', u'filesystem-change-evt?',
  694. u'filesystem-root-list', u'filter', u'filter-map', u'filter-not',
  695. u'filter-read-input-port', u'find-executable-path', u'find-files',
  696. u'find-library-collection-links', u'find-library-collection-paths',
  697. u'find-relative-path', u'find-system-path', u'findf', u'first',
  698. u'first-or/c', u'fixnum?', u'flat-contract', u'flat-contract-predicate',
  699. u'flat-contract-property?', u'flat-contract?', u'flat-named-contract',
  700. u'flatten', u'floating-point-bytes->real', u'flonum?', u'floor',
  701. u'flush-output', u'fold-files', u'foldl', u'foldr', u'for-each', u'force',
  702. u'format', u'fourth', u'fprintf', u'free-identifier=?',
  703. u'free-label-identifier=?', u'free-template-identifier=?',
  704. u'free-transformer-identifier=?', u'fsemaphore-count', u'fsemaphore-post',
  705. u'fsemaphore-try-wait?', u'fsemaphore-wait', u'fsemaphore?', u'future',
  706. u'future?', u'futures-enabled?', u'gcd', u'generate-member-key',
  707. u'generate-temporaries', u'generic-set?', u'generic?', u'gensym',
  708. u'get-output-bytes', u'get-output-string', u'get-preference',
  709. u'get/build-late-neg-projection', u'get/build-val-first-projection',
  710. u'getenv', u'global-port-print-handler', u'group-by', u'group-execute-bit',
  711. u'group-read-bit', u'group-write-bit', u'guard-evt', u'handle-evt',
  712. u'handle-evt?', u'has-blame?', u'has-contract?', u'hash', u'hash->list',
  713. u'hash-clear', u'hash-clear!', u'hash-copy', u'hash-copy-clear',
  714. u'hash-count', u'hash-empty?', u'hash-eq?', u'hash-equal?', u'hash-eqv?',
  715. u'hash-for-each', u'hash-has-key?', u'hash-iterate-first',
  716. u'hash-iterate-key', u'hash-iterate-key+value', u'hash-iterate-next',
  717. u'hash-iterate-pair', u'hash-iterate-value', u'hash-keys', u'hash-map',
  718. u'hash-placeholder?', u'hash-ref', u'hash-ref!', u'hash-remove',
  719. u'hash-remove!', u'hash-set', u'hash-set!', u'hash-set*', u'hash-set*!',
  720. u'hash-update', u'hash-update!', u'hash-values', u'hash-weak?', u'hash/c',
  721. u'hash?', u'hasheq', u'hasheqv', u'identifier-binding',
  722. u'identifier-binding-symbol', u'identifier-label-binding',
  723. u'identifier-prune-lexical-context',
  724. u'identifier-prune-to-source-module',
  725. u'identifier-remove-from-definition-context',
  726. u'identifier-template-binding', u'identifier-transformer-binding',
  727. u'identifier?', u'identity', u'if/c', u'imag-part', u'immutable?',
  728. u'impersonate-box', u'impersonate-channel',
  729. u'impersonate-continuation-mark-key', u'impersonate-hash',
  730. u'impersonate-hash-set', u'impersonate-procedure',
  731. u'impersonate-procedure*', u'impersonate-prompt-tag',
  732. u'impersonate-struct', u'impersonate-vector', u'impersonator-contract?',
  733. u'impersonator-ephemeron', u'impersonator-of?',
  734. u'impersonator-prop:application-mark', u'impersonator-prop:blame',
  735. u'impersonator-prop:contracted',
  736. u'impersonator-property-accessor-procedure?', u'impersonator-property?',
  737. u'impersonator?', u'implementation?', u'implementation?/c', u'in-bytes',
  738. u'in-bytes-lines', u'in-combinations', u'in-cycle', u'in-dict',
  739. u'in-dict-keys', u'in-dict-pairs', u'in-dict-values', u'in-directory',
  740. u'in-hash', u'in-hash-keys', u'in-hash-pairs', u'in-hash-values',
  741. u'in-immutable-hash', u'in-immutable-hash-keys',
  742. u'in-immutable-hash-pairs', u'in-immutable-hash-values',
  743. u'in-immutable-set', u'in-indexed', u'in-input-port-bytes',
  744. u'in-input-port-chars', u'in-lines', u'in-list', u'in-mlist',
  745. u'in-mutable-hash', u'in-mutable-hash-keys', u'in-mutable-hash-pairs',
  746. u'in-mutable-hash-values', u'in-mutable-set', u'in-naturals',
  747. u'in-parallel', u'in-permutations', u'in-port', u'in-producer', u'in-range',
  748. u'in-sequences', u'in-set', u'in-slice', u'in-stream', u'in-string',
  749. u'in-syntax', u'in-value', u'in-values*-sequence', u'in-values-sequence',
  750. u'in-vector', u'in-weak-hash', u'in-weak-hash-keys', u'in-weak-hash-pairs',
  751. u'in-weak-hash-values', u'in-weak-set', u'inexact->exact',
  752. u'inexact-real?', u'inexact?', u'infinite?', u'input-port-append',
  753. u'input-port?', u'inspector?', u'instanceof/c', u'integer->char',
  754. u'integer->integer-bytes', u'integer-bytes->integer', u'integer-in',
  755. u'integer-length', u'integer-sqrt', u'integer-sqrt/remainder', u'integer?',
  756. u'interface->method-names', u'interface-extension?', u'interface?',
  757. u'internal-definition-context-binding-identifiers',
  758. u'internal-definition-context-introduce',
  759. u'internal-definition-context-seal', u'internal-definition-context?',
  760. u'is-a?', u'is-a?/c', u'keyword->string', u'keyword-apply', u'keyword<?',
  761. u'keyword?', u'keywords-match', u'kill-thread', u'last', u'last-pair',
  762. u'lcm', u'length', u'liberal-define-context?', u'link-exists?', u'list',
  763. u'list*', u'list*of', u'list->bytes', u'list->mutable-set',
  764. u'list->mutable-seteq', u'list->mutable-seteqv', u'list->set',
  765. u'list->seteq', u'list->seteqv', u'list->string', u'list->vector',
  766. u'list->weak-set', u'list->weak-seteq', u'list->weak-seteqv',
  767. u'list-contract?', u'list-prefix?', u'list-ref', u'list-set', u'list-tail',
  768. u'list-update', u'list/c', u'list?', u'listen-port-number?', u'listof',
  769. u'load', u'load-extension', u'load-on-demand-enabled', u'load-relative',
  770. u'load-relative-extension', u'load/cd', u'load/use-compiled',
  771. u'local-expand', u'local-expand/capture-lifts',
  772. u'local-transformer-expand', u'local-transformer-expand/capture-lifts',
  773. u'locale-string-encoding', u'log', u'log-all-levels', u'log-level-evt',
  774. u'log-level?', u'log-max-level', u'log-message', u'log-receiver?',
  775. u'logger-name', u'logger?', u'magnitude', u'make-arity-at-least',
  776. u'make-base-empty-namespace', u'make-base-namespace', u'make-bytes',
  777. u'make-channel', u'make-chaperone-contract',
  778. u'make-continuation-mark-key', u'make-continuation-prompt-tag',
  779. u'make-contract', u'make-custodian', u'make-custodian-box',
  780. u'make-custom-hash', u'make-custom-hash-types', u'make-custom-set',
  781. u'make-custom-set-types', u'make-date', u'make-date*',
  782. u'make-derived-parameter', u'make-directory', u'make-directory*',
  783. u'make-do-sequence', u'make-empty-namespace',
  784. u'make-environment-variables', u'make-ephemeron', u'make-exn',
  785. u'make-exn:break', u'make-exn:break:hang-up', u'make-exn:break:terminate',
  786. u'make-exn:fail', u'make-exn:fail:contract',
  787. u'make-exn:fail:contract:arity', u'make-exn:fail:contract:blame',
  788. u'make-exn:fail:contract:continuation',
  789. u'make-exn:fail:contract:divide-by-zero',
  790. u'make-exn:fail:contract:non-fixnum-result',
  791. u'make-exn:fail:contract:variable', u'make-exn:fail:filesystem',
  792. u'make-exn:fail:filesystem:errno', u'make-exn:fail:filesystem:exists',
  793. u'make-exn:fail:filesystem:missing-module',
  794. u'make-exn:fail:filesystem:version', u'make-exn:fail:network',
  795. u'make-exn:fail:network:errno', u'make-exn:fail:object',
  796. u'make-exn:fail:out-of-memory', u'make-exn:fail:read',
  797. u'make-exn:fail:read:eof', u'make-exn:fail:read:non-char',
  798. u'make-exn:fail:syntax', u'make-exn:fail:syntax:missing-module',
  799. u'make-exn:fail:syntax:unbound', u'make-exn:fail:unsupported',
  800. u'make-exn:fail:user', u'make-file-or-directory-link',
  801. u'make-flat-contract', u'make-fsemaphore', u'make-generic',
  802. u'make-handle-get-preference-locked', u'make-hash',
  803. u'make-hash-placeholder', u'make-hasheq', u'make-hasheq-placeholder',
  804. u'make-hasheqv', u'make-hasheqv-placeholder',
  805. u'make-immutable-custom-hash', u'make-immutable-hash',
  806. u'make-immutable-hasheq', u'make-immutable-hasheqv',
  807. u'make-impersonator-property', u'make-input-port',
  808. u'make-input-port/read-to-peek', u'make-inspector',
  809. u'make-keyword-procedure', u'make-known-char-range-list',
  810. u'make-limited-input-port', u'make-list', u'make-lock-file-name',
  811. u'make-log-receiver', u'make-logger', u'make-mixin-contract',
  812. u'make-mutable-custom-set', u'make-none/c', u'make-object',
  813. u'make-output-port', u'make-parameter', u'make-parent-directory*',
  814. u'make-phantom-bytes', u'make-pipe', u'make-pipe-with-specials',
  815. u'make-placeholder', u'make-plumber', u'make-polar', u'make-prefab-struct',
  816. u'make-primitive-class', u'make-proj-contract',
  817. u'make-pseudo-random-generator', u'make-reader-graph', u'make-readtable',
  818. u'make-rectangular', u'make-rename-transformer',
  819. u'make-resolved-module-path', u'make-security-guard', u'make-semaphore',
  820. u'make-set!-transformer', u'make-shared-bytes', u'make-sibling-inspector',
  821. u'make-special-comment', u'make-srcloc', u'make-string',
  822. u'make-struct-field-accessor', u'make-struct-field-mutator',
  823. u'make-struct-type', u'make-struct-type-property',
  824. u'make-syntax-delta-introducer', u'make-syntax-introducer',
  825. u'make-temporary-file', u'make-tentative-pretty-print-output-port',
  826. u'make-thread-cell', u'make-thread-group', u'make-vector',
  827. u'make-weak-box', u'make-weak-custom-hash', u'make-weak-custom-set',
  828. u'make-weak-hash', u'make-weak-hasheq', u'make-weak-hasheqv',
  829. u'make-will-executor', u'map', u'match-equality-test',
  830. u'matches-arity-exactly?', u'max', u'mcar', u'mcdr', u'mcons', u'member',
  831. u'member-name-key-hash-code', u'member-name-key=?', u'member-name-key?',
  832. u'memf', u'memq', u'memv', u'merge-input', u'method-in-interface?', u'min',
  833. u'mixin-contract', u'module->exports', u'module->imports',
  834. u'module->language-info', u'module->namespace',
  835. u'module-compiled-cross-phase-persistent?', u'module-compiled-exports',
  836. u'module-compiled-imports', u'module-compiled-language-info',
  837. u'module-compiled-name', u'module-compiled-submodules',
  838. u'module-declared?', u'module-path-index-join',
  839. u'module-path-index-resolve', u'module-path-index-split',
  840. u'module-path-index-submodule', u'module-path-index?', u'module-path?',
  841. u'module-predefined?', u'module-provide-protected?', u'modulo', u'mpair?',
  842. u'mutable-set', u'mutable-seteq', u'mutable-seteqv', u'n->th',
  843. u'nack-guard-evt', u'namespace-anchor->empty-namespace',
  844. u'namespace-anchor->namespace', u'namespace-anchor?',
  845. u'namespace-attach-module', u'namespace-attach-module-declaration',
  846. u'namespace-base-phase', u'namespace-mapped-symbols',
  847. u'namespace-module-identifier', u'namespace-module-registry',
  848. u'namespace-require', u'namespace-require/constant',
  849. u'namespace-require/copy', u'namespace-require/expansion-time',
  850. u'namespace-set-variable-value!', u'namespace-symbol->identifier',
  851. u'namespace-syntax-introduce', u'namespace-undefine-variable!',
  852. u'namespace-unprotect-module', u'namespace-variable-value', u'namespace?',
  853. u'nan?', u'natural-number/c', u'negate', u'negative?', u'never-evt',
  854. u'new-∀/c', u'new-∃/c', u'newline', u'ninth', u'non-empty-listof',
  855. u'non-empty-string?', u'none/c', u'normal-case-path', u'normalize-arity',
  856. u'normalize-path', u'normalized-arity?', u'not', u'not/c', u'null', u'null?',
  857. u'number->string', u'number?', u'numerator', u'object%', u'object->vector',
  858. u'object-info', u'object-interface', u'object-method-arity-includes?',
  859. u'object-name', u'object-or-false=?', u'object=?', u'object?', u'odd?',
  860. u'one-of/c', u'open-input-bytes', u'open-input-file',
  861. u'open-input-output-file', u'open-input-string', u'open-output-bytes',
  862. u'open-output-file', u'open-output-nowhere', u'open-output-string',
  863. u'or/c', u'order-of-magnitude', u'ormap', u'other-execute-bit',
  864. u'other-read-bit', u'other-write-bit', u'output-port?', u'pair?',
  865. u'parameter-procedure=?', u'parameter/c', u'parameter?',
  866. u'parameterization?', u'parse-command-line', u'partition', u'path->bytes',
  867. u'path->complete-path', u'path->directory-path', u'path->string',
  868. u'path-add-suffix', u'path-convention-type', u'path-element->bytes',
  869. u'path-element->string', u'path-element?', u'path-for-some-system?',
  870. u'path-list-string->path-list', u'path-only', u'path-replace-suffix',
  871. u'path-string?', u'path<?', u'path?', u'pathlist-closure', u'peek-byte',
  872. u'peek-byte-or-special', u'peek-bytes', u'peek-bytes!', u'peek-bytes!-evt',
  873. u'peek-bytes-avail!', u'peek-bytes-avail!*', u'peek-bytes-avail!-evt',
  874. u'peek-bytes-avail!/enable-break', u'peek-bytes-evt', u'peek-char',
  875. u'peek-char-or-special', u'peek-string', u'peek-string!',
  876. u'peek-string!-evt', u'peek-string-evt', u'peeking-input-port',
  877. u'permutations', u'phantom-bytes?', u'pi', u'pi.f', u'pipe-content-length',
  878. u'place-break', u'place-channel', u'place-channel-get',
  879. u'place-channel-put', u'place-channel-put/get', u'place-channel?',
  880. u'place-dead-evt', u'place-enabled?', u'place-kill', u'place-location?',
  881. u'place-message-allowed?', u'place-sleep', u'place-wait', u'place?',
  882. u'placeholder-get', u'placeholder-set!', u'placeholder?',
  883. u'plumber-add-flush!', u'plumber-flush-all',
  884. u'plumber-flush-handle-remove!', u'plumber-flush-handle?', u'plumber?',
  885. u'poll-guard-evt', u'port->bytes', u'port->bytes-lines', u'port->lines',
  886. u'port->list', u'port->string', u'port-closed-evt', u'port-closed?',
  887. u'port-commit-peeked', u'port-count-lines!', u'port-count-lines-enabled',
  888. u'port-counts-lines?', u'port-display-handler', u'port-file-identity',
  889. u'port-file-unlock', u'port-next-location', u'port-number?',
  890. u'port-print-handler', u'port-progress-evt',
  891. u'port-provides-progress-evts?', u'port-read-handler',
  892. u'port-try-file-lock?', u'port-write-handler', u'port-writes-atomic?',
  893. u'port-writes-special?', u'port?', u'positive?', u'predicate/c',
  894. u'prefab-key->struct-type', u'prefab-key?', u'prefab-struct-key',
  895. u'preferences-lock-file-mode', u'pregexp', u'pregexp?', u'pretty-display',
  896. u'pretty-format', u'pretty-print', u'pretty-print-.-symbol-without-bars',
  897. u'pretty-print-abbreviate-read-macros', u'pretty-print-columns',
  898. u'pretty-print-current-style-table', u'pretty-print-depth',
  899. u'pretty-print-exact-as-decimal', u'pretty-print-extend-style-table',
  900. u'pretty-print-handler', u'pretty-print-newline',
  901. u'pretty-print-post-print-hook', u'pretty-print-pre-print-hook',
  902. u'pretty-print-print-hook', u'pretty-print-print-line',
  903. u'pretty-print-remap-stylable', u'pretty-print-show-inexactness',
  904. u'pretty-print-size-hook', u'pretty-print-style-table?',
  905. u'pretty-printing', u'pretty-write', u'primitive-closure?',
  906. u'primitive-result-arity', u'primitive?', u'print', u'print-as-expression',
  907. u'print-boolean-long-form', u'print-box', u'print-graph',
  908. u'print-hash-table', u'print-mpair-curly-braces',
  909. u'print-pair-curly-braces', u'print-reader-abbreviations',
  910. u'print-struct', u'print-syntax-width', u'print-unreadable',
  911. u'print-vector-length', u'printable/c', u'printable<%>', u'printf',
  912. u'println', u'procedure->method', u'procedure-arity',
  913. u'procedure-arity-includes/c', u'procedure-arity-includes?',
  914. u'procedure-arity?', u'procedure-closure-contents-eq?',
  915. u'procedure-extract-target', u'procedure-keywords',
  916. u'procedure-reduce-arity', u'procedure-reduce-keyword-arity',
  917. u'procedure-rename', u'procedure-result-arity', u'procedure-specialize',
  918. u'procedure-struct-type?', u'procedure?', u'process', u'process*',
  919. u'process*/ports', u'process/ports', u'processor-count', u'progress-evt?',
  920. u'promise-forced?', u'promise-running?', u'promise/c', u'promise/name?',
  921. u'promise?', u'prop:arity-string', u'prop:arrow-contract',
  922. u'prop:arrow-contract-get-info', u'prop:arrow-contract?', u'prop:blame',
  923. u'prop:chaperone-contract', u'prop:checked-procedure', u'prop:contract',
  924. u'prop:contracted', u'prop:custom-print-quotable', u'prop:custom-write',
  925. u'prop:dict', u'prop:dict/contract', u'prop:equal+hash', u'prop:evt',
  926. u'prop:exn:missing-module', u'prop:exn:srclocs',
  927. u'prop:expansion-contexts', u'prop:flat-contract',
  928. u'prop:impersonator-of', u'prop:input-port',
  929. u'prop:liberal-define-context', u'prop:object-name',
  930. u'prop:opt-chaperone-contract', u'prop:opt-chaperone-contract-get-test',
  931. u'prop:opt-chaperone-contract?', u'prop:orc-contract',
  932. u'prop:orc-contract-get-subcontracts', u'prop:orc-contract?',
  933. u'prop:output-port', u'prop:place-location', u'prop:procedure',
  934. u'prop:recursive-contract', u'prop:recursive-contract-unroll',
  935. u'prop:recursive-contract?', u'prop:rename-transformer', u'prop:sequence',
  936. u'prop:set!-transformer', u'prop:stream', u'proper-subset?',
  937. u'pseudo-random-generator->vector', u'pseudo-random-generator-vector?',
  938. u'pseudo-random-generator?', u'put-preferences', u'putenv', u'quotient',
  939. u'quotient/remainder', u'radians->degrees', u'raise',
  940. u'raise-argument-error', u'raise-arguments-error', u'raise-arity-error',
  941. u'raise-blame-error', u'raise-contract-error', u'raise-mismatch-error',
  942. u'raise-not-cons-blame-error', u'raise-range-error',
  943. u'raise-result-error', u'raise-syntax-error', u'raise-type-error',
  944. u'raise-user-error', u'random', u'random-seed', u'range', u'rational?',
  945. u'rationalize', u'read', u'read-accept-bar-quote', u'read-accept-box',
  946. u'read-accept-compiled', u'read-accept-dot', u'read-accept-graph',
  947. u'read-accept-infix-dot', u'read-accept-lang', u'read-accept-quasiquote',
  948. u'read-accept-reader', u'read-byte', u'read-byte-or-special',
  949. u'read-bytes', u'read-bytes!', u'read-bytes!-evt', u'read-bytes-avail!',
  950. u'read-bytes-avail!*', u'read-bytes-avail!-evt',
  951. u'read-bytes-avail!/enable-break', u'read-bytes-evt', u'read-bytes-line',
  952. u'read-bytes-line-evt', u'read-case-sensitive', u'read-cdot', u'read-char',
  953. u'read-char-or-special', u'read-curly-brace-as-paren',
  954. u'read-curly-brace-with-tag', u'read-decimal-as-inexact',
  955. u'read-eval-print-loop', u'read-language', u'read-line', u'read-line-evt',
  956. u'read-on-demand-source', u'read-square-bracket-as-paren',
  957. u'read-square-bracket-with-tag', u'read-string', u'read-string!',
  958. u'read-string!-evt', u'read-string-evt', u'read-syntax',
  959. u'read-syntax/recursive', u'read/recursive', u'readtable-mapping',
  960. u'readtable?', u'real->decimal-string', u'real->double-flonum',
  961. u'real->floating-point-bytes', u'real->single-flonum', u'real-in',
  962. u'real-part', u'real?', u'reencode-input-port', u'reencode-output-port',
  963. u'regexp', u'regexp-match', u'regexp-match*', u'regexp-match-evt',
  964. u'regexp-match-exact?', u'regexp-match-peek',
  965. u'regexp-match-peek-immediate', u'regexp-match-peek-positions',
  966. u'regexp-match-peek-positions*',
  967. u'regexp-match-peek-positions-immediate',
  968. u'regexp-match-peek-positions-immediate/end',
  969. u'regexp-match-peek-positions/end', u'regexp-match-positions',
  970. u'regexp-match-positions*', u'regexp-match-positions/end',
  971. u'regexp-match/end', u'regexp-match?', u'regexp-max-lookbehind',
  972. u'regexp-quote', u'regexp-replace', u'regexp-replace*',
  973. u'regexp-replace-quote', u'regexp-replaces', u'regexp-split',
  974. u'regexp-try-match', u'regexp?', u'relative-path?', u'relocate-input-port',
  975. u'relocate-output-port', u'remainder', u'remf', u'remf*', u'remove',
  976. u'remove*', u'remove-duplicates', u'remq', u'remq*', u'remv', u'remv*',
  977. u'rename-contract', u'rename-file-or-directory',
  978. u'rename-transformer-target', u'rename-transformer?', u'replace-evt',
  979. u'reroot-path', u'resolve-path', u'resolved-module-path-name',
  980. u'resolved-module-path?', u'rest', u'reverse', u'round', u'second',
  981. u'seconds->date', u'security-guard?', u'semaphore-peek-evt',
  982. u'semaphore-peek-evt?', u'semaphore-post', u'semaphore-try-wait?',
  983. u'semaphore-wait', u'semaphore-wait/enable-break', u'semaphore?',
  984. u'sequence->list', u'sequence->stream', u'sequence-add-between',
  985. u'sequence-andmap', u'sequence-append', u'sequence-count',
  986. u'sequence-filter', u'sequence-fold', u'sequence-for-each',
  987. u'sequence-generate', u'sequence-generate*', u'sequence-length',
  988. u'sequence-map', u'sequence-ormap', u'sequence-ref', u'sequence-tail',
  989. u'sequence/c', u'sequence?', u'set', u'set!-transformer-procedure',
  990. u'set!-transformer?', u'set->list', u'set->stream', u'set-add', u'set-add!',
  991. u'set-box!', u'set-clear', u'set-clear!', u'set-copy', u'set-copy-clear',
  992. u'set-count', u'set-empty?', u'set-eq?', u'set-equal?', u'set-eqv?',
  993. u'set-first', u'set-for-each', u'set-implements/c', u'set-implements?',
  994. u'set-intersect', u'set-intersect!', u'set-map', u'set-mcar!', u'set-mcdr!',
  995. u'set-member?', u'set-mutable?', u'set-phantom-bytes!',
  996. u'set-port-next-location!', u'set-remove', u'set-remove!', u'set-rest',
  997. u'set-some-basic-contracts!', u'set-subtract', u'set-subtract!',
  998. u'set-symmetric-difference', u'set-symmetric-difference!', u'set-union',
  999. u'set-union!', u'set-weak?', u'set/c', u'set=?', u'set?', u'seteq', u'seteqv',
  1000. u'seventh', u'sgn', u'shared-bytes', u'shell-execute', u'shrink-path-wrt',
  1001. u'shuffle', u'simple-form-path', u'simplify-path', u'sin',
  1002. u'single-flonum?', u'sinh', u'sixth', u'skip-projection-wrapper?', u'sleep',
  1003. u'some-system-path->string', u'sort', u'special-comment-value',
  1004. u'special-comment?', u'special-filter-input-port', u'split-at',
  1005. u'split-at-right', u'split-common-prefix', u'split-path', u'splitf-at',
  1006. u'splitf-at-right', u'sqr', u'sqrt', u'srcloc', u'srcloc->string',
  1007. u'srcloc-column', u'srcloc-line', u'srcloc-position', u'srcloc-source',
  1008. u'srcloc-span', u'srcloc?', u'stop-after', u'stop-before', u'stream->list',
  1009. u'stream-add-between', u'stream-andmap', u'stream-append', u'stream-count',
  1010. u'stream-empty?', u'stream-filter', u'stream-first', u'stream-fold',
  1011. u'stream-for-each', u'stream-length', u'stream-map', u'stream-ormap',
  1012. u'stream-ref', u'stream-rest', u'stream-tail', u'stream/c', u'stream?',
  1013. u'string', u'string->bytes/latin-1', u'string->bytes/locale',
  1014. u'string->bytes/utf-8', u'string->immutable-string', u'string->keyword',
  1015. u'string->list', u'string->number', u'string->path',
  1016. u'string->path-element', u'string->some-system-path', u'string->symbol',
  1017. u'string->uninterned-symbol', u'string->unreadable-symbol',
  1018. u'string-append', u'string-append*', u'string-ci<=?', u'string-ci<?',
  1019. u'string-ci=?', u'string-ci>=?', u'string-ci>?', u'string-contains?',
  1020. u'string-copy', u'string-copy!', u'string-downcase',
  1021. u'string-environment-variable-name?', u'string-fill!', u'string-foldcase',
  1022. u'string-join', u'string-len/c', u'string-length', u'string-locale-ci<?',
  1023. u'string-locale-ci=?', u'string-locale-ci>?', u'string-locale-downcase',
  1024. u'string-locale-upcase', u'string-locale<?', u'string-locale=?',
  1025. u'string-locale>?', u'string-no-nuls?', u'string-normalize-nfc',
  1026. u'string-normalize-nfd', u'string-normalize-nfkc',
  1027. u'string-normalize-nfkd', u'string-normalize-spaces', u'string-port?',
  1028. u'string-prefix?', u'string-ref', u'string-replace', u'string-set!',
  1029. u'string-split', u'string-suffix?', u'string-titlecase', u'string-trim',
  1030. u'string-upcase', u'string-utf-8-length', u'string<=?', u'string<?',
  1031. u'string=?', u'string>=?', u'string>?', u'string?', u'struct->vector',
  1032. u'struct-accessor-procedure?', u'struct-constructor-procedure?',
  1033. u'struct-info', u'struct-mutator-procedure?',
  1034. u'struct-predicate-procedure?', u'struct-type-info',
  1035. u'struct-type-make-constructor', u'struct-type-make-predicate',
  1036. u'struct-type-property-accessor-procedure?', u'struct-type-property/c',
  1037. u'struct-type-property?', u'struct-type?', u'struct:arity-at-least',
  1038. u'struct:arrow-contract-info', u'struct:date', u'struct:date*',
  1039. u'struct:exn', u'struct:exn:break', u'struct:exn:break:hang-up',
  1040. u'struct:exn:break:terminate', u'struct:exn:fail',
  1041. u'struct:exn:fail:contract', u'struct:exn:fail:contract:arity',
  1042. u'struct:exn:fail:contract:blame',
  1043. u'struct:exn:fail:contract:continuation',
  1044. u'struct:exn:fail:contract:divide-by-zero',
  1045. u'struct:exn:fail:contract:non-fixnum-result',
  1046. u'struct:exn:fail:contract:variable', u'struct:exn:fail:filesystem',
  1047. u'struct:exn:fail:filesystem:errno',
  1048. u'struct:exn:fail:filesystem:exists',
  1049. u'struct:exn:fail:filesystem:missing-module',
  1050. u'struct:exn:fail:filesystem:version', u'struct:exn:fail:network',
  1051. u'struct:exn:fail:network:errno', u'struct:exn:fail:object',
  1052. u'struct:exn:fail:out-of-memory', u'struct:exn:fail:read',
  1053. u'struct:exn:fail:read:eof', u'struct:exn:fail:read:non-char',
  1054. u'struct:exn:fail:syntax', u'struct:exn:fail:syntax:missing-module',
  1055. u'struct:exn:fail:syntax:unbound', u'struct:exn:fail:unsupported',
  1056. u'struct:exn:fail:user', u'struct:srcloc',
  1057. u'struct:wrapped-extra-arg-arrow', u'struct?', u'sub1', u'subbytes',
  1058. u'subclass?', u'subclass?/c', u'subprocess', u'subprocess-group-enabled',
  1059. u'subprocess-kill', u'subprocess-pid', u'subprocess-status',
  1060. u'subprocess-wait', u'subprocess?', u'subset?', u'substring', u'suggest/c',
  1061. u'symbol->string', u'symbol-interned?', u'symbol-unreadable?', u'symbol<?',
  1062. u'symbol=?', u'symbol?', u'symbols', u'sync', u'sync/enable-break',
  1063. u'sync/timeout', u'sync/timeout/enable-break', u'syntax->datum',
  1064. u'syntax->list', u'syntax-arm', u'syntax-column', u'syntax-debug-info',
  1065. u'syntax-disarm', u'syntax-e', u'syntax-line',
  1066. u'syntax-local-bind-syntaxes', u'syntax-local-certifier',
  1067. u'syntax-local-context', u'syntax-local-expand-expression',
  1068. u'syntax-local-get-shadower', u'syntax-local-identifier-as-binding',
  1069. u'syntax-local-introduce', u'syntax-local-lift-context',
  1070. u'syntax-local-lift-expression', u'syntax-local-lift-module',
  1071. u'syntax-local-lift-module-end-declaration',
  1072. u'syntax-local-lift-provide', u'syntax-local-lift-require',
  1073. u'syntax-local-lift-values-expression',
  1074. u'syntax-local-make-definition-context',
  1075. u'syntax-local-make-delta-introducer',
  1076. u'syntax-local-module-defined-identifiers',
  1077. u'syntax-local-module-exports',
  1078. u'syntax-local-module-required-identifiers', u'syntax-local-name',
  1079. u'syntax-local-phase-level', u'syntax-local-submodules',
  1080. u'syntax-local-transforming-module-provides?', u'syntax-local-value',
  1081. u'syntax-local-value/immediate', u'syntax-original?', u'syntax-position',
  1082. u'syntax-property', u'syntax-property-preserved?',
  1083. u'syntax-property-symbol-keys', u'syntax-protect', u'syntax-rearm',
  1084. u'syntax-recertify', u'syntax-shift-phase-level', u'syntax-source',
  1085. u'syntax-source-module', u'syntax-span', u'syntax-taint',
  1086. u'syntax-tainted?', u'syntax-track-origin',
  1087. u'syntax-transforming-module-expression?',
  1088. u'syntax-transforming-with-lifts?', u'syntax-transforming?', u'syntax/c',
  1089. u'syntax?', u'system', u'system*', u'system*/exit-code',
  1090. u'system-big-endian?', u'system-idle-evt', u'system-language+country',
  1091. u'system-library-subpath', u'system-path-convention-type', u'system-type',
  1092. u'system/exit-code', u'tail-marks-match?', u'take', u'take-common-prefix',
  1093. u'take-right', u'takef', u'takef-right', u'tan', u'tanh',
  1094. u'tcp-abandon-port', u'tcp-accept', u'tcp-accept-evt',
  1095. u'tcp-accept-ready?', u'tcp-accept/enable-break', u'tcp-addresses',
  1096. u'tcp-close', u'tcp-connect', u'tcp-connect/enable-break', u'tcp-listen',
  1097. u'tcp-listener?', u'tcp-port?', u'tentative-pretty-print-port-cancel',
  1098. u'tentative-pretty-print-port-transfer', u'tenth', u'terminal-port?',
  1099. u'the-unsupplied-arg', u'third', u'thread', u'thread-cell-ref',
  1100. u'thread-cell-set!', u'thread-cell-values?', u'thread-cell?',
  1101. u'thread-dead-evt', u'thread-dead?', u'thread-group?', u'thread-receive',
  1102. u'thread-receive-evt', u'thread-resume', u'thread-resume-evt',
  1103. u'thread-rewind-receive', u'thread-running?', u'thread-send',
  1104. u'thread-suspend', u'thread-suspend-evt', u'thread-try-receive',
  1105. u'thread-wait', u'thread/suspend-to-kill', u'thread?', u'time-apply',
  1106. u'touch', u'transplant-input-port', u'transplant-output-port', u'true',
  1107. u'truncate', u'udp-addresses', u'udp-bind!', u'udp-bound?', u'udp-close',
  1108. u'udp-connect!', u'udp-connected?', u'udp-multicast-interface',
  1109. u'udp-multicast-join-group!', u'udp-multicast-leave-group!',
  1110. u'udp-multicast-loopback?', u'udp-multicast-set-interface!',
  1111. u'udp-multicast-set-loopback!', u'udp-multicast-set-ttl!',
  1112. u'udp-multicast-ttl', u'udp-open-socket', u'udp-receive!',
  1113. u'udp-receive!*', u'udp-receive!-evt', u'udp-receive!/enable-break',
  1114. u'udp-receive-ready-evt', u'udp-send', u'udp-send*', u'udp-send-evt',
  1115. u'udp-send-ready-evt', u'udp-send-to', u'udp-send-to*', u'udp-send-to-evt',
  1116. u'udp-send-to/enable-break', u'udp-send/enable-break', u'udp?', u'unbox',
  1117. u'uncaught-exception-handler', u'unit?', u'unspecified-dom',
  1118. u'unsupplied-arg?', u'use-collection-link-paths',
  1119. u'use-compiled-file-paths', u'use-user-specific-search-paths',
  1120. u'user-execute-bit', u'user-read-bit', u'user-write-bit', u'value-blame',
  1121. u'value-contract', u'values', u'variable-reference->empty-namespace',
  1122. u'variable-reference->module-base-phase',
  1123. u'variable-reference->module-declaration-inspector',
  1124. u'variable-reference->module-path-index',
  1125. u'variable-reference->module-source', u'variable-reference->namespace',
  1126. u'variable-reference->phase',
  1127. u'variable-reference->resolved-module-path',
  1128. u'variable-reference-constant?', u'variable-reference?', u'vector',
  1129. u'vector->immutable-vector', u'vector->list',
  1130. u'vector->pseudo-random-generator', u'vector->pseudo-random-generator!',
  1131. u'vector->values', u'vector-append', u'vector-argmax', u'vector-argmin',
  1132. u'vector-copy', u'vector-copy!', u'vector-count', u'vector-drop',
  1133. u'vector-drop-right', u'vector-fill!', u'vector-filter',
  1134. u'vector-filter-not', u'vector-immutable', u'vector-immutable/c',
  1135. u'vector-immutableof', u'vector-length', u'vector-map', u'vector-map!',
  1136. u'vector-member', u'vector-memq', u'vector-memv', u'vector-ref',
  1137. u'vector-set!', u'vector-set*!', u'vector-set-performance-stats!',
  1138. u'vector-split-at', u'vector-split-at-right', u'vector-take',
  1139. u'vector-take-right', u'vector/c', u'vector?', u'vectorof', u'version',
  1140. u'void', u'void?', u'weak-box-value', u'weak-box?', u'weak-set',
  1141. u'weak-seteq', u'weak-seteqv', u'will-execute', u'will-executor?',
  1142. u'will-register', u'will-try-execute', u'with-input-from-bytes',
  1143. u'with-input-from-file', u'with-input-from-string',
  1144. u'with-output-to-bytes', u'with-output-to-file', u'with-output-to-string',
  1145. u'would-be-future', u'wrap-evt', u'wrapped-extra-arg-arrow',
  1146. u'wrapped-extra-arg-arrow-extra-neg-party-argument',
  1147. u'wrapped-extra-arg-arrow-real-func', u'wrapped-extra-arg-arrow?',
  1148. u'writable<%>', u'write', u'write-byte', u'write-bytes',
  1149. u'write-bytes-avail', u'write-bytes-avail*', u'write-bytes-avail-evt',
  1150. u'write-bytes-avail/enable-break', u'write-char', u'write-special',
  1151. u'write-special-avail*', u'write-special-evt', u'write-string',
  1152. u'write-to-file', u'writeln', u'xor', u'zero?', u'~.a', u'~.s', u'~.v', u'~a',
  1153. u'~e', u'~r', u'~s', u'~v'
  1154. )
  1155. _opening_parenthesis = r'[([{]'
  1156. _closing_parenthesis = r'[)\]}]'
  1157. _delimiters = r'()[\]{}",\'`;\s'
  1158. _symbol = r'(?:\|[^|]*\||\\[\w\W]|[^|\\%s]+)+' % _delimiters
  1159. _exact_decimal_prefix = r'(?:#e)?(?:#d)?(?:#e)?'
  1160. _exponent = r'(?:[defls][-+]?\d+)'
  1161. _inexact_simple_no_hashes = r'(?:\d+(?:/\d+|\.\d*)?|\.\d+)'
  1162. _inexact_simple = (r'(?:%s|(?:\d+#+(?:\.#*|/\d+#*)?|\.\d+#+|'
  1163. r'\d+(?:\.\d*#+|/\d+#+)))' % _inexact_simple_no_hashes)
  1164. _inexact_normal_no_hashes = r'(?:%s%s?)' % (_inexact_simple_no_hashes,
  1165. _exponent)
  1166. _inexact_normal = r'(?:%s%s?)' % (_inexact_simple, _exponent)
  1167. _inexact_special = r'(?:(?:inf|nan)\.[0f])'
  1168. _inexact_real = r'(?:[-+]?%s|[-+]%s)' % (_inexact_normal,
  1169. _inexact_special)
  1170. _inexact_unsigned = r'(?:%s|%s)' % (_inexact_normal, _inexact_special)
  1171. tokens = {
  1172. 'root': [
  1173. (_closing_parenthesis, Error),
  1174. (r'(?!\Z)', Text, 'unquoted-datum')
  1175. ],
  1176. 'datum': [
  1177. (r'(?s)#;|#![ /]([^\\\n]|\\.)*', Comment),
  1178. (u';[^\\n\\r\x85\u2028\u2029]*', Comment.Single),
  1179. (r'#\|', Comment.Multiline, 'block-comment'),
  1180. # Whitespaces
  1181. (r'(?u)\s+', Text),
  1182. # Numbers: Keep in mind Racket reader hash prefixes, which
  1183. # can denote the base or the type. These don't map neatly
  1184. # onto Pygments token types; some judgment calls here.
  1185. # #d or no prefix
  1186. (r'(?i)%s[-+]?\d+(?=[%s])' % (_exact_decimal_prefix, _delimiters),
  1187. Number.Integer, '#pop'),
  1188. (r'(?i)%s[-+]?(\d+(\.\d*)?|\.\d+)([deflst][-+]?\d+)?(?=[%s])' %
  1189. (_exact_decimal_prefix, _delimiters), Number.Float, '#pop'),
  1190. (r'(?i)%s[-+]?(%s([-+]%s?i)?|[-+]%s?i)(?=[%s])' %
  1191. (_exact_decimal_prefix, _inexact_normal_no_hashes,
  1192. _inexact_normal_no_hashes, _inexact_normal_no_hashes,
  1193. _delimiters), Number, '#pop'),
  1194. # Inexact without explicit #i
  1195. (r'(?i)(#d)?(%s([-+]%s?i)?|[-+]%s?i|%s@%s)(?=[%s])' %
  1196. (_inexact_real, _inexact_unsigned, _inexact_unsigned,
  1197. _inexact_real, _inexact_real, _delimiters), Number.Float,
  1198. '#pop'),
  1199. # The remaining extflonums
  1200. (r'(?i)(([-+]?%st[-+]?\d+)|[-+](inf|nan)\.t)(?=[%s])' %
  1201. (_inexact_simple, _delimiters), Number.Float, '#pop'),
  1202. # #b
  1203. (r'(?iu)(#[ei])?#b%s' % _symbol, Number.Bin, '#pop'),
  1204. # #o
  1205. (r'(?iu)(#[ei])?#o%s' % _symbol, Number.Oct, '#pop'),
  1206. # #x
  1207. (r'(?iu)(#[ei])?#x%s' % _symbol, Number.Hex, '#pop'),
  1208. # #i is always inexact, i.e. float
  1209. (r'(?iu)(#d)?#i%s' % _symbol, Number.Float, '#pop'),
  1210. # Strings and characters
  1211. (r'#?"', String.Double, ('#pop', 'string')),
  1212. (r'#<<(.+)\n(^(?!\1$).*$\n)*^\1$', String.Heredoc, '#pop'),
  1213. (r'#\\(u[\da-fA-F]{1,4}|U[\da-fA-F]{1,8})', String.Char, '#pop'),
  1214. (r'(?is)#\\([0-7]{3}|[a-z]+|.)', String.Char, '#pop'),
  1215. (r'(?s)#[pr]x#?"(\\?.)*?"', String.Regex, '#pop'),
  1216. # Constants
  1217. (r'#(true|false|[tTfF])', Name.Constant, '#pop'),
  1218. # Keyword argument names (e.g. #:keyword)
  1219. (r'(?u)#:%s' % _symbol, Keyword.Declaration, '#pop'),
  1220. # Reader extensions
  1221. (r'(#lang |#!)(\S+)',
  1222. bygroups(Keyword.Namespace, Name.Namespace)),
  1223. (r'#reader', Keyword.Namespace, 'quoted-datum'),
  1224. # Other syntax
  1225. (r"(?i)\.(?=[%s])|#c[is]|#['`]|#,@?" % _delimiters, Operator),
  1226. (r"'|#[s&]|#hash(eqv?)?|#\d*(?=%s)" % _opening_parenthesis,
  1227. Operator, ('#pop', 'quoted-datum'))
  1228. ],
  1229. 'datum*': [
  1230. (r'`|,@?', Operator),
  1231. (_symbol, String.Symbol, '#pop'),
  1232. (r'[|\\]', Error),
  1233. default('#pop')
  1234. ],
  1235. 'list': [
  1236. (_closing_parenthesis, Punctuation, '#pop')
  1237. ],
  1238. 'unquoted-datum': [
  1239. include('datum'),
  1240. (r'quote(?=[%s])' % _delimiters, Keyword,
  1241. ('#pop', 'quoted-datum')),
  1242. (r'`', Operator, ('#pop', 'quasiquoted-datum')),
  1243. (r'quasiquote(?=[%s])' % _delimiters, Keyword,
  1244. ('#pop', 'quasiquoted-datum')),
  1245. (_opening_parenthesis, Punctuation, ('#pop', 'unquoted-list')),
  1246. (words(_keywords, prefix='(?u)', suffix='(?=[%s])' % _delimiters),
  1247. Keyword, '#pop'),
  1248. (words(_builtins, prefix='(?u)', suffix='(?=[%s])' % _delimiters),
  1249. Name.Builtin, '#pop'),
  1250. (_symbol, Name, '#pop'),
  1251. include('datum*')
  1252. ],
  1253. 'unquoted-list': [
  1254. include('list'),
  1255. (r'(?!\Z)', Text, 'unquoted-datum')
  1256. ],
  1257. 'quasiquoted-datum': [
  1258. include('datum'),
  1259. (r',@?', Operator, ('#pop', 'unquoted-datum')),
  1260. (r'unquote(-splicing)?(?=[%s])' % _delimiters, Keyword,
  1261. ('#pop', 'unquoted-datum')),
  1262. (_opening_parenthesis, Punctuation, ('#pop', 'quasiquoted-list')),
  1263. include('datum*')
  1264. ],
  1265. 'quasiquoted-list': [
  1266. include('list'),
  1267. (r'(?!\Z)', Text, 'quasiquoted-datum')
  1268. ],
  1269. 'quoted-datum': [
  1270. include('datum'),
  1271. (_opening_parenthesis, Punctuation, ('#pop', 'quoted-list')),
  1272. include('datum*')
  1273. ],
  1274. 'quoted-list': [
  1275. include('list'),
  1276. (r'(?!\Z)', Text, 'quoted-datum')
  1277. ],
  1278. 'block-comment': [
  1279. (r'#\|', Comment.Multiline, '#push'),
  1280. (r'\|#', Comment.Multiline, '#pop'),
  1281. (r'[^#|]+|.', Comment.Multiline)
  1282. ],
  1283. 'string': [
  1284. (r'"', String.Double, '#pop'),
  1285. (r'(?s)\\([0-7]{1,3}|x[\da-fA-F]{1,2}|u[\da-fA-F]{1,4}|'
  1286. r'U[\da-fA-F]{1,8}|.)', String.Escape),
  1287. (r'[^\\"]+', String.Double)
  1288. ]
  1289. }
  1290. class NewLispLexer(RegexLexer):
  1291. """
  1292. For `newLISP. <http://www.newlisp.org/>`_ source code (version 10.3.0).
  1293. .. versionadded:: 1.5
  1294. """
  1295. name = 'NewLisp'
  1296. aliases = ['newlisp']
  1297. filenames = ['*.lsp', '*.nl', '*.kif']
  1298. mimetypes = ['text/x-newlisp', 'application/x-newlisp']
  1299. flags = re.IGNORECASE | re.MULTILINE | re.UNICODE
  1300. # list of built-in functions for newLISP version 10.3
  1301. builtins = (
  1302. '^', '--', '-', ':', '!', '!=', '?', '@', '*', '/', '&', '%', '+', '++',
  1303. '<', '<<', '<=', '=', '>', '>=', '>>', '|', '~', '$', '$0', '$1', '$10',
  1304. '$11', '$12', '$13', '$14', '$15', '$2', '$3', '$4', '$5', '$6', '$7',
  1305. '$8', '$9', '$args', '$idx', '$it', '$main-args', 'abort', 'abs',
  1306. 'acos', 'acosh', 'add', 'address', 'amb', 'and', 'append-file',
  1307. 'append', 'apply', 'args', 'array-list', 'array?', 'array', 'asin',
  1308. 'asinh', 'assoc', 'atan', 'atan2', 'atanh', 'atom?', 'base64-dec',
  1309. 'base64-enc', 'bayes-query', 'bayes-train', 'begin',
  1310. 'beta', 'betai', 'bind', 'binomial', 'bits', 'callback',
  1311. 'case', 'catch', 'ceil', 'change-dir', 'char', 'chop', 'Class', 'clean',
  1312. 'close', 'command-event', 'cond', 'cons', 'constant',
  1313. 'context?', 'context', 'copy-file', 'copy', 'cos', 'cosh', 'count',
  1314. 'cpymem', 'crc32', 'crit-chi2', 'crit-z', 'current-line', 'curry',
  1315. 'date-list', 'date-parse', 'date-value', 'date', 'debug', 'dec',
  1316. 'def-new', 'default', 'define-macro', 'define',
  1317. 'delete-file', 'delete-url', 'delete', 'destroy', 'det', 'device',
  1318. 'difference', 'directory?', 'directory', 'div', 'do-until', 'do-while',
  1319. 'doargs', 'dolist', 'dostring', 'dotimes', 'dotree', 'dump', 'dup',
  1320. 'empty?', 'encrypt', 'ends-with', 'env', 'erf', 'error-event',
  1321. 'eval-string', 'eval', 'exec', 'exists', 'exit', 'exp', 'expand',
  1322. 'explode', 'extend', 'factor', 'fft', 'file-info', 'file?', 'filter',
  1323. 'find-all', 'find', 'first', 'flat', 'float?', 'float', 'floor', 'flt',
  1324. 'fn', 'for-all', 'for', 'fork', 'format', 'fv', 'gammai', 'gammaln',
  1325. 'gcd', 'get-char', 'get-float', 'get-int', 'get-long', 'get-string',
  1326. 'get-url', 'global?', 'global', 'if-not', 'if', 'ifft', 'import', 'inc',
  1327. 'index', 'inf?', 'int', 'integer?', 'integer', 'intersect', 'invert',
  1328. 'irr', 'join', 'lambda-macro', 'lambda?', 'lambda', 'last-error',
  1329. 'last', 'legal?', 'length', 'let', 'letex', 'letn',
  1330. 'list?', 'list', 'load', 'local', 'log', 'lookup',
  1331. 'lower-case', 'macro?', 'main-args', 'MAIN', 'make-dir', 'map', 'mat',
  1332. 'match', 'max', 'member', 'min', 'mod', 'module', 'mul', 'multiply',
  1333. 'NaN?', 'net-accept', 'net-close', 'net-connect', 'net-error',
  1334. 'net-eval', 'net-interface', 'net-ipv', 'net-listen', 'net-local',
  1335. 'net-lookup', 'net-packet', 'net-peek', 'net-peer', 'net-ping',
  1336. 'net-receive-from', 'net-receive-udp', 'net-receive', 'net-select',
  1337. 'net-send-to', 'net-send-udp', 'net-send', 'net-service',
  1338. 'net-sessions', 'new', 'nil?', 'nil', 'normal', 'not', 'now', 'nper',
  1339. 'npv', 'nth', 'null?', 'number?', 'open', 'or', 'ostype', 'pack',
  1340. 'parse-date', 'parse', 'peek', 'pipe', 'pmt', 'pop-assoc', 'pop',
  1341. 'post-url', 'pow', 'prefix', 'pretty-print', 'primitive?', 'print',
  1342. 'println', 'prob-chi2', 'prob-z', 'process', 'prompt-event',
  1343. 'protected?', 'push', 'put-url', 'pv', 'quote?', 'quote', 'rand',
  1344. 'random', 'randomize', 'read', 'read-char', 'read-expr', 'read-file',
  1345. 'read-key', 'read-line', 'read-utf8', 'reader-event',
  1346. 'real-path', 'receive', 'ref-all', 'ref', 'regex-comp', 'regex',
  1347. 'remove-dir', 'rename-file', 'replace', 'reset', 'rest', 'reverse',
  1348. 'rotate', 'round', 'save', 'search', 'seed', 'seek', 'select', 'self',
  1349. 'semaphore', 'send', 'sequence', 'series', 'set-locale', 'set-ref-all',
  1350. 'set-ref', 'set', 'setf', 'setq', 'sgn', 'share', 'signal', 'silent',
  1351. 'sin', 'sinh', 'sleep', 'slice', 'sort', 'source', 'spawn', 'sqrt',
  1352. 'starts-with', 'string?', 'string', 'sub', 'swap', 'sym', 'symbol?',
  1353. 'symbols', 'sync', 'sys-error', 'sys-info', 'tan', 'tanh', 'term',
  1354. 'throw-error', 'throw', 'time-of-day', 'time', 'timer', 'title-case',
  1355. 'trace-highlight', 'trace', 'transpose', 'Tree', 'trim', 'true?',
  1356. 'true', 'unicode', 'unify', 'unique', 'unless', 'unpack', 'until',
  1357. 'upper-case', 'utf8', 'utf8len', 'uuid', 'wait-pid', 'when', 'while',
  1358. 'write', 'write-char', 'write-file', 'write-line',
  1359. 'xfer-event', 'xml-error', 'xml-parse', 'xml-type-tags', 'zero?',
  1360. )
  1361. # valid names
  1362. valid_name = r'([\w!$%&*+.,/<=>?@^~|-])+|(\[.*?\])+'
  1363. tokens = {
  1364. 'root': [
  1365. # shebang
  1366. (r'#!(.*?)$', Comment.Preproc),
  1367. # comments starting with semicolon
  1368. (r';.*$', Comment.Single),
  1369. # comments starting with #
  1370. (r'#.*$', Comment.Single),
  1371. # whitespace
  1372. (r'\s+', Text),
  1373. # strings, symbols and characters
  1374. (r'"(\\\\|\\"|[^"])*"', String),
  1375. # braces
  1376. (r'\{', String, "bracestring"),
  1377. # [text] ... [/text] delimited strings
  1378. (r'\[text\]*', String, "tagstring"),
  1379. # 'special' operators...
  1380. (r"('|:)", Operator),
  1381. # highlight the builtins
  1382. (words(builtins, suffix=r'\b'),
  1383. Keyword),
  1384. # the remaining functions
  1385. (r'(?<=\()' + valid_name, Name.Variable),
  1386. # the remaining variables
  1387. (valid_name, String.Symbol),
  1388. # parentheses
  1389. (r'(\(|\))', Punctuation),
  1390. ],
  1391. # braced strings...
  1392. 'bracestring': [
  1393. (r'\{', String, "#push"),
  1394. (r'\}', String, "#pop"),
  1395. ('[^{}]+', String),
  1396. ],
  1397. # tagged [text]...[/text] delimited strings...
  1398. 'tagstring': [
  1399. (r'(?s)(.*?)(\[/text\])', String, '#pop'),
  1400. ],
  1401. }
  1402. class EmacsLispLexer(RegexLexer):
  1403. """
  1404. An ELisp lexer, parsing a stream and outputting the tokens
  1405. needed to highlight elisp code.
  1406. .. versionadded:: 2.1
  1407. """
  1408. name = 'EmacsLisp'
  1409. aliases = ['emacs', 'elisp', 'emacs-lisp']
  1410. filenames = ['*.el']
  1411. mimetypes = ['text/x-elisp', 'application/x-elisp']
  1412. flags = re.MULTILINE
  1413. # couple of useful regexes
  1414. # characters that are not macro-characters and can be used to begin a symbol
  1415. nonmacro = r'\\.|[\w!$%&*+-/<=>?@^{}~|]'
  1416. constituent = nonmacro + '|[#.:]'
  1417. terminated = r'(?=[ "()\]\'\n,;`])' # whitespace or terminating macro characters
  1418. # symbol token, reverse-engineered from hyperspec
  1419. # Take a deep breath...
  1420. symbol = r'((?:%s)(?:%s)*)' % (nonmacro, constituent)
  1421. macros = {
  1422. 'atomic-change-group', 'case', 'block', 'cl-block', 'cl-callf', 'cl-callf2',
  1423. 'cl-case', 'cl-decf', 'cl-declaim', 'cl-declare',
  1424. 'cl-define-compiler-macro', 'cl-defmacro', 'cl-defstruct',
  1425. 'cl-defsubst', 'cl-deftype', 'cl-defun', 'cl-destructuring-bind',
  1426. 'cl-do', 'cl-do*', 'cl-do-all-symbols', 'cl-do-symbols', 'cl-dolist',
  1427. 'cl-dotimes', 'cl-ecase', 'cl-etypecase', 'eval-when', 'cl-eval-when', 'cl-flet',
  1428. 'cl-flet*', 'cl-function', 'cl-incf', 'cl-labels', 'cl-letf',
  1429. 'cl-letf*', 'cl-load-time-value', 'cl-locally', 'cl-loop',
  1430. 'cl-macrolet', 'cl-multiple-value-bind', 'cl-multiple-value-setq',
  1431. 'cl-progv', 'cl-psetf', 'cl-psetq', 'cl-pushnew', 'cl-remf',
  1432. 'cl-return', 'cl-return-from', 'cl-rotatef', 'cl-shiftf',
  1433. 'cl-symbol-macrolet', 'cl-tagbody', 'cl-the', 'cl-typecase',
  1434. 'combine-after-change-calls', 'condition-case-unless-debug', 'decf',
  1435. 'declaim', 'declare', 'declare-function', 'def-edebug-spec',
  1436. 'defadvice', 'defclass', 'defcustom', 'defface', 'defgeneric',
  1437. 'defgroup', 'define-advice', 'define-alternatives',
  1438. 'define-compiler-macro', 'define-derived-mode', 'define-generic-mode',
  1439. 'define-global-minor-mode', 'define-globalized-minor-mode',
  1440. 'define-minor-mode', 'define-modify-macro',
  1441. 'define-obsolete-face-alias', 'define-obsolete-function-alias',
  1442. 'define-obsolete-variable-alias', 'define-setf-expander',
  1443. 'define-skeleton', 'defmacro', 'defmethod', 'defsetf', 'defstruct',
  1444. 'defsubst', 'deftheme', 'deftype', 'defun', 'defvar-local',
  1445. 'delay-mode-hooks', 'destructuring-bind', 'do', 'do*',
  1446. 'do-all-symbols', 'do-symbols', 'dolist', 'dont-compile', 'dotimes',
  1447. 'dotimes-with-progress-reporter', 'ecase', 'ert-deftest', 'etypecase',
  1448. 'eval-and-compile', 'eval-when-compile', 'flet', 'ignore-errors',
  1449. 'incf', 'labels', 'lambda', 'letrec', 'lexical-let', 'lexical-let*',
  1450. 'loop', 'multiple-value-bind', 'multiple-value-setq', 'noreturn',
  1451. 'oref', 'oref-default', 'oset', 'oset-default', 'pcase',
  1452. 'pcase-defmacro', 'pcase-dolist', 'pcase-exhaustive', 'pcase-let',
  1453. 'pcase-let*', 'pop', 'psetf', 'psetq', 'push', 'pushnew', 'remf',
  1454. 'return', 'rotatef', 'rx', 'save-match-data', 'save-selected-window',
  1455. 'save-window-excursion', 'setf', 'setq-local', 'shiftf',
  1456. 'track-mouse', 'typecase', 'unless', 'use-package', 'when',
  1457. 'while-no-input', 'with-case-table', 'with-category-table',
  1458. 'with-coding-priority', 'with-current-buffer', 'with-demoted-errors',
  1459. 'with-eval-after-load', 'with-file-modes', 'with-local-quit',
  1460. 'with-output-to-string', 'with-output-to-temp-buffer',
  1461. 'with-parsed-tramp-file-name', 'with-selected-frame',
  1462. 'with-selected-window', 'with-silent-modifications', 'with-slots',
  1463. 'with-syntax-table', 'with-temp-buffer', 'with-temp-file',
  1464. 'with-temp-message', 'with-timeout', 'with-tramp-connection-property',
  1465. 'with-tramp-file-property', 'with-tramp-progress-reporter',
  1466. 'with-wrapper-hook', 'load-time-value', 'locally', 'macrolet', 'progv',
  1467. 'return-from',
  1468. }
  1469. special_forms = {
  1470. 'and', 'catch', 'cond', 'condition-case', 'defconst', 'defvar',
  1471. 'function', 'if', 'interactive', 'let', 'let*', 'or', 'prog1',
  1472. 'prog2', 'progn', 'quote', 'save-current-buffer', 'save-excursion',
  1473. 'save-restriction', 'setq', 'setq-default', 'subr-arity',
  1474. 'unwind-protect', 'while',
  1475. }
  1476. builtin_function = {
  1477. '%', '*', '+', '-', '/', '/=', '1+', '1-', '<', '<=', '=', '>', '>=',
  1478. 'Snarf-documentation', 'abort-recursive-edit', 'abs',
  1479. 'accept-process-output', 'access-file', 'accessible-keymaps', 'acos',
  1480. 'active-minibuffer-window', 'add-face-text-property',
  1481. 'add-name-to-file', 'add-text-properties', 'all-completions',
  1482. 'append', 'apply', 'apropos-internal', 'aref', 'arrayp', 'aset',
  1483. 'ash', 'asin', 'assoc', 'assoc-string', 'assq', 'atan', 'atom',
  1484. 'autoload', 'autoload-do-load', 'backtrace', 'backtrace--locals',
  1485. 'backtrace-debug', 'backtrace-eval', 'backtrace-frame',
  1486. 'backward-char', 'backward-prefix-chars', 'barf-if-buffer-read-only',
  1487. 'base64-decode-region', 'base64-decode-string',
  1488. 'base64-encode-region', 'base64-encode-string', 'beginning-of-line',
  1489. 'bidi-find-overridden-directionality', 'bidi-resolved-levels',
  1490. 'bitmap-spec-p', 'bobp', 'bolp', 'bool-vector',
  1491. 'bool-vector-count-consecutive', 'bool-vector-count-population',
  1492. 'bool-vector-exclusive-or', 'bool-vector-intersection',
  1493. 'bool-vector-not', 'bool-vector-p', 'bool-vector-set-difference',
  1494. 'bool-vector-subsetp', 'bool-vector-union', 'boundp',
  1495. 'buffer-base-buffer', 'buffer-chars-modified-tick',
  1496. 'buffer-enable-undo', 'buffer-file-name', 'buffer-has-markers-at',
  1497. 'buffer-list', 'buffer-live-p', 'buffer-local-value',
  1498. 'buffer-local-variables', 'buffer-modified-p', 'buffer-modified-tick',
  1499. 'buffer-name', 'buffer-size', 'buffer-string', 'buffer-substring',
  1500. 'buffer-substring-no-properties', 'buffer-swap-text', 'bufferp',
  1501. 'bury-buffer-internal', 'byte-code', 'byte-code-function-p',
  1502. 'byte-to-position', 'byte-to-string', 'byteorder',
  1503. 'call-interactively', 'call-last-kbd-macro', 'call-process',
  1504. 'call-process-region', 'cancel-kbd-macro-events', 'capitalize',
  1505. 'capitalize-region', 'capitalize-word', 'car', 'car-less-than-car',
  1506. 'car-safe', 'case-table-p', 'category-docstring',
  1507. 'category-set-mnemonics', 'category-table', 'category-table-p',
  1508. 'ccl-execute', 'ccl-execute-on-string', 'ccl-program-p', 'cdr',
  1509. 'cdr-safe', 'ceiling', 'char-after', 'char-before',
  1510. 'char-category-set', 'char-charset', 'char-equal', 'char-or-string-p',
  1511. 'char-resolve-modifiers', 'char-syntax', 'char-table-extra-slot',
  1512. 'char-table-p', 'char-table-parent', 'char-table-range',
  1513. 'char-table-subtype', 'char-to-string', 'char-width', 'characterp',
  1514. 'charset-after', 'charset-id-internal', 'charset-plist',
  1515. 'charset-priority-list', 'charsetp', 'check-coding-system',
  1516. 'check-coding-systems-region', 'clear-buffer-auto-save-failure',
  1517. 'clear-charset-maps', 'clear-face-cache', 'clear-font-cache',
  1518. 'clear-image-cache', 'clear-string', 'clear-this-command-keys',
  1519. 'close-font', 'clrhash', 'coding-system-aliases',
  1520. 'coding-system-base', 'coding-system-eol-type', 'coding-system-p',
  1521. 'coding-system-plist', 'coding-system-priority-list',
  1522. 'coding-system-put', 'color-distance', 'color-gray-p',
  1523. 'color-supported-p', 'combine-after-change-execute',
  1524. 'command-error-default-function', 'command-remapping', 'commandp',
  1525. 'compare-buffer-substrings', 'compare-strings',
  1526. 'compare-window-configurations', 'completing-read',
  1527. 'compose-region-internal', 'compose-string-internal',
  1528. 'composition-get-gstring', 'compute-motion', 'concat', 'cons',
  1529. 'consp', 'constrain-to-field', 'continue-process',
  1530. 'controlling-tty-p', 'coordinates-in-window-p', 'copy-alist',
  1531. 'copy-category-table', 'copy-file', 'copy-hash-table', 'copy-keymap',
  1532. 'copy-marker', 'copy-sequence', 'copy-syntax-table', 'copysign',
  1533. 'cos', 'current-active-maps', 'current-bidi-paragraph-direction',
  1534. 'current-buffer', 'current-case-table', 'current-column',
  1535. 'current-global-map', 'current-idle-time', 'current-indentation',
  1536. 'current-input-mode', 'current-local-map', 'current-message',
  1537. 'current-minor-mode-maps', 'current-time', 'current-time-string',
  1538. 'current-time-zone', 'current-window-configuration',
  1539. 'cygwin-convert-file-name-from-windows',
  1540. 'cygwin-convert-file-name-to-windows', 'daemon-initialized',
  1541. 'daemonp', 'dbus--init-bus', 'dbus-get-unique-name',
  1542. 'dbus-message-internal', 'debug-timer-check', 'declare-equiv-charset',
  1543. 'decode-big5-char', 'decode-char', 'decode-coding-region',
  1544. 'decode-coding-string', 'decode-sjis-char', 'decode-time',
  1545. 'default-boundp', 'default-file-modes', 'default-printer-name',
  1546. 'default-toplevel-value', 'default-value', 'define-category',
  1547. 'define-charset-alias', 'define-charset-internal',
  1548. 'define-coding-system-alias', 'define-coding-system-internal',
  1549. 'define-fringe-bitmap', 'define-hash-table-test', 'define-key',
  1550. 'define-prefix-command', 'delete',
  1551. 'delete-all-overlays', 'delete-and-extract-region', 'delete-char',
  1552. 'delete-directory-internal', 'delete-field', 'delete-file',
  1553. 'delete-frame', 'delete-other-windows-internal', 'delete-overlay',
  1554. 'delete-process', 'delete-region', 'delete-terminal',
  1555. 'delete-window-internal', 'delq', 'describe-buffer-bindings',
  1556. 'describe-vector', 'destroy-fringe-bitmap', 'detect-coding-region',
  1557. 'detect-coding-string', 'ding', 'directory-file-name',
  1558. 'directory-files', 'directory-files-and-attributes', 'discard-input',
  1559. 'display-supports-face-attributes-p', 'do-auto-save', 'documentation',
  1560. 'documentation-property', 'downcase', 'downcase-region',
  1561. 'downcase-word', 'draw-string', 'dump-colors', 'dump-emacs',
  1562. 'dump-face', 'dump-frame-glyph-matrix', 'dump-glyph-matrix',
  1563. 'dump-glyph-row', 'dump-redisplay-history', 'dump-tool-bar-row',
  1564. 'elt', 'emacs-pid', 'encode-big5-char', 'encode-char',
  1565. 'encode-coding-region', 'encode-coding-string', 'encode-sjis-char',
  1566. 'encode-time', 'end-kbd-macro', 'end-of-line', 'eobp', 'eolp', 'eq',
  1567. 'eql', 'equal', 'equal-including-properties', 'erase-buffer',
  1568. 'error-message-string', 'eval', 'eval-buffer', 'eval-region',
  1569. 'event-convert-list', 'execute-kbd-macro', 'exit-recursive-edit',
  1570. 'exp', 'expand-file-name', 'expt', 'external-debugging-output',
  1571. 'face-attribute-relative-p', 'face-attributes-as-vector', 'face-font',
  1572. 'fboundp', 'fceiling', 'fetch-bytecode', 'ffloor',
  1573. 'field-beginning', 'field-end', 'field-string',
  1574. 'field-string-no-properties', 'file-accessible-directory-p',
  1575. 'file-acl', 'file-attributes', 'file-attributes-lessp',
  1576. 'file-directory-p', 'file-executable-p', 'file-exists-p',
  1577. 'file-locked-p', 'file-modes', 'file-name-absolute-p',
  1578. 'file-name-all-completions', 'file-name-as-directory',
  1579. 'file-name-completion', 'file-name-directory',
  1580. 'file-name-nondirectory', 'file-newer-than-file-p', 'file-readable-p',
  1581. 'file-regular-p', 'file-selinux-context', 'file-symlink-p',
  1582. 'file-system-info', 'file-system-info', 'file-writable-p',
  1583. 'fillarray', 'find-charset-region', 'find-charset-string',
  1584. 'find-coding-systems-region-internal', 'find-composition-internal',
  1585. 'find-file-name-handler', 'find-font', 'find-operation-coding-system',
  1586. 'float', 'float-time', 'floatp', 'floor', 'fmakunbound',
  1587. 'following-char', 'font-at', 'font-drive-otf', 'font-face-attributes',
  1588. 'font-family-list', 'font-get', 'font-get-glyphs',
  1589. 'font-get-system-font', 'font-get-system-normal-font', 'font-info',
  1590. 'font-match-p', 'font-otf-alternates', 'font-put',
  1591. 'font-shape-gstring', 'font-spec', 'font-variation-glyphs',
  1592. 'font-xlfd-name', 'fontp', 'fontset-font', 'fontset-info',
  1593. 'fontset-list', 'fontset-list-all', 'force-mode-line-update',
  1594. 'force-window-update', 'format', 'format-mode-line',
  1595. 'format-network-address', 'format-time-string', 'forward-char',
  1596. 'forward-comment', 'forward-line', 'forward-word',
  1597. 'frame-border-width', 'frame-bottom-divider-width',
  1598. 'frame-can-run-window-configuration-change-hook', 'frame-char-height',
  1599. 'frame-char-width', 'frame-face-alist', 'frame-first-window',
  1600. 'frame-focus', 'frame-font-cache', 'frame-fringe-width', 'frame-list',
  1601. 'frame-live-p', 'frame-or-buffer-changed-p', 'frame-parameter',
  1602. 'frame-parameters', 'frame-pixel-height', 'frame-pixel-width',
  1603. 'frame-pointer-visible-p', 'frame-right-divider-width',
  1604. 'frame-root-window', 'frame-scroll-bar-height',
  1605. 'frame-scroll-bar-width', 'frame-selected-window', 'frame-terminal',
  1606. 'frame-text-cols', 'frame-text-height', 'frame-text-lines',
  1607. 'frame-text-width', 'frame-total-cols', 'frame-total-lines',
  1608. 'frame-visible-p', 'framep', 'frexp', 'fringe-bitmaps-at-pos',
  1609. 'fround', 'fset', 'ftruncate', 'funcall', 'funcall-interactively',
  1610. 'function-equal', 'functionp', 'gap-position', 'gap-size',
  1611. 'garbage-collect', 'gc-status', 'generate-new-buffer-name', 'get',
  1612. 'get-buffer', 'get-buffer-create', 'get-buffer-process',
  1613. 'get-buffer-window', 'get-byte', 'get-char-property',
  1614. 'get-char-property-and-overlay', 'get-file-buffer', 'get-file-char',
  1615. 'get-internal-run-time', 'get-load-suffixes', 'get-pos-property',
  1616. 'get-process', 'get-screen-color', 'get-text-property',
  1617. 'get-unicode-property-internal', 'get-unused-category',
  1618. 'get-unused-iso-final-char', 'getenv-internal', 'gethash',
  1619. 'gfile-add-watch', 'gfile-rm-watch', 'global-key-binding',
  1620. 'gnutls-available-p', 'gnutls-boot', 'gnutls-bye', 'gnutls-deinit',
  1621. 'gnutls-error-fatalp', 'gnutls-error-string', 'gnutls-errorp',
  1622. 'gnutls-get-initstage', 'gnutls-peer-status',
  1623. 'gnutls-peer-status-warning-describe', 'goto-char', 'gpm-mouse-start',
  1624. 'gpm-mouse-stop', 'group-gid', 'group-real-gid',
  1625. 'handle-save-session', 'handle-switch-frame', 'hash-table-count',
  1626. 'hash-table-p', 'hash-table-rehash-size',
  1627. 'hash-table-rehash-threshold', 'hash-table-size', 'hash-table-test',
  1628. 'hash-table-weakness', 'iconify-frame', 'identity', 'image-flush',
  1629. 'image-mask-p', 'image-metadata', 'image-size', 'imagemagick-types',
  1630. 'imagep', 'indent-to', 'indirect-function', 'indirect-variable',
  1631. 'init-image-library', 'inotify-add-watch', 'inotify-rm-watch',
  1632. 'input-pending-p', 'insert', 'insert-and-inherit',
  1633. 'insert-before-markers', 'insert-before-markers-and-inherit',
  1634. 'insert-buffer-substring', 'insert-byte', 'insert-char',
  1635. 'insert-file-contents', 'insert-startup-screen', 'int86',
  1636. 'integer-or-marker-p', 'integerp', 'interactive-form', 'intern',
  1637. 'intern-soft', 'internal--track-mouse', 'internal-char-font',
  1638. 'internal-complete-buffer', 'internal-copy-lisp-face',
  1639. 'internal-default-process-filter',
  1640. 'internal-default-process-sentinel', 'internal-describe-syntax-value',
  1641. 'internal-event-symbol-parse-modifiers',
  1642. 'internal-face-x-get-resource', 'internal-get-lisp-face-attribute',
  1643. 'internal-lisp-face-attribute-values', 'internal-lisp-face-empty-p',
  1644. 'internal-lisp-face-equal-p', 'internal-lisp-face-p',
  1645. 'internal-make-lisp-face', 'internal-make-var-non-special',
  1646. 'internal-merge-in-global-face',
  1647. 'internal-set-alternative-font-family-alist',
  1648. 'internal-set-alternative-font-registry-alist',
  1649. 'internal-set-font-selection-order',
  1650. 'internal-set-lisp-face-attribute',
  1651. 'internal-set-lisp-face-attribute-from-resource',
  1652. 'internal-show-cursor', 'internal-show-cursor-p', 'interrupt-process',
  1653. 'invisible-p', 'invocation-directory', 'invocation-name', 'isnan',
  1654. 'iso-charset', 'key-binding', 'key-description',
  1655. 'keyboard-coding-system', 'keymap-parent', 'keymap-prompt', 'keymapp',
  1656. 'keywordp', 'kill-all-local-variables', 'kill-buffer', 'kill-emacs',
  1657. 'kill-local-variable', 'kill-process', 'last-nonminibuffer-frame',
  1658. 'lax-plist-get', 'lax-plist-put', 'ldexp', 'length',
  1659. 'libxml-parse-html-region', 'libxml-parse-xml-region',
  1660. 'line-beginning-position', 'line-end-position', 'line-pixel-height',
  1661. 'list', 'list-fonts', 'list-system-processes', 'listp', 'load',
  1662. 'load-average', 'local-key-binding', 'local-variable-if-set-p',
  1663. 'local-variable-p', 'locale-info', 'locate-file-internal',
  1664. 'lock-buffer', 'log', 'logand', 'logb', 'logior', 'lognot', 'logxor',
  1665. 'looking-at', 'lookup-image', 'lookup-image-map', 'lookup-key',
  1666. 'lower-frame', 'lsh', 'macroexpand', 'make-bool-vector',
  1667. 'make-byte-code', 'make-category-set', 'make-category-table',
  1668. 'make-char', 'make-char-table', 'make-directory-internal',
  1669. 'make-frame-invisible', 'make-frame-visible', 'make-hash-table',
  1670. 'make-indirect-buffer', 'make-keymap', 'make-list',
  1671. 'make-local-variable', 'make-marker', 'make-network-process',
  1672. 'make-overlay', 'make-serial-process', 'make-sparse-keymap',
  1673. 'make-string', 'make-symbol', 'make-symbolic-link', 'make-temp-name',
  1674. 'make-terminal-frame', 'make-variable-buffer-local',
  1675. 'make-variable-frame-local', 'make-vector', 'makunbound',
  1676. 'map-char-table', 'map-charset-chars', 'map-keymap',
  1677. 'map-keymap-internal', 'mapatoms', 'mapc', 'mapcar', 'mapconcat',
  1678. 'maphash', 'mark-marker', 'marker-buffer', 'marker-insertion-type',
  1679. 'marker-position', 'markerp', 'match-beginning', 'match-data',
  1680. 'match-end', 'matching-paren', 'max', 'max-char', 'md5', 'member',
  1681. 'memory-info', 'memory-limit', 'memory-use-counts', 'memq', 'memql',
  1682. 'menu-bar-menu-at-x-y', 'menu-or-popup-active-p',
  1683. 'menu-or-popup-active-p', 'merge-face-attribute', 'message',
  1684. 'message-box', 'message-or-box', 'min',
  1685. 'minibuffer-completion-contents', 'minibuffer-contents',
  1686. 'minibuffer-contents-no-properties', 'minibuffer-depth',
  1687. 'minibuffer-prompt', 'minibuffer-prompt-end',
  1688. 'minibuffer-selected-window', 'minibuffer-window', 'minibufferp',
  1689. 'minor-mode-key-binding', 'mod', 'modify-category-entry',
  1690. 'modify-frame-parameters', 'modify-syntax-entry',
  1691. 'mouse-pixel-position', 'mouse-position', 'move-overlay',
  1692. 'move-point-visually', 'move-to-column', 'move-to-window-line',
  1693. 'msdos-downcase-filename', 'msdos-long-file-names', 'msdos-memget',
  1694. 'msdos-memput', 'msdos-mouse-disable', 'msdos-mouse-enable',
  1695. 'msdos-mouse-init', 'msdos-mouse-p', 'msdos-remember-default-colors',
  1696. 'msdos-set-keyboard', 'msdos-set-mouse-buttons',
  1697. 'multibyte-char-to-unibyte', 'multibyte-string-p', 'narrow-to-region',
  1698. 'natnump', 'nconc', 'network-interface-info',
  1699. 'network-interface-list', 'new-fontset', 'newline-cache-check',
  1700. 'next-char-property-change', 'next-frame', 'next-overlay-change',
  1701. 'next-property-change', 'next-read-file-uses-dialog-p',
  1702. 'next-single-char-property-change', 'next-single-property-change',
  1703. 'next-window', 'nlistp', 'nreverse', 'nth', 'nthcdr', 'null',
  1704. 'number-or-marker-p', 'number-to-string', 'numberp',
  1705. 'open-dribble-file', 'open-font', 'open-termscript',
  1706. 'optimize-char-table', 'other-buffer', 'other-window-for-scrolling',
  1707. 'overlay-buffer', 'overlay-end', 'overlay-get', 'overlay-lists',
  1708. 'overlay-properties', 'overlay-put', 'overlay-recenter',
  1709. 'overlay-start', 'overlayp', 'overlays-at', 'overlays-in',
  1710. 'parse-partial-sexp', 'play-sound-internal', 'plist-get',
  1711. 'plist-member', 'plist-put', 'point', 'point-marker', 'point-max',
  1712. 'point-max-marker', 'point-min', 'point-min-marker',
  1713. 'pos-visible-in-window-p', 'position-bytes', 'posix-looking-at',
  1714. 'posix-search-backward', 'posix-search-forward', 'posix-string-match',
  1715. 'posn-at-point', 'posn-at-x-y', 'preceding-char',
  1716. 'prefix-numeric-value', 'previous-char-property-change',
  1717. 'previous-frame', 'previous-overlay-change',
  1718. 'previous-property-change', 'previous-single-char-property-change',
  1719. 'previous-single-property-change', 'previous-window', 'prin1',
  1720. 'prin1-to-string', 'princ', 'print', 'process-attributes',
  1721. 'process-buffer', 'process-coding-system', 'process-command',
  1722. 'process-connection', 'process-contact', 'process-datagram-address',
  1723. 'process-exit-status', 'process-filter', 'process-filter-multibyte-p',
  1724. 'process-id', 'process-inherit-coding-system-flag', 'process-list',
  1725. 'process-mark', 'process-name', 'process-plist',
  1726. 'process-query-on-exit-flag', 'process-running-child-p',
  1727. 'process-send-eof', 'process-send-region', 'process-send-string',
  1728. 'process-sentinel', 'process-status', 'process-tty-name',
  1729. 'process-type', 'processp', 'profiler-cpu-log',
  1730. 'profiler-cpu-running-p', 'profiler-cpu-start', 'profiler-cpu-stop',
  1731. 'profiler-memory-log', 'profiler-memory-running-p',
  1732. 'profiler-memory-start', 'profiler-memory-stop', 'propertize',
  1733. 'purecopy', 'put', 'put-text-property',
  1734. 'put-unicode-property-internal', 'puthash', 'query-font',
  1735. 'query-fontset', 'quit-process', 'raise-frame', 'random', 'rassoc',
  1736. 'rassq', 're-search-backward', 're-search-forward', 'read',
  1737. 'read-buffer', 'read-char', 'read-char-exclusive',
  1738. 'read-coding-system', 'read-command', 'read-event',
  1739. 'read-from-minibuffer', 'read-from-string', 'read-function',
  1740. 'read-key-sequence', 'read-key-sequence-vector',
  1741. 'read-no-blanks-input', 'read-non-nil-coding-system', 'read-string',
  1742. 'read-variable', 'recent-auto-save-p', 'recent-doskeys',
  1743. 'recent-keys', 'recenter', 'recursion-depth', 'recursive-edit',
  1744. 'redirect-debugging-output', 'redirect-frame-focus', 'redisplay',
  1745. 'redraw-display', 'redraw-frame', 'regexp-quote', 'region-beginning',
  1746. 'region-end', 'register-ccl-program', 'register-code-conversion-map',
  1747. 'remhash', 'remove-list-of-text-properties', 'remove-text-properties',
  1748. 'rename-buffer', 'rename-file', 'replace-match',
  1749. 'reset-this-command-lengths', 'resize-mini-window-internal',
  1750. 'restore-buffer-modified-p', 'resume-tty', 'reverse', 'round',
  1751. 'run-hook-with-args', 'run-hook-with-args-until-failure',
  1752. 'run-hook-with-args-until-success', 'run-hook-wrapped', 'run-hooks',
  1753. 'run-window-configuration-change-hook', 'run-window-scroll-functions',
  1754. 'safe-length', 'scan-lists', 'scan-sexps', 'scroll-down',
  1755. 'scroll-left', 'scroll-other-window', 'scroll-right', 'scroll-up',
  1756. 'search-backward', 'search-forward', 'secure-hash', 'select-frame',
  1757. 'select-window', 'selected-frame', 'selected-window',
  1758. 'self-insert-command', 'send-string-to-terminal', 'sequencep',
  1759. 'serial-process-configure', 'set', 'set-buffer',
  1760. 'set-buffer-auto-saved', 'set-buffer-major-mode',
  1761. 'set-buffer-modified-p', 'set-buffer-multibyte', 'set-case-table',
  1762. 'set-category-table', 'set-char-table-extra-slot',
  1763. 'set-char-table-parent', 'set-char-table-range', 'set-charset-plist',
  1764. 'set-charset-priority', 'set-coding-system-priority',
  1765. 'set-cursor-size', 'set-default', 'set-default-file-modes',
  1766. 'set-default-toplevel-value', 'set-file-acl', 'set-file-modes',
  1767. 'set-file-selinux-context', 'set-file-times', 'set-fontset-font',
  1768. 'set-frame-height', 'set-frame-position', 'set-frame-selected-window',
  1769. 'set-frame-size', 'set-frame-width', 'set-fringe-bitmap-face',
  1770. 'set-input-interrupt-mode', 'set-input-meta-mode', 'set-input-mode',
  1771. 'set-keyboard-coding-system-internal', 'set-keymap-parent',
  1772. 'set-marker', 'set-marker-insertion-type', 'set-match-data',
  1773. 'set-message-beep', 'set-minibuffer-window',
  1774. 'set-mouse-pixel-position', 'set-mouse-position',
  1775. 'set-network-process-option', 'set-output-flow-control',
  1776. 'set-process-buffer', 'set-process-coding-system',
  1777. 'set-process-datagram-address', 'set-process-filter',
  1778. 'set-process-filter-multibyte',
  1779. 'set-process-inherit-coding-system-flag', 'set-process-plist',
  1780. 'set-process-query-on-exit-flag', 'set-process-sentinel',
  1781. 'set-process-window-size', 'set-quit-char',
  1782. 'set-safe-terminal-coding-system-internal', 'set-screen-color',
  1783. 'set-standard-case-table', 'set-syntax-table',
  1784. 'set-terminal-coding-system-internal', 'set-terminal-local-value',
  1785. 'set-terminal-parameter', 'set-text-properties', 'set-time-zone-rule',
  1786. 'set-visited-file-modtime', 'set-window-buffer',
  1787. 'set-window-combination-limit', 'set-window-configuration',
  1788. 'set-window-dedicated-p', 'set-window-display-table',
  1789. 'set-window-fringes', 'set-window-hscroll', 'set-window-margins',
  1790. 'set-window-new-normal', 'set-window-new-pixel',
  1791. 'set-window-new-total', 'set-window-next-buffers',
  1792. 'set-window-parameter', 'set-window-point', 'set-window-prev-buffers',
  1793. 'set-window-redisplay-end-trigger', 'set-window-scroll-bars',
  1794. 'set-window-start', 'set-window-vscroll', 'setcar', 'setcdr',
  1795. 'setplist', 'show-face-resources', 'signal', 'signal-process', 'sin',
  1796. 'single-key-description', 'skip-chars-backward', 'skip-chars-forward',
  1797. 'skip-syntax-backward', 'skip-syntax-forward', 'sleep-for', 'sort',
  1798. 'sort-charsets', 'special-variable-p', 'split-char',
  1799. 'split-window-internal', 'sqrt', 'standard-case-table',
  1800. 'standard-category-table', 'standard-syntax-table', 'start-kbd-macro',
  1801. 'start-process', 'stop-process', 'store-kbd-macro-event', 'string',
  1802. 'string=', 'string<', 'string>', 'string-as-multibyte',
  1803. 'string-as-unibyte', 'string-bytes', 'string-collate-equalp',
  1804. 'string-collate-lessp', 'string-equal', 'string-greaterp',
  1805. 'string-lessp', 'string-make-multibyte', 'string-make-unibyte',
  1806. 'string-match', 'string-to-char', 'string-to-multibyte',
  1807. 'string-to-number', 'string-to-syntax', 'string-to-unibyte',
  1808. 'string-width', 'stringp', 'subr-name', 'subrp',
  1809. 'subst-char-in-region', 'substitute-command-keys',
  1810. 'substitute-in-file-name', 'substring', 'substring-no-properties',
  1811. 'suspend-emacs', 'suspend-tty', 'suspicious-object', 'sxhash',
  1812. 'symbol-function', 'symbol-name', 'symbol-plist', 'symbol-value',
  1813. 'symbolp', 'syntax-table', 'syntax-table-p', 'system-groups',
  1814. 'system-move-file-to-trash', 'system-name', 'system-users', 'tan',
  1815. 'terminal-coding-system', 'terminal-list', 'terminal-live-p',
  1816. 'terminal-local-value', 'terminal-name', 'terminal-parameter',
  1817. 'terminal-parameters', 'terpri', 'test-completion',
  1818. 'text-char-description', 'text-properties-at', 'text-property-any',
  1819. 'text-property-not-all', 'this-command-keys',
  1820. 'this-command-keys-vector', 'this-single-command-keys',
  1821. 'this-single-command-raw-keys', 'time-add', 'time-less-p',
  1822. 'time-subtract', 'tool-bar-get-system-style', 'tool-bar-height',
  1823. 'tool-bar-pixel-width', 'top-level', 'trace-redisplay',
  1824. 'trace-to-stderr', 'translate-region-internal', 'transpose-regions',
  1825. 'truncate', 'try-completion', 'tty-display-color-cells',
  1826. 'tty-display-color-p', 'tty-no-underline',
  1827. 'tty-suppress-bold-inverse-default-colors', 'tty-top-frame',
  1828. 'tty-type', 'type-of', 'undo-boundary', 'unencodable-char-position',
  1829. 'unhandled-file-name-directory', 'unibyte-char-to-multibyte',
  1830. 'unibyte-string', 'unicode-property-table-internal', 'unify-charset',
  1831. 'unintern', 'unix-sync', 'unlock-buffer', 'upcase', 'upcase-initials',
  1832. 'upcase-initials-region', 'upcase-region', 'upcase-word',
  1833. 'use-global-map', 'use-local-map', 'user-full-name',
  1834. 'user-login-name', 'user-real-login-name', 'user-real-uid',
  1835. 'user-uid', 'variable-binding-locus', 'vconcat', 'vector',
  1836. 'vector-or-char-table-p', 'vectorp', 'verify-visited-file-modtime',
  1837. 'vertical-motion', 'visible-frame-list', 'visited-file-modtime',
  1838. 'w16-get-clipboard-data', 'w16-selection-exists-p',
  1839. 'w16-set-clipboard-data', 'w32-battery-status',
  1840. 'w32-default-color-map', 'w32-define-rgb-color',
  1841. 'w32-display-monitor-attributes-list', 'w32-frame-menu-bar-size',
  1842. 'w32-frame-rect', 'w32-get-clipboard-data',
  1843. 'w32-get-codepage-charset', 'w32-get-console-codepage',
  1844. 'w32-get-console-output-codepage', 'w32-get-current-locale-id',
  1845. 'w32-get-default-locale-id', 'w32-get-keyboard-layout',
  1846. 'w32-get-locale-info', 'w32-get-valid-codepages',
  1847. 'w32-get-valid-keyboard-layouts', 'w32-get-valid-locale-ids',
  1848. 'w32-has-winsock', 'w32-long-file-name', 'w32-reconstruct-hot-key',
  1849. 'w32-register-hot-key', 'w32-registered-hot-keys',
  1850. 'w32-selection-exists-p', 'w32-send-sys-command',
  1851. 'w32-set-clipboard-data', 'w32-set-console-codepage',
  1852. 'w32-set-console-output-codepage', 'w32-set-current-locale',
  1853. 'w32-set-keyboard-layout', 'w32-set-process-priority',
  1854. 'w32-shell-execute', 'w32-short-file-name', 'w32-toggle-lock-key',
  1855. 'w32-unload-winsock', 'w32-unregister-hot-key', 'w32-window-exists-p',
  1856. 'w32notify-add-watch', 'w32notify-rm-watch',
  1857. 'waiting-for-user-input-p', 'where-is-internal', 'widen',
  1858. 'widget-apply', 'widget-get', 'widget-put',
  1859. 'window-absolute-pixel-edges', 'window-at', 'window-body-height',
  1860. 'window-body-width', 'window-bottom-divider-width', 'window-buffer',
  1861. 'window-combination-limit', 'window-configuration-frame',
  1862. 'window-configuration-p', 'window-dedicated-p',
  1863. 'window-display-table', 'window-edges', 'window-end', 'window-frame',
  1864. 'window-fringes', 'window-header-line-height', 'window-hscroll',
  1865. 'window-inside-absolute-pixel-edges', 'window-inside-edges',
  1866. 'window-inside-pixel-edges', 'window-left-child',
  1867. 'window-left-column', 'window-line-height', 'window-list',
  1868. 'window-list-1', 'window-live-p', 'window-margins',
  1869. 'window-minibuffer-p', 'window-mode-line-height', 'window-new-normal',
  1870. 'window-new-pixel', 'window-new-total', 'window-next-buffers',
  1871. 'window-next-sibling', 'window-normal-size', 'window-old-point',
  1872. 'window-parameter', 'window-parameters', 'window-parent',
  1873. 'window-pixel-edges', 'window-pixel-height', 'window-pixel-left',
  1874. 'window-pixel-top', 'window-pixel-width', 'window-point',
  1875. 'window-prev-buffers', 'window-prev-sibling',
  1876. 'window-redisplay-end-trigger', 'window-resize-apply',
  1877. 'window-resize-apply-total', 'window-right-divider-width',
  1878. 'window-scroll-bar-height', 'window-scroll-bar-width',
  1879. 'window-scroll-bars', 'window-start', 'window-system',
  1880. 'window-text-height', 'window-text-pixel-size', 'window-text-width',
  1881. 'window-top-child', 'window-top-line', 'window-total-height',
  1882. 'window-total-width', 'window-use-time', 'window-valid-p',
  1883. 'window-vscroll', 'windowp', 'write-char', 'write-region',
  1884. 'x-backspace-delete-keys-p', 'x-change-window-property',
  1885. 'x-change-window-property', 'x-close-connection',
  1886. 'x-close-connection', 'x-create-frame', 'x-create-frame',
  1887. 'x-delete-window-property', 'x-delete-window-property',
  1888. 'x-disown-selection-internal', 'x-display-backing-store',
  1889. 'x-display-backing-store', 'x-display-color-cells',
  1890. 'x-display-color-cells', 'x-display-grayscale-p',
  1891. 'x-display-grayscale-p', 'x-display-list', 'x-display-list',
  1892. 'x-display-mm-height', 'x-display-mm-height', 'x-display-mm-width',
  1893. 'x-display-mm-width', 'x-display-monitor-attributes-list',
  1894. 'x-display-pixel-height', 'x-display-pixel-height',
  1895. 'x-display-pixel-width', 'x-display-pixel-width', 'x-display-planes',
  1896. 'x-display-planes', 'x-display-save-under', 'x-display-save-under',
  1897. 'x-display-screens', 'x-display-screens', 'x-display-visual-class',
  1898. 'x-display-visual-class', 'x-family-fonts', 'x-file-dialog',
  1899. 'x-file-dialog', 'x-file-dialog', 'x-focus-frame', 'x-frame-geometry',
  1900. 'x-frame-geometry', 'x-get-atom-name', 'x-get-resource',
  1901. 'x-get-selection-internal', 'x-hide-tip', 'x-hide-tip',
  1902. 'x-list-fonts', 'x-load-color-file', 'x-menu-bar-open-internal',
  1903. 'x-menu-bar-open-internal', 'x-open-connection', 'x-open-connection',
  1904. 'x-own-selection-internal', 'x-parse-geometry', 'x-popup-dialog',
  1905. 'x-popup-menu', 'x-register-dnd-atom', 'x-select-font',
  1906. 'x-select-font', 'x-selection-exists-p', 'x-selection-owner-p',
  1907. 'x-send-client-message', 'x-server-max-request-size',
  1908. 'x-server-max-request-size', 'x-server-vendor', 'x-server-vendor',
  1909. 'x-server-version', 'x-server-version', 'x-show-tip', 'x-show-tip',
  1910. 'x-synchronize', 'x-synchronize', 'x-uses-old-gtk-dialog',
  1911. 'x-window-property', 'x-window-property', 'x-wm-set-size-hint',
  1912. 'xw-color-defined-p', 'xw-color-defined-p', 'xw-color-values',
  1913. 'xw-color-values', 'xw-display-color-p', 'xw-display-color-p',
  1914. 'yes-or-no-p', 'zlib-available-p', 'zlib-decompress-region',
  1915. 'forward-point',
  1916. }
  1917. builtin_function_highlighted = {
  1918. 'defvaralias', 'provide', 'require',
  1919. 'with-no-warnings', 'define-widget', 'with-electric-help',
  1920. 'throw', 'defalias', 'featurep'
  1921. }
  1922. lambda_list_keywords = {
  1923. '&allow-other-keys', '&aux', '&body', '&environment', '&key', '&optional',
  1924. '&rest', '&whole',
  1925. }
  1926. error_keywords = {
  1927. 'cl-assert', 'cl-check-type', 'error', 'signal',
  1928. 'user-error', 'warn',
  1929. }
  1930. def get_tokens_unprocessed(self, text):
  1931. stack = ['root']
  1932. for index, token, value in RegexLexer.get_tokens_unprocessed(self, text, stack):
  1933. if token is Name.Variable:
  1934. if value in EmacsLispLexer.builtin_function:
  1935. yield index, Name.Function, value
  1936. continue
  1937. if value in EmacsLispLexer.special_forms:
  1938. yield index, Keyword, value
  1939. continue
  1940. if value in EmacsLispLexer.error_keywords:
  1941. yield index, Name.Exception, value
  1942. continue
  1943. if value in EmacsLispLexer.builtin_function_highlighted:
  1944. yield index, Name.Builtin, value
  1945. continue
  1946. if value in EmacsLispLexer.macros:
  1947. yield index, Name.Builtin, value
  1948. continue
  1949. if value in EmacsLispLexer.lambda_list_keywords:
  1950. yield index, Keyword.Pseudo, value
  1951. continue
  1952. yield index, token, value
  1953. tokens = {
  1954. 'root': [
  1955. default('body'),
  1956. ],
  1957. 'body': [
  1958. # whitespace
  1959. (r'\s+', Text),
  1960. # single-line comment
  1961. (r';.*$', Comment.Single),
  1962. # strings and characters
  1963. (r'"', String, 'string'),
  1964. (r'\?([^\\]|\\.)', String.Char),
  1965. # quoting
  1966. (r":" + symbol, Name.Builtin),
  1967. (r"::" + symbol, String.Symbol),
  1968. (r"'" + symbol, String.Symbol),
  1969. (r"'", Operator),
  1970. (r"`", Operator),
  1971. # decimal numbers
  1972. (r'[-+]?\d+\.?' + terminated, Number.Integer),
  1973. (r'[-+]?\d+/\d+' + terminated, Number),
  1974. (r'[-+]?(\d*\.\d+([defls][-+]?\d+)?|\d+(\.\d*)?[defls][-+]?\d+)' +
  1975. terminated, Number.Float),
  1976. # vectors
  1977. (r'\[|\]', Punctuation),
  1978. # uninterned symbol
  1979. (r'#:' + symbol, String.Symbol),
  1980. # read syntax for char tables
  1981. (r'#\^\^?', Operator),
  1982. # function shorthand
  1983. (r'#\'', Name.Function),
  1984. # binary rational
  1985. (r'#[bB][+-]?[01]+(/[01]+)?', Number.Bin),
  1986. # octal rational
  1987. (r'#[oO][+-]?[0-7]+(/[0-7]+)?', Number.Oct),
  1988. # hex rational
  1989. (r'#[xX][+-]?[0-9a-fA-F]+(/[0-9a-fA-F]+)?', Number.Hex),
  1990. # radix rational
  1991. (r'#\d+r[+-]?[0-9a-zA-Z]+(/[0-9a-zA-Z]+)?', Number),
  1992. # reference
  1993. (r'#\d+=', Operator),
  1994. (r'#\d+#', Operator),
  1995. # special operators that should have been parsed already
  1996. (r'(,@|,|\.|:)', Operator),
  1997. # special constants
  1998. (r'(t|nil)' + terminated, Name.Constant),
  1999. # functions and variables
  2000. (r'\*' + symbol + r'\*', Name.Variable.Global),
  2001. (symbol, Name.Variable),
  2002. # parentheses
  2003. (r'#\(', Operator, 'body'),
  2004. (r'\(', Punctuation, 'body'),
  2005. (r'\)', Punctuation, '#pop'),
  2006. ],
  2007. 'string': [
  2008. (r'[^"\\`]+', String),
  2009. (r'`%s\'' % symbol, String.Symbol),
  2010. (r'`', String),
  2011. (r'\\.', String),
  2012. (r'\\\n', String),
  2013. (r'"', String, '#pop'),
  2014. ],
  2015. }
  2016. class ShenLexer(RegexLexer):
  2017. """
  2018. Lexer for `Shen <http://shenlanguage.org/>`_ source code.
  2019. .. versionadded:: 2.1
  2020. """
  2021. name = 'Shen'
  2022. aliases = ['shen']
  2023. filenames = ['*.shen']
  2024. mimetypes = ['text/x-shen', 'application/x-shen']
  2025. DECLARATIONS = (
  2026. 'datatype', 'define', 'defmacro', 'defprolog', 'defcc',
  2027. 'synonyms', 'declare', 'package', 'type', 'function',
  2028. )
  2029. SPECIAL_FORMS = (
  2030. 'lambda', 'get', 'let', 'if', 'cases', 'cond', 'put', 'time', 'freeze',
  2031. 'value', 'load', '$', 'protect', 'or', 'and', 'not', 'do', 'output',
  2032. 'prolog?', 'trap-error', 'error', 'make-string', '/.', 'set', '@p',
  2033. '@s', '@v',
  2034. )
  2035. BUILTINS = (
  2036. '==', '=', '*', '+', '-', '/', '<', '>', '>=', '<=', '<-address',
  2037. '<-vector', 'abort', 'absvector', 'absvector?', 'address->', 'adjoin',
  2038. 'append', 'arity', 'assoc', 'bind', 'boolean?', 'bound?', 'call', 'cd',
  2039. 'close', 'cn', 'compile', 'concat', 'cons', 'cons?', 'cut', 'destroy',
  2040. 'difference', 'element?', 'empty?', 'enable-type-theory',
  2041. 'error-to-string', 'eval', 'eval-kl', 'exception', 'explode', 'external',
  2042. 'fail', 'fail-if', 'file', 'findall', 'fix', 'fst', 'fwhen', 'gensym',
  2043. 'get-time', 'hash', 'hd', 'hdstr', 'hdv', 'head', 'identical',
  2044. 'implementation', 'in', 'include', 'include-all-but', 'inferences',
  2045. 'input', 'input+', 'integer?', 'intern', 'intersection', 'is', 'kill',
  2046. 'language', 'length', 'limit', 'lineread', 'loaded', 'macro', 'macroexpand',
  2047. 'map', 'mapcan', 'maxinferences', 'mode', 'n->string', 'nl', 'nth', 'null',
  2048. 'number?', 'occurrences', 'occurs-check', 'open', 'os', 'out', 'port',
  2049. 'porters', 'pos', 'pr', 'preclude', 'preclude-all-but', 'print', 'profile',
  2050. 'profile-results', 'ps', 'quit', 'read', 'read+', 'read-byte', 'read-file',
  2051. 'read-file-as-bytelist', 'read-file-as-string', 'read-from-string',
  2052. 'release', 'remove', 'return', 'reverse', 'run', 'save', 'set',
  2053. 'simple-error', 'snd', 'specialise', 'spy', 'step', 'stinput', 'stoutput',
  2054. 'str', 'string->n', 'string->symbol', 'string?', 'subst', 'symbol?',
  2055. 'systemf', 'tail', 'tc', 'tc?', 'thaw', 'tl', 'tlstr', 'tlv', 'track',
  2056. 'tuple?', 'undefmacro', 'unify', 'unify!', 'union', 'unprofile',
  2057. 'unspecialise', 'untrack', 'variable?', 'vector', 'vector->', 'vector?',
  2058. 'verified', 'version', 'warn', 'when', 'write-byte', 'write-to-file',
  2059. 'y-or-n?',
  2060. )
  2061. BUILTINS_ANYWHERE = ('where', 'skip', '>>', '_', '!', '<e>', '<!>')
  2062. MAPPINGS = {s: Keyword for s in DECLARATIONS}
  2063. MAPPINGS.update((s, Name.Builtin) for s in BUILTINS)
  2064. MAPPINGS.update((s, Keyword) for s in SPECIAL_FORMS)
  2065. valid_symbol_chars = r'[\w!$%*+,<=>?/.\'@&#:-]'
  2066. valid_name = '%s+' % valid_symbol_chars
  2067. symbol_name = r'[a-z!$%%*+,<=>?/.\'@&#_-]%s*' % valid_symbol_chars
  2068. variable = r'[A-Z]%s*' % valid_symbol_chars
  2069. tokens = {
  2070. 'string': [
  2071. (r'"', String, '#pop'),
  2072. (r'c#\d{1,3};', String.Escape),
  2073. (r'~[ARS%]', String.Interpol),
  2074. (r'(?s).', String),
  2075. ],
  2076. 'root': [
  2077. (r'(?s)\\\*.*?\*\\', Comment.Multiline), # \* ... *\
  2078. (r'\\\\.*', Comment.Single), # \\ ...
  2079. (r'\s+', Text),
  2080. (r'_{5,}', Punctuation),
  2081. (r'={5,}', Punctuation),
  2082. (r'(;|:=|\||--?>|<--?)', Punctuation),
  2083. (r'(:-|:|\{|\})', Literal),
  2084. (r'[+-]*\d*\.\d+(e[+-]?\d+)?', Number.Float),
  2085. (r'[+-]*\d+', Number.Integer),
  2086. (r'"', String, 'string'),
  2087. (variable, Name.Variable),
  2088. (r'(true|false|<>|\[\])', Keyword.Pseudo),
  2089. (symbol_name, Literal),
  2090. (r'(\[|\]|\(|\))', Punctuation),
  2091. ],
  2092. }
  2093. def get_tokens_unprocessed(self, text):
  2094. tokens = RegexLexer.get_tokens_unprocessed(self, text)
  2095. tokens = self._process_symbols(tokens)
  2096. tokens = self._process_declarations(tokens)
  2097. return tokens
  2098. def _relevant(self, token):
  2099. return token not in (Text, Comment.Single, Comment.Multiline)
  2100. def _process_declarations(self, tokens):
  2101. opening_paren = False
  2102. for index, token, value in tokens:
  2103. yield index, token, value
  2104. if self._relevant(token):
  2105. if opening_paren and token == Keyword and value in self.DECLARATIONS:
  2106. declaration = value
  2107. for index, token, value in \
  2108. self._process_declaration(declaration, tokens):
  2109. yield index, token, value
  2110. opening_paren = value == '(' and token == Punctuation
  2111. def _process_symbols(self, tokens):
  2112. opening_paren = False
  2113. for index, token, value in tokens:
  2114. if opening_paren and token in (Literal, Name.Variable):
  2115. token = self.MAPPINGS.get(value, Name.Function)
  2116. elif token == Literal and value in self.BUILTINS_ANYWHERE:
  2117. token = Name.Builtin
  2118. opening_paren = value == '(' and token == Punctuation
  2119. yield index, token, value
  2120. def _process_declaration(self, declaration, tokens):
  2121. for index, token, value in tokens:
  2122. if self._relevant(token):
  2123. break
  2124. yield index, token, value
  2125. if declaration == 'datatype':
  2126. prev_was_colon = False
  2127. token = Keyword.Type if token == Literal else token
  2128. yield index, token, value
  2129. for index, token, value in tokens:
  2130. if prev_was_colon and token == Literal:
  2131. token = Keyword.Type
  2132. yield index, token, value
  2133. if self._relevant(token):
  2134. prev_was_colon = token == Literal and value == ':'
  2135. elif declaration == 'package':
  2136. token = Name.Namespace if token == Literal else token
  2137. yield index, token, value
  2138. elif declaration == 'define':
  2139. token = Name.Function if token == Literal else token
  2140. yield index, token, value
  2141. for index, token, value in tokens:
  2142. if self._relevant(token):
  2143. break
  2144. yield index, token, value
  2145. if value == '{' and token == Literal:
  2146. yield index, Punctuation, value
  2147. for index, token, value in self._process_signature(tokens):
  2148. yield index, token, value
  2149. else:
  2150. yield index, token, value
  2151. else:
  2152. token = Name.Function if token == Literal else token
  2153. yield index, token, value
  2154. return
  2155. def _process_signature(self, tokens):
  2156. for index, token, value in tokens:
  2157. if token == Literal and value == '}':
  2158. yield index, Punctuation, value
  2159. return
  2160. elif token in (Literal, Name.Function):
  2161. token = Name.Variable if value.istitle() else Keyword.Type
  2162. yield index, token, value
  2163. class CPSALexer(SchemeLexer):
  2164. """
  2165. A CPSA lexer based on the CPSA language as of version 2.2.12
  2166. .. versionadded:: 2.1
  2167. """
  2168. name = 'CPSA'
  2169. aliases = ['cpsa']
  2170. filenames = ['*.cpsa']
  2171. mimetypes = []
  2172. # list of known keywords and builtins taken form vim 6.4 scheme.vim
  2173. # syntax file.
  2174. _keywords = (
  2175. 'herald', 'vars', 'defmacro', 'include', 'defprotocol', 'defrole',
  2176. 'defskeleton', 'defstrand', 'deflistener', 'non-orig', 'uniq-orig',
  2177. 'pen-non-orig', 'precedes', 'trace', 'send', 'recv', 'name', 'text',
  2178. 'skey', 'akey', 'data', 'mesg',
  2179. )
  2180. _builtins = (
  2181. 'cat', 'enc', 'hash', 'privk', 'pubk', 'invk', 'ltk', 'gen', 'exp',
  2182. )
  2183. # valid names for identifiers
  2184. # well, names can only not consist fully of numbers
  2185. # but this should be good enough for now
  2186. valid_name = r'[\w!$%&*+,/:<=>?@^~|-]+'
  2187. tokens = {
  2188. 'root': [
  2189. # the comments - always starting with semicolon
  2190. # and going to the end of the line
  2191. (r';.*$', Comment.Single),
  2192. # whitespaces - usually not relevant
  2193. (r'\s+', Text),
  2194. # numbers
  2195. (r'-?\d+\.\d+', Number.Float),
  2196. (r'-?\d+', Number.Integer),
  2197. # support for uncommon kinds of numbers -
  2198. # have to figure out what the characters mean
  2199. # (r'(#e|#i|#b|#o|#d|#x)[\d.]+', Number),
  2200. # strings, symbols and characters
  2201. (r'"(\\\\|\\"|[^"])*"', String),
  2202. (r"'" + valid_name, String.Symbol),
  2203. (r"#\\([()/'\"._!§$%& ?=+-]|[a-zA-Z0-9]+)", String.Char),
  2204. # constants
  2205. (r'(#t|#f)', Name.Constant),
  2206. # special operators
  2207. (r"('|#|`|,@|,|\.)", Operator),
  2208. # highlight the keywords
  2209. (words(_keywords, suffix=r'\b'), Keyword),
  2210. # first variable in a quoted string like
  2211. # '(this is syntactic sugar)
  2212. (r"(?<='\()" + valid_name, Name.Variable),
  2213. (r"(?<=#\()" + valid_name, Name.Variable),
  2214. # highlight the builtins
  2215. (words(_builtins, prefix=r'(?<=\()', suffix=r'\b'), Name.Builtin),
  2216. # the remaining functions
  2217. (r'(?<=\()' + valid_name, Name.Function),
  2218. # find the remaining variables
  2219. (valid_name, Name.Variable),
  2220. # the famous parentheses!
  2221. (r'(\(|\))', Punctuation),
  2222. (r'(\[|\])', Punctuation),
  2223. ],
  2224. }
  2225. class XtlangLexer(RegexLexer):
  2226. """An xtlang lexer for the `Extempore programming environment
  2227. <http://extempore.moso.com.au>`_.
  2228. This is a mixture of Scheme and xtlang, really. Keyword lists are
  2229. taken from the Extempore Emacs mode
  2230. (https://github.com/extemporelang/extempore-emacs-mode)
  2231. .. versionadded:: 2.2
  2232. """
  2233. name = 'xtlang'
  2234. aliases = ['extempore']
  2235. filenames = ['*.xtm']
  2236. mimetypes = []
  2237. common_keywords = (
  2238. 'lambda', 'define', 'if', 'else', 'cond', 'and',
  2239. 'or', 'let', 'begin', 'set!', 'map', 'for-each',
  2240. )
  2241. scheme_keywords = (
  2242. 'do', 'delay', 'quasiquote', 'unquote', 'unquote-splicing', 'eval',
  2243. 'case', 'let*', 'letrec', 'quote',
  2244. )
  2245. xtlang_bind_keywords = (
  2246. 'bind-func', 'bind-val', 'bind-lib', 'bind-type', 'bind-alias',
  2247. 'bind-poly', 'bind-dylib', 'bind-lib-func', 'bind-lib-val',
  2248. )
  2249. xtlang_keywords = (
  2250. 'letz', 'memzone', 'cast', 'convert', 'dotimes', 'doloop',
  2251. )
  2252. common_functions = (
  2253. '*', '+', '-', '/', '<', '<=', '=', '>', '>=', '%', 'abs', 'acos',
  2254. 'angle', 'append', 'apply', 'asin', 'assoc', 'assq', 'assv',
  2255. 'atan', 'boolean?', 'caaaar', 'caaadr', 'caaar', 'caadar',
  2256. 'caaddr', 'caadr', 'caar', 'cadaar', 'cadadr', 'cadar',
  2257. 'caddar', 'cadddr', 'caddr', 'cadr', 'car', 'cdaaar',
  2258. 'cdaadr', 'cdaar', 'cdadar', 'cdaddr', 'cdadr', 'cdar',
  2259. 'cddaar', 'cddadr', 'cddar', 'cdddar', 'cddddr', 'cdddr',
  2260. 'cddr', 'cdr', 'ceiling', 'cons', 'cos', 'floor', 'length',
  2261. 'list', 'log', 'max', 'member', 'min', 'modulo', 'not',
  2262. 'reverse', 'round', 'sin', 'sqrt', 'substring', 'tan',
  2263. 'println', 'random', 'null?', 'callback', 'now',
  2264. )
  2265. scheme_functions = (
  2266. 'call-with-current-continuation', 'call-with-input-file',
  2267. 'call-with-output-file', 'call-with-values', 'call/cc',
  2268. 'char->integer', 'char-alphabetic?', 'char-ci<=?', 'char-ci<?',
  2269. 'char-ci=?', 'char-ci>=?', 'char-ci>?', 'char-downcase',
  2270. 'char-lower-case?', 'char-numeric?', 'char-ready?',
  2271. 'char-upcase', 'char-upper-case?', 'char-whitespace?',
  2272. 'char<=?', 'char<?', 'char=?', 'char>=?', 'char>?', 'char?',
  2273. 'close-input-port', 'close-output-port', 'complex?',
  2274. 'current-input-port', 'current-output-port', 'denominator',
  2275. 'display', 'dynamic-wind', 'eof-object?', 'eq?', 'equal?',
  2276. 'eqv?', 'even?', 'exact->inexact', 'exact?', 'exp', 'expt',
  2277. 'force', 'gcd', 'imag-part', 'inexact->exact', 'inexact?',
  2278. 'input-port?', 'integer->char', 'integer?',
  2279. 'interaction-environment', 'lcm', 'list->string',
  2280. 'list->vector', 'list-ref', 'list-tail', 'list?', 'load',
  2281. 'magnitude', 'make-polar', 'make-rectangular', 'make-string',
  2282. 'make-vector', 'memq', 'memv', 'negative?', 'newline',
  2283. 'null-environment', 'number->string', 'number?',
  2284. 'numerator', 'odd?', 'open-input-file', 'open-output-file',
  2285. 'output-port?', 'pair?', 'peek-char', 'port?', 'positive?',
  2286. 'procedure?', 'quotient', 'rational?', 'rationalize', 'read',
  2287. 'read-char', 'real-part', 'real?',
  2288. 'remainder', 'scheme-report-environment', 'set-car!', 'set-cdr!',
  2289. 'string', 'string->list', 'string->number', 'string->symbol',
  2290. 'string-append', 'string-ci<=?', 'string-ci<?', 'string-ci=?',
  2291. 'string-ci>=?', 'string-ci>?', 'string-copy', 'string-fill!',
  2292. 'string-length', 'string-ref', 'string-set!', 'string<=?',
  2293. 'string<?', 'string=?', 'string>=?', 'string>?', 'string?',
  2294. 'symbol->string', 'symbol?', 'transcript-off', 'transcript-on',
  2295. 'truncate', 'values', 'vector', 'vector->list', 'vector-fill!',
  2296. 'vector-length', 'vector?',
  2297. 'with-input-from-file', 'with-output-to-file', 'write',
  2298. 'write-char', 'zero?',
  2299. )
  2300. xtlang_functions = (
  2301. 'toString', 'afill!', 'pfill!', 'tfill!', 'tbind', 'vfill!',
  2302. 'array-fill!', 'pointer-fill!', 'tuple-fill!', 'vector-fill!', 'free',
  2303. 'array', 'tuple', 'list', '~', 'cset!', 'cref', '&', 'bor',
  2304. 'ang-names', '<<', '>>', 'nil', 'printf', 'sprintf', 'null', 'now',
  2305. 'pset!', 'pref-ptr', 'vset!', 'vref', 'aset!', 'aref', 'aref-ptr',
  2306. 'tset!', 'tref', 'tref-ptr', 'salloc', 'halloc', 'zalloc', 'alloc',
  2307. 'schedule', 'exp', 'log', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan',
  2308. 'sqrt', 'expt', 'floor', 'ceiling', 'truncate', 'round',
  2309. 'llvm_printf', 'push_zone', 'pop_zone', 'memzone', 'callback',
  2310. 'llvm_sprintf', 'make-array', 'array-set!', 'array-ref',
  2311. 'array-ref-ptr', 'pointer-set!', 'pointer-ref', 'pointer-ref-ptr',
  2312. 'stack-alloc', 'heap-alloc', 'zone-alloc', 'make-tuple', 'tuple-set!',
  2313. 'tuple-ref', 'tuple-ref-ptr', 'closure-set!', 'closure-ref', 'pref',
  2314. 'pdref', 'impc_null', 'bitcast', 'void', 'ifret', 'ret->', 'clrun->',
  2315. 'make-env-zone', 'make-env', '<>', 'dtof', 'ftod', 'i1tof',
  2316. 'i1tod', 'i1toi8', 'i1toi32', 'i1toi64', 'i8tof', 'i8tod',
  2317. 'i8toi1', 'i8toi32', 'i8toi64', 'i32tof', 'i32tod', 'i32toi1',
  2318. 'i32toi8', 'i32toi64', 'i64tof', 'i64tod', 'i64toi1',
  2319. 'i64toi8', 'i64toi32',
  2320. )
  2321. # valid names for Scheme identifiers (names cannot consist fully
  2322. # of numbers, but this should be good enough for now)
  2323. valid_scheme_name = r'[\w!$%&*+,/:<=>?@^~|-]+'
  2324. # valid characters in xtlang names & types
  2325. valid_xtlang_name = r'[\w.!-]+'
  2326. valid_xtlang_type = r'[]{}[\w<>,*/|!-]+'
  2327. tokens = {
  2328. # keep track of when we're exiting the xtlang form
  2329. 'xtlang': [
  2330. (r'\(', Punctuation, '#push'),
  2331. (r'\)', Punctuation, '#pop'),
  2332. (r'(?<=bind-func\s)' + valid_xtlang_name, Name.Function),
  2333. (r'(?<=bind-val\s)' + valid_xtlang_name, Name.Function),
  2334. (r'(?<=bind-type\s)' + valid_xtlang_name, Name.Function),
  2335. (r'(?<=bind-alias\s)' + valid_xtlang_name, Name.Function),
  2336. (r'(?<=bind-poly\s)' + valid_xtlang_name, Name.Function),
  2337. (r'(?<=bind-lib\s)' + valid_xtlang_name, Name.Function),
  2338. (r'(?<=bind-dylib\s)' + valid_xtlang_name, Name.Function),
  2339. (r'(?<=bind-lib-func\s)' + valid_xtlang_name, Name.Function),
  2340. (r'(?<=bind-lib-val\s)' + valid_xtlang_name, Name.Function),
  2341. # type annotations
  2342. (r':' + valid_xtlang_type, Keyword.Type),
  2343. # types
  2344. (r'(<' + valid_xtlang_type + r'>|\|' + valid_xtlang_type + r'\||/' +
  2345. valid_xtlang_type + r'/|' + valid_xtlang_type + r'\*)\**',
  2346. Keyword.Type),
  2347. # keywords
  2348. (words(xtlang_keywords, prefix=r'(?<=\()'), Keyword),
  2349. # builtins
  2350. (words(xtlang_functions, prefix=r'(?<=\()'), Name.Function),
  2351. include('common'),
  2352. # variables
  2353. (valid_xtlang_name, Name.Variable),
  2354. ],
  2355. 'scheme': [
  2356. # quoted symbols
  2357. (r"'" + valid_scheme_name, String.Symbol),
  2358. # char literals
  2359. (r"#\\([()/'\"._!§$%& ?=+-]|[a-zA-Z0-9]+)", String.Char),
  2360. # special operators
  2361. (r"('|#|`|,@|,|\.)", Operator),
  2362. # keywords
  2363. (words(scheme_keywords, prefix=r'(?<=\()'), Keyword),
  2364. # builtins
  2365. (words(scheme_functions, prefix=r'(?<=\()'), Name.Function),
  2366. include('common'),
  2367. # variables
  2368. (valid_scheme_name, Name.Variable),
  2369. ],
  2370. # common to both xtlang and Scheme
  2371. 'common': [
  2372. # comments
  2373. (r';.*$', Comment.Single),
  2374. # whitespaces - usually not relevant
  2375. (r'\s+', Text),
  2376. # numbers
  2377. (r'-?\d+\.\d+', Number.Float),
  2378. (r'-?\d+', Number.Integer),
  2379. # binary/oct/hex literals
  2380. (r'(#b|#o|#x)[\d.]+', Number),
  2381. # strings
  2382. (r'"(\\\\|\\"|[^"])*"', String),
  2383. # true/false constants
  2384. (r'(#t|#f)', Name.Constant),
  2385. # keywords
  2386. (words(common_keywords, prefix=r'(?<=\()'), Keyword),
  2387. # builtins
  2388. (words(common_functions, prefix=r'(?<=\()'), Name.Function),
  2389. # the famous parentheses!
  2390. (r'(\(|\))', Punctuation),
  2391. ],
  2392. 'root': [
  2393. # go into xtlang mode
  2394. (words(xtlang_bind_keywords, prefix=r'(?<=\()', suffix=r'\b'),
  2395. Keyword, 'xtlang'),
  2396. include('scheme')
  2397. ],
  2398. }
  2399. class FennelLexer(RegexLexer):
  2400. """A lexer for the `Fennel programming language <https://fennel-lang.org>`_.
  2401. Fennel compiles to Lua, so all the Lua builtins are recognized as well
  2402. as the special forms that are particular to the Fennel compiler.
  2403. .. versionadded:: 2.3
  2404. """
  2405. name = 'Fennel'
  2406. aliases = ['fennel', 'fnl']
  2407. filenames = ['*.fnl']
  2408. # these two lists are taken from fennel-mode.el:
  2409. # https://gitlab.com/technomancy/fennel-mode
  2410. # this list is current as of Fennel version 0.1.0.
  2411. special_forms = (
  2412. u'require-macros', u'eval-compiler',
  2413. u'do', u'values', u'if', u'when', u'each', u'for', u'fn', u'lambda',
  2414. u'λ', u'set', u'global', u'var', u'local', u'let', u'tset', u'doto',
  2415. u'set-forcibly!', u'defn', u'partial', u'while', u'or', u'and', u'true',
  2416. u'false', u'nil', u'.', u'+', u'..', u'^', u'-', u'*', u'%', u'/', u'>',
  2417. u'<', u'>=', u'<=', u'=', u'~=', u'#', u'...', u':', u'->', u'->>',
  2418. )
  2419. # Might be nicer to use the list from _lua_builtins.py but it's unclear how?
  2420. builtins = (
  2421. u'_G', u'_VERSION', u'arg', u'assert', u'bit32', u'collectgarbage',
  2422. u'coroutine', u'debug', u'dofile', u'error', u'getfenv',
  2423. u'getmetatable', u'io', u'ipairs', u'load', u'loadfile', u'loadstring',
  2424. u'math', u'next', u'os', u'package', u'pairs', u'pcall', u'print',
  2425. u'rawequal', u'rawget', u'rawlen', u'rawset', u'require', u'select',
  2426. u'setfenv', u'setmetatable', u'string', u'table', u'tonumber',
  2427. u'tostring', u'type', u'unpack', u'xpcall'
  2428. )
  2429. # based on the scheme definition, but disallowing leading digits and commas
  2430. valid_name = r'[a-zA-Z_!$%&*+/:<=>?@^~|-][\w!$%&*+/:<=>?@^~|\.-]*'
  2431. tokens = {
  2432. 'root': [
  2433. # the only comment form is a semicolon; goes to the end of the line
  2434. (r';.*$', Comment.Single),
  2435. (r'[,\s]+', Text),
  2436. (r'-?\d+\.\d+', Number.Float),
  2437. (r'-?\d+', Number.Integer),
  2438. (r'"(\\\\|\\"|[^"])*"', String),
  2439. (r"'(\\\\|\\'|[^'])*'", String),
  2440. # these are technically strings, but it's worth visually
  2441. # distinguishing them because their intent is different
  2442. # from regular strings.
  2443. (r':' + valid_name, String.Symbol),
  2444. # special forms are keywords
  2445. (words(special_forms, suffix=' '), Keyword),
  2446. # lua standard library are builtins
  2447. (words(builtins, suffix=' '), Name.Builtin),
  2448. # special-case the vararg symbol
  2449. (r'\.\.\.', Name.Variable),
  2450. # regular identifiers
  2451. (valid_name, Name.Variable),
  2452. # all your normal paired delimiters for your programming enjoyment
  2453. (r'(\(|\))', Punctuation),
  2454. (r'(\[|\])', Punctuation),
  2455. (r'(\{|\})', Punctuation),
  2456. ]
  2457. }