Skip to content

Commit a78d2cb

Browse files
committed
Improve repl regexp handling
- handle regexp with flags in repl completion - group config_jscalc customisations
1 parent 8180d3d commit a78d2cb

File tree

1 file changed

+35
-37
lines changed

1 file changed

+35
-37
lines changed

repl.js

+35-37
Original file line numberDiff line numberDiff line change
@@ -67,38 +67,20 @@ import * as os from "os";
6767
bright_white: "\x1b[37;1m",
6868
};
6969

70-
var styles;
71-
if (config_numcalc) {
72-
styles = {
73-
'default': 'black',
74-
'comment': 'white',
75-
'string': 'green',
76-
'regex': 'cyan',
77-
'number': 'green',
78-
'keyword': 'blue',
79-
'function': 'gray',
80-
'type': 'bright_magenta',
81-
'identifier': 'yellow',
82-
'error': 'bright_red',
83-
'result': 'black',
84-
'error_msg': 'bright_red',
85-
};
86-
} else {
87-
styles = {
88-
'default': 'bright_green',
89-
'comment': 'white',
90-
'string': 'bright_cyan',
91-
'regex': 'cyan',
92-
'number': 'green',
93-
'keyword': 'bright_white',
94-
'function': 'bright_yellow',
95-
'type': 'bright_magenta',
96-
'identifier': 'bright_green',
97-
'error': 'red',
98-
'result': 'bright_white',
99-
'error_msg': 'bright_red',
100-
};
101-
}
70+
var styles = {
71+
'default': 'bright_green',
72+
'comment': 'white',
73+
'string': 'bright_cyan',
74+
'regex': 'cyan',
75+
'number': 'green',
76+
'keyword': 'bright_white',
77+
'function': 'bright_yellow',
78+
'type': 'bright_magenta',
79+
'identifier': 'bright_green',
80+
'error': 'red',
81+
'result': 'bright_white',
82+
'error_msg': 'bright_red',
83+
};
10284

10385
var history = [];
10486
var clip_board = "";
@@ -109,11 +91,7 @@ import * as os from "os";
10991
var pstate = "";
11092
var prompt = "";
11193
var plen = 0;
112-
var ps1;
113-
if (config_numcalc)
114-
ps1 = "> ";
115-
else
116-
ps1 = "qjs > ";
94+
var ps1 = "qjs > ";
11795
var ps2 = " ... ";
11896
var utf8 = true;
11997
var show_time = false;
@@ -613,6 +591,9 @@ import * as os from "os";
613591
base = get_context_word(line, pos);
614592
if (["true", "false", "null", "this"].includes(base) || !isNaN(+base))
615593
return eval(base);
594+
// Check if `base` is a set of regexp flags
595+
if (pos - base.length >= 3 && line[pos - base.length - 1] === '/')
596+
return new RegExp('', base);
616597
obj = get_context_object(line, pos - base.length);
617598
if (obj === null || obj === void 0)
618599
return obj;
@@ -1181,6 +1162,23 @@ import * as os from "os";
11811162
}
11821163

11831164
if (config_numcalc) {
1165+
styles = {
1166+
'default': 'black',
1167+
'comment': 'white',
1168+
'string': 'green',
1169+
'regex': 'cyan',
1170+
'number': 'green',
1171+
'keyword': 'blue',
1172+
'function': 'gray',
1173+
'type': 'bright_magenta',
1174+
'identifier': 'yellow',
1175+
'error': 'bright_red',
1176+
'result': 'black',
1177+
'error_msg': 'bright_red',
1178+
};
1179+
1180+
ps1 = "> ";
1181+
11841182
/* called by the GUI */
11851183
g.execCmd = function (cmd) {
11861184
switch(cmd) {

0 commit comments

Comments
 (0)