logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

clojure.lua (10464B)


  1. -- Copyright 2018-2024 Mitchell. See LICENSE.
  2. -- Clojure LPeg lexer.
  3. -- Contributed by Christos Chatzifountas.
  4. local lexer = require('lexer')
  5. local token, word_match = lexer.token, lexer.word_match
  6. local P, S = lpeg.P, lpeg.S
  7. local lex = lexer.new('clojure')
  8. -- Whitespace.
  9. lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
  10. -- Keywords.
  11. lex:add_rule('keyword', token(lexer.KEYWORD, word_match{
  12. 'fn', 'try', 'catch', 'finaly', 'defonce', 'and', 'case', 'cond', 'def', 'defn', 'defmacro', 'do',
  13. 'else', 'when', 'when-let', 'if-let', 'if', 'let', 'loop', 'or', 'recur', 'quote'
  14. }))
  15. -- Functions.
  16. lex:add_rule('function', token(lexer.FUNCTION, word_match{
  17. '*', '+', '-', '->ArrayChunk', '->Eduction', '->Vec', '->VecNode', '->VecSeq', '/', '<', '<=',
  18. '=', '==', '>', '>=', 'StackTraceElement->vec', 'Throwable->map', 'accessor', 'aclone',
  19. 'add-classpath', 'add-watch', 'agent', 'agent-error', 'agent-errors', 'aget', 'alength', 'alias',
  20. 'all-ns', 'alter', 'alter-meta!', 'alter-var-root', 'ancestors', 'any?', 'apply', 'array-map',
  21. 'aset', 'aset-boolean', 'aset-byte', 'aset-char', 'aset-double', 'aset-float', 'aset-int',
  22. 'aset-long', 'aset-short', 'assoc', 'assoc!', 'assoc-in', 'associative?', 'atom', 'await',
  23. 'await-for', 'bases', 'bean', 'bigdec', 'bigint', 'biginteger', 'bit-and', 'bit-and-not',
  24. 'bit-clear', 'bit-flip', 'bit-not', 'bit-or', 'bit-set', 'bit-shift-left', 'bit-shift-right',
  25. 'bit-test', 'bit-xor', 'boolean', 'boolean-array', 'boolean?', 'booleans', 'bound-fn*', 'bound?',
  26. 'bounded-count', 'butlast', 'byte', 'byte-array', 'bytes', 'bytes?', 'cast', 'cat', 'char',
  27. 'char-array', 'char?', 'chars', 'class', 'class?', 'clear-agent-errors', 'clojure-version',
  28. 'coll?', 'commute', 'comp', 'comparator', 'compare', 'compare-and-set!', 'compile', 'complement',
  29. 'completing', 'concat', 'conj', 'conj!', 'cons', 'constantly', 'construct-proxy', 'contains?',
  30. 'count', 'counted?', 'create-ns', 'create-struct', 'cycle', 'dec', 'decimal?', 'dedupe', 'delay?',
  31. 'deliver', 'denominator', 'deref', 'derive', 'descendants', 'disj', 'disj!', 'dissoc', 'dissoc!',
  32. 'distinct', 'distinct?', 'doall', 'dorun', 'double', 'double-array', 'double?', 'doubles', 'drop',
  33. 'drop-last', 'drop-while', 'eduction', 'empty', 'empty?', 'ensure', 'ensure-reduced',
  34. 'enumeration-seq', 'error-handler', 'error-mode', 'eval', 'even?', 'every-pred', 'every?',
  35. 'ex-data', 'ex-info', 'extend', 'extenders', 'extends?', 'false?', 'ffirst', 'file-seq', 'filter',
  36. 'filterv', 'find', 'find-keyword', 'find-ns', 'find-var', 'first', 'flatten', 'float',
  37. 'float-array', 'float?', 'floats', 'flush', 'fn?', 'fnext', 'fnil', 'force', 'format',
  38. 'frequencies', 'future-call', 'future-cancel', 'future-cancelled?', 'future-done?', 'future?',
  39. 'gensym', 'get', 'get-in', 'get-method', 'get-proxy-class', 'get-thread-bindings',
  40. 'get-validator', 'group-by', 'halt-when', 'hash', 'hash-map', 'hash-ordered-coll', 'hash-set',
  41. 'hash-unordered-coll', 'ident?', 'identical?', 'identity', 'ifn?', 'in-ns', 'inc', 'inc',
  42. 'indexed?', 'init-proxy', 'inst-ms', 'inst?', 'instance?', 'int', 'int-array', 'int?', 'integer?',
  43. 'interleave', 'intern', 'interpose', 'into', 'into-array', 'ints', 'isa?', 'iterate',
  44. 'iterator-seq', 'juxt', 'keep', 'keep-indexed', 'key', 'keys', 'keyword', 'keyword?', 'last',
  45. 'line-seq', 'list', 'list*', 'list?', 'load', 'load-file', 'load-reader', 'load-string',
  46. 'loaded-libs', 'long', 'long-array', 'longs', 'macroexpand', 'macroexpand-1', 'make-array',
  47. 'make-hierarchy', 'map', 'map-entry?', 'map-indexed', 'map?', 'mapcat', 'mapv', 'max', 'max-key',
  48. 'memoize', 'merge', 'merge-with', 'meta', 'methods', 'min', 'min-key', 'mix-collection-hash',
  49. 'mod', 'name', 'namespace', 'namespace-munge', 'nat-int?', 'neg-int?', 'neg?', 'newline', 'next',
  50. 'nfirst', 'nil?', 'nnext', 'not', 'not-any?', 'not-empty', 'not-every?', 'not=', 'ns-aliases',
  51. 'ns-imports', 'ns-interns', 'ns-map', 'ns-name', 'ns-publics', 'ns-refers', 'ns-resolve',
  52. 'ns-unalias', 'ns-unmap', 'nth', 'nthnext', 'nthrest', 'num', 'number?', 'numerator',
  53. 'object-array', 'odd?', 'parents', 'partial', 'partition', 'partition-all', 'partition-by',
  54. 'pcalls', 'peek', 'persistent!', 'pmap', 'pop', 'pop!', 'pop-thread-bindings', 'pos-int?', 'pos?',
  55. 'pr-str', 'prefer-method', 'prefers', 'print', 'print-str', 'printf', 'println', 'println-str',
  56. 'prn', 'prn-str', 'promise', 'proxy-mappings', 'push-thread-bindings', 'qualified-ident?',
  57. 'qualified-keyword?', 'qualified-symbol?', 'quot', 'rand', 'rand-int', 'rand-nth',
  58. 'random-sample', 'range', 'ratio?', 'rational?', 'rationalize', 're-find', 're-groups',
  59. 're-matcher', 're-matches', 're-pattern', 're-seq', 'read', 'read-line', 'read-string',
  60. 'reader-conditional', 'reader-conditional?', 'realized?', 'record?', 'reduce', 'reduce-kv',
  61. 'reduced', 'reduced?', 'reductions', 'ref', 'ref-history-count', 'ref-max-history',
  62. 'ref-min-history', 'ref-set', 'refer', 'release-pending-sends', 'rem', 'remove',
  63. 'remove-all-methods', 'remove-method', 'remove-ns', 'remove-watch', 'repeat', 'repeatedly',
  64. 'replace', 'replicate', 'require', 'reset!', 'reset-meta!', 'reset-vals!', 'resolve', 'rest',
  65. 'restart-agent', 'resultset-seq', 'reverse', 'reversible?', 'rseq', 'rsubseq', 'run!',
  66. 'satisfies?', 'second', 'select-keys', 'send', 'send-off', 'send-via', 'seq', 'seq?', 'seqable?',
  67. 'seque', 'sequence', 'sequential?', 'set', 'set-agent-send-executor!',
  68. 'set-agent-send-off-executor!', 'set-error-handler!', 'set-error-mode!', 'set-validator!', 'set?',
  69. 'short', 'short-array', 'shorts', 'shuffle', 'shutdown-agents', 'simple-ident?',
  70. 'simple-keyword?', 'simple-symbol?', 'slurp', 'some', 'some-fn', 'some?', 'sort', 'sort-by',
  71. 'sorted-map', 'sorted-map-by', 'sorted-set', 'sorted-set-by', 'sorted?', 'special-symbol?',
  72. 'spit', 'split-at', 'split-with', 'str', 'string?', 'struct', 'struct-map', 'subs', 'subseq',
  73. 'subvec', 'supers', 'swap!', 'swap-vals!', 'symbol', 'symbol?', 'tagged-literal',
  74. 'tagged-literal?', 'take', 'take-last', 'take-nth', 'take-while', 'test', 'the-ns',
  75. 'thread-bound?', 'to-array', 'to-array-2d', 'trampoline', 'transduce', 'transient', 'tree-seq',
  76. 'true?', 'type', 'unchecked-add', 'unchecked-add-int', 'unchecked-byte', 'unchecked-char',
  77. 'unchecked-dec', 'unchecked-dec-int', 'unchecked-divide-int', 'unchecked-double',
  78. 'unchecked-float', 'unchecked-inc', 'unchecked-inc-int', 'unchecked-int', 'unchecked-long',
  79. 'unchecked-multiply', 'unchecked-multiply-int', 'unchecked-negate', 'unchecked-negate-int',
  80. 'unchecked-remainder-int', 'unchecked-short', 'unchecked-subtract', 'unchecked-subtract-int',
  81. 'underive', 'unreduced', 'unsigned-bit-shift-right', 'update', 'update-in', 'update-proxy',
  82. 'uri?', 'use', 'uuid?', 'val', 'vals', 'var-get', 'var-set', 'var?', 'vary-meta', 'vec', 'vector',
  83. 'vector-of', 'vector?', 'volatile!', 'volatile?', 'vreset!', 'with-bindings*', 'with-meta',
  84. 'with-redefs-fn', 'xml-seq', 'zero?', 'zipmap', 'diff-similar', 'equality-partition', 'diff',
  85. 'inspect', 'inspect-table', 'inspect-tree', 'validated', 'browse-url', 'as-file', 'as-url',
  86. 'make-input-stream', 'make-output-stream', 'make-reader', 'make-writer', 'as-relative-path',
  87. 'copy', 'delete-file', 'file', 'input-stream', 'make-parents', 'output-stream', 'reader',
  88. 'resource', 'writer', 'add-local-javadoc', 'add-remote-javadoc', 'javadoc', 'sh', 'demunge',
  89. 'load-script', 'main', 'repl', 'repl-caught', 'repl-exception', 'repl-prompt', 'repl-read',
  90. 'root-cause', 'skip-if-eol', 'skip-whitespace', 'stack-element-str', 'cl-format', 'fresh-line',
  91. 'get-pretty-writer', 'pprint', 'pprint-indent', 'pprint-newline', 'pprint-tab', 'print-table',
  92. 'set-pprint-dispatch', 'write', 'write-out', 'resolve-class', 'do-reflect', 'typename',
  93. '->AsmReflector', '->Constructor', '->Field', '->JavaReflector', '->Method', 'map->Constructor',
  94. 'map->Field', 'map->Method', 'reflect', 'type-reflect', 'apropos', 'dir-fn', 'find-doc', 'pst',
  95. 'set-break-handler!', 'source-fn', 'thread-stopper', 'difference', 'index', 'intersection',
  96. 'join', 'map-invert', 'project', 'rename', 'rename-keys', 'select', 'subset?', 'superset?',
  97. 'union', 'e', 'print-cause-trace', 'print-stack-trace', 'print-throwable', 'print-trace-element',
  98. 'blank?', 'capitalize', 'ends-with?', 'escape', 'includes?', 'index-of', 'last-index-of',
  99. 'lower-case', 're-quote-replacement', 'replace-first', 'split', 'split-lines', 'starts-with?',
  100. 'trim', 'trim-newline', 'triml', 'trimr', 'upper-case', 'apply-template', 'assert-any',
  101. 'assert-predicate', 'compose-fixtures', 'do-report', 'file-position', 'function?',
  102. 'get-possibly-unbound-var', 'inc-report-counter', 'join-fixtures', 'run-all-tests', 'run-tests',
  103. 'successful?', 'test-all-vars', 'test-ns', 'test-vars', 'testing-contexts-str',
  104. 'testing-vars-str', 'keywordize-keys', 'macroexpand-all', 'postwalk', 'postwalk-demo',
  105. 'postwalk-replace', 'prewalk', 'prewalk-demo', 'prewalk-replace', 'stringify-keys', 'walk',
  106. 'append-child', 'branch?', 'children', 'down', 'edit', 'end?', 'insert-child', 'insert-left',
  107. 'insert-right', 'left', 'leftmost', 'lefts', 'make-node', 'node', 'path', 'prev', 'right',
  108. 'rightmost', 'rights', 'root', 'seq-zip', 'up', 'vector-zip', 'xml-zip', 'zipper'
  109. }))
  110. -- Numbers.
  111. lex:add_rule('number', token(lexer.NUMBER, P('-')^-1 * lexer.digit^1 * (S('./') * lexer.digit^1)^-1))
  112. -- Identifiers.
  113. local word = (lexer.alpha + S('-!?*$=-')) * (lexer.alnum + S('.-!?*$+-'))^0
  114. lex:add_rule('identifier', token(lexer.IDENTIFIER, word))
  115. -- Strings.
  116. lex:add_rule('string', token(lexer.STRING, lexer.range('"')))
  117. -- Comments.
  118. local line_comment = lexer.to_eol(';')
  119. local block_comment = lexer.range('#_(', ')')
  120. lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
  121. -- Operators.
  122. lex:add_rule('operator', token(lexer.OPERATOR, S('`@()')))
  123. -- Clojure keywords.
  124. lex:add_rule('clojure_keyword', token('clojure_keyword', ':' * S(':')^-1 * word * ('/' * word)^-1))
  125. lex:add_style('clojure_keyword', lexer.styles.type)
  126. lex:add_rule('clojure_symbol', token('clojure_symbol', "\'" * word * ('/' * word)^-1))
  127. lex:add_style('clojure_symbol', lexer.styles.type .. {bold = true})
  128. -- Fold points.
  129. lex:add_fold_point(lexer.COMMENT, '#_(', ')')
  130. lex:add_fold_point(lexer.OPERATOR, '(', ')')
  131. lex:add_fold_point(lexer.OPERATOR, '[', ']')
  132. lex:add_fold_point(lexer.OPERATOR, '{', '}')
  133. lexer.property['scintillua.comment'] = ';'
  134. return lex