| 1 |
|
| 2 |
ace.define( 'ace/mode/abusefilter_highlight_rules', [ 'require', 'exports', 'module', 'ace/lib/oop', 'ace/mode/text_highlight_rules' ], function ( require, exports ) { |
| 3 |
'use strict'; |
| 4 |
|
| 5 |
var oop = require( 'ace/lib/oop' ), |
| 6 |
TextHighlightRules = require( './text_highlight_rules' ).TextHighlightRules, |
| 7 |
AFHighlightRules = function () { |
| 8 |
var cfg = mw.config.get( 'aceConfig' ), |
| 9 |
constants = ( 'true|false|null' ), |
| 10 |
keywords = this.createKeywordMapper( |
| 11 |
{ |
| 12 |
keyword: cfg.keywords, |
| 13 |
'support.function': cfg.functions, |
| 14 |
'constant.language': constants |
| 15 |
}, |
| 16 |
|
| 17 |
null |
| 18 |
), |
| 19 |
variables = this.createKeywordMapper( |
| 20 |
{ |
| 21 |
'variable.language': cfg.variables, |
| 22 |
'invalid.deprecated': cfg.deprecated, |
| 23 |
'invalid.illegal': cfg.disabled |
| 24 |
}, |
| 25 |
'identifier', |
| 26 |
true |
| 27 |
), |
| 28 |
isKeywordOrVariable = function ( value ) { |
| 29 |
if ( keywords( value ) !== null ) { |
| 30 |
return keywords( value ); |
| 31 |
} else { |
| 32 |
return variables( value ); |
| 33 |
} |
| 34 |
}, |
| 35 |
integer = '(?:(?:[1-9]\\d*)|(?:0))', |
| 36 |
fraction = '(?:\\.\\d+)', |
| 37 |
intPart = '(?:\\d+)', |
| 38 |
pointFloat = '(?:(?:' + intPart + '?' + fraction + ')|(?:' + intPart + '\\.))', |
| 39 |
floatNumber = '(?:' + pointFloat + ')'; |
| 40 |
|
| 41 |
this.$rules = { |
| 42 |
start: [ { |
| 43 |
token: 'comment', |
| 44 |
regex: '\\/\\*', |
| 45 |
next: 'comment' |
| 46 |
}, { |
| 47 |
token: 'string', |
| 48 |
regex: '"', |
| 49 |
next: 'doublequotestring' |
| 50 |
}, { |
| 51 |
token: 'string', |
| 52 |
regex: "'", |
| 53 |
next: 'singlequotestring' |
| 54 |
}, { |
| 55 |
token: 'constant.numeric', |
| 56 |
regex: floatNumber |
| 57 |
}, { |
| 58 |
token: 'constant.numeric', |
| 59 |
regex: integer + '\\b' |
| 60 |
}, { |
| 61 |
token: isKeywordOrVariable, |
| 62 |
regex: '[a-zA-Z_][a-zA-Z0-9_]*\\b' |
| 63 |
}, { |
| 64 |
token: 'keyword.operator', |
| 65 |
regex: cfg.operators |
| 66 |
}, { |
| 67 |
token: 'paren.lparen', |
| 68 |
regex: '[\\[\\(]' |
| 69 |
}, { |
| 70 |
token: 'paren.rparen', |
| 71 |
regex: '[\\]\\)]' |
| 72 |
}, { |
| 73 |
token: 'text', |
| 74 |
regex: '\\s+|\\w+' |
| 75 |
} ], |
| 76 |
comment: [ |
| 77 |
{ token: 'comment', regex: '\\*\\/', next: 'start' }, |
| 78 |
{ defaultToken: 'comment' } |
| 79 |
], |
| 80 |
doublequotestring: [ |
| 81 |
{ token: 'constant.language.escape', regex: /\\["\\]/ }, |
| 82 |
{ token: 'string', regex: '"', next: 'start' }, |
| 83 |
{ defaultToken: 'string' } |
| 84 |
], |
| 85 |
singlequotestring: [ |
| 86 |
{ token: 'constant.language.escape', regex: /\\['\\]/ }, |
| 87 |
{ token: 'string', regex: "'", next: 'start' }, |
| 88 |
{ defaultToken: 'string' } |
| 89 |
] |
| 90 |
}; |
| 91 |
|
| 92 |
this.normalizeRules(); |
| 93 |
}; |
| 94 |
|
| 95 |
oop.inherits( AFHighlightRules, TextHighlightRules ); |
| 96 |
|
| 97 |
exports.AFHighlightRules = AFHighlightRules; |
| 98 |
} ); |
| 99 |
|
| 100 |
ace.define( 'ace/mode/abusefilter', [ 'require', 'exports', 'module', 'ace/lib/oop', 'ace/mode/text', 'ace/mode/abusefilter_highlight_rules', 'ace/worker/worker_client' ], function ( require, exports ) { |
| 101 |
'use strict'; |
| 102 |
|
| 103 |
var oop = require( 'ace/lib/oop' ), |
| 104 |
TextMode = require( './text' ).Mode, |
| 105 |
WorkerClient = require( 'ace/worker/worker_client' ).WorkerClient, |
| 106 |
AFHighlightRules = require( './abusefilter_highlight_rules' ).AFHighlightRules, |
| 107 |
MatchingBraceOutdent = require( './matching_brace_outdent' ).MatchingBraceOutdent, |
| 108 |
Mode = function () { |
| 109 |
this.HighlightRules = AFHighlightRules; |
| 110 |
this.$behaviour = this.$defaultBehaviour; |
| 111 |
this.$outdent = new MatchingBraceOutdent(); |
| 112 |
}; |
| 113 |
oop.inherits( Mode, TextMode ); |
| 114 |
|
| 115 |
( function () { |
| 116 |
this.blockComment = { |
| 117 |
start: '/*', |
| 118 |
end: '*/' |
| 119 |
}; |
| 120 |
this.getNextLineIndent = function ( state, line ) { |
| 121 |
var indent = this.$getIndent( line ); |
| 122 |
return indent; |
| 123 |
}; |
| 124 |
this.checkOutdent = function ( state, line, input ) { |
| 125 |
return this.$outdent.checkOutdent( line, input ); |
| 126 |
}; |
| 127 |
this.autoOutdent = function ( state, doc, row ) { |
| 128 |
this.$outdent.autoOutdent( doc, row ); |
| 129 |
}; |
| 130 |
|
| 131 |
this.createWorker = function ( session ) { |
| 132 |
var extPath = mw.config.get( 'wgExtensionAssetsPath' ); |
| 133 |
ace.config.set( 'workerPath', extPath + '/AbuseFilter/modules' ); |
| 134 |
var worker = new WorkerClient( [ 'ace' ], 'ace/mode/abusefilter_worker', 'AbuseFilterWorker' ); |
| 135 |
|
| 136 |
var apiPath = mw.config.get( 'wgServer' ) + new mw.Api().defaults.ajax.url; |
| 137 |
if ( apiPath.slice( 0, 2 ) === '//' ) { |
| 138 |
apiPath = window.location.protocol + apiPath; |
| 139 |
} |
| 140 |
worker.$worker.postMessage( { apipath: apiPath } ); |
| 141 |
|
| 142 |
worker.attachToDocument( session.getDocument() ); |
| 143 |
|
| 144 |
worker.on( 'annotate', function ( results ) { |
| 145 |
session.setAnnotations( results.data ); |
| 146 |
} ); |
| 147 |
|
| 148 |
worker.on( 'terminate', function () { |
| 149 |
session.clearAnnotations(); |
| 150 |
} ); |
| 151 |
|
| 152 |
return worker; |
| 153 |
}; |
| 154 |
} ) |
| 155 |
.call( Mode.prototype ); |
| 156 |
|
| 157 |
exports.Mode = Mode; |
| 158 |
} ); |