Add expression mode for Haskell and JS

This commit is contained in:
1computer1 2019-03-13 01:51:49 -04:00
parent 4b73ece01c
commit d16942c0a7
5 changed files with 38 additions and 10 deletions

View file

@ -71,12 +71,13 @@ Options are optionally set in `options`, which is a semicolon-delimited list of
For JavaScript: For JavaScript:
- `harmony` enables harmony features (`--harmony` on node) - `harmony` enables harmony features (`--harmony` on node)
- `e` prints the result of evaluating the code
For Python: For Python:
- `2` runs Python 2 instead of Python 3 - `2` runs Python 2 instead of Python 3
For Haskell: For Haskell:
- None - `e` evaluates a single expression instead of a module
For Pascal: For Pascal:
- None - None

View file

@ -1,2 +1,6 @@
echo "$1" > program.hs if [ "$EVAL_EXPR" = "true" ]; then
ghc -O0 -j +RTS -A128m -n2m -RTS program.hs >/dev/null && ./program ghc -e "$1"
else
echo "$1" > program.hs
ghc -O0 -j +RTS -A128m -n2m -RTS program.hs >/dev/null && ./program
fi

View file

@ -1,5 +1,11 @@
if [ "$EVAL_HARMONY" = "true" ]; then if [ "$EVAL_EXPR" = "true" ]; then
node --harmony -e "$1" flag="-p"
else else
node -e "$1" flag="-e"
fi
if [ "$EVAL_HARMONY" = "true" ]; then
node --harmony "$flag" "$1"
else
node "$flag" "$1"
fi fi

View file

@ -4,9 +4,20 @@ class Haskell extends Language {
constructor() { constructor() {
super('haskell', { super('haskell', {
highlight: 'hs', highlight: 'hs',
aliases: ['haskell', 'hs'] aliases: ['haskell', 'hs'],
options: {
e: () => ''
}
}); });
} }
runWith(options) {
if (options.has('e')) {
return { id: this.id, env: { EVAL_EXPR: 'true' } };
}
return super.runWith(options);
}
} }
module.exports = Haskell; module.exports = Haskell;

View file

@ -6,17 +6,23 @@ class JavaScript extends Language {
highlight: 'js', highlight: 'js',
aliases: ['javascript', 'js'], aliases: ['javascript', 'js'],
options: { options: {
harmony: () => '' harmony: () => '',
e: () => ''
} }
}); });
} }
runWith(options) { runWith(options) {
const ret = { id: this.id, env: {} };
if (options.has('harmony')) { if (options.has('harmony')) {
return { id: this.id, env: { EVAL_HARMONY: 'true' } }; ret.env.EVAL_HARMONY = 'true';
} }
return { id: this.id, env: {} }; if (options.has('e')) {
ret.env.EVAL_EXPR = 'true';
}
return ret;
} }
} }