Skip to content

How to add a language to klipse

Yehonathan Sharvit edited this page Nov 30, 2017 · 14 revisions

Let's say that you want to integrate a language named lingvo into Klipse.

Before you start manipulating code inside Klipse, you need to provide a standalone javascript file that can evaluate lingvo code.

Create a namespace for your language

  1. Create a file src/klipse/lang/lingvo.cljs for your namespace klipse.lang.lingvo.
  2. Inside the namespace, call:
(ns klipse.lang.lingvo
  (:require-macros
   [cljs.core.async.macros :refer [go]])
  (:require
   [goog.dom :as gdom]
   [klipse.common.registry :refer [scripts-src codemirror-mode-src register-mode]]))

(defn eval [src opts]
  (go (js/evalLingvoString src)))

(def opts {:editor-in-mode "text/lingvo" ;; the codemirror mode that fits your language
           :editor-out-mode "text"
           :eval-fn eval ;; the function that evals code in your language
           :external-scripts [(codemirror-mode-src "lingvo") lingvo-standalone-url] ;; the url of lingvo standalone javascript file that implements the global javascript function `window.evalLingvoString`
           :comment-str "--"})

(register-mode "lingvo" "selector_lingvo" opts)

Take a look for instance at https://github.com/viebel/klipse/blob/master/src/klipse/lang/oblivion.cljs or any other namespace under https://github.com/viebel/klipse/tree/master/src/klipse/lang.

require the namespace you created

You need to require the namespace you just created from 3 files:

  • src/klipse/run/all.cljs
  • src/klipse/run/plugin/plugin.cljs
  • src/klipse/run/plugin_prod/plugin.cljs

Test

Create a test page for your language resources/public/lingvo-dbg.html for your language.

Take a look for instance at the lua test page

Launch Klipse with figwheel:

rlwrap lein run -m clojure.main scripts/figwheel.clj

Open your test page e.g. http://localhost:5014/lingvo-dbg.html