https://github.com/aziis98/ergolas
an Embeddable Random GOlang LAnguage for Scripting
https://github.com/aziis98/ergolas
embeddable-scripting-language golang library programming-language
Last synced: 12 months ago
JSON representation
an Embeddable Random GOlang LAnguage for Scripting
- Host: GitHub
- URL: https://github.com/aziis98/ergolas
- Owner: aziis98
- License: agpl-3.0
- Created: 2023-06-20T22:35:59.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-06-21T06:56:40.000Z (over 2 years ago)
- Last Synced: 2024-06-21T19:53:09.426Z (over 1 year ago)
- Topics: embeddable-scripting-language, golang, library, programming-language
- Language: Go
- Homepage:
- Size: 24.4 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ergolas (WIP)
This is just an **e**mbeddable **r**andom **go**lang **la**nguage for **s**cripting. Recently I use Golang very often and sometimes I want to add some extensibility features to my projects using some kind of scripting languages or DSL so I made this mini language for experimenting. There is an included tree walking interpreter but I plan to make it really easy to just parse an expression and get an AST to evaluate with a custom interpreter.
The syntax is very simple and pretty general and inherits many things from [Lisp](https://en.wikipedia.org/wiki/Lisp_(programming_language)), [REBOL](http://www.rebol.com/)/[Red](https://www.red-lang.org/) and [Julia](https://julialang.org/).
```lua
println "Hello, World!"
```
## Features
- [ ] Parser
- [x] Function calls without parentheses
- [x] Property access
- [x] Quoted forms
- [x] Binary operators
- [x] Quasi-quotes with `:` for quoting and `$` for unquoting (might change `:` to `#` and comments to `//`)
- [ ] Unary operators
- [ ] String templating (for now missing, maybe something can be done just using quasiquotes)
- [ ] Interpreter
- [ ] Simple tree walking interpreter
- [x] Basic operators and arithmetic
- [x] Basic printing and exiting
- [x] Basic variable assignment
- [ ] Lexical scoping
- [ ] Control flow
- [ ] Objects and complex values
- [ ] Dynamic scoping
- [ ] Hygienic macros
- [ ] More advanced interpreters...
- [ ] Easily usable as a library
- [ ] Small standard library
- [ ] Interop from and with Go
- [ ] Tooling
- [ ] Syntax highlighting for common editors
- [ ] `PKGBUILD` for easy global installation on Arch Linux thorough GitHub releases (mostly for trying this out with GitHub Actions)
## Usage
To try this out in a REPL (with colors!)
```bash shell
$ go run ./cmd/repl
```
## Reference
### Literals
```perl
# Integer
1
# Decimal
3.14
# Identifier
an-Example_identifier
# String
"an example string"
# List (?) (not implemented)
[1 2 3 4 5] # equivalent to "List 1 2 3 4 5"
# Maps (?) (not implemented)
{ a -> 1, b -> 2, c -> 3 }
```
### Comments
```perl
# This is an inline comment
```
### Functions
Function call don't require parentheses if they
```perl
# [x] Parses ok, [x] Evals ok
println "a" "b" c"
```
```perl
# [x] Parses ok, [x] Evals ok
exit 1
```
### Anonymous Functions
```perl
# [x] Parses ok, [ ] Evals ok
# anonymous function with params
my-func := fn x y { x + y }
```
```perl
# [ ] Parses ok, [ ] Evals ok
# anonymous lexical block without params, can be called with a context
my-block := { x + y }
ctx := Map [ x -> 1, y -> 2 ]
call my-block ctx
```
### Operators
The following binds "a" to 9, arithmetic operators don't have any precedence and are all left associative. There are a only a few right associative operators that for now just are `:=`, `::` even if only `:=` is used for binding variables, `::` will later be used to tell the type of variables.
```perl
# [x] Parses ok, [x] Evals ok
a := 1 + 2 * 3
```
#### Overloading
```perl
# [x] Parses ok, [ ] Evals ok
operator lhs ++ rhs {
return List.join lhs rhs
}
```
### Quotes
```perl
# [x] Parses ok, [ ] Evals ok
a := (1 + 1) # 2
b := :(1 + 1) # :(1 + 1)
```
### Misc
Some more examples and ideas for the language syntax and semantics
```perl
# [x] Parses ok, [ ] Evals ok
len := (v.x ^ 2) + (v.y ^ 2)
# [x] Parses ok, [ ] Evals ok
if { a > b } {
println "True case"
} {
println "False case"
}
# [x] Parses ok, [ ] Evals ok
my-list-1 := list 1 2 3 4 5
# [x] Parses ok, [ ] Evals ok
for item my-list-1 {
printfln "item = {}" item
}
```