a parser that loads and runs lua Venus scripts
Go to file
theFox6 b49c3ea09a
increase accuracy of lambda detection
2020-02-12 13:44:59 +01:00
.settings initialize project 2020-02-11 10:41:41 +01:00
testout increase accuracy of lambda detection 2020-02-12 13:44:59 +01:00
.project initialize project 2020-02-11 10:41:41 +01:00
LICENSE write some documentation 2020-02-11 18:03:59 +01:00
README.md added lambdas 2020-02-12 12:51:02 +01:00
init.lua increase accuracy of lambda detection 2020-02-12 13:44:59 +01:00
runTest.lua write some documentation 2020-02-11 18:03:59 +01:00
test.venus increase accuracy of lambda detection 2020-02-12 13:44:59 +01:00
translateTest.lua added curly brace syntax, "fn" and a translation function 2020-02-12 10:53:41 +01:00

README.md

venus lua parser

A parser that loads venus files into lua. Written in lua.
The parser reads a venus file and replaces venus syntax by lua syntax.
It can also load and run the result.

features

foreach

The foreach statement will geneate a pairs statement.

local table = {2,1,3,"test"}

foreach el in table {
  print(el)
}

will generate

local table = {2,1,3,"test"}

for _, el in table do
  print(el)
end

comments

for comments --, // and ## can be used if something follows a -- it will always be treated as comment

curly braces

The do,then and end statements can be replaced by curly brace syntax.
They can be used in functions, loops, conditions.
For example:

local table = {2,1,3,"test","test2",3}

function findTest(t) {
	repeat {
		local found = false
		local el = table.remove(t)
		if el == "test" {
			found = true
		} else {
			print(el)
		}
	} until found
}

will generate

local table = {2,1,3,"test","test2",3}

function findTest(t) 
	repeat
		local found = false
		local el = table.remove(t)
		if el == "test" then
			found = true
		else
			print(el)
		end
	until found
end

functions

fn can be used instead of function.

fn test() {
	print("hi")
}

will generate

function test()
	print("hi")
end

lambdas

Lambda syntax (args) => {...} can be used to create functions.

local result
fn store_it(f) {
	result = f(10,6)
}

store_it((a,b) => {
	return (a - b) * 2
})

will generate

local result
function store_it(f)
	result = f(10,6)
end

store_it(function(a,b)
	return (a - b) * 2
end)

working with the parser

loading

The init.lua returns a table containing the parser.
In case you have the VenusParser directory within your project's
ways of loding it may be:

-- using require (cached)
local vc = require("VenusParser")
-- using dofile
local vc = dofile("VenusParser/init.lua")

running venus files

vc.dovenus(file) works like dofile(file)
It's argument can be a relative or absolute path to the file that should be run.

loading venus files

vc.loadvenus(file) works like loadfile(file)
It's argument can be a relative or absolute path to the file that should be loaded.
It returns a function that runs the generated lua.

generating lua code

vp.translate_venus(file) returns the lua generated from the files contents
It's argument can be a relative or absolute path to the file that should be translated.
It returns the generated lua as string.

##todo

  • increment, decrement, etc.
  • generate lua from a venus string
  • perhaps write generated lua files to disk