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

Add clojure templates #68

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
3 changes: 3 additions & 0 deletions config/stub_templates/clojure/loop.clj.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(dotimes [{{ index_ident }} {{ count_var }}]
{% for line in inner %}{{line}}
{% endfor %})
37 changes: 37 additions & 0 deletions config/stub_templates/clojure/loopline.clj.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{%- set clj_split = '(filter #(not-empty %) (str/split (read-line) #" "))' -%}
{%- set vars_length = vars | length -%}

{# SINGLE_TYPE #}
{%- if vars_length == 1 -%}
{%- set var = vars[0] -%}
{%- if var.var_type == "String" or var.var_type == "Word" -%}
{%- set fn = "" -%}
{%- else -%}
{%- set fn = "map #(" ~ type_tokens[var.var_type] ~ " %) " -%}
{%- endif -%}

(doseq
[{{ var.ident }} ({{ fn }}{{ clj_split }})]
( ))
{# MULTIPLE_TYPE #}
{%- else -%}
{%- set idents = vars | map(attribute="ident") | join(sep=" ") -%}
{%- set idents = "[" ~ idents ~ "]" -%}

{%- set_global fns = [] %}
{%- for var in vars %}
{%- if var.var_type == "String" or var.var_type == "Word" -%}
{%- set fn = var.ident -%}
{%- else -%}
{%- set fn = "(" ~ type_tokens[var.var_type] ~ " " ~ var.ident ~ ")" -%}
{%- endif %}
{%- set_global fns = fns | concat(with=fn) -%}
{%- endfor -%}

(doseq
[{{ idents }} (map (fn [{{ idents }}] [{{ fns | join(sep=" ") }}])
(partition {{ vars_length }} {{ clj_split }}))
]
( ))

{%- endif %}
15 changes: 15 additions & 0 deletions config/stub_templates/clojure/main.clj.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(ns Solution
(:require [clojure.string :as str])
(:gen-class))

(defn output [msg] (println msg) (flush))
(defn debug [msg] (binding [*out* *err*] (println msg) (flush)))
{% for line in statement %}
;; {{ line }}
{%- endfor %}

(defn -main [& args]
{%- for line in code_lines %}
{{ line }}
{%- endfor %}
)
5 changes: 5 additions & 0 deletions config/stub_templates/clojure/read_batch.clj.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(let [{% for line in read_lines %}{{line}}
{% endfor %}]
{% for line in nested_lines %}{{line}}
{% endfor %}
)
26 changes: 26 additions & 0 deletions config/stub_templates/clojure/read_many.clj.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{%- set clj_split = '(filter #(not-empty %) (str/split (read-line) #" "))' -%}
{%- set idents = vars | map(attribute="ident") | join(sep=" ")-%}

{%- for var in vars %}
{%- if var.input_comment -%}; {{ var.ident }}: {{ var.input_comment }}
{% endif -%}
{% endfor -%}

{%- if single_type -%}
{%- set var = vars[0] -%}
{%- if var.var_type == "String" or var.var_type == "Word" -%}
{%- set fn = "" -%}
{%- else -%}
{%- set fn = "map #(" ~ type_tokens[var.var_type] ~ " %) " -%}
{%- endif -%}

[{{ idents }}] ({{ fn }}{{ clj_split }})
{% else -%}

[{{ idents }}] {{ clj_split }}
{% for var in vars -%}
{%- if var.var_type != "String" and var.var_type != "Word" -%}
{{ var.ident }} ({{type_tokens[var.var_type]}} {{var.ident}})
{% endif -%}
{%- endfor -%}
{% endif %}
10 changes: 10 additions & 0 deletions config/stub_templates/clojure/read_one.clj.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{%- set sym = format_symbols[var.var_type] -%}
{%- if var.var_type == "String" or var.var_type == "Word" -%}
{%- set fn = "(read-line)" -%}
{%- else -%}
{%- set fn = "(" ~ type_tokens[var.var_type] ~ " (read-line))" -%}
{%- endif -%}

{%- if var.input_comment %}; {{ var.input_comment }}
{% endif -%}
{{ var.ident }} {{ fn }}
28 changes: 28 additions & 0 deletions config/stub_templates/clojure/stub_config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name = "clojure"
source_file_ext = "clj"

preprocessor = "lisp-like"

[type_tokens]
Int = "Integer/parseInt"
Long = "Long/parseLong"
Float = "Float/parseFloat"
Bool = "not= \"0\""
String = "NONE"
Word = "NONE"

[variable_name_options]
casing = "kebab_case"
allow_uppercase_vars = false
keywords = [
"def", "fn", "let", "if", "do", "quote", "recur", "loop", "apply", "map",
"conj", "println", "when", "or", "with-open", "cond", "vec", "for",
"partition", "assoc", "into", "str", "nth", "merge", "into-array", "println",
"require", "while", "and", "defn", "list", "name", "strcat", "as", "ref",
"quote'", "or", "condp", "import", "when-first", "inc", "dec", "doseq", "defmacro", "resolve",
"reify", "throw", "try", "catch", "new", "set", "type", "re-find",
"letfn", "proxy", "remove", "deftype", "keys", "defrecord", "into-array", "sort", "flush",
"mapv", "repeatedly", "deftype'", "identity", "get-in", "println", "definline",
"class", "dec'", "quote", "defonce", "recur", "ref-set", "proxy-mappings", "assert", "assert-args",
"defstruct", "throw", "throw-arity", "println", "recur", "reduced", "repeatedly",
]
6 changes: 6 additions & 0 deletions config/stub_templates/clojure/write.clj.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{%- for line in output_comments %}
;; {{ line }}
{% endfor %}
{%- for line in messages -%}
(output "{{line}}")
{% endfor %}
14 changes: 14 additions & 0 deletions config/stub_templates/clojure/write_join.clj.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{%- set_global out = [] -%}
{%- for term in terms -%}
{%- if term.var_type -%}
{%- set ident = term.ident -%}
{%- else -%}
{%- set ident = '"' ~ term.ident ~ '"' -%}
{%- endif -%}
{%- set_global out = out | concat(with=ident) -%}
{%- endfor -%}

{%- for line in output_comments -%};; {{ line }}
{% endfor -%}
(print {{ out | join(sep=" ") }})
(output "")