ace: Add support for multiline strings

In the AF language,
```
foo := "abc
   def"
```

declares a valid string with a linebreak inside. This wasn't previously
highlighted by ace, since normal rules are scanned line-by-line. The
code added here is essentially copied from the PHP highlighter [1],
whose rules should be almost the same as AF.

This new syntax also highlights escape sequences inside strings, e.g. in
"foo\\bar" see how the backslashes have a different color.

[1] - https://github.com/ajaxorg/ace/blob/master/lib/ace/mode/php_highlight_rules.js#L1058

Change-Id: Idb51001af00ff2ef118741cd686dc1adf19aebee
This commit is contained in:
Daimona Eaytoy 2021-10-02 17:15:15 +02:00
parent 0dae59616c
commit 1b41a61cf2

View file

@ -36,9 +36,7 @@ ace.define( 'ace/mode/abusefilter_highlight_rules', [ 'require', 'exports', 'mod
fraction = '(?:\\.\\d+)',
intPart = '(?:\\d+)',
pointFloat = '(?:(?:' + intPart + '?' + fraction + ')|(?:' + intPart + '\\.))',
floatNumber = '(?:' + pointFloat + ')',
singleQuoteString = '\'(?:[^\\\\]|\\\\.)*?\'',
doubleQuoteString = '"(?:[^\\\\]|\\\\.)*?"';
floatNumber = '(?:' + pointFloat + ')';
this.$rules = {
start: [ {
@ -47,10 +45,12 @@ ace.define( 'ace/mode/abusefilter_highlight_rules', [ 'require', 'exports', 'mod
next: 'comment'
}, {
token: 'string',
regex: doubleQuoteString
regex: '"',
next: 'doublequotestring'
}, {
token: 'string',
regex: singleQuoteString
regex: "'",
next: 'singlequotestring'
}, {
token: 'constant.numeric',
regex: floatNumber
@ -73,13 +73,20 @@ ace.define( 'ace/mode/abusefilter_highlight_rules', [ 'require', 'exports', 'mod
token: 'text',
regex: '\\s+|\\w+'
} ],
comment: [ {
token: 'comment',
regex: '\\*\\/',
next: 'start'
}, {
defaultToken: 'comment'
} ]
comment: [
{ token: 'comment', regex: '\\*\\/', next: 'start' },
{ defaultToken: 'comment' }
],
doublequotestring: [
{ token: 'constant.language.escape', regex: /\\["\\]/ },
{ token: 'string', regex: '"', next: 'start' },
{ defaultToken: 'string' }
],
singlequotestring: [
{ token: 'constant.language.escape', regex: /\\['\\]/ },
{ token: 'string', regex: "'", next: 'start' },
{ defaultToken: 'string' }
]
};
this.normalizeRules();