Skip to content

Commit

Permalink
Refactoring: Define 'column' as a keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
haiiro-shimeji committed Apr 17, 2013
1 parent be677b0 commit c6b4c02
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions data/js/kismet.js
Expand Up @@ -24,6 +24,7 @@ var kismet = {
OP_MENTION_HAS: 16,
OP_HAS_GEO: 17,
OP_HAS_LINK: 18,
OP_COLUMN: 19,

ACT_DROP: 100,
ACT_NOTIFY: 101,
Expand All @@ -43,7 +44,7 @@ var kismet = {

MASK_TEXT: '******** Masked Text Field ********',

reserved_words: ['has', 'name', 'tag', 'via', 'do', 'mention', 'retweet'],
reserved_words: ['has', 'name', 'tag', 'via', 'do', 'mention', 'retweet', 'column'],

mute_list: {},

Expand Down Expand Up @@ -651,6 +652,10 @@ function process_field(tokens, pos) {
case 'has':
return kismet.process_has(val);
break;
case 'column':
kismet.cond_string_array.push('ON COLUMN ' + second[1].replace('|',' or '));
return [[kismet.OP_COLUMN, second[1].split('|')], 3];
break;
default:
return [kismet.ERROR, 3];
break;
Expand Down Expand Up @@ -724,13 +729,11 @@ function read_tokens(str) {
if (flag.length != 0) pos += 1;
} else if (ch === ' ') {
pos += 1;
/*
} else if (/[^():,]/.test(ch)) {
end_pos = kismet.recognize_keyword(str, pos);
token = [kismet.TYPE_WORD, str.slice(pos, end_pos)];
token_list.push(token);
pos = end_pos;
*/
} else if (ch === '(') {
token_list.push([kismet.TYPE_LBRA, '(']);
pos += 1;
Expand Down Expand Up @@ -765,19 +768,7 @@ function compile(str) {
inst = null;
switch (token[0]) {
case kismet.TYPE_WORD:
if (token[1] === "column"){
column = tokens[i + 2][1]
kismet.cond_string_array.push('ON COLUMN ' + column.replace('|',' or '));
if(column.indexOf('|') === -1){
rule.column.push(column);
}else{
columns = column.split('|')
for(var i=0;i<columns.length;i++){
rule.column.push(columns[i]);
}
}
i += 3;
} else if (kismet.reserved_words.indexOf(token[1]) == -1) {
if (kismet.reserved_words.indexOf(token[1]) == -1) {
kismet.cond_string_array.push('CONTAINS ' + token[1].replace('|',' or '));
inst = [kismet.OP_STR_HAS, "$TEXT", token[1]];
i += 1;
Expand Down Expand Up @@ -805,6 +796,10 @@ function compile(str) {
if (inst != null) {
if (kismet.act_code_map.indexOf(inst[0]) != -1) {
rule.action.push(inst);
} else if (kismet.OP_COLUMN == inst[0]) {
$.each(inst[1], function(i, c) {
rule.column.push(c);
});
} else {
rule.cond.push(inst);
}
Expand Down

0 comments on commit c6b4c02

Please sign in to comment.