File tree Expand file tree Collapse file tree 4 files changed +16
-4
lines changed Expand file tree Collapse file tree 4 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ Website: https://www.gnu.org/software/bash/
6
6
Category: common
7
7
*/
8
8
9
+ import * as regex from '../lib/regex.js' ;
10
+
9
11
/** @type LanguageFn */
10
12
export default function ( hljs ) {
11
13
const VAR = { } ;
@@ -23,7 +25,7 @@ export default function(hljs) {
23
25
Object . assign ( VAR , {
24
26
className : 'variable' ,
25
27
variants : [
26
- { begin : / \$ [ \w \d # @ ] [ \w \d _ ] * / } ,
28
+ { begin : regex . concat ( / \$ [ \w \d # @ ] [ \w \d _ ] * / , `(?![\\w\\d])(?![$])` ) } ,
27
29
BRACED_VAR
28
30
]
29
31
} ) ;
Original file line number Diff line number Diff line change @@ -5,6 +5,9 @@ Website: https://www.perl.org
5
5
Category: common
6
6
*/
7
7
8
+ import * as regex from '../lib/regex.js' ;
9
+
10
+ /** @type LanguageFn */
8
11
export default function ( hljs ) {
9
12
var PERL_KEYWORDS = {
10
13
$pattern : / [ \w . ] + / ,
@@ -40,7 +43,12 @@ export default function(hljs) {
40
43
var VAR = {
41
44
variants : [
42
45
{ begin : / \$ \d / } ,
43
- { begin : / [ $ % @ ] ( \^ \w \b | # \w + ( : : \w + ) * | \{ \w + \} | \w + ( : : \w * ) * ) / } ,
46
+ { begin : regex . concat (
47
+ / [ $ % @ ] ( \^ \w \b | # \w + ( : : \w + ) * | \{ \w + \} | \w + ( : : \w * ) * ) / ,
48
+ // negative look-ahead tries to avoid matching patterns that are not
49
+ // Perl at all like $ident$, @ident@, etc.
50
+ `(?![A-Za-z])(?![@$%])`
51
+ ) } ,
44
52
{ begin : / [ $ % @ ] [ ^ \s \w { ] / , relevance : 0 }
45
53
]
46
54
} ;
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ Category: common
13
13
export default function ( hljs ) {
14
14
const VARIABLE = {
15
15
className : 'variable' ,
16
- begin : '\\$+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'
16
+ begin : '\\$+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' + `(?![A-Za-z0-9])(?![$])`
17
17
} ;
18
18
const PREPROCESSOR = {
19
19
className : 'meta' ,
Original file line number Diff line number Diff line change @@ -160,8 +160,10 @@ export default function(hljs) {
160
160
} ,
161
161
NUMBER ,
162
162
{
163
+ // negative-look forward attemps to prevent false matches like:
164
+ // @ident @ or $ident$ that might indicate this is not ruby at all
163
165
className : "variable" ,
164
- begin : '(\\$\\W)|((\\$|@@?)(\\w+))' // variables
166
+ begin : '(\\$\\W)|((\\$|@@?)(\\w+))(?=[^@$?])' + `(?![A-Za-z])(?![@$?'])`
165
167
} ,
166
168
{
167
169
className : 'params' ,
You can’t perform that action at this time.
0 commit comments