Comparing version 0.0.1 to 0.0.2
@@ -21,2 +21,8 @@ #!/usr/bin/env node | ||
-- indicate the end of CLI options / script files | ||
-p, --profile=... select interpreter profile | ||
S S-expression parser | ||
L, lisp (default) lisp interpreter (return single value) | ||
LM lisp interpreter (return multiple values) | ||
lisp_async lisp interpreter (return single value, enable async) | ||
LM_async lisp interpreter (return multiple values, enable async) | ||
-e, --eval=... evaluate script | ||
@@ -33,2 +39,3 @@ -i, --interactive always enter the REPL even if stdin does not appear to be a terminal | ||
function cli() { | ||
let profileName = 'lisp'; | ||
let evalCode = void 0; | ||
@@ -41,3 +48,3 @@ let optsPos = 2; | ||
switch (x) { | ||
case '--help': case '-?': | ||
case '--help': case '-h': case '-?': | ||
help(); | ||
@@ -53,2 +60,6 @@ process.exit(0); | ||
break ParseOpts; | ||
case '-p': | ||
optsPos++; | ||
profileName = process.argv[optsPos]; | ||
break; | ||
case '-e': | ||
@@ -62,3 +73,5 @@ optsPos++; | ||
default: | ||
if (x.startsWith('--eval=')) { | ||
if (x.startsWith('--profile=')) { | ||
profileName = x.split('=', 2)[1]; | ||
} else if (x.startsWith('--eval=')) { | ||
evalCode = x.split('=', 2)[1]; | ||
@@ -72,2 +85,25 @@ } else { | ||
let lisp = void 0; | ||
switch (profileName) { | ||
case 'S': | ||
lisp = liyad.S; | ||
break; | ||
case 'L': case 'lisp': | ||
lisp = liyad.lisp; | ||
break; | ||
case 'LM': | ||
lisp = liyad.LM; | ||
break; | ||
case 'L_async': case 'lisp_async': | ||
lisp = liyad.lisp_async; | ||
break; | ||
case 'LM_async': | ||
lisp = liyad.LM_async; | ||
break; | ||
default: | ||
console.error(`Unknown profile name is specified: ${profileName} .`); | ||
process.exit(-1); | ||
break; | ||
} | ||
const fileNames = []; | ||
@@ -101,2 +137,16 @@ const filesPromises = []; | ||
} | ||
async function getCodes() { | ||
try { | ||
prepareFilePromises(); | ||
const codes = await Promise.all(filesPromises); | ||
if (evalCode) { | ||
codes.push(evalCode); | ||
} | ||
return codes.join('\n'); | ||
} catch (e) { | ||
console.error(e); | ||
process.exit(-1); | ||
} | ||
} | ||
@@ -110,10 +160,6 @@ const appOpts = process.argv.slice(optsPos); | ||
const repl = require('./repl'); | ||
prepareFilePromises(); | ||
(async () => { | ||
try { | ||
const codes = await Promise.all(filesPromises); | ||
if (evalCode) { | ||
codes.push(evalCode); | ||
} | ||
repl.startRepl(liyad, codes.join('\n')); | ||
const codes = await getCodes(); | ||
await repl.startRepl(liyad.S, lisp, codes); | ||
} catch (e) { | ||
@@ -127,8 +173,24 @@ console.error(e); | ||
try { | ||
prepareFilePromises(); | ||
const codes = await Promise.all(filesPromises); | ||
if (evalCode) { | ||
codes.push(evalCode); | ||
const codes = await getCodes(); | ||
let r = await lisp(codes); | ||
switch (typeof r) { | ||
case 'string': | ||
break; | ||
case 'number': case 'boolean': case 'undefined': | ||
r = String(r); | ||
break; | ||
case 'object': | ||
if (r === null) { | ||
r = String(r); | ||
} else if (r instanceof Date) { | ||
r = String(r); | ||
} else { | ||
r = JSON.stringify(r); | ||
} | ||
break; | ||
default: | ||
r = JSON.stringify(r); | ||
break; | ||
} | ||
await io.writeToStdout(JSON.stringify(liyad.lisp(codes.join('\n')))); | ||
await io.writeToStdout(r); | ||
} catch (e) { | ||
@@ -135,0 +197,0 @@ console.error(e); |
@@ -81,5 +81,5 @@ // Copyright (c) 2018, Shellyl_N and Authors | ||
if (trimmed.startsWith('(') && trimmed.endsWith(')')) { | ||
v = repl(str); | ||
v = repl.sync(str); | ||
} else { | ||
v = repl(`($last\n\n ${str} \n\n)`); | ||
v = repl.sync(`($last\n\n ${str} \n\n)`); | ||
} | ||
@@ -86,0 +86,0 @@ fs.writeSync(1, `\nType: ${typeof v}, Value: ${JSON.stringify(v)}\n`); |
@@ -11,3 +11,3 @@ // Copyright (c) 2018, Shellyl_N and Authors | ||
function startRepl(liyad, startup) { | ||
async function startRepl(S, lisp, startup) { | ||
const prompt = '>>> '; | ||
@@ -17,4 +17,2 @@ let pkgName = 'Liyad'; | ||
const S = liyad.S; | ||
try { | ||
@@ -35,7 +33,7 @@ const pkgJson = require('liyad/package.json'); | ||
const replRef = {}; | ||
liyad.lisp.appendGlobals({ | ||
lisp.appendGlobals({ | ||
'$pause': dbg.createDebugger(replRef, rl), | ||
}); | ||
const repl = liyad.lisp.repl(); | ||
const repl = lisp.repl(); | ||
replRef.repl = repl; | ||
@@ -53,33 +51,35 @@ | ||
rl.on('line', (input) => { | ||
buf += input; | ||
(async () =>{ | ||
buf += input; | ||
try { | ||
S(buf); | ||
} catch (e0) { | ||
// TODO: Use 'e0 instanceof ???' | ||
if (String(e0).includes('Unexpected termination of script')) { | ||
buf += '\n'; | ||
rl.setPrompt('... '); | ||
rl.prompt(); | ||
return; | ||
try { | ||
S(buf); | ||
} catch (e0) { | ||
// TODO: Use 'e0 instanceof ???' | ||
if (String(e0).includes('Unexpected termination of script')) { | ||
buf += '\n'; | ||
rl.setPrompt('... '); | ||
rl.prompt(); | ||
return; | ||
} | ||
} | ||
} | ||
try { | ||
const trimmed = buf.trim(); | ||
if (trimmed.length > 0) { | ||
if (trimmed.startsWith('(') && trimmed.endsWith(')')) { | ||
console.dir(repl(buf)); | ||
} else { | ||
console.dir(repl(`($last\n\n ${buf} \n\n)`)); | ||
try { | ||
const trimmed = buf.trim(); | ||
if (trimmed.length > 0) { | ||
if (trimmed.startsWith('(') && trimmed.endsWith(')')) { | ||
console.dir(await repl(buf)); | ||
} else { | ||
console.dir(await repl(`($last\n\n ${buf} \n\n)`)); | ||
} | ||
} | ||
} catch (e) { | ||
console.error(e); | ||
} finally { | ||
buf = ''; | ||
} | ||
} catch (e) { | ||
console.error(e); | ||
} finally { | ||
buf = ''; | ||
} | ||
rl.setPrompt(prompt); | ||
rl.prompt(); | ||
rl.setPrompt(prompt); | ||
rl.prompt(); | ||
})(); | ||
}) | ||
@@ -86,0 +86,0 @@ .on('close', () => { |
{ | ||
"name": "liyad-cli", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "CLI and REPL for Liyad (Lisp yet another DSL interpreter).", | ||
@@ -36,3 +36,3 @@ "keywords": [ | ||
"dependencies": { | ||
"liyad": "^0.0.15" | ||
"liyad": "^0.0.18" | ||
}, | ||
@@ -39,0 +39,0 @@ "repository": { |
@@ -5,2 +5,8 @@ # Liyad CLI | ||
[![npm](https://img.shields.io/npm/v/liyad-cli.svg)](https://www.npmjs.com/package/liyad-cli) | ||
[![GitHub release](https://img.shields.io/github/release/shellyln/liyad-cli.svg)](https://github.com/shellyln/liyad-cli/releases) | ||
[![Travis](https://img.shields.io/travis/shellyln/liyad-cli/master.svg)](https://travis-ci.org/shellyln/liyad-cli) | ||
[![GitHub forks](https://img.shields.io/github/forks/shellyln/liyad-cli.svg?style=social&label=Fork)](https://github.com/shellyln/liyad-cli/fork) | ||
[![GitHub stars](https://img.shields.io/github/stars/shellyln/liyad-cli.svg?style=social&label=Star)](https://github.com/shellyln/liyad-cli) | ||
---- | ||
@@ -16,3 +22,3 @@ | ||
$ npm install -g liyad-cli | ||
$ liyad | ||
$ liyad --version | ||
``` | ||
@@ -40,4 +46,6 @@ | ||
$ npm install -g pkg | ||
$ git clone https://github.com/shellyln/liyad-cli.git | ||
$ cd liyad-cli | ||
$ pkg . --output liyad | ||
$ ./liyad | ||
$ ./liyad --version | ||
``` | ||
@@ -44,0 +52,0 @@ |
Sorry, the diff of this file is not supported yet
17954
401
55
+ Addedliyad@0.0.18(transitive)
- Removedliyad@0.0.15(transitive)
Updatedliyad@^0.0.18