mode-pig.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. ace.define("ace/mode/pig_highlight_rules",[], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5. var PigHighlightRules = function() {
  6. this.$rules = {
  7. start: [{
  8. token: "comment.block.pig",
  9. regex: /\/\*/,
  10. push: [{
  11. token: "comment.block.pig",
  12. regex: /\*\//,
  13. next: "pop"
  14. }, {
  15. defaultToken: "comment.block.pig"
  16. }]
  17. }, {
  18. token: "comment.line.double-dash.asciidoc",
  19. regex: /--.*$/
  20. }, {
  21. token: "keyword.control.pig",
  22. regex: /\b(?:ASSERT|LOAD|STORE|DUMP|FILTER|DISTINCT|FOREACH|GENERATE|STREAM|JOIN|COGROUP|GROUP|CROSS|ORDER|LIMIT|UNION|SPLIT|DESCRIBE|EXPLAIN|ILLUSTRATE|AS|BY|INTO|USING|LIMIT|PARALLEL|OUTER|INNER|DEFAULT|LEFT|SAMPLE|RANK|CUBE|ALL|KILL|QUIT|MAPREDUCE|ASC|DESC|THROUGH|SHIP|CACHE|DECLARE|CASE|WHEN|THEN|END|IN|PARTITION|FULL|IMPORT|IF|ONSCHEMA|INPUT|OUTPUT)\b/,
  23. caseInsensitive: true
  24. }, {
  25. token: "storage.datatypes.pig",
  26. regex: /\b(?:int|long|float|double|chararray|bytearray|boolean|datetime|biginteger|bigdecimal|tuple|bag|map)\b/,
  27. caseInsensitive: true
  28. }, {
  29. token: "support.function.storage.pig",
  30. regex: /\b(?:PigStorage|BinStorage|BinaryStorage|PigDump|HBaseStorage|JsonLoader|JsonStorage|AvroStorage|TextLoader|PigStreaming|TrevniStorage|AccumuloStorage)\b/
  31. }, {
  32. token: "support.function.udf.pig",
  33. regex: /\b(?:DIFF|TOBAG|TOMAP|TOP|TOTUPLE|RANDOM|FLATTEN|flatten|CUBE|ROLLUP|IsEmpty|ARITY|PluckTuple|SUBTRACT|BagToString)\b/
  34. }, {
  35. token: "support.function.udf.math.pig",
  36. regex: /\b(?:ABS|ACOS|ASIN|ATAN|CBRT|CEIL|COS|COSH|EXP|FLOOR|LOG|LOG10|ROUND|ROUND_TO|SIN|SINH|SQRT|TAN|TANH|AVG|COUNT|COUNT_STAR|MAX|MIN|SUM|COR|COV)\b/
  37. }, {
  38. token: "support.function.udf.string.pig",
  39. regex: /\b(?:CONCAT|INDEXOF|LAST_INDEX_OF|LCFIRST|LOWER|REGEX_EXTRACT|REGEX_EXTRACT_ALL|REPLACE|SIZE|STRSPLIT|SUBSTRING|TOKENIZE|TRIM|UCFIRST|UPPER|LTRIM|RTRIM|ENDSWITH|STARTSWITH|TRIM)\b/
  40. }, {
  41. token: "support.function.udf.datetime.pig",
  42. regex: /\b(?:AddDuration|CurrentTime|DaysBetween|GetDay|GetHour|GetMilliSecond|GetMinute|GetMonth|GetSecond|GetWeek|GetWeekYear|GetYear|HoursBetween|MilliSecondsBetween|MinutesBetween|MonthsBetween|SecondsBetween|SubtractDuration|ToDate|WeeksBetween|YearsBetween|ToMilliSeconds|ToString|ToUnixTime)\b/
  43. }, {
  44. token: "support.function.command.pig",
  45. regex: /\b(?:cat|cd|copyFromLocal|copyToLocal|cp|ls|mkdir|mv|pwd|rm)\b/
  46. }, {
  47. token: "variable.pig",
  48. regex: /\$[a_zA-Z0-9_]+/
  49. }, {
  50. token: "constant.language.pig",
  51. regex: /\b(?:NULL|true|false|stdin|stdout|stderr)\b/,
  52. caseInsensitive: true
  53. }, {
  54. token: "constant.numeric.pig",
  55. regex: /\b\d+(?:\.\d+)?\b/
  56. }, {
  57. token: "keyword.operator.comparison.pig",
  58. regex: /!=|==|<|>|<=|>=|\b(?:MATCHES|IS|OR|AND|NOT)\b/,
  59. caseInsensitive: true
  60. }, {
  61. token: "keyword.operator.arithmetic.pig",
  62. regex: /\+|\-|\*|\/|\%|\?|:|::|\.\.|#/
  63. }, {
  64. token: "string.quoted.double.pig",
  65. regex: /"/,
  66. push: [{
  67. token: "string.quoted.double.pig",
  68. regex: /"/,
  69. next: "pop"
  70. }, {
  71. token: "constant.character.escape.pig",
  72. regex: /\\./
  73. }, {
  74. defaultToken: "string.quoted.double.pig"
  75. }]
  76. }, {
  77. token: "string.quoted.single.pig",
  78. regex: /'/,
  79. push: [{
  80. token: "string.quoted.single.pig",
  81. regex: /'/,
  82. next: "pop"
  83. }, {
  84. token: "constant.character.escape.pig",
  85. regex: /\\./
  86. }, {
  87. defaultToken: "string.quoted.single.pig"
  88. }]
  89. }, {
  90. todo: {
  91. token: [
  92. "text",
  93. "keyword.parameter.pig",
  94. "text",
  95. "storage.type.parameter.pig"
  96. ],
  97. regex: /^(\s*)(set)(\s+)(\S+)/,
  98. caseInsensitive: true,
  99. push: [{
  100. token: "text",
  101. regex: /$/,
  102. next: "pop"
  103. }, {
  104. include: "$self"
  105. }]
  106. }
  107. }, {
  108. token: [
  109. "text",
  110. "keyword.alias.pig",
  111. "text",
  112. "storage.type.alias.pig"
  113. ],
  114. regex: /(\s*)(DEFINE|DECLARE|REGISTER)(\s+)(\S+)/,
  115. caseInsensitive: true,
  116. push: [{
  117. token: "text",
  118. regex: /;?$/,
  119. next: "pop"
  120. }]
  121. }]
  122. };
  123. this.normalizeRules();
  124. };
  125. PigHighlightRules.metaData = {
  126. fileTypes: ["pig"],
  127. name: "Pig",
  128. scopeName: "source.pig"
  129. };
  130. oop.inherits(PigHighlightRules, TextHighlightRules);
  131. exports.PigHighlightRules = PigHighlightRules;
  132. });
  133. ace.define("ace/mode/folding/cstyle",[], function(require, exports, module) {
  134. "use strict";
  135. var oop = require("../../lib/oop");
  136. var Range = require("../../range").Range;
  137. var BaseFoldMode = require("./fold_mode").FoldMode;
  138. var FoldMode = exports.FoldMode = function(commentRegex) {
  139. if (commentRegex) {
  140. this.foldingStartMarker = new RegExp(
  141. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  142. );
  143. this.foldingStopMarker = new RegExp(
  144. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  145. );
  146. }
  147. };
  148. oop.inherits(FoldMode, BaseFoldMode);
  149. (function() {
  150. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  151. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  152. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  153. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  154. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  155. this._getFoldWidgetBase = this.getFoldWidget;
  156. this.getFoldWidget = function(session, foldStyle, row) {
  157. var line = session.getLine(row);
  158. if (this.singleLineBlockCommentRe.test(line)) {
  159. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  160. return "";
  161. }
  162. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  163. if (!fw && this.startRegionRe.test(line))
  164. return "start"; // lineCommentRegionStart
  165. return fw;
  166. };
  167. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  168. var line = session.getLine(row);
  169. if (this.startRegionRe.test(line))
  170. return this.getCommentRegionBlock(session, line, row);
  171. var match = line.match(this.foldingStartMarker);
  172. if (match) {
  173. var i = match.index;
  174. if (match[1])
  175. return this.openingBracketBlock(session, match[1], row, i);
  176. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  177. if (range && !range.isMultiLine()) {
  178. if (forceMultiline) {
  179. range = this.getSectionRange(session, row);
  180. } else if (foldStyle != "all")
  181. range = null;
  182. }
  183. return range;
  184. }
  185. if (foldStyle === "markbegin")
  186. return;
  187. var match = line.match(this.foldingStopMarker);
  188. if (match) {
  189. var i = match.index + match[0].length;
  190. if (match[1])
  191. return this.closingBracketBlock(session, match[1], row, i);
  192. return session.getCommentFoldRange(row, i, -1);
  193. }
  194. };
  195. this.getSectionRange = function(session, row) {
  196. var line = session.getLine(row);
  197. var startIndent = line.search(/\S/);
  198. var startRow = row;
  199. var startColumn = line.length;
  200. row = row + 1;
  201. var endRow = row;
  202. var maxRow = session.getLength();
  203. while (++row < maxRow) {
  204. line = session.getLine(row);
  205. var indent = line.search(/\S/);
  206. if (indent === -1)
  207. continue;
  208. if (startIndent > indent)
  209. break;
  210. var subRange = this.getFoldWidgetRange(session, "all", row);
  211. if (subRange) {
  212. if (subRange.start.row <= startRow) {
  213. break;
  214. } else if (subRange.isMultiLine()) {
  215. row = subRange.end.row;
  216. } else if (startIndent == indent) {
  217. break;
  218. }
  219. }
  220. endRow = row;
  221. }
  222. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  223. };
  224. this.getCommentRegionBlock = function(session, line, row) {
  225. var startColumn = line.search(/\s*$/);
  226. var maxRow = session.getLength();
  227. var startRow = row;
  228. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  229. var depth = 1;
  230. while (++row < maxRow) {
  231. line = session.getLine(row);
  232. var m = re.exec(line);
  233. if (!m) continue;
  234. if (m[1]) depth--;
  235. else depth++;
  236. if (!depth) break;
  237. }
  238. var endRow = row;
  239. if (endRow > startRow) {
  240. return new Range(startRow, startColumn, endRow, line.length);
  241. }
  242. };
  243. }).call(FoldMode.prototype);
  244. });
  245. ace.define("ace/mode/pig",[], function(require, exports, module) {
  246. "use strict";
  247. var oop = require("../lib/oop");
  248. var TextMode = require("./text").Mode;
  249. var PigHighlightRules = require("./pig_highlight_rules").PigHighlightRules;
  250. var FoldMode = require("./folding/cstyle").FoldMode;
  251. var Mode = function() {
  252. this.HighlightRules = PigHighlightRules;
  253. this.foldingRules = new FoldMode();
  254. };
  255. oop.inherits(Mode, TextMode);
  256. (function() {
  257. this.lineCommentStart = "--";
  258. this.blockComment = {start: "/*", end: "*/"};
  259. this.$id = "ace/mode/pig";
  260. }).call(Mode.prototype);
  261. exports.Mode = Mode;
  262. });
  263. (function() {
  264. ace.require(["ace/mode/pig"], function(m) {
  265. if (typeof module == "object" && typeof exports == "object" && module) {
  266. module.exports = m;
  267. }
  268. });
  269. })();