* org-babel support for haxe
@ 2020-06-12 4:37 ian martins
2020-09-05 7:24 ` Bastien
2020-09-06 15:24 ` Kyle Meyer
0 siblings, 2 replies; 8+ messages in thread
From: ian martins @ 2020-06-12 4:37 UTC (permalink / raw)
To: Emacs-orgmode
[-- Attachment #1.1: Type: text/plain, Size: 1029 bytes --]
Hello. The included patch adds org-babel support for haxe (https://haxe.org/).
It allows main class and function definitions to be optional, accepts
variables and supports babel functional mode. Please review.
I believe the same approach should work for java also. If this is fine I
could try to write an ob-java based on this to give java the same features
listed above.
One thing I would like to change is that this dumps the generated source
files in the current directory instead of burying them in the babel temp
dir (org-babel-temporary-directory). The same applies to the current
ob-java implementation. In order to put the temp source files in the babel
temp dir, there would have to be changes made in ob-core to allow creation
and removal of directories in the babel temp dir. If that seems reasonable
then I could try doing it, but let me know if there are reasons not to or
complications that I haven't thought of.
I've not done the FSF release. If this is acceptable I understand that I'll
have to do that.
-Ian
[-- Attachment #1.2: Type: text/html, Size: 1222 bytes --]
[-- Attachment #2: ob-haxe.patch --]
[-- Type: text/x-patch, Size: 27481 bytes --]
diff --git a/lisp/ob-haxe.el b/lisp/ob-haxe.el
new file mode 100644
index 000000000..5b0a42c7a
--- /dev/null
+++ b/lisp/ob-haxe.el
@@ -0,0 +1,260 @@
+;;; ob-haxe.el --- org-babel functions for haxe evaluation
+
+;; Copyright (C) 2020 Free Software Foundation, Inc.
+
+;; Author: Ian Martins
+;; Keywords: literate programming, reproducible research
+;; Homepage: http://orgmode.org
+
+;; This file is not part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Org-Babel support for evaluating haxe source code.
+
+;;; Code:
+(require 'ob)
+
+(defvar org-babel-tangle-lang-exts)
+(add-to-list 'org-babel-tangle-lang-exts '("haxe" . "hx"))
+
+(defvar org-babel-default-header-args:haxe '()
+ "Default header args for haxe source blocks.")
+
+(defconst org-babel-header-args:haxe '((target . '(interp neko hashlink))
+ (imports . :any))
+ "Haxe-specific header arguments.
+org-babel supports three of the platforms the haxe compiler can target.
+
+ `interp' runs the haxe compiler with the `--interp' option.
+ `neko' and `hashlink' compile to bytecode and run the
+ respective VMs.")
+
+(defvar org-babel-haxe-command "haxe"
+ "Name of the haxe command.")
+
+(defcustom org-babel-haxe-hline-to "null"
+ "Replace hlines in incoming tables with this when translating to haxe."
+ :group 'org-babel
+ :version "25.2"
+ :package-version '(Org . "9.3")
+ :type 'string)
+
+(defcustom org-babel-haxe-null-to 'hline
+ "Replace `null' in haxe tables with this before returning."
+ :group 'org-babel
+ :version "25.2"
+ :package-version '(Org . "9.3")
+ :type 'symbol)
+
+(defun org-babel-execute:haxe (body params)
+ "Execute a haxe source block with BODY code and PARAMS params."
+ (let* ((fullclassname (or (cdr (assq :classname params)) ; class and package
+ (org-babel-haxe-find-classname body)
+ "Main"))
+ (classname (if (seq-contains fullclassname ?.) ; just class name
+ (file-name-extension fullclassname)
+ fullclassname))
+ (packagename (if (seq-contains fullclassname ?.) ; just package name
+ (file-name-base fullclassname)
+ ""))
+ (packagedir (if (not (seq-empty-p packagename)) ; package name as a path
+ (replace-regexp-in-string "\\\." "/" packagename)))
+ (src-file (concat (replace-regexp-in-string "\\\." "/" fullclassname) ".hx"))
+ (cmdline (or (cdr (assq :cmdline params)) ""))
+ (target-name (cdr (assq :target params)))
+ (target (cond ((string= target-name "neko") "-neko main.n -cmd \"neko main.n\"")
+ ((string= target-name "hashlink") "-hl main.hl -cmd \"hl main.hl\"")
+ (t "--interp")))
+ (cmd (concat org-babel-haxe-command
+ " " cmdline " -main " fullclassname " " target))
+ (result-type (cdr (assq :result-type params)))
+ (result-params (cdr (assq :result-params params)))
+ (tmp-file (and (eq result-type 'value)
+ (org-babel-temp-file "haxe-")))
+ (full-body (org-babel-expand-body:haxe
+ body params classname packagename result-type tmp-file)))
+
+ ;; created package-name directories if missing
+ (unless (or (not packagedir) (file-exists-p packagedir))
+ (make-directory packagedir 'parents))
+ (with-temp-file src-file (insert full-body))
+ (org-babel-reassemble-table
+ (org-babel-haxe-evaluate cmd target-name result-type result-params tmp-file)
+ (org-babel-pick-name
+ (cdr (assoc :colname-names params)) (cdr (assoc :colnames params)))
+ (org-babel-pick-name
+ (cdr (assoc :rowname-names params)) (cdr (assoc :rownames params))))))
+
+;; helper functions
+
+(defun org-babel-haxe-find-classname (body)
+ "Try to find fully qualified classname in BODY."
+ (let ((package (if (string-match "package \\\([^ ]*\\\);" body)
+ (match-string 1 body)))
+ (class (if (string-match "class \\\([^ \n]*\\\)" body)
+ (match-string 1 body))))
+ (or (and package class (concat package "." class))
+ class)))
+
+(defun org-babel-expand-body:haxe (body params classname packagename
+ result-type tmp-file)
+ "Expand BODY with PARAMS.
+BODY could be a few statements, or could include a full class
+definition specifying package, imports, and class. Because we
+allow this flexibility in what the source block can contain, it
+is simplest to expand the code block from the inside out.
+
+CLASSNAME name of the class, which may have been specified
+in multiple ways.
+
+PACKAGENAME name of the java package containing this class.
+
+RESULT-TYPE output or value.
+
+TMP-FILE name of tempfile to write to if value `result-type'."
+ (let* ((var-lines (org-babel-variable-assignments:haxe params))
+ (imports-val (assq :imports params))
+ (imports (if imports-val
+ (split-string (org-babel-read (cdr imports-val) nil) " ")
+ nil)))
+ (with-temp-buffer
+ (insert body)
+
+ ;; wrap main
+ (goto-char (point-min))
+ (when (not (re-search-forward "static .*function main\(\)" nil t))
+ (while (re-search-forward "^[[:space:]]*import .*;$" nil t) ; if imports are defined, move past them
+ (goto-char (1+ (match-end 0))))
+ (insert "public static function main() {\n")
+ (goto-char (point-max))
+ (insert "\n}"))
+
+ ;; insert variables
+ (when var-lines
+ (goto-char (point-min))
+ (if (re-search-forward "^[[:space:]]*class .*\n?{[[:space:]]*$" nil t)
+ (goto-char (1+ (match-end 0))))
+ (insert (mapconcat 'identity var-lines "\n"))
+ (insert "\n"))
+
+ ;; special handling to return value
+ (when (eq result-type 'value)
+ (goto-char (point-min))
+ (re-search-forward "^[[:space:]]*class .*\n?{" nil t)
+ (insert "\n")
+ (insert " public static function main() {\n")
+ (insert (format " var output = File.write(\"%s\");\n" (org-babel-process-file-name tmp-file 'noquote)))
+ (insert " output.writeString(haxe.Json.stringify(_main()));\n")
+ (insert " output.close();\n")
+ (insert " }\n")
+ (search-forward "function main()") ; rename existing main
+ (replace-match "function _main()"))
+
+ ;; wrap class
+ (goto-char (point-min))
+ (when (not (re-search-forward "^[[:space:]]*class [^ ]*" nil t))
+ (while (re-search-forward "^[[:space:]]*import .*;$" nil t) ; if imports are defined, move past them
+ (goto-char (1+ (match-end 0))))
+ (insert (concat "class " (file-name-base classname) " {\n"))
+ (goto-char (point-max))
+ (insert "\n}"))
+
+ ;; add imports
+ (if (eq result-type 'value)
+ (setq imports (append '("sys.io.File") imports)))
+ (when imports
+ (if (re-search-forward "^[[:space:]]*package .*;$" nil t) ; if package is defined, move past it
+ (goto-char (1+ (match-end 0))))
+ (goto-char (point-min))
+ (insert (mapconcat (lambda (ii) (concat "import " ii ";\n")) imports "\n")))
+
+ ;; add package at the top
+ (goto-char (point-min))
+ (when (not (re-search-forward "^[[:space:]]*package .*;$" nil t))
+ (insert (concat "package " packagename ";\n\n")))
+
+ (buffer-string)))) ; return expanded body
+
+(defun org-babel-variable-assignments:haxe (params)
+ "Return a list of haxe statements assigning the block's variables.
+variables are contained in PARAMS."
+ (mapcar
+ (lambda (pair)
+ (format " static var %s %s = %s;"
+ (car pair)
+ (if (and (sequencep (cdr pair))
+ (not (stringp (cdr pair)))) ":Array<Dynamic> " "")
+ (org-babel-haxe-var-to-haxe (cdr pair))))
+ (org-babel--get-vars params)))
+
+(defun org-babel-haxe-var-to-haxe (var)
+ "Convert an elisp value to a haxe variable.
+Convert an elisp value, VAR, into a string of haxe source code
+specifying a variable of the same value."
+ (cond ((and (sequencep var)
+ (not (stringp var)))
+ (concat "[" (mapconcat #'org-babel-haxe-var-to-haxe var ", ") "]"))
+ ((equal var 'hline)
+ org-babel-haxe-hline-to)
+ (t
+ (format "%S" (if (stringp var) (substring-no-properties var) var)))))
+
+(defun org-babel-haxe-table-or-string (results)
+ "Convert RESULTS into an appropriate elisp value.
+If the results look like a list or vector, then convert them into an
+Emacs-lisp table, otherwise return the results as a string."
+ (let ((res (org-babel-script-escape results)))
+ ;; (mapcar (lambda (el) (message "el %s %s" el (eq 'null el))) res)
+ (if (listp res)
+ (mapcar (lambda (el) (if (eq 'null el)
+ org-babel-haxe-null-to
+ el))
+ res)
+ res)))
+
+(defun org-babel-haxe-evaluate
+ (cmd target result-type result-params tmp-file)
+ "Evaluate using an external haxe process.
+CMD the command to execute.
+
+TARGET the platform the haxe compiler should target.
+
+If RESULT-TYPE equals 'output then return standard output as a
+string. If RESULT-TYPE equals 'value then return the value
+returned by the source block, as elisp.
+
+RESULT-PARAMS input params used to format the reponse.
+
+TMP-FILE filename of the tempfile to store the returned value in
+for 'value RESULT-TYPE. Not used for 'output RESULT-TYPE."
+ (let ((raw (cond ((eq result-type 'output)
+ (org-babel-eval cmd ""))
+ (t
+ (org-babel-eval cmd "")
+ (org-babel-eval-read-file tmp-file)))))
+ (if (and
+ (or (string= target "neko")
+ (string= target "hashlink"))
+ (eq result-type 'output))
+ (setq raw (substring raw 0 -1))) ; neko and hashlink runtimes add a trailing endline
+ (org-babel-result-cond result-params
+ raw
+ (org-babel-haxe-table-or-string raw))))
+
+(provide 'ob-haxe)
+
+;;; ob-haxe.el ends here
diff --git a/testing/examples/ob-haxe-test.org b/testing/examples/ob-haxe-test.org
new file mode 100644
index 000000000..ba9119d58
--- /dev/null
+++ b/testing/examples/ob-haxe-test.org
@@ -0,0 +1,247 @@
+#+Title: a collection of examples for ob-haxe tests
+#+OPTIONS: ^:nil
+* Simple
+ :PROPERTIES:
+ :ID: 966875e9-d10e-406c-9211-449555e3d3b2
+ :END:
+#+name: simple
+#+begin_src haxe :results output silent
+ Sys.print(42);
+#+end_src
+
+#+name: simple_with_main
+#+begin_src haxe :results output silent
+ static function main() {
+ Sys.print(42);
+ }
+#+end_src
+
+#+name: simple_with_public_main_interp
+#+begin_src haxe :results output silent
+ public static function main() {
+ Sys.print(42);
+ }
+#+end_src
+
+#+name: simple_with_public_main_neko
+#+begin_src haxe :target neko :results output silent
+ public static function main() {
+ Sys.print(42);
+ }
+#+end_src
+
+#+name: simple_with_public_main_hashlink
+#+begin_src haxe :target hashlink :results output silent
+ public static function main() {
+ Sys.print(42);
+ }
+#+end_src
+
+#+name: simple_with_class
+#+begin_src haxe :results output silent
+ class Simple {
+ public static function main() {
+ Sys.print(42);
+ }
+ }
+#+end_src
+
+#+name: simple_with_class_and_package
+#+begin_src haxe :results output silent
+ package pkg;
+ class Simple {
+ public static function main() {
+ Sys.print(42);
+ }
+ }
+#+end_src
+
+#+name: simple_with_class_attr
+#+begin_src haxe :results output silent :classname Simple
+ public static function main() {
+ Sys.print(42);
+ }
+#+end_src
+
+#+name: simple_with_class_attr_with_package
+#+begin_src haxe :results output silent :classname pkg.Simple
+ public static function main() {
+ Sys.print(42);
+ }
+#+end_src
+
+* Variables
+ :PROPERTIES:
+ :ID: ecbe8740-e254-4c53-84b2-21a61bf1afb4
+ :END:
+
+#+name: integer_var
+#+begin_src haxe :var a=42 :results output silent
+ Sys.print(a);
+#+end_src
+
+#+name: var_with_main
+#+begin_src haxe :var a=42 :results output silent
+ public static function main() {
+ Sys.print(a);
+ }
+#+end_src
+
+#+name: var_with_class
+#+begin_src haxe :var a=42 :results output silent
+ class Main {
+ public static function main() {
+ Sys.print(a);
+ }
+ }
+#+end_src
+
+#+name: var_with_class_and_package
+#+begin_src haxe :var a=42 :results output silent
+ package pkg;
+ class Main {
+ public static function main() {
+ Sys.print(a);
+ }
+ }
+#+end_src
+
+#+name: var_with_class_and_hanging_curlies
+#+begin_src haxe :var a=42 :results output silent
+ class Main
+ {
+ public static function main()
+ {
+ Sys.print(a);
+ }
+ }
+#+end_src
+
+#+name: two_vars
+#+begin_src haxe :var a=21 b=2 :results output silent
+ Sys.print(a*b);
+#+end_src
+
+#+name: string_var
+#+begin_src haxe :var a="forty two" :results output silent
+ Sys.print('$a, len=${a.length}');
+#+end_src
+
+#+name: mulitline_string_var
+#+begin_src haxe :var a="forty\ntwo" :results output silent
+ Sys.print('$a, len=${a.length}');
+#+end_src
+
+* Array
+ :PROPERTIES:
+ :ID: 1e93864d-385b-4901-9d12-b566fdb5b813
+ :END:
+
+#+name: haxe_list
+- forty
+- two
+
+#+name: return_vector
+#+begin_src haxe :results vector silent
+ return [[4], [2]];
+#+end_src
+
+#+name: read_return_list
+#+begin_src haxe :var a=haxe_list :results silent
+ return [a[0][0], a[1][0]];
+#+end_src
+
+this is not an interesting test, but it demonstrates how to use
+~:results output~ to write a neatly formatted list of strings which
+can include spaces.
+
+#+name: read_output_list
+#+begin_src haxe :var a=haxe_list :results output list raw silent
+ Sys.println('forty two');
+ Sys.println('forty two');
+#+end_src
+
+* Matrix
+ :PROPERTIES:
+ :ID: a93bb906-eef8-4089-b490-64f266f5696c
+ :END:
+#+name: haxe_matrix
+| 2 | 1 |
+| 4 | 2 |
+
+#+name: list_var
+#+begin_src haxe :var a='("forty" "two") :results silent
+ return [a[0], a[1]];
+#+end_src
+
+#+name: vector_var
+#+begin_src haxe :var a='["forty" "two"] :results silent
+ return [a[0], a[1]];
+#+end_src
+
+#+name: matrix_var
+#+begin_src haxe :var a=haxe_matrix :results silent
+ return [[a[0][0], a[1][0]], // transpose
+ [a[0][1], a[1][1]]];
+#+end_src
+
+#+name: matrix_var_with_header
+#+begin_src haxe :var a=haxe_matrix :results value table silent
+ return [["col1","col2"],
+ null,
+ [a[0][0], a[1][0]], // transpose
+ [a[0][1], a[1][1]]];
+#+end_src
+
+this is not an interesting test, but it demonstrates how to use
+~:results output~ to write a table with header.
+
+#+name: output_table_with_header
+#+begin_src haxe :var a=haxe_matrix :results output raw table silent
+ Sys.println("|col1|col2|");
+ Sys.println("|-");
+ for (ii in 0...a.length) {
+ for (jj in 0...a[0].length) {
+ Sys.print('|${a[ii][jj]}');
+ }
+ Sys.println("");
+ }
+#+end_src
+
+* Inhomogeneous Table
+ :PROPERTIES:
+ :ID: 192cbb7d-9038-47ca-bab3-a0cbf44b487d
+ :END:
+
+#+name: haxe_table
+ | string | number |
+ |--------+--------|
+ | forty | 2 |
+ | two | 1 |
+
+#+name: inhomogeneous_table
+#+begin_src haxe :var a=haxe_table :results silent
+ return [[a[0][0], a[0][1]*2],
+ [a[1][0], a[1][1]*2]];
+#+end_src
+
+* Library
+ :PROPERTIES:
+ :ID: 0b945cde-55a1-4723-8d78-5f69d98d09fa
+ :END:
+
+#+name: import_library
+#+begin_src haxe :results output silent :imports haxe.crypto.Base64 haxe.io.Bytes
+ var encoded = Base64.encode(Bytes.ofString("42"));
+ var decoded = Base64.decode(encoded);
+ Sys.print('encoded=$encoded, decoded=$decoded');
+#+end_src
+
+#+name: import_library_inline
+#+begin_src haxe :results output silent
+ import haxe.crypto.Base64;
+ import haxe.io.Bytes;
+ var encoded = Base64.encode(Bytes.ofString("42"));
+ var decoded = Base64.decode(encoded);
+ Sys.print('encoded=$encoded, decoded=$decoded');
+#+end_src
diff --git a/testing/lisp/test-ob-haxe.el b/testing/lisp/test-ob-haxe.el
new file mode 100644
index 000000000..b8c33c4b8
--- /dev/null
+++ b/testing/lisp/test-ob-haxe.el
@@ -0,0 +1,234 @@
+;;; test-ob-haxe.el --- tests for ob-haxe.el
+
+;; Copyright (c) 2020 Ian Martins
+;; Authors: Ian Martins
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
+(org-test-for-executable "haxe")
+(unless (featurep 'ob-haxe)
+ (signal 'missing-test-dependency "Support for haxe code blocks"))
+
+(ert-deftest ob-haxe/simple ()
+ "Hello world program."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "966875e9-d10e-406c-9211-449555e3d3b2"
+ (org-babel-next-src-block 1)
+ (should (string= "42" (org-babel-execute-src-block))))))
+
+(ert-deftest ob-haxe/simple-with-main ()
+ "Hello world program that defines a main function."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "966875e9-d10e-406c-9211-449555e3d3b2"
+ (org-babel-next-src-block 2)
+ (should (string= "42" (org-babel-execute-src-block))))))
+
+(ert-deftest ob-haxe/simple-with-public-main-interp ()
+ "Hello world program that defines a public main function targeting interp."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "966875e9-d10e-406c-9211-449555e3d3b2"
+ (org-babel-next-src-block 3)
+ (should (string= "42" (org-babel-execute-src-block))))))
+
+(ert-deftest ob-haxe/simple-with-public-main-neko ()
+ "Hello world program that defines a public main function targeting neko."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "966875e9-d10e-406c-9211-449555e3d3b2"
+ (org-babel-next-src-block 4)
+ (should (string= "42" (org-babel-execute-src-block))))))
+
+(ert-deftest ob-haxe/simple-with-public-main-hashlink ()
+ "Hello world program that defines a public main function targeting hashlink."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "966875e9-d10e-406c-9211-449555e3d3b2"
+ (org-babel-next-src-block 5)
+ (should (string= "42" (org-babel-execute-src-block))))))
+
+(ert-deftest ob-haxe/simple-with-class ()
+ "Hello world program that defines a class."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "966875e9-d10e-406c-9211-449555e3d3b2"
+ (org-babel-next-src-block 6)
+ (should (string= "42" (org-babel-execute-src-block))))))
+
+(ert-deftest ob-haxe/simple-with-class-and-package ()
+ "Hello world program that defines a class and package."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "966875e9-d10e-406c-9211-449555e3d3b2"
+ (org-babel-next-src-block 7)
+ (should (string= "42" (org-babel-execute-src-block))))))
+
+(ert-deftest ob-haxe/simple-with-class-attr ()
+ "Hello world program with class header attribute."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "966875e9-d10e-406c-9211-449555e3d3b2"
+ (org-babel-next-src-block 8)
+ (should (string= "42" (org-babel-execute-src-block))))))
+
+(ert-deftest ob-haxe/simple-with-class-attr-with-package ()
+ "Hello world program with class attr with package."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "966875e9-d10e-406c-9211-449555e3d3b2"
+ (org-babel-next-src-block 9)
+ (should (string= "42" (org-babel-execute-src-block))))))
+
+
+(ert-deftest ob-haxe/integer-var ()
+ "Read and write an integer variable."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "ecbe8740-e254-4c53-84b2-21a61bf1afb4"
+ (org-babel-next-src-block 1)
+ (should (string= "42" (org-babel-execute-src-block))))))
+
+(ert-deftest ob-haxe/var-with-main ()
+ "Read and write an integer variable, with main function provided."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "ecbe8740-e254-4c53-84b2-21a61bf1afb4"
+ (org-babel-next-src-block 2)
+ (should (string= "42" (org-babel-execute-src-block))))))
+
+(ert-deftest ob-haxe/var-with-class ()
+ "Read and write an integer variable, with class provided."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "ecbe8740-e254-4c53-84b2-21a61bf1afb4"
+ (org-babel-next-src-block 3)
+ (should (string= "42" (org-babel-execute-src-block))))))
+
+(ert-deftest ob-haxe/var-with-class-and-package ()
+ "Read and write an integer variable, with class and package provided."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "ecbe8740-e254-4c53-84b2-21a61bf1afb4"
+ (org-babel-next-src-block 4)
+ (should (string= "42" (org-babel-execute-src-block))))))
+
+(ert-deftest ob-haxe/var-with-class-and-hanging-curlies ()
+ "Read and write an integer variable, with class with hanging curlies."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "ecbe8740-e254-4c53-84b2-21a61bf1afb4"
+ (org-babel-next-src-block 5)
+ (should (string= "42" (org-babel-execute-src-block))))))
+
+(ert-deftest ob-haxe/two-vars ()
+ "Read two integer variables, combine and write them."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "ecbe8740-e254-4c53-84b2-21a61bf1afb4"
+ (org-babel-next-src-block 6)
+ (should (string= "42" (org-babel-execute-src-block))))))
+
+(ert-deftest ob-haxe/string-var ()
+ "Read and write a string variable."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "ecbe8740-e254-4c53-84b2-21a61bf1afb4"
+ (org-babel-next-src-block 7)
+ (should (string= "forty two, len=9" (org-babel-execute-src-block))))))
+
+(ert-deftest ob-haxe/multiline-string-var ()
+ "Read and write a multi-line string variable."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "ecbe8740-e254-4c53-84b2-21a61bf1afb4"
+ (org-babel-next-src-block 8)
+ (should (string= "forty\ntwo, len=9" (org-babel-execute-src-block))))))
+
+
+(ert-deftest ob-haxe/return-vector ()
+ "Return a vector."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "1e93864d-385b-4901-9d12-b566fdb5b813"
+ (org-babel-next-src-block 1)
+ (should (equal '((4) (2)) (org-babel-execute-src-block))))))
+
+(ert-deftest ob-haxe/read-return-list ()
+ "Return a vector."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "1e93864d-385b-4901-9d12-b566fdb5b813"
+ (org-babel-next-src-block 2)
+ (should (equal '("forty" "two") (org-babel-execute-src-block))))))
+
+(ert-deftest ob-haxe/read-output-list ()
+ "Return a vector."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "1e93864d-385b-4901-9d12-b566fdb5b813"
+ (org-babel-next-src-block 3)
+ (should (equal "forty two\nforty two\n" (org-babel-execute-src-block))))))
+
+
+(ert-deftest ob-haxe/list-var ()
+ "Read and write a list variable."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "a93bb906-eef8-4089-b490-64f266f5696c"
+ (org-babel-next-src-block 1)
+ (should (equal '("forty" "two") (org-babel-execute-src-block))))))
+
+(ert-deftest ob-haxe/vector-var ()
+ "Read and write a vector variable."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "a93bb906-eef8-4089-b490-64f266f5696c"
+ (org-babel-next-src-block 2)
+ (should (equal '("forty" "two") (org-babel-execute-src-block))))))
+
+(ert-deftest ob-haxe/matrix-var ()
+ "Read and write matrix variable."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "a93bb906-eef8-4089-b490-64f266f5696c"
+ (org-babel-next-src-block 3)
+ (should (equal '((2 4) (1 2)) (org-babel-execute-src-block))))))
+
+(ert-deftest ob-haxe/matrix-var-with-header ()
+ "Read matrix variable and write it with header."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "a93bb906-eef8-4089-b490-64f266f5696c"
+ (org-babel-next-src-block 4)
+ (should (equal '(("col1" "col2") hline (2 4) (1 2)) (org-babel-execute-src-block))))))
+
+(ert-deftest ob-haxe/output-table-with-header ()
+ "Write a table that includes a header."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "a93bb906-eef8-4089-b490-64f266f5696c"
+ (org-babel-next-src-block 5)
+ (should (equal "|col1|col2|\n|-\n|2|1\n|4|2\n" (org-babel-execute-src-block))))))
+
+
+(ert-deftest ob-haxe/inhomogeneous_table ()
+ "Read and write an inhomogeneous table."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "192cbb7d-9038-47ca-bab3-a0cbf44b487d"
+ (org-babel-next-src-block 1)
+ (should (equal
+ '(("forty" 4) ("two" 2))
+ (org-babel-execute-src-block))))))
+
+
+(ert-deftest ob-haxe/import_library ()
+ "Import a standard haxe library."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "0b945cde-55a1-4723-8d78-5f69d98d09fa"
+ (org-babel-next-src-block 1)
+ (should (string=
+ "encoded=NDI=, decoded=42"
+ (org-babel-execute-src-block))))))
+
+(ert-deftest ob-haxe/import_library_inline ()
+ "Import a standard haxe library."
+ (if (executable-find org-babel-haxe-command)
+ (org-test-at-id "0b945cde-55a1-4723-8d78-5f69d98d09fa"
+ (org-babel-next-src-block 2)
+ (should (string=
+ "encoded=NDI=, decoded=42"
+ (org-babel-execute-src-block))))))
+
+
+;;; test-ob-haxe.el ends here
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: org-babel support for haxe
2020-06-12 4:37 org-babel support for haxe ian martins
@ 2020-09-05 7:24 ` Bastien
2020-09-05 11:48 ` ian martins
2020-09-06 15:24 ` Kyle Meyer
1 sibling, 1 reply; 8+ messages in thread
From: Bastien @ 2020-09-05 7:24 UTC (permalink / raw)
To: ian martins; +Cc: Emacs-orgmode
Hi Ian,
ian martins <ianxm@jhu.edu> writes:
> Hello. The included patch adds org-babel support for haxe (https://
> haxe.org/). It allows main class and function definitions to be
> optional, accepts variables and supports babel functional mode.
> Please review.
I'm not an Haxe user, so I cannot review the functionnalities, but
from a cursory look, it seems fine.
After 9.4, we will probably remove some Babel libraries from Org's
core: we still need to decide on what criterium, but one candidate
is to remove a Babel library if the corresponding language is not
supported within Emacs core itself.
If we go that route, we also need to do a better job at promoting
external Babel libraries: perhaps a page on https://orgmode.org/worg
would help.
2 cents,
--
Bastien
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: org-babel support for haxe
2020-09-05 7:24 ` Bastien
@ 2020-09-05 11:48 ` ian martins
0 siblings, 0 replies; 8+ messages in thread
From: ian martins @ 2020-09-05 11:48 UTC (permalink / raw)
To: Bastien; +Cc: Org-Mode mailing list
[-- Attachment #1: Type: text/plain, Size: 1099 bytes --]
That makes sense.
It's probably enough to keep the languages page [1] complete and up to
date. External repos should already have docs with the code.
[1] https://orgmode.org/worg/org-contrib/babel/languages.html
On Sat, Sep 5, 2020 at 3:24 AM Bastien <bzg@gnu.org> wrote:
> Hi Ian,
>
> ian martins <ianxm@jhu.edu> writes:
>
> > Hello. The included patch adds org-babel support for haxe (https://
> > haxe.org/). It allows main class and function definitions to be
> > optional, accepts variables and supports babel functional mode.
> > Please review.
>
> I'm not an Haxe user, so I cannot review the functionnalities, but
> from a cursory look, it seems fine.
>
> After 9.4, we will probably remove some Babel libraries from Org's
> core: we still need to decide on what criterium, but one candidate
> is to remove a Babel library if the corresponding language is not
> supported within Emacs core itself.
>
> If we go that route, we also need to do a better job at promoting
> external Babel libraries: perhaps a page on https://orgmode.org/worg
> would help.
>
> 2 cents,
>
> --
> Bastien
>
[-- Attachment #2: Type: text/html, Size: 1814 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: org-babel support for haxe
2020-06-12 4:37 org-babel support for haxe ian martins
2020-09-05 7:24 ` Bastien
@ 2020-09-06 15:24 ` Kyle Meyer
2020-09-12 15:18 ` ian martins
1 sibling, 1 reply; 8+ messages in thread
From: Kyle Meyer @ 2020-09-06 15:24 UTC (permalink / raw)
To: ian martins; +Cc: Emacs-orgmode
Hi ian,
It looks like this library is instead going to be available through an
ELPA, but FWIW here are a couple of comments on the tests.
ian martins writes:
> diff --git a/testing/examples/ob-haxe-test.org b/testing/examples/ob-haxe-test.org
> new file mode 100644
> index 000000000..ba9119d58
> --- /dev/null
> +++ b/testing/examples/ob-haxe-test.org
> @@ -0,0 +1,247 @@
> +#+Title: a collection of examples for ob-haxe tests
> +#+OPTIONS: ^:nil
> +* Simple
> + :PROPERTIES:
> + :ID: 966875e9-d10e-406c-9211-449555e3d3b2
> + :END:
> +#+name: simple
> +#+begin_src haxe :results output silent
> + Sys.print(42);
> +#+end_src
I know some other babel tests use a separate .org file, but I find this
setup harder to follow compared to having the Org content within the
test (e.g. using org-test-with-temp-text or
org-test-with-temp-text-in-file). Perhaps I'm missing why it's needed
in this case though.
> diff --git a/testing/lisp/test-ob-haxe.el b/testing/lisp/test-ob-haxe.el
[...]
> +;;; Code:
> +(org-test-for-executable "haxe")
> +(unless (featurep 'ob-haxe)
> + (signal 'missing-test-dependency "Support for haxe code blocks"))
> +
> +(ert-deftest ob-haxe/simple ()
> + "Hello world program."
> + (if (executable-find org-babel-haxe-command)
I think you can avoid the executable-find here and in all the other
tests because you have (org-test-for-executable "haxe") at the beginning
of the file.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: org-babel support for haxe
2020-09-06 15:24 ` Kyle Meyer
@ 2020-09-12 15:18 ` ian martins
2020-09-13 20:04 ` Kyle Meyer
0 siblings, 1 reply; 8+ messages in thread
From: ian martins @ 2020-09-12 15:18 UTC (permalink / raw)
To: Kyle Meyer; +Cc: Org-Mode mailing list
[-- Attachment #1: Type: text/plain, Size: 1918 bytes --]
Thanks for the feedback. There's no special reason for the external test
data file or repeated executable-find calls. I was following the convention
from ob-C. I'll make those changes.
ob-haxe and ob-java both involve a few changes to ob-core to allow temp
directories instead of just temp files. Should I submit that as a separate
patch?
On Sun, Sep 6, 2020 at 11:24 AM Kyle Meyer <kyle@kyleam.com> wrote:
> Hi ian,
>
> It looks like this library is instead going to be available through an
> ELPA, but FWIW here are a couple of comments on the tests.
>
> ian martins writes:
>
> > diff --git a/testing/examples/ob-haxe-test.org b/testing/examples/
> ob-haxe-test.org
> > new file mode 100644
> > index 000000000..ba9119d58
> > --- /dev/null
> > +++ b/testing/examples/ob-haxe-test.org
> > @@ -0,0 +1,247 @@
> > +#+Title: a collection of examples for ob-haxe tests
> > +#+OPTIONS: ^:nil
> > +* Simple
> > + :PROPERTIES:
> > + :ID: 966875e9-d10e-406c-9211-449555e3d3b2
> > + :END:
> > +#+name: simple
> > +#+begin_src haxe :results output silent
> > + Sys.print(42);
> > +#+end_src
>
> I know some other babel tests use a separate .org file, but I find this
> setup harder to follow compared to having the Org content within the
> test (e.g. using org-test-with-temp-text or
> org-test-with-temp-text-in-file). Perhaps I'm missing why it's needed
> in this case though.
>
> > diff --git a/testing/lisp/test-ob-haxe.el b/testing/lisp/test-ob-haxe.el
> [...]
> > +;;; Code:
> > +(org-test-for-executable "haxe")
> > +(unless (featurep 'ob-haxe)
> > + (signal 'missing-test-dependency "Support for haxe code blocks"))
> > +
> > +(ert-deftest ob-haxe/simple ()
> > + "Hello world program."
> > + (if (executable-find org-babel-haxe-command)
>
> I think you can avoid the executable-find here and in all the other
> tests because you have (org-test-for-executable "haxe") at the beginning
> of the file.
>
[-- Attachment #2: Type: text/html, Size: 2729 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: org-babel support for haxe
2020-09-12 15:18 ` ian martins
@ 2020-09-13 20:04 ` Kyle Meyer
2020-09-24 21:17 ` ian martins
0 siblings, 1 reply; 8+ messages in thread
From: Kyle Meyer @ 2020-09-13 20:04 UTC (permalink / raw)
To: ian martins; +Cc: Org-Mode mailing list
ian martins writes:
> ob-haxe and ob-java both involve a few changes to ob-core to allow temp
> directories instead of just temp files. Should I submit that as a separate
> patch?
It looks like that change is included with your ob-java patch [0], which
will be considered after 9.4 is released [1], so I think it's fine as
is. (In my opinion, splitting up that patch would have been nice, but I
don't think it's worth a reroll, at least until some initial comments
come in.)
[0] https://orgmode.org/list/CAC=rjb7AhmnRQ9Nc4Ao07qK3QZF4LVaTmU_R1fWqr+97NpnRJQ@mail.gmail.com
[1] https://orgmode.org/list/87sgbwgvx6.fsf@gnu.org
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: org-babel support for haxe
2020-09-13 20:04 ` Kyle Meyer
@ 2020-09-24 21:17 ` ian martins
2020-09-30 10:08 ` ian martins
0 siblings, 1 reply; 8+ messages in thread
From: ian martins @ 2020-09-24 21:17 UTC (permalink / raw)
To: Kyle Meyer; +Cc: Org-Mode mailing list
[-- Attachment #1: Type: text/plain, Size: 949 bytes --]
with ob-java I assumed I shouldn't change ob-core, so I advised/overrode
ob-core instead of changing it. But it would be much better to change
ob-core. I'll submit those changes as a separate patch that modifies
ob-core.
On Sun, Sep 13, 2020 at 4:04 PM Kyle Meyer <kyle@kyleam.com> wrote:
> ian martins writes:
>
> > ob-haxe and ob-java both involve a few changes to ob-core to allow temp
> > directories instead of just temp files. Should I submit that as a
> separate
> > patch?
>
> It looks like that change is included with your ob-java patch [0], which
> will be considered after 9.4 is released [1], so I think it's fine as
> is. (In my opinion, splitting up that patch would have been nice, but I
> don't think it's worth a reroll, at least until some initial comments
> come in.)
>
> [0]
> https://orgmode.org/list/CAC=rjb7AhmnRQ9Nc4Ao07qK3QZF4LVaTmU_R1fWqr+97NpnRJQ@mail.gmail.com
> [1] https://orgmode.org/list/87sgbwgvx6.fsf@gnu.org
>
[-- Attachment #2: Type: text/html, Size: 1531 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: org-babel support for haxe
2020-09-24 21:17 ` ian martins
@ 2020-09-30 10:08 ` ian martins
0 siblings, 0 replies; 8+ messages in thread
From: ian martins @ 2020-09-30 10:08 UTC (permalink / raw)
To: Kyle Meyer; +Cc: Org-Mode mailing list
[-- Attachment #1: Type: text/plain, Size: 1666 bytes --]
I wrote the ob-core patch I mentioned before but white writing the commit
message I realized there's probably no need to modify ob-core at all. I was
doing it in order to allow haxe and java to create subdirectories in the
babel temp directory since both languages require class names to match file
names and directory structures to match the class' package (which is like
namespace in C). But for executing babel code blocks from the temp
directory all that is needed is the output; the source file doesn't matter.
I'll try updating the haxe and java patches to build and run directly from
the babel temp directory.
On Thu, Sep 24, 2020 at 5:17 PM ian martins <ianxm@jhu.edu> wrote:
> with ob-java I assumed I shouldn't change ob-core, so I advised/overrode
> ob-core instead of changing it. But it would be much better to change
> ob-core. I'll submit those changes as a separate patch that modifies
> ob-core.
>
> On Sun, Sep 13, 2020 at 4:04 PM Kyle Meyer <kyle@kyleam.com> wrote:
>
>> ian martins writes:
>>
>> > ob-haxe and ob-java both involve a few changes to ob-core to allow temp
>> > directories instead of just temp files. Should I submit that as a
>> separate
>> > patch?
>>
>> It looks like that change is included with your ob-java patch [0], which
>> will be considered after 9.4 is released [1], so I think it's fine as
>> is. (In my opinion, splitting up that patch would have been nice, but I
>> don't think it's worth a reroll, at least until some initial comments
>> come in.)
>>
>> [0]
>> https://orgmode.org/list/CAC=rjb7AhmnRQ9Nc4Ao07qK3QZF4LVaTmU_R1fWqr+97NpnRJQ@mail.gmail.com
>> [1] https://orgmode.org/list/87sgbwgvx6.fsf@gnu.org
>>
>
[-- Attachment #2: Type: text/html, Size: 2542 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2020-09-30 10:13 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-12 4:37 org-babel support for haxe ian martins
2020-09-05 7:24 ` Bastien
2020-09-05 11:48 ` ian martins
2020-09-06 15:24 ` Kyle Meyer
2020-09-12 15:18 ` ian martins
2020-09-13 20:04 ` Kyle Meyer
2020-09-24 21:17 ` ian martins
2020-09-30 10:08 ` ian martins
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).