Merge "Improve Ace syntax highlight"

This commit is contained in:
jenkins-bot 2018-08-23 10:14:57 +00:00 committed by Gerrit Code Review
commit 81a4fdc964
3 changed files with 37 additions and 17 deletions

View file

@ -2104,17 +2104,26 @@ class AbuseFilter {
public static function getAceConfig( $canEdit ) {
$values = self::getBuilderValues();
$deprecatedVars = self::getDeprecatedVariables();
$builderVariables = implode( '|',
array_keys( array_merge( $values['vars'], $deprecatedVars ) ) );
$builderVariables = implode( '|', array_keys( $values['vars'] ) );
$builderFunctions = implode( '|', array_keys( AbuseFilterParser::$mFunctions ) );
// AbuseFilterTokenizer::$keywords also includes constants (true, false and null),
// but Ace redefines these constants afterwards so this will not be an issue
$builderKeywords = implode( '|', AbuseFilterTokenizer::$keywords );
// Extract operators from tokenizer like we do in AbuseFilterParserTest
$operators = implode( '|', array_map( function ( $op ) {
return preg_quote( $op, '/' );
}, AbuseFilterTokenizer::$operators ) );
$deprecatedVariables = implode( '|', array_keys( $deprecatedVars ) );
$disabledVariables = implode( '|', array_keys( self::$disabledVars ) );
return [
'variables' => $builderVariables,
'functions' => $builderFunctions,
'keywords' => $builderKeywords,
'operators' => $operators,
'deprecated' => $deprecatedVariables,
'disabled' => $disabledVariables,
'aceReadOnly' => !$canEdit
];
}

View file

@ -152,3 +152,14 @@ ul li.mw-abusefilter-changeslist-match {
.mw-abusefilter-history-buttons {
text-align: center;
}
/* Ace highlight customisation */
span.ace_invalid.ace_deprecated {
color: #fe6767;
background-color: initial;
}
span.ace_support.ace_function {
color: #495dd0;
}

View file

@ -6,18 +6,16 @@ ace.define( 'ace/mode/abusefilter_highlight_rules', [ 'require', 'exports', 'mod
TextHighlightRules = require( './text_highlight_rules' ).TextHighlightRules,
AFHighlightRules = function () {
var keywords = ( mw.config.get( 'aceConfig' ).keywords ),
var cfg = mw.config.get( 'aceConfig' ),
constants = ( 'true|false|null' ),
functions = ( mw.config.get( 'aceConfig' ).functions ),
variables = ( mw.config.get( 'aceConfig' ).variables ),
deprecated = ( '' ), // Template for deprecated vars, already registered within ace settings.
keywordMapper = this.createKeywordMapper(
{
keyword: keywords,
'support.function': functions,
keyword: cfg.keywords,
'support.function': cfg.functions,
'constant.language': constants,
'variable.language': variables,
'keyword.deprecated': deprecated
'variable.language': cfg.variables,
'invalid.deprecated': cfg.deprecated,
'invalid.illegal': cfg.disabled
},
'identifier'
),
@ -27,7 +25,9 @@ ace.define( 'ace/mode/abusefilter_highlight_rules', [ 'require', 'exports', 'mod
fraction = '(?:\\.\\d+)',
intPart = '(?:\\d+)',
pointFloat = '(?:(?:' + intPart + '?' + fraction + ')|(?:' + intPart + '\\.))',
floatNumber = '(?:' + pointFloat + ')';
floatNumber = '(?:' + pointFloat + ')',
singleQuoteString = '\'(?:[^\\\\]|\\\\.)*?\'',
doubleQuoteString = '"(?:[^\\\\]|\\\\.)*?"';
this.$rules = {
start: [ {
@ -35,11 +35,11 @@ ace.define( 'ace/mode/abusefilter_highlight_rules', [ 'require', 'exports', 'mod
regex: '\\/\\*',
next: 'comment'
}, {
token: 'string', // " string
regex: '"(?:[^\\\\]|\\\\.)*?"'
token: 'string',
regex: doubleQuoteString
}, {
token: 'string', // ' string
regex: '\'(?:[^\\\\]|\\\\.)*?\''
token: 'string',
regex: singleQuoteString
}, {
token: 'constant.numeric', // float
regex: floatNumber
@ -48,10 +48,10 @@ ace.define( 'ace/mode/abusefilter_highlight_rules', [ 'require', 'exports', 'mod
regex: integer + '\\b'
}, {
token: keywordMapper,
regex: '[a-zA-Z_$][a-zA-Z0-9_$]*\\b'
regex: '[a-zA-Z_][a-zA-Z0-9_]*\\b'
}, {
token: 'keyword.operator',
regex: '\\+|\\-|\\*\\*|\\*|\\/|%|\\^|&|\\||<|>|<=|=>|==|!=|===|!==|:=|=|!'
regex: cfg.operators
}, {
token: 'paren.lparen',
regex: '[\\[\\(]'