~xigoi/xongue

A library for giving any programming language a Lisp-like syntax

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~xigoi/xongue
read/write
git@git.sr.ht:~xigoi/xongue

You can also use your local clone with git send-email.

#👅 xongue

Tired of every language having a different syntax which you have to remember and pay attention to? Do you want to focus on the code logic rather than playing around with characters? Then xongue might be for you!

xongue is a Lua library that allows easily creating transpilers (source-to-source compilers) from a family of related languages (tongues) that can target any programming language.

Currently it's just an experiment, but I'm planning to eventually turn it into a fully usable tool.

#Example

Create and use a transpiler for a tiny subset of JavaScript like this:

local xongue = require "xongue"

local js_xongue = xongue.new {
  -- Keywords that will produce syntactic forms in the target language
  keywords = {
    var = function(name, init)
      return string.format("let %s = %s", name, init)
    end,
    ["*"] = function(x, y)
      return string.format("(%s * %s)", x, y)
    end,
  },
  -- What to do with a call that isn't a keyword
  call = function(name, args)
    return string.format("%s(%s)", name, xongue.concat(args, ", "))
  end,
  -- How to join top-level statements together
  top_level = function(stmts)
    return xongue.concat(stmts, ";\n")
  end,
}

local code = [[
  (var six 6)
  (var seven 7)
  (var answer (* six seven))
  (console.log answer)
]]
print(js_xongue:transpile(code))

Output:

let six = 6;
let seven = 7;
let answer = (six * seven);
console.log(answer)