pig_highlight_rules.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. var keywords = (
  24. "%DECLARE|%DEFAULT|VOID|IMPORT|RETURNS|ARRANGE|DEFINE|LOAD|FILTER|FOREACH|ORDER|CUBE|DISTINCT|COGROUP|CP|CD|DU|JOIN|CROSS|UNION|SPLIT|INTO|IF|OTHERWISE|ALL|AS|BY|USING|INNER|OUTER|ONSCHEMA|PARALLEL|PARTITION|GROUP|AND|ANY|OR|NOT|GENERATE|FLATTEN|ASC|DESC|DESCRIBE|EXPLAIN|IS|STREAM|THROUGH|STORE|MAPREDUCE|SHIP|CACHE|INPUT|OUTPUT|STDERROR|STDIN|STDOUT|LIMIT|SAMPLE|LEFT|RIGHT|FULL|EQ|GT|LT|GTE|LTE|NEQ|MATCHES|TRUE|FALSE|REGISTER|DUMP|EXEC|HELP|ILLUSTRATE|KILL|LS|MKDIR|MV|PIG|PWD|QUIT|RM|RMF|RUN|SET"
  25. );
  26. var builtinFunctions = (
  27. "ABS|ACOS|ARITY|ASIN|ATAN|AVG|BAGSIZE|BINSTORAGE|BLOOM|BUILDBLOOM|CBRT|CEIL|CONCAT|COPYFROMLOCAL|COPYTOLOCAL|CAT|COR|COS|COSH|COUNT|COUNT_STAR|COV|CONSTANTSIZE|CUBEDIMENSIONS|DIFF|DISTINCT|DOUBLEABS|DOUBLEAVG|DOUBLEBASE|DOUBLEMAX|DOUBLEMIN|DOUBLEROUND|DOUBLESUM|EXP|FLOOR|FLOATABS|FLOATAVG|FLOATMAX|FLOATMIN|FLOATROUND|FLOATSUM|GENERICINVOKER|INDEXOF|INTABS|INTAVG|INTMAX|INTMIN|INTSUM|INVOKEFORDOUBLE|INVOKEFORFLOAT|INVOKEFORINT|INVOKEFORLONG|INVOKEFORSTRING|INVOKER|ISEMPTY|JSONLOADER|JSONMETADATA|JSONSTORAGE|LAST_INDEX_OF|LCFIRST|LOG|LOG10|LOWER|LONGABS|LONGAVG|LONGMAX|LONGMIN|LONGSUM|MAX|MIN|MAPSIZE|MONITOREDUDF|NONDETERMINISTIC|OUTPUTSCHEMA||PIGSTORAGE|PIGSTREAMING|RANDOM|REGEX_EXTRACT|REGEX_EXTRACT_ALL|REPLACE|ROUND|SIN|SINH|SIZE|SQRT|STRSPLIT|SUBSTRING|SUM|STRINGCONCAT|STRINGMAX|STRINGMIN|STRINGSIZE|TAN|TANH|TOBAG|TOKENIZE|TOMAP|TOP|TOTUPLE|TRIM|TEXTLOADER|TUPLESIZE|UCFIRST|UPPER|UTF8STORAGECONVERTER|EVAL|PIGDUMP|PIGSTORAGE"
  28. );
  29. var keywordMapper = this.createKeywordMapper({
  30. "keyword": keywords,
  31. "support.function": builtinFunctions
  32. }, "identifier", true);
  33. this.$rules = {
  34. start: [
  35. {
  36. token: "comment.line.double-dash",
  37. regex: /--.*$/
  38. },
  39. {
  40. token: "comment.block",
  41. regex: /\/\*/,
  42. push: [
  43. {
  44. token: "comment.block",
  45. regex: /\*\//,
  46. next: "pop"
  47. },
  48. {
  49. defaultToken: "comment.block"
  50. }
  51. ]
  52. },
  53. {
  54. token: "constant.language",
  55. regex: /\b(?:null|true|false|stdin|stdout|stderr)\b/,
  56. caseInsensitive: true
  57. },
  58. {
  59. token: "constant.numeric",
  60. regex: /\b[\d]+(?:\.[\d]+)?(?:e[\d]+)?[LF]?\b/,
  61. caseInsensitive: true
  62. },
  63. {
  64. token: "string.quoted.double",
  65. regex: /"/,
  66. push: [
  67. {
  68. token: "string.quoted.double",
  69. regex: /"/,
  70. next: "pop"
  71. },
  72. {
  73. token: "constant.character.escape",
  74. regex: /\\./
  75. },
  76. {
  77. defaultToken: "string.quoted.double"
  78. }
  79. ]
  80. },
  81. {
  82. token: "string.quoted.single",
  83. regex: /'/,
  84. push: [
  85. {
  86. token: "string.quoted.single",
  87. regex: /'/,
  88. next: "pop"
  89. },
  90. {
  91. token: "constant.character.escape",
  92. regex: /\\./
  93. },
  94. {
  95. defaultToken: "string.quoted.single"
  96. }
  97. ]
  98. },
  99. {
  100. token: "string.quoted.other",
  101. regex: /`/,
  102. push: [
  103. {
  104. token: "string.quoted.other",
  105. regex: /`/,
  106. next: "pop"
  107. },
  108. {
  109. token: "constant.character.escape",
  110. regex: /\\./
  111. },
  112. {
  113. defaultToken: "string.quoted.other"
  114. }
  115. ]
  116. },
  117. {
  118. token: "keyword.operator.arithmetic",
  119. regex: /\+|-|\*|\/|%/
  120. },
  121. {
  122. token: "keyword.operator.bincond",
  123. regex: /\?|:/
  124. },
  125. {
  126. token: "keyword.operator.comparison",
  127. regex: /==|!=|<=|>=|<|>|\bmatches\b/,
  128. caseInsensitive: true
  129. },
  130. {
  131. token: "keyword.operator.null",
  132. regex: /\b(?:is\s+null|is\s+not\s+null)\b/,
  133. caseInsensitive: true
  134. },
  135. {
  136. token: "keyword.operator.boolean",
  137. regex: /\b(?:and|or|not)\b/,
  138. caseInsensitive: true
  139. },
  140. {
  141. token: "keyword.operator.relation",
  142. regex: /\b::\b/
  143. },
  144. {
  145. token: "keyword.operator.dereference",
  146. regex: /\b(?:\.|#)\b/
  147. },
  148. {
  149. token: "keyword.control.conditional",
  150. regex: /\b(?:CASE|WHEN|THEN|ELSE|END)\b/,
  151. caseInsensitive: true
  152. },
  153. {
  154. token: "keyword.control.relational",
  155. regex: /\b(?:ASSERT|COGROUP|CROSS|CUBE|distinct|filter|foreach|generate|group|join|limit|load|order|sample|split|store|stream|union)\b/,
  156. caseInsensitive: true
  157. },
  158. {
  159. token: "keyword.control.diagnostic",
  160. regex: /\b(?:describe|dump|explain|illustrate)\b/,
  161. caseInsensitive: true
  162. },
  163. {
  164. token: "keyword.control.macro",
  165. regex: /\b(?:define|import|register)\b/,
  166. caseInsensitive: true
  167. },
  168. {
  169. token: "keyword.control.clause",
  170. regex: /\b(?:any|all|asc|arrange|as|asc|by|desc|full|if|inner|into|left|outer|parallel|returns|right|through|using)\b/,
  171. caseInsensitive: true
  172. },
  173. {
  174. token: "support.function.operator",
  175. regex: /\bFLATTEN\b/,
  176. caseInsensitive: true
  177. },
  178. {
  179. token: "support.function.operation",
  180. regex: /\b(?:CUBE|ROLLUP)\b/,
  181. caseInsensitive: true
  182. },
  183. {
  184. token: "support.function.eval",
  185. regex: /\b(?:AVG|CONCAT|COUNT|COUNT_STAR|DIFF|IsEmpty|MAX|MIN|PluckTuple|SIZE|SUBTRACT|SUM|Terms|TOKENIZE|Usage)\b/
  186. },
  187. {
  188. token: "support.function.math",
  189. regex: /\b(?:ABS|ACOS|ASIN|ATAN|CBRT|CEIL|COS|COSH|EXP|FLOOR|LOG|LOG10|RANDOM|ROUND|SIN|SINH|SORT|TAN|TANH)\b/
  190. },
  191. {
  192. token: "support.function.string",
  193. 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/
  194. },
  195. {
  196. token: "support.function.datetime",
  197. 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/
  198. },
  199. {
  200. token: "support.function.tuple",
  201. regex: /\b(?:TOTUPLE|TOBAG|TOMAP|TOP)\b/,
  202. caseInsensitive: true
  203. },
  204. {
  205. token: "support.function.macro",
  206. regex: /\b(?:input|output|ship|cache)\b/,
  207. caseInsensitive: true
  208. },
  209. {
  210. token: "support.function.storage",
  211. regex: /\b(?:AvroStorage|BinStorage|BinaryStorage|HBaseStorage|JsonLoader|JsonStorage|PigDump|PigStorage|PigStreaming|TextLoader|TrevniStorage)\b/,
  212. caseInsensitive: true
  213. },
  214. {
  215. token: "keyword.other.command.shell",
  216. regex: /\b(?:fs|sh)\b/,
  217. caseInsensitive: true
  218. },
  219. {
  220. token: "keyword.other.command.shell.file",
  221. regex: /\b(?:cat|cd|copyFromLocal|copyToLocal|cp|ls|mkdir|mv|pwd|rm|rmf)\b/,
  222. caseInsensitive: true
  223. },
  224. {
  225. token: "keyword.other.command.shell.utility",
  226. regex: /\b(?:clear|exec|help|history|kill|quit|run|set)\b/,
  227. caseInsensitive: true
  228. },
  229. {
  230. token: "storage.type.simple",
  231. regex: /\b(?:int|long|float|double|chararray|bytearray|boolean|datetime|biginteger|bigdecimal)\b/,
  232. caseInsensitive: true
  233. },
  234. {
  235. token: "storage.type.complex",
  236. regex: /\b(?:tuple|bag|map)\b/,
  237. caseInsensitive: true
  238. },
  239. {
  240. token: "variable.other.positional",
  241. regex: /\$[0-9_]+/
  242. },
  243. {
  244. token: "variable.other.alias",
  245. regex: /\b[a-z][a-z0-9_]*\b/,
  246. caseInsensitive: true
  247. },
  248. {
  249. token : keywordMapper,
  250. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  251. }
  252. ]
  253. };
  254. this.normalizeRules();
  255. };
  256. PigLatinHighlightRules.metaData = {
  257. fileTypes: ["pig"],
  258. name: "Pig Latin",
  259. scopeName: "source.pig_latin"
  260. };
  261. oop.inherits(PigLatinHighlightRules, TextHighlightRules);
  262. exports.PigLatinHighlightRules = PigLatinHighlightRules;
  263. });