11
if (typeof exports == "object" && typeof module == "object")
12
mod(require("../../lib/codemirror"));
13
else if (typeof define == "function" && define.amd)
14
define(["../../lib/codemirror"], mod);
17
})(function(CodeMirror) {
20
CodeMirror.defineMode("pig", function(_config, parserConfig) {
21
var keywords = parserConfig.keywords,
22
builtins = parserConfig.builtins,
23
types = parserConfig.types,
24
multiLineStrings = parserConfig.multiLineStrings;
26
var isOperatorChar = /[*+\-%<>=&?:\/!|]/;
28
function chain(stream, state, f) {
30
return f(stream, state);
33
function tokenComment(stream, state) {
36
while(ch = stream.next()) {
37
if(ch == "/" && isEnd) {
38
state.tokenize = tokenBase;
46
function tokenString(quote) {
47
return function(stream, state) {
48
var escaped = false, next, end = false;
49
while((next = stream.next()) != null) {
50
if (next == quote && !escaped) {
53
escaped = !escaped && next == "\\";
55
if (end || !(escaped || multiLineStrings))
56
state.tokenize = tokenBase;
62
function tokenBase(stream, state) {
63
var ch = stream.next();
66
if (ch == '"' || ch == "'")
67
return chain(stream, state, tokenString(ch));
69
else if(/[\[\]{}\(\),;\.]/.test(ch))
72
else if(/\d/.test(ch)) {
73
stream.eatWhile(/[\w\.]/);
78
if (stream.eat("*")) {
79
return chain(stream, state, tokenComment);
82
stream.eatWhile(isOperatorChar);
93
stream.eatWhile(isOperatorChar);
98
else if (isOperatorChar.test(ch)) {
99
stream.eatWhile(isOperatorChar);
104
stream.eatWhile(/[\w\$_]/);
106
if (keywords && keywords.propertyIsEnumerable(stream.current().toUpperCase())) {
108
if (!stream.eat(")") && !stream.eat("."))
112
if (builtins && builtins.propertyIsEnumerable(stream.current().toUpperCase()))
115
if (types && types.propertyIsEnumerable(stream.current().toUpperCase()))
124
startState: function() {
131
token: function(stream, state) {
132
if(stream.eatSpace()) return null;
133
var style = state.tokenize(stream, state);
140
function keywords(str) {
141
var obj = {}, words = str.split(" ");
142
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
147
var pBuiltins = "ABS ACOS ARITY ASIN ATAN AVG BAGSIZE BINSTORAGE BLOOM BUILDBLOOM CBRT CEIL "
148
+ "CONCAT COR COS COSH COUNT COUNT_STAR COV CONSTANTSIZE CUBEDIMENSIONS DIFF DISTINCT DOUBLEABS "
149
+ "DOUBLEAVG DOUBLEBASE DOUBLEMAX DOUBLEMIN DOUBLEROUND DOUBLESUM EXP FLOOR FLOATABS FLOATAVG "
150
+ "FLOATMAX FLOATMIN FLOATROUND FLOATSUM GENERICINVOKER INDEXOF INTABS INTAVG INTMAX INTMIN "
151
+ "INTSUM INVOKEFORDOUBLE INVOKEFORFLOAT INVOKEFORINT INVOKEFORLONG INVOKEFORSTRING INVOKER "
152
+ "ISEMPTY JSONLOADER JSONMETADATA JSONSTORAGE LAST_INDEX_OF LCFIRST LOG LOG10 LOWER LONGABS "
153
+ "LONGAVG LONGMAX LONGMIN LONGSUM MAX MIN MAPSIZE MONITOREDUDF NONDETERMINISTIC OUTPUTSCHEMA "
154
+ "PIGSTORAGE PIGSTREAMING RANDOM REGEX_EXTRACT REGEX_EXTRACT_ALL REPLACE ROUND SIN SINH SIZE "
155
+ "SQRT STRSPLIT SUBSTRING SUM STRINGCONCAT STRINGMAX STRINGMIN STRINGSIZE TAN TANH TOBAG "
156
+ "TOKENIZE TOMAP TOP TOTUPLE TRIM TEXTLOADER TUPLESIZE UCFIRST UPPER UTF8STORAGECONVERTER ";
159
var pKeywords = "VOID IMPORT RETURNS DEFINE LOAD FILTER FOREACH ORDER CUBE DISTINCT COGROUP "
160
+ "JOIN CROSS UNION SPLIT INTO IF OTHERWISE ALL AS BY USING INNER OUTER ONSCHEMA PARALLEL "
161
+ "PARTITION GROUP AND OR NOT GENERATE FLATTEN ASC DESC IS STREAM THROUGH STORE MAPREDUCE "
162
+ "SHIP CACHE INPUT OUTPUT STDERROR STDIN STDOUT LIMIT SAMPLE LEFT RIGHT FULL EQ GT LT GTE LTE "
163
+ "NEQ MATCHES TRUE FALSE DUMP";
166
var pTypes = "BOOLEAN INT LONG FLOAT DOUBLE CHARARRAY BYTEARRAY BAG TUPLE MAP ";
168
CodeMirror.defineMIME("text/x-pig", {
170
builtins: keywords(pBuiltins),
171
keywords: keywords(pKeywords),
172
types: keywords(pTypes)
175
CodeMirror.registerHelper("hintWords", "pig", (pBuiltins + pTypes + pKeywords).split(" "));