Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP perl support #358

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions resources/public/perl-dbg.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>KLIPSE: a simple and elegant online cljs compiler and evaluator</title>
<link rel='shortcut icon' type='image/x-icon' href='img/klipse.png' />
<link rel="stylesheet" type="text/css" href="css/codemirror.css">
</head>
<body>

<h2> eval </h2>

<pre>
<code class="eval-perl">
say "hello"
</code>
</pre>

<textarea id="print-result">empty res</textarea>

<pre>
<script>
window.klipse_settings = {
selector_eval_perl: '.eval-perl',
};
</script>
<script src="/cljs-out/dev-main.js"></script>
</body>
</html>
43 changes: 43 additions & 0 deletions src/klipse/lang/perl.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
(ns klipse.lang.perl
(:require-macros
[gadjett.core :refer [dbg my-with-redefs]]
[cljs.core.async.macros :refer [go]])
(:require
[clojure.string :as string]
[cljs.core.async :refer [chan put!]]
[klipse.common.registry :refer [codemirror-mode-src register-mode]]
[applied-science.js-interop :as j]))

(def eval-in-global-scope js/eval); this is the trick to make `eval` work in the global scope: http://perfectionkills.com/global-eval-what-are-the-options/

(defn perl-to-js [src]
(js/Perlito.compile_p6_to_js src))

(defn eval-perl [exp _]
(let [c (chan)]
(my-with-redefs [js/print (fn[& args]
(put! c (string/join " " args))
(put! c "\n"))]

(try
(set! js/exports #js {})
(let [res (perl-to-js exp)]
(put! c (-> res
eval-in-global-scope
str)))
(catch :default o
(str o))))
c))


(defn comment-out [src]
(str "#" src))

(def eval-opts {:editor-in-mode "text/x-perl"
:editor-out-mode "text/x-perl"
:beautify? false
:eval-fn eval-perl
:external-scripts [ "http://fglock.github.io/Perlito/perlito/perlito6.js"]
:comment-str comment-out})

(register-mode "eval-perl" "selector_eval_perl" eval-opts)
1 change: 1 addition & 0 deletions src/klipse/run/all.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
klipse.lang.server-eval
klipse.lang.php
klipse.lang.ocaml
klipse.lang.perl
klipse.lang.reason))
1 change: 1 addition & 0 deletions src/klipse/run/plugin/plugin.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
klipse.lang.clojure
klipse.lang.reagent
klipse.lang.ocaml
klipse.lang.perl
klipse.lang.reason
[klipse.plugin :as plugin]))

Expand Down
3 changes: 2 additions & 1 deletion src/klipse/run/plugin_prod/plugin.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
klipse.lang.server-eval
klipse.lang.markdown
klipse.lang.lambdaway
; DO NOT include clojure it inflates the build size and anyway it doesn't work with advanced compilation klipse.lang.clojure
; DO NOT include clojure it inflates the build size and anyway it doesn't work with advanced compilation klipse.lang.clojure
klipse.lang.html
klipse.lang.ocaml
klipse.lang.perl
klipse.lang.reason
[klipse.plugin :as plugin]))

Expand Down