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
|
||||
static macro function macroMain():Expr {
|
||||
var k = Kiss.defaultKissState();
|
||||
k.wrapListExps = false;
|
||||
if (Sys.args().indexOf("--all") != -1) {
|
||||
var kissInputStream = Stream.fromString(Sys.stdin().readAll().toString());
|
||||
Reader.readAndProcess(kissInputStream, k, (readerExp) -> {
|
||||
|
@@ -466,6 +466,7 @@
|
||||
num 3
|
||||
l1 ["a" "b" "c"]
|
||||
l2 [1 2 3]]
|
||||
// string interpolation:
|
||||
(Assert.equals "it's 3asy as [a,b,c] [1,2,3]" "$str ${num}asy as $l1 $l2")))
|
||||
|
||||
(defun _testArrowLambdas []
|
||||
|
@@ -2,12 +2,14 @@ package;
|
||||
|
||||
import kiss.Kiss;
|
||||
import kiss.Prelude;
|
||||
import kiss.Operand;
|
||||
import vscode.*;
|
||||
import js.lib.Promise;
|
||||
import js.node.ChildProcess;
|
||||
import js.node.buffer.Buffer;
|
||||
import hscript.Parser;
|
||||
import hscript.Interp;
|
||||
import hscript.Expr;
|
||||
|
||||
typedef Command = (String) -> Void;
|
||||
|
||||
|
@@ -53,13 +53,25 @@
|
||||
* Functionality
|
||||
*/
|
||||
|
||||
(defun convertToHScript [kiss]
|
||||
(.toString (the Buffer .stdout (ChildProcess.spawnSync "haxelib" ["run" "kiss" "--all"] (object input kiss)))))
|
||||
(defun :String convertToHScript [kissStr]
|
||||
(.toString (the Buffer .stdout (ChildProcess.spawnSync "haxelib" ["run" "kiss" "--all"] (object input kissStr)))))
|
||||
|
||||
(defun evalString [kiss]
|
||||
(interp.execute
|
||||
(parser.parseString
|
||||
(convertToHScript kiss))))
|
||||
(defun :Dynamic evalString [:String kissStr]
|
||||
(try
|
||||
(interp.execute
|
||||
(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]
|
||||
(if command
|
||||
@@ -73,8 +85,9 @@
|
||||
picked null
|
||||
alwaysShow null))]
|
||||
(awaitLet [chosenCommand (quickPick commandList)]
|
||||
(set lastCommand chosenCommand.label)
|
||||
((dictGet commands chosenCommand.label) (selectedText))))))
|
||||
(when chosenCommand
|
||||
(set lastCommand chosenCommand.label)
|
||||
((dictGet commands chosenCommand.label) (selectedText)))))))
|
||||
|
||||
(defun :Void runLastCommand [&opt _]
|
||||
(if lastCommand
|
||||
@@ -90,4 +103,25 @@
|
||||
|
||||
(defun :Void registerBuiltins []
|
||||
(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 = {
|
||||
registerBuiltins:() -> Void,
|
||||
registerCommand:(String, Command) -> Void,
|
||||
prepareInterp:() -> Void,
|
||||
runCommand:Command,
|
||||
runLastCommand:Command,
|
||||
runKeyboardShortcut:Command,
|
||||
|
@@ -37,9 +37,11 @@
|
||||
uniqueConfigFile (Path.join [activeConfigDir "$(.toShort (Uuid.v4)).js"])]
|
||||
(File.copy activeConfigFile uniqueConfigFile)
|
||||
(set config .KissConfig (Node.require uniqueConfigFile))
|
||||
(FileSystem.deleteFile uniqueConfigFile)
|
||||
// (FileSystem.deleteFile uniqueConfigFile)
|
||||
(.registerBuiltins (the KissConfig config))
|
||||
(.registerCommand (the KissConfig config) "Reload Kiss config" tryLoadConfig)
|
||||
(.prepareInterp (the KissConfig config))
|
||||
// User-defined init:
|
||||
(.init (the KissConfig config))
|
||||
(Vscode.window.showInformationMessage "Config loaded successfully!"))
|
||||
// If there's a build error, restore the config.js backup
|
||||
|
Reference in New Issue
Block a user