3535
3636cmds.exit = python.exit;
3737cmds.python = function pythonCmd(...args) {
38+ var retval;
3839 const cmd = args.join(' ').trim();
3940
4041 if (cmd === 'reset')
4647 }
4748
4849 if (cmd === '')
49- {
5050 return;
51- }
52-
53- try {
51+
52+ try
53+ {
5454 if (arguments[0] === 'from' || arguments[0] === 'import')
55- {
5655 return python.exec(cmd);
57- }
58-
59- const retval = python.eval(cmd);
56+ retval = python.eval(cmd);
6057 }
61- catch(error) {
58+ catch(error)
59+ {
6260 globalThis._error = error;
6361 return util.inspect(error);
6462 }
65-
63+
6664 pythonCmd.serial = (pythonCmd.serial || 0) + 1;
6765 globalThis['$' + pythonCmd.serial] = retval;
6866 python.stdout.write('$' + pythonCmd.serial + ' = ');
7270/**
7371 * Handle a .xyz repl command. Invokes function cmds[XXX], passing arguments that the user typed as the
7472 * function arguments. The function arguments are space-delimited arguments; arguments surrounded by
75- * quotes can include spaces, similar to how bash parses arguments. Argument parsing cribbed from
73+ * quotes can include spaces, similar to how bash parses arguments. Argument parsing cribbed from
7674 * stackoverflow user Tsuneo Yoshioka, question 4031900.
7775 *
7876 * @param {string} cmdLine the command the user typed, without the leading .
107105 var result;
108106 var mightBeObjectLiteral = false;
109107
110- /* A statement which starts with a { and does not end with a ; is treated as an object literal,
108+ /* A statement which starts with a { and does not end with a ; is treated as an object literal,
111109 * and to get the parser in to Expression mode instead of Statement mode, we surround any expression
112- * like that which is also a valid compilation unit with parens, then if that is a syntax error,
110+ * like that which is also a valid compilation unit with parens, then if that is a syntax error,
113111 * we re-evaluate without the parens.
114112 */
115113 if (/^\\ s*\\ {.*[^;\\ s]\\ s*$/.test(statement))
@@ -152,7 +150,7 @@ def repl():
152150 Start a REPL to evaluate JavaScript code in the extra-module environment. Multi-line statements and
153151 readline history are supported. ^C support is sketchy. Exit the REPL with ^D or ".quit".
154152 """
155-
153+
156154 print ('Welcome to PythonMonkey v' + pm .__version__ + '.' )
157155 print ('Type ".help" for more information.' )
158156 readline .parse_and_bind ('set editing-mode emacs' )
@@ -167,7 +165,7 @@ def repl():
167165 statement = ''
168166 readline_skip_chars = 0
169167 inner_loop = False
170-
168+
171169 def save_history ():
172170 nonlocal histfile
173171 readline .write_history_file (histfile )
@@ -240,7 +238,7 @@ def sigint_handler(signum, frame):
240238 if (statement == "" ):
241239 statement = input ('> ' )[readline_skip_chars :]
242240 readline_skip_chars = 0
243-
241+
244242 if (len (statement ) == 0 ):
245243 continue
246244 if (statement [0 ] == '.' ):
@@ -291,7 +289,7 @@ def usage():
291289 -v, --version print PythonMonkey version
292290 --use-strict evaluate -e, -p, and REPL code in strict mode
293291 --inspect enable pmdb, a gdb-like JavaScript debugger interface
294-
292+
295293Environment variables:
296294TZ specify the timezone configuration
297295PMJS_PATH ':'-separated list of directories prefixed to the module search path
@@ -322,7 +320,7 @@ def main():
322320 forceRepl = False
323321 globalInitModule = initGlobalThis ()
324322 global requirePath
325-
323+
326324 try :
327325 opts , args = getopt .getopt (sys .argv [1 :], "hie:p:r:v" , ["help" , "eval=" , "print=" , "require=" , "version" , "interactive" , "use-strict" , "inspect" ])
328326 except getopt .GetoptError as err :
0 commit comments