lisp.py 138 KB

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