Fixed typos

I fixed some typos on the readme
This commit is contained in:
Dario 2020-05-09 04:41:22 -04:00 committed by GitHub
parent dfad1085e7
commit 367b1fe67f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 53 additions and 55 deletions

108
README.md
View File

@ -1,13 +1,12 @@
# LuaVenusCompiler # LuaVenusCompiler
[![luacheck][luacheck badge]][luacheck workflow] [![luacheck][luacheck badge]][luacheck workflow]
A compiler that translates venus files into lua. Written in lua. A compiler that translates Venus files into Lua. Written in Lua.
The compiler reads a venus file and replaces venus syntax by lua syntax. The compiler reads a Venus file and replaces Venus syntax by Lua syntax.
It can also load and run the result. It can also load and run the result.
## features ## Features:
### foreach ### "foreach" loop
The `foreach` statement will geneate a `pairs` statement. The `foreach` statement will geneate a `pairs` statement.
```lua ```lua
local table = {2,1,3,"test"} local table = {2,1,3,"test"}
@ -15,7 +14,7 @@ foreach el in table {
print(el) print(el)
} }
``` ```
will generate will generate:
```lua ```lua
local table = {2,1,3,"test"} local table = {2,1,3,"test"}
@ -24,19 +23,34 @@ for _, el in table do
end end
``` ```
### comments ### Comments
for comments `--` and `##` can be used For comments `--` and `##` can be used
if something follows a `--` it will always be treated as comment 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. ### Functions
They can be used in functions, loops, conditions. `fn` can be used instead of `function`.
```lua
fn test() {
print("hi")
}
```
will generate
```lua
function test()
print("hi")
end
```
### Curly braces based syntax
The `do`,`then` and `end` statements can be replaced by curly braces syntax.
They can be used in functions, loops, conditions, etcetera.
For example: For example:
```lua ```lua
do { do {
local table = {2,1,3,"test","test2",3} local table = {2,1,3,"test","test2",3}
function findTest(t) { fn findTest(t) {
repeat { repeat {
local found = false local found = false
local el = table.remove(t) local el = table.remove(t)
@ -49,7 +63,7 @@ do {
} }
} }
``` ```
will generate will generate:
```lua ```lua
do do
local table = {2,1,3,"test","test2",3} local table = {2,1,3,"test","test2",3}
@ -68,22 +82,8 @@ do
end end
``` ```
### functions ### Lambdas / Anonymous functions
`fn` can be used instead of `function`. Lambda syntax `(args) => {...}` can be used to create anonymous functions.
```lua
fn test() {
print("hi")
}
```
will generate
```lua
function test()
print("hi")
end
```
### lambdas
Lambda syntax `(args) => {...}` can be used to create functions.
```lua ```lua
local result local result
fn store_it(f) { fn store_it(f) {
@ -94,7 +94,7 @@ store_it((a,b) => {
return (a - b) * 2 return (a - b) * 2
}) })
``` ```
will generate will generate:
```lua ```lua
local result local result
function store_it(f) function store_it(f)
@ -106,8 +106,8 @@ store_it(function(a,b)
end) end)
``` ```
### incrrement and decrement ### Increment and Decrement
`++` and `--` can be used to in/decrement by 1 `++` and `--` can be used to add/sub by 1
```lua ```lua
local i = 0 local i = 0
local j = 0 local j = 0
@ -115,7 +115,7 @@ local j = 0
i++ i++
j-- j--
``` ```
will generate will generate:
```lua ```lua
local i = 0 local i = 0
local j = 0 local j = 0
@ -123,45 +123,43 @@ local j = 0
i = i + 1 i = i + 1
j = j - 1 j = j - 1
``` ```
`--` can also be a comment!
If there is anything behind a `--` the `--` treated as comment.
### assignments ### assignments
Assignment operators `+=`, `-=`, `*=`, `/=`, `^=` and `.=` can be used. Assignment operators `+=`, `-=`, `*=`, `/=`, `^=` and `.=` can be used for math on variables.
```lua ```lua
local a = 0 local a = 0
-- increment -- Increased by
a += 2 a += 2
## decrement ## Decreased by
a -= 1 a -= 1
## multiply ## Multiplied by
a *= 8 a *= 8
-- divide -- Divided by
a /= 2 a /= 2
-- to the power of -- Powered by
a ^= 3 a ^= 3
## concatenate string ## Concatenate string
a .= " str" a .= " str"
``` ```
will generate will generate
```lua ```lua
local a = 0 local a = 0
-- increment -- Increased by
a = a + 2 a = a + 2
-- decrement -- Decreased by
a = a - 1 a = a - 1
-- multiply -- Multiplied by
a = a * 8 a = a * 8
-- divide -- Divided by
a = a / 2 a = a / 2
-- to the power of -- Powered by
a = a ^ 3 a = a ^ 3
-- concatenate string -- Concatenate string
a = a .. " str" a = a .. " str"
``` ```
## working with the compiler ## Working with the compiler
### loading ### Loading
The init.lua returns a function for loading the compiler. The init.lua returns a function for loading the compiler.
You have to call it with the path to the script itself as argument. You have to call it with the path to the script itself as argument.
In case you have the LuaVenusCompiler directory within your project's In case you have the LuaVenusCompiler directory within your project's
@ -176,16 +174,16 @@ local vc = require("LuaVenusCompiler")("LuaVenusCompiler/")
``` ```
When it is loaded it can also be accessed with the global called "LuaVenusCompiler". When it is loaded it can also be accessed with the global called "LuaVenusCompiler".
### running venus files ### Running Venus files
`vc.dovenus(file)` works like `dofile(file)` `vc.dovenus(file)` works like `dofile(file)`
It's argument can be a relative or absolute path to the file that should be run. It's argument can be a relative or absolute path to the file that should be run.
### loading venus files ### Loading Venus files
`vc.loadvenus(file)` works like `loadfile(file)` `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'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. It returns a function that runs the generated lua.
### generating lua code ### Generating Lua code
`vc.tl_venus_file(file)` returns the lua generated from the files contents `vc.tl_venus_file(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's argument can be a relative or absolute path to the file that should be translated.
It returns the generated lua as string. It returns the generated lua as string.
@ -193,7 +191,7 @@ It returns the generated lua as string.
`vc.tl_venus_string(str)` returns the lua generated from the given string `vc.tl_venus_string(str)` returns the lua generated from the given string
It returns the generated lua as string. It returns the generated lua as string.
### generating lua files ### Generating Lua files
`vc.convert_venus_file(venus_file_in,lua_file_out)` generates a lua file `vc.convert_venus_file(venus_file_in,lua_file_out)` generates a lua file
It's arguments can be relative or absolute paths. It's arguments can be relative or absolute paths.
The venus_file_in will be converted to lua and written to lua_file_out. The venus_file_in will be converted to lua and written to lua_file_out.