haskell_highlight_rules.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2012, Ajax.org B.V.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Ajax.org B.V. nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * ***** END LICENSE BLOCK ***** */
  30. /* This file was autogenerated from tm bundles\haskell.tmbundle\Syntaxes\Haskell.plist (uuid: ) */
  31. /****************************************************************************************
  32. * IT MIGHT NOT BE PERFECT ...But it's a good start from an existing *.tmlanguage file. *
  33. * fileTypes *
  34. ****************************************************************************************/
  35. define(function(require, exports, module) {
  36. "use strict";
  37. var oop = require("../lib/oop");
  38. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  39. var HaskellHighlightRules = function() {
  40. // regexp must not have capturing parentheses. Use (?:) instead.
  41. // regexps are ordered -> the first match is used
  42. this.$rules = { start:
  43. [ { token:
  44. [ 'punctuation.definition.entity.haskell',
  45. 'keyword.operator.function.infix.haskell',
  46. 'punctuation.definition.entity.haskell' ],
  47. regex: '(`)([a-zA-Z_\']*?)(`)',
  48. comment: 'In case this regex seems unusual for an infix operator, note that Haskell allows any ordinary function application (elem 4 [1..10]) to be rewritten as an infix expression (4 `elem` [1..10]).' },
  49. { token: 'constant.language.unit.haskell', regex: '\\(\\)' },
  50. { token: 'constant.language.empty-list.haskell',
  51. regex: '\\[\\]' },
  52. { token: 'keyword.other.haskell',
  53. regex: '\\bmodule\\b',
  54. push:
  55. [ { token: 'keyword.other.haskell', regex: '\\bwhere\\b', next: 'pop' },
  56. { include: '#module_name' },
  57. { include: '#module_exports' },
  58. { token: 'invalid', regex: '[a-z]+' },
  59. { defaultToken: 'meta.declaration.module.haskell' } ] },
  60. { token: 'keyword.other.haskell',
  61. regex: '\\bclass\\b',
  62. push:
  63. [ { token: 'keyword.other.haskell',
  64. regex: '\\bwhere\\b',
  65. next: 'pop' },
  66. { token: 'support.class.prelude.haskell',
  67. regex: '\\b(?:Monad|Functor|Eq|Ord|Read|Show|Num|(?:Frac|Ra)tional|Enum|Bounded|Real(?:Frac|Float)?|Integral|Floating)\\b' },
  68. { token: 'entity.other.inherited-class.haskell',
  69. regex: '[A-Z][A-Za-z_\']*' },
  70. { token: 'variable.other.generic-type.haskell',
  71. regex: '\\b[a-z][a-zA-Z0-9_\']*\\b' },
  72. { defaultToken: 'meta.declaration.class.haskell' } ] },
  73. { token: 'keyword.other.haskell',
  74. regex: '\\binstance\\b',
  75. push:
  76. [ { token: 'keyword.other.haskell',
  77. regex: '\\bwhere\\b|$',
  78. next: 'pop' },
  79. { include: '#type_signature' },
  80. { defaultToken: 'meta.declaration.instance.haskell' } ] },
  81. { token: 'keyword.other.haskell',
  82. regex: 'import',
  83. push:
  84. [ { token: 'meta.import.haskell', regex: '$|;', next: 'pop' },
  85. { token: 'keyword.other.haskell', regex: 'qualified|as|hiding' },
  86. { include: '#module_name' },
  87. { include: '#module_exports' },
  88. { defaultToken: 'meta.import.haskell' } ] },
  89. { token: [ 'keyword.other.haskell', 'meta.deriving.haskell' ],
  90. regex: '(deriving)(\\s*\\()',
  91. push:
  92. [ { token: 'meta.deriving.haskell', regex: '\\)', next: 'pop' },
  93. { token: 'entity.other.inherited-class.haskell',
  94. regex: '\\b[A-Z][a-zA-Z_\']*' },
  95. { defaultToken: 'meta.deriving.haskell' } ] },
  96. { token: 'keyword.other.haskell',
  97. regex: '\\b(?:deriving|where|data|type|case|of|let|in|newtype|default)\\b' },
  98. { token: 'keyword.operator.haskell', regex: '\\binfix[lr]?\\b' },
  99. { token: 'keyword.control.haskell',
  100. regex: '\\b(?:do|if|then|else)\\b' },
  101. { token: 'constant.numeric.float.haskell',
  102. regex: '\\b(?:[0-9]+\\.[0-9]+(?:[eE][+-]?[0-9]+)?|[0-9]+[eE][+-]?[0-9]+)\\b',
  103. comment: 'Floats are always decimal' },
  104. { token: 'constant.numeric.haskell',
  105. regex: '\\b(?:[0-9]+|0(?:[xX][0-9a-fA-F]+|[oO][0-7]+))\\b' },
  106. { token:
  107. [ 'meta.preprocessor.c',
  108. 'punctuation.definition.preprocessor.c',
  109. 'meta.preprocessor.c' ],
  110. regex: '^(\\s*)(#)(\\s*\\w+)',
  111. comment: 'In addition to Haskell\'s "native" syntax, GHC permits the C preprocessor to be run on a source file.' },
  112. { include: '#pragma' },
  113. { token: 'punctuation.definition.string.begin.haskell',
  114. regex: '"',
  115. push:
  116. [ { token: 'punctuation.definition.string.end.haskell',
  117. regex: '"',
  118. next: 'pop' },
  119. { token: 'constant.character.escape.haskell',
  120. regex: '\\\\(?:NUL|SOH|STX|ETX|EOT|ENQ|ACK|BEL|BS|HT|LF|VT|FF|CR|SO|SI|DLE|DC1|DC2|DC3|DC4|NAK|SYN|ETB|CAN|EM|SUB|ESC|FS|GS|RS|US|SP|DEL|[abfnrtv\\\\\\"\'\\&])' },
  121. { token: 'constant.character.escape.octal.haskell',
  122. regex: '\\\\o[0-7]+|\\\\x[0-9A-Fa-f]+|\\\\[0-9]+' },
  123. { token: 'constant.character.escape.control.haskell',
  124. regex: '\\^[A-Z@\\[\\]\\\\\\^_]' },
  125. { defaultToken: 'string.quoted.double.haskell' } ] },
  126. { token:
  127. [ 'punctuation.definition.string.begin.haskell',
  128. 'string.quoted.single.haskell',
  129. 'constant.character.escape.haskell',
  130. 'constant.character.escape.octal.haskell',
  131. 'constant.character.escape.hexadecimal.haskell',
  132. 'constant.character.escape.control.haskell',
  133. 'punctuation.definition.string.end.haskell' ],
  134. regex: '(\')(?:([\\ -\\[\\]-~])|(\\\\(?:NUL|SOH|STX|ETX|EOT|ENQ|ACK|BEL|BS|HT|LF|VT|FF|CR|SO|SI|DLE|DC1|DC2|DC3|DC4|NAK|SYN|ETB|CAN|EM|SUB|ESC|FS|GS|RS|US|SP|DEL|[abfnrtv\\\\\\"\'\\&]))|(\\\\o[0-7]+)|(\\\\x[0-9A-Fa-f]+)|(\\^[A-Z@\\[\\]\\\\\\^_]))(\')' },
  135. { token:
  136. [ 'meta.function.type-declaration.haskell',
  137. 'entity.name.function.haskell',
  138. 'meta.function.type-declaration.haskell',
  139. 'keyword.other.double-colon.haskell' ],
  140. regex: '^(\\s*)([a-z_][a-zA-Z0-9_\']*|\\([|!%$+\\-.,=</>]+\\))(\\s*)(::)',
  141. push:
  142. [ { token: 'meta.function.type-declaration.haskell',
  143. regex: '$',
  144. next: 'pop' },
  145. { include: '#type_signature' },
  146. { defaultToken: 'meta.function.type-declaration.haskell' } ] },
  147. { token: 'support.constant.haskell',
  148. regex: '\\b(?:Just|Nothing|Left|Right|True|False|LT|EQ|GT|\\(\\)|\\[\\])\\b' },
  149. { token: 'constant.other.haskell', regex: '\\b[A-Z]\\w*\\b' },
  150. { include: '#comments' },
  151. { token: 'support.function.prelude.haskell',
  152. regex: '\\b(?:abs|acos|acosh|all|and|any|appendFile|applyM|asTypeOf|asin|asinh|atan|atan2|atanh|break|catch|ceiling|compare|concat|concatMap|const|cos|cosh|curry|cycle|decodeFloat|div|divMod|drop|dropWhile|elem|encodeFloat|enumFrom|enumFromThen|enumFromThenTo|enumFromTo|error|even|exp|exponent|fail|filter|flip|floatDigits|floatRadix|floatRange|floor|fmap|foldl|foldl1|foldr|foldr1|fromEnum|fromInteger|fromIntegral|fromRational|fst|gcd|getChar|getContents|getLine|head|id|init|interact|ioError|isDenormalized|isIEEE|isInfinite|isNaN|isNegativeZero|iterate|last|lcm|length|lex|lines|log|logBase|lookup|map|mapM|mapM_|max|maxBound|maximum|maybe|min|minBound|minimum|mod|negate|not|notElem|null|odd|or|otherwise|pi|pred|print|product|properFraction|putChar|putStr|putStrLn|quot|quotRem|read|readFile|readIO|readList|readLn|readParen|reads|readsPrec|realToFrac|recip|rem|repeat|replicate|return|reverse|round|scaleFloat|scanl|scanl1|scanr|scanr1|seq|sequence|sequence_|show|showChar|showList|showParen|showString|shows|showsPrec|significand|signum|sin|sinh|snd|span|splitAt|sqrt|subtract|succ|sum|tail|take|takeWhile|tan|tanh|toEnum|toInteger|toRational|truncate|uncurry|undefined|unlines|until|unwords|unzip|unzip3|userError|words|writeFile|zip|zip3|zipWith|zipWith3)\\b' },
  153. { include: '#infix_op' },
  154. { token: 'keyword.operator.haskell',
  155. regex: '[|!%$?~+:\\-.=</>\\\\]+',
  156. comment: 'In case this regex seems overly general, note that Haskell permits the definition of new operators which can be nearly any string of punctuation characters, such as $%^&*.' },
  157. { token: 'punctuation.separator.comma.haskell', regex: ',' } ],
  158. '#block_comment':
  159. [ { token: 'punctuation.definition.comment.haskell',
  160. regex: '\\{-(?!#)',
  161. push:
  162. [ { include: '#block_comment' },
  163. { token: 'punctuation.definition.comment.haskell',
  164. regex: '-\\}',
  165. next: 'pop' },
  166. { defaultToken: 'comment.block.haskell' } ] } ],
  167. '#comments':
  168. [ { token: 'punctuation.definition.comment.haskell',
  169. regex: '--.*',
  170. push_:
  171. [ { token: 'comment.line.double-dash.haskell',
  172. regex: '$',
  173. next: 'pop' },
  174. { defaultToken: 'comment.line.double-dash.haskell' } ] },
  175. { include: '#block_comment' } ],
  176. '#infix_op':
  177. [ { token: 'entity.name.function.infix.haskell',
  178. regex: '\\([|!%$+:\\-.=</>]+\\)|\\(,+\\)' } ],
  179. '#module_exports':
  180. [ { token: 'meta.declaration.exports.haskell',
  181. regex: '\\(',
  182. push:
  183. [ { token: 'meta.declaration.exports.haskell',
  184. regex: '\\)',
  185. next: 'pop' },
  186. { token: 'entity.name.function.haskell',
  187. regex: '\\b[a-z][a-zA-Z_\']*' },
  188. { token: 'storage.type.haskell', regex: '\\b[A-Z][A-Za-z_\']*' },
  189. { token: 'punctuation.separator.comma.haskell', regex: ',' },
  190. { include: '#infix_op' },
  191. { token: 'meta.other.unknown.haskell',
  192. regex: '\\(.*?\\)',
  193. comment: 'So named because I don\'t know what to call this.' },
  194. { defaultToken: 'meta.declaration.exports.haskell' } ] } ],
  195. '#module_name':
  196. [ { token: 'support.other.module.haskell',
  197. regex: '[A-Z][A-Za-z._\']*' } ],
  198. '#pragma':
  199. [ { token: 'meta.preprocessor.haskell',
  200. regex: '\\{-#',
  201. push:
  202. [ { token: 'meta.preprocessor.haskell',
  203. regex: '#-\\}',
  204. next: 'pop' },
  205. { token: 'keyword.other.preprocessor.haskell',
  206. regex: '\\b(?:LANGUAGE|UNPACK|INLINE)\\b' },
  207. { defaultToken: 'meta.preprocessor.haskell' } ] } ],
  208. '#type_signature':
  209. [ { token:
  210. [ 'meta.class-constraint.haskell',
  211. 'entity.other.inherited-class.haskell',
  212. 'meta.class-constraint.haskell',
  213. 'variable.other.generic-type.haskell',
  214. 'meta.class-constraint.haskell',
  215. 'keyword.other.big-arrow.haskell' ],
  216. regex: '(\\(\\s*)([A-Z][A-Za-z]*)(\\s+)([a-z][A-Za-z_\']*)(\\)\\s*)(=>)' },
  217. { include: '#pragma' },
  218. { token: 'keyword.other.arrow.haskell', regex: '->' },
  219. { token: 'keyword.other.big-arrow.haskell', regex: '=>' },
  220. { token: 'support.type.prelude.haskell',
  221. regex: '\\b(?:Int(?:eger)?|Maybe|Either|Bool|Float|Double|Char|String|Ordering|ShowS|ReadS|FilePath|IO(?:Error)?)\\b' },
  222. { token: 'variable.other.generic-type.haskell',
  223. regex: '\\b[a-z][a-zA-Z0-9_\']*\\b' },
  224. { token: 'storage.type.haskell',
  225. regex: '\\b[A-Z][a-zA-Z0-9_\']*\\b' },
  226. { token: 'support.constant.unit.haskell', regex: '\\(\\)' },
  227. { include: '#comments' } ] }
  228. this.normalizeRules();
  229. };
  230. HaskellHighlightRules.metaData = { fileTypes: [ 'hs' ],
  231. keyEquivalent: '^~H',
  232. name: 'Haskell',
  233. scopeName: 'source.haskell' }
  234. oop.inherits(HaskellHighlightRules, TextHighlightRules);
  235. exports.HaskellHighlightRules = HaskellHighlightRules;
  236. });