pig_highlight_rules.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. // Licensed to Cloudera, Inc. under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. Cloudera, Inc. licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. define(function (require, exports, module) {
  17. "use strict";
  18. var oop = require("../lib/oop");
  19. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  20. var PigLatinHighlightRules = function () {
  21. // regexp must not have capturing parentheses. Use (?:) instead.
  22. // regexps are ordered -> the first match is used
  23. this.$rules = {
  24. start: [
  25. {
  26. token: "comment.line.double-dash",
  27. regex: /--.*$/
  28. },
  29. {
  30. token: "comment.block",
  31. regex: /\/\*/,
  32. push: [
  33. {
  34. token: "comment.block",
  35. regex: /\*\//,
  36. next: "pop"
  37. },
  38. {
  39. defaultToken: "comment.block"
  40. }
  41. ]
  42. },
  43. {
  44. token: "constant.language",
  45. regex: /\b(?:null|true|false|stdin|stdout|stderr)\b/,
  46. caseInsensitive: true
  47. },
  48. {
  49. token: "constant.numeric",
  50. regex: /\b[\d]+(?:\.[\d]+)?(?:e[\d]+)?[LF]?\b/,
  51. caseInsensitive: true
  52. },
  53. {
  54. token: "string.quoted.double",
  55. regex: /"/,
  56. push: [
  57. {
  58. token: "string.quoted.double",
  59. regex: /"/,
  60. next: "pop"
  61. },
  62. {
  63. token: "constant.character.escape",
  64. regex: /\\./
  65. },
  66. {
  67. defaultToken: "string.quoted.double"
  68. }
  69. ]
  70. },
  71. {
  72. token: "string.quoted.single",
  73. regex: /'/,
  74. push: [
  75. {
  76. token: "string.quoted.single",
  77. regex: /'/,
  78. next: "pop"
  79. },
  80. {
  81. token: "constant.character.escape",
  82. regex: /\\./
  83. },
  84. {
  85. defaultToken: "string.quoted.single"
  86. }
  87. ]
  88. },
  89. {
  90. token: "string.quoted.other",
  91. regex: /`/,
  92. push: [
  93. {
  94. token: "string.quoted.other",
  95. regex: /`/,
  96. next: "pop"
  97. },
  98. {
  99. token: "constant.character.escape",
  100. regex: /\\./
  101. },
  102. {
  103. defaultToken: "string.quoted.other"
  104. }
  105. ]
  106. },
  107. {
  108. token: "keyword.operator.arithmetic",
  109. regex: /\+|-|\*|\/|%/
  110. },
  111. {
  112. token: "keyword.operator.bincond",
  113. regex: /\?|:/
  114. },
  115. {
  116. token: "keyword.operator.comparison",
  117. regex: /==|!=|<=|>=|<|>|\bmatches\b/,
  118. caseInsensitive: true
  119. },
  120. {
  121. token: "keyword.operator.null",
  122. regex: /\b(?:is\s+null|is\s+not\s+null)\b/,
  123. caseInsensitive: true
  124. },
  125. {
  126. token: "keyword.operator.boolean",
  127. regex: /\b(?:and|or|not)\b/,
  128. caseInsensitive: true
  129. },
  130. {
  131. token: "keyword.operator.relation",
  132. regex: /\b::\b/
  133. },
  134. {
  135. token: "keyword.operator.dereference",
  136. regex: /\b(?:\.|#)\b/
  137. },
  138. {
  139. token: "keyword.control.conditional",
  140. regex: /\b(?:CASE|WHEN|THEN|ELSE|END)\b/,
  141. caseInsensitive: true
  142. },
  143. {
  144. token: "keyword.control.relational",
  145. regex: /\b(?:ASSERT|COGROUP|CROSS|CUBE|distinct|filter|foreach|generate|group|join|limit|load|order|sample|split|store|stream|union)\b/,
  146. caseInsensitive: true
  147. },
  148. {
  149. token: "keyword.control.diagnostic",
  150. regex: /\b(?:describe|dump|explain|illustrate)\b/,
  151. caseInsensitive: true
  152. },
  153. {
  154. token: "keyword.control.macro",
  155. regex: /\b(?:define|import|register)\b/,
  156. caseInsensitive: true
  157. },
  158. {
  159. token: "keyword.control.clause",
  160. regex: /\b(?:any|all|asc|arrange|as|asc|by|desc|full|if|inner|into|left|outer|parallel|returns|right|through|using)\b/,
  161. caseInsensitive: true
  162. },
  163. {
  164. token: "support.function.operator",
  165. regex: /\bFLATTEN\b/,
  166. caseInsensitive: true
  167. },
  168. {
  169. token: "support.function.operation",
  170. regex: /\b(?:CUBE|ROLLUP)\b/,
  171. caseInsensitive: true
  172. },
  173. {
  174. token: "support.function.eval",
  175. regex: /\b(?:AVG|CONCAT|COUNT|COUNT_STAR|DIFF|IsEmpty|MAX|MIN|PluckTuple|SIZE|SUBTRACT|SUM|Terms|TOKENIZE|Usage)\b/
  176. },
  177. {
  178. token: "support.function.math",
  179. regex: /\b(?:ABS|ACOS|ASIN|ATAN|CBRT|CEIL|COS|COSH|EXP|FLOOR|LOG|LOG10|RANDOM|ROUND|SIN|SINH|SORT|TAN|TANH)\b/
  180. },
  181. {
  182. token: "support.function.string",
  183. regex: /\b(?:ENDSWITH|EqualsIgnoreCase|INDEXOF|LAST_INDEX_OF|LCFIRST|LOWER|LTRIM|REGEX_EXTRACT|REGEX_EXTRACT_ALL|REPLACE|RTRIM|STARTSWITH|STRSPLIT|SUBSTRING|TRIM|UCFIRST|UPPER)\b/
  184. },
  185. {
  186. token: "support.function.datetime",
  187. regex: /\b(?:AddDuration|CurrentTime|DaysBetween|GetDay|GetHour|GetMilliSecond|GetMinute|GetMonth|GetSecond|GetWeek|GetWeekYear|GetYear|HoursBetween|MilliSecondsBetween|MinutesBetween|MonthsBetween|SecondsBetween|SubtractDuration|ToDate|ToMilliSeconds|ToString|ToUnixTime|WeeksBetween|YearsBetween)\b/
  188. },
  189. {
  190. token: "support.function.tuple",
  191. regex: /\b(?:TOTUPLE|TOBAG|TOMAP|TOP)\b/,
  192. caseInsensitive: true
  193. },
  194. {
  195. token: "support.function.macro",
  196. regex: /\b(?:input|output|ship|cache)\b/,
  197. caseInsensitive: true
  198. },
  199. {
  200. token: "support.function.storage",
  201. regex: /\b(?:AvroStorage|BinStorage|BinaryStorage|HBaseStorage|JsonLoader|JsonStorage|PigDump|PigStorage|PigStreaming|TextLoader|TrevniStorage)\b/,
  202. caseInsensitive: true
  203. },
  204. {
  205. token: "keyword.other.command.shell",
  206. regex: /\b(?:fs|sh)\b/,
  207. caseInsensitive: true
  208. },
  209. {
  210. token: "keyword.other.command.shell.file",
  211. regex: /\b(?:cat|cd|copyFromLocal|copyToLocal|cp|ls|mkdir|mv|pwd|rm|rmf)\b/,
  212. caseInsensitive: true
  213. },
  214. {
  215. token: "keyword.other.command.shell.utility",
  216. regex: /\b(?:clear|exec|help|history|kill|quit|run|set)\b/,
  217. caseInsensitive: true
  218. },
  219. {
  220. token: "storage.type.simple",
  221. regex: /\b(?:int|long|float|double|chararray|bytearray|boolean|datetime|biginteger|bigdecimal)\b/,
  222. caseInsensitive: true
  223. },
  224. {
  225. token: "storage.type.complex",
  226. regex: /\b(?:tuple|bag|map)\b/,
  227. caseInsensitive: true
  228. },
  229. {
  230. token: "variable.other.positional",
  231. regex: /\$[0-9_]+/
  232. },
  233. {
  234. token: "variable.other.alias",
  235. regex: /\b[a-z][a-z0-9_]*\b/,
  236. caseInsensitive: true
  237. }
  238. ]
  239. }
  240. this.normalizeRules();
  241. };
  242. PigLatinHighlightRules.metaData = {
  243. fileTypes: ["pig"],
  244. name: "Pig Latin",
  245. scopeName: "source.pig_latin"
  246. }
  247. oop.inherits(PigLatinHighlightRules, TextHighlightRules);
  248. exports.PigLatinHighlightRules = PigLatinHighlightRules;
  249. });