Kiss VSCode runtime Kiss evaluation
This commit is contained in:
@@ -22,6 +22,7 @@ class Main {
|
|||||||
// TODO use this to implement runAtRuntime() for sys targets by running a haxe subprocess
|
// TODO use this to implement runAtRuntime() for sys targets by running a haxe subprocess
|
||||||
static macro function macroMain():Expr {
|
static macro function macroMain():Expr {
|
||||||
var k = Kiss.defaultKissState();
|
var k = Kiss.defaultKissState();
|
||||||
|
k.wrapListExps = false;
|
||||||
if (Sys.args().indexOf("--all") != -1) {
|
if (Sys.args().indexOf("--all") != -1) {
|
||||||
var kissInputStream = Stream.fromString(Sys.stdin().readAll().toString());
|
var kissInputStream = Stream.fromString(Sys.stdin().readAll().toString());
|
||||||
Reader.readAndProcess(kissInputStream, k, (readerExp) -> {
|
Reader.readAndProcess(kissInputStream, k, (readerExp) -> {
|
||||||
|
@@ -466,6 +466,7 @@
|
|||||||
num 3
|
num 3
|
||||||
l1 ["a" "b" "c"]
|
l1 ["a" "b" "c"]
|
||||||
l2 [1 2 3]]
|
l2 [1 2 3]]
|
||||||
|
// string interpolation:
|
||||||
(Assert.equals "it's 3asy as [a,b,c] [1,2,3]" "$str ${num}asy as $l1 $l2")))
|
(Assert.equals "it's 3asy as [a,b,c] [1,2,3]" "$str ${num}asy as $l1 $l2")))
|
||||||
|
|
||||||
(defun _testArrowLambdas []
|
(defun _testArrowLambdas []
|
||||||
|
@@ -2,12 +2,14 @@ package;
|
|||||||
|
|
||||||
import kiss.Kiss;
|
import kiss.Kiss;
|
||||||
import kiss.Prelude;
|
import kiss.Prelude;
|
||||||
|
import kiss.Operand;
|
||||||
import vscode.*;
|
import vscode.*;
|
||||||
import js.lib.Promise;
|
import js.lib.Promise;
|
||||||
import js.node.ChildProcess;
|
import js.node.ChildProcess;
|
||||||
import js.node.buffer.Buffer;
|
import js.node.buffer.Buffer;
|
||||||
import hscript.Parser;
|
import hscript.Parser;
|
||||||
import hscript.Interp;
|
import hscript.Interp;
|
||||||
|
import hscript.Expr;
|
||||||
|
|
||||||
typedef Command = (String) -> Void;
|
typedef Command = (String) -> Void;
|
||||||
|
|
||||||
|
@@ -53,13 +53,25 @@
|
|||||||
* Functionality
|
* Functionality
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(defun convertToHScript [kiss]
|
(defun :String convertToHScript [kissStr]
|
||||||
(.toString (the Buffer .stdout (ChildProcess.spawnSync "haxelib" ["run" "kiss" "--all"] (object input kiss)))))
|
(.toString (the Buffer .stdout (ChildProcess.spawnSync "haxelib" ["run" "kiss" "--all"] (object input kissStr)))))
|
||||||
|
|
||||||
(defun evalString [kiss]
|
(defun :Dynamic evalString [:String kissStr]
|
||||||
(interp.execute
|
(try
|
||||||
(parser.parseString
|
(interp.execute
|
||||||
(convertToHScript kiss))))
|
(parser.parseString
|
||||||
|
(convertToHScript kissStr)))
|
||||||
|
(catch [e]
|
||||||
|
(trace "fuckkkkk")
|
||||||
|
(errorMessage "Error `${e}` from $kissStr")
|
||||||
|
null)))
|
||||||
|
|
||||||
|
(defun :Void evalAndPrint [&opt :String selectedText]
|
||||||
|
(if selectedText
|
||||||
|
(infoMessage (Std.string (evalString selectedText))))
|
||||||
|
|
||||||
|
(awaitLet [kissStr (inputBox)]
|
||||||
|
(infoMessage (Std.string (evalString kissStr)))))
|
||||||
|
|
||||||
(defun :Void runCommand [&opt command]
|
(defun :Void runCommand [&opt command]
|
||||||
(if command
|
(if command
|
||||||
@@ -73,8 +85,9 @@
|
|||||||
picked null
|
picked null
|
||||||
alwaysShow null))]
|
alwaysShow null))]
|
||||||
(awaitLet [chosenCommand (quickPick commandList)]
|
(awaitLet [chosenCommand (quickPick commandList)]
|
||||||
(set lastCommand chosenCommand.label)
|
(when chosenCommand
|
||||||
((dictGet commands chosenCommand.label) (selectedText))))))
|
(set lastCommand chosenCommand.label)
|
||||||
|
((dictGet commands chosenCommand.label) (selectedText)))))))
|
||||||
|
|
||||||
(defun :Void runLastCommand [&opt _]
|
(defun :Void runLastCommand [&opt _]
|
||||||
(if lastCommand
|
(if lastCommand
|
||||||
@@ -90,4 +103,25 @@
|
|||||||
|
|
||||||
(defun :Void registerBuiltins []
|
(defun :Void registerBuiltins []
|
||||||
(registerCommand "Rerun last command" runLastCommand)
|
(registerCommand "Rerun last command" runLastCommand)
|
||||||
(registerCommand "Run a keyboard shortcut command" runKeyboardShortcut))
|
(registerCommand "Run a keyboard shortcut command" runKeyboardShortcut)
|
||||||
|
(registerCommand "Evaluate and print a Kiss expression" evalAndPrint))
|
||||||
|
|
||||||
|
(defun :Void prepareInterp []
|
||||||
|
(interp.variables.set "kiss"
|
||||||
|
(object
|
||||||
|
Operand
|
||||||
|
(object
|
||||||
|
fromDynamic Operand.fromDynamic)
|
||||||
|
Prelude
|
||||||
|
Prelude))
|
||||||
|
//interp.variables.set("Helpers", Helpers);
|
||||||
|
(interp.variables.set "Prelude" Prelude)
|
||||||
|
(interp.variables.set "Lambda" Lambda)
|
||||||
|
// TODO for some reason, (interp.variables.set "Std" Std) doesn't capture
|
||||||
|
// some static functions, like parseInt. So this kludgy bit is necessary:
|
||||||
|
(interp.variables.set "Std"
|
||||||
|
(object
|
||||||
|
parseInt Std.parseInt
|
||||||
|
string Std.string
|
||||||
|
random Std.random
|
||||||
|
int Std.int)))
|
||||||
|
@@ -16,6 +16,7 @@ typedef Command = (?String) -> Void;
|
|||||||
typedef KissConfig = {
|
typedef KissConfig = {
|
||||||
registerBuiltins:() -> Void,
|
registerBuiltins:() -> Void,
|
||||||
registerCommand:(String, Command) -> Void,
|
registerCommand:(String, Command) -> Void,
|
||||||
|
prepareInterp:() -> Void,
|
||||||
runCommand:Command,
|
runCommand:Command,
|
||||||
runLastCommand:Command,
|
runLastCommand:Command,
|
||||||
runKeyboardShortcut:Command,
|
runKeyboardShortcut:Command,
|
||||||
|
@@ -37,9 +37,11 @@
|
|||||||
uniqueConfigFile (Path.join [activeConfigDir "$(.toShort (Uuid.v4)).js"])]
|
uniqueConfigFile (Path.join [activeConfigDir "$(.toShort (Uuid.v4)).js"])]
|
||||||
(File.copy activeConfigFile uniqueConfigFile)
|
(File.copy activeConfigFile uniqueConfigFile)
|
||||||
(set config .KissConfig (Node.require uniqueConfigFile))
|
(set config .KissConfig (Node.require uniqueConfigFile))
|
||||||
(FileSystem.deleteFile uniqueConfigFile)
|
// (FileSystem.deleteFile uniqueConfigFile)
|
||||||
(.registerBuiltins (the KissConfig config))
|
(.registerBuiltins (the KissConfig config))
|
||||||
(.registerCommand (the KissConfig config) "Reload Kiss config" tryLoadConfig)
|
(.registerCommand (the KissConfig config) "Reload Kiss config" tryLoadConfig)
|
||||||
|
(.prepareInterp (the KissConfig config))
|
||||||
|
// User-defined init:
|
||||||
(.init (the KissConfig config))
|
(.init (the KissConfig config))
|
||||||
(Vscode.window.showInformationMessage "Config loaded successfully!"))
|
(Vscode.window.showInformationMessage "Config loaded successfully!"))
|
||||||
// If there's a build error, restore the config.js backup
|
// If there's a build error, restore the config.js backup
|
||||||
|
Reference in New Issue
Block a user