]>
git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/pretty-json/node_modules/jsonminify/report/assets/scripts/vendor/codemirror/util/pig-hint.js
149b468158836bd7038e2d8a38f502960a22d2fc
2 function forEach(arr
, f
) {
3 for (var i
= 0, e
= arr
.length
; i
< e
; ++i
) f(arr
[i
]);
6 function arrayContains(arr
, item
) {
7 if (!Array
.prototype.indexOf
) {
10 if (arr
[i
] === item
) {
16 return arr
.indexOf(item
) != -1;
19 function scriptHint(editor
, _keywords
, getToken
) {
20 // Find the token at the cursor
21 var cur
= editor
.getCursor(), token
= getToken(editor
, cur
), tprop
= token
;
22 // If it's not a 'word-style' token, ignore the token.
24 if (!/^[\w$_]*$/.test(token
.string
)) {
25 token
= tprop
= {start: cur
.ch
, end: cur
.ch
, string: "", state: token
.state
,
26 className: token
.string
== ":" ? "pig-type" : null};
29 if (!context
) var context
= [];
32 var completionList
= getCompletions(token
, context
);
33 completionList
= completionList
.sort();
34 //prevent autocomplete for last word, instead show dropdown with one word
35 if(completionList
.length
== 1) {
36 completionList
.push(" ");
39 return {list: completionList
,
40 from: {line: cur
.line
, ch: token
.start
},
41 to: {line: cur
.line
, ch: token
.end
}};
44 CodeMirror
.pigHint = function(editor
) {
45 return scriptHint(editor
, pigKeywordsU
, function (e
, cur
) {return e
.getTokenAt(cur
);});
48 var pigKeywords
= "VOID IMPORT RETURNS DEFINE LOAD FILTER FOREACH ORDER CUBE DISTINCT COGROUP "
49 + "JOIN CROSS UNION SPLIT INTO IF OTHERWISE ALL AS BY USING INNER OUTER ONSCHEMA PARALLEL "
50 + "PARTITION GROUP AND OR NOT GENERATE FLATTEN ASC DESC IS STREAM THROUGH STORE MAPREDUCE "
51 + "SHIP CACHE INPUT OUTPUT STDERROR STDIN STDOUT LIMIT SAMPLE LEFT RIGHT FULL EQ GT LT GTE LTE "
52 + "NEQ MATCHES TRUE FALSE";
53 var pigKeywordsU
= pigKeywords
.split(" ");
54 var pigKeywordsL
= pigKeywords
.toLowerCase().split(" ");
56 var pigTypes
= "BOOLEAN INT LONG FLOAT DOUBLE CHARARRAY BYTEARRAY BAG TUPLE MAP";
57 var pigTypesU
= pigTypes
.split(" ");
58 var pigTypesL
= pigTypes
.toLowerCase().split(" ");
60 var pigBuiltins
= "ABS ACOS ARITY ASIN ATAN AVG BAGSIZE BINSTORAGE BLOOM BUILDBLOOM CBRT CEIL "
61 + "CONCAT COR COS COSH COUNT COUNT_STAR COV CONSTANTSIZE CUBEDIMENSIONS DIFF DISTINCT DOUBLEABS "
62 + "DOUBLEAVG DOUBLEBASE DOUBLEMAX DOUBLEMIN DOUBLEROUND DOUBLESUM EXP FLOOR FLOATABS FLOATAVG "
63 + "FLOATMAX FLOATMIN FLOATROUND FLOATSUM GENERICINVOKER INDEXOF INTABS INTAVG INTMAX INTMIN "
64 + "INTSUM INVOKEFORDOUBLE INVOKEFORFLOAT INVOKEFORINT INVOKEFORLONG INVOKEFORSTRING INVOKER "
65 + "ISEMPTY JSONLOADER JSONMETADATA JSONSTORAGE LAST_INDEX_OF LCFIRST LOG LOG10 LOWER LONGABS "
66 + "LONGAVG LONGMAX LONGMIN LONGSUM MAX MIN MAPSIZE MONITOREDUDF NONDETERMINISTIC OUTPUTSCHEMA "
67 + "PIGSTORAGE PIGSTREAMING RANDOM REGEX_EXTRACT REGEX_EXTRACT_ALL REPLACE ROUND SIN SINH SIZE "
68 + "SQRT STRSPLIT SUBSTRING SUM STRINGCONCAT STRINGMAX STRINGMIN STRINGSIZE TAN TANH TOBAG "
69 + "TOKENIZE TOMAP TOP TOTUPLE TRIM TEXTLOADER TUPLESIZE UCFIRST UPPER UTF8STORAGECONVERTER";
70 var pigBuiltinsU
= pigBuiltins
.split(" ").join("() ").split(" ");
71 var pigBuiltinsL
= pigBuiltins
.toLowerCase().split(" ").join("() ").split(" ");
72 var pigBuiltinsC
= ("BagSize BinStorage Bloom BuildBloom ConstantSize CubeDimensions DoubleAbs "
73 + "DoubleAvg DoubleBase DoubleMax DoubleMin DoubleRound DoubleSum FloatAbs FloatAvg FloatMax "
74 + "FloatMin FloatRound FloatSum GenericInvoker IntAbs IntAvg IntMax IntMin IntSum "
75 + "InvokeForDouble InvokeForFloat InvokeForInt InvokeForLong InvokeForString Invoker "
76 + "IsEmpty JsonLoader JsonMetadata JsonStorage LongAbs LongAvg LongMax LongMin LongSum MapSize "
77 + "MonitoredUDF Nondeterministic OutputSchema PigStorage PigStreaming StringConcat StringMax "
78 + "StringMin StringSize TextLoader TupleSize Utf8StorageConverter").split(" ").join("() ").split(" ");
80 function getCompletions(token
, context
) {
81 var found
= [], start
= token
.string
;
82 function maybeAdd(str
) {
83 if (str
.indexOf(start
) == 0 && !arrayContains(found
, str
)) found
.push(str
);
86 function gatherCompletions(obj
) {
88 forEach(pigTypesL
, maybeAdd
);
91 forEach(pigBuiltinsU
, maybeAdd
);
92 forEach(pigBuiltinsL
, maybeAdd
);
93 forEach(pigBuiltinsC
, maybeAdd
);
94 forEach(pigTypesU
, maybeAdd
);
95 forEach(pigTypesL
, maybeAdd
);
96 forEach(pigKeywordsU
, maybeAdd
);
97 forEach(pigKeywordsL
, maybeAdd
);
102 // If this is a property, see if it belongs to some object we can
103 // find in the current environment.
104 var obj
= context
.pop(), base
;
106 if (obj
.type
== "variable")
108 else if(obj
.type
== "variable-3")
109 base
= ":" + obj
.string
;
111 while (base
!= null && context
.length
)
112 base
= base
[context
.pop().string
];
113 if (base
!= null) gatherCompletions(base
);