Og-Lang
v0.1.0
Language inspired from Livescript that compiles to a subset of GoLang.
To be pronounced Oh-Jee.
Built with Antlr4 from their Golang grammar.
og is written in og. See the src folder for og source, and the lib folder for the compiled one.
Index
Goal
To provide a usable language that compiles to Golang
The main goal is to simplify the syntax, to borrow some concepts from Livescript and other functional languages, to implement Generics and macro processing, as well as some syntaxic sugar to avoid all the boilerplate Golang force us into.
Exemple
This is an exemple of how og looks like actualy. See the Exemples folder.
package main
import
fmt
strings
"some/repo"
type Foo struct
bar int
Foo::myFunc(foo int) : int -> return this.bar + foo
myFunc(a string): string -> return a
main ->
test := "foo"
if test == "foo"
fmt.Println(test)
else
fmt.Println("Not foo")
for _, v in someArray
fmt.Println(v)
Build
Here is the procedure to regenerate the parser from the grammar if you want to make changes to it.
If you just want to (re)build the binary, you can call make build or just go build
Build Antlr
This implementation needs the TreeVisitor pattern from Antlr. You have to get and build the https://github.com/wxio/antlr4/tree/go-visitor into jar and Go runtime, as the official antlr4 repo don't have fully implemented them yet.
You will need Maven.
# Install maven
sudo apt install maven
# Get the repo
cd $GO_ROOT/src
go get -u github.com/wxio/antlr4
cd github.com/wxio/antlr4
# Switch to go-visitor branch
git checkout go-visitor
# Build the jar
mvn install -DskipTests=true
Og
# Get Og
go get -u github.com/champii/og
cd $GO_ROOT/src/github.com/champii/og
# This will generate the grammar,
# Compile the existing sources,
# Regenerate the go sources from og,
# Recompile the new go sources to be sure
# And run the tests.
make
# This will just build the sources (if needed)
make build
# And install
sudo make install
# Simple exemple
og exemples/import.og
Long term goal
!main
import fmt
struct Generic<T>
// attributes
pub test T
// Class method
pub @new(v T) : Generic<T> -> Generic<T>{ v }
// Instance method
fn : T -> @test
genericFunc<T>(g Generic<T>): T -> g.test
main ->
t := Generic<string>::new("str")
fmt.Println(t.fn())
TODO
- Efficient multi-path recursive compile
- Perfs
- Binary operator (
<<, >>, ., |)
- Interfaces
- Empty Function body
- Struct compostion ("Inheritance")
- Auto return for last statement in a block
- For with a range (for i in [0..10])
- For with a custom variable (for i = 0; i < 10; i++) or (for i < 10)
-
pub visibility instead of capitalizing
- Existance test (if toto?) for non-nil value test
- Returnable and assignable statements (if, for, ...)
- Generics
- Error bubbling
- Class-like method declaration (nested into the struct)
- Pattern matching
- Import renaming and pattern matching
Done
- Rewrite Og in Og
- Package declaration
- Import
- Structure
- Top level Function
- Function arguments and type
- Function return type
- Return keyword
- Assignation
- Bool
- Int
- Float
- String
- Array
- Nested property (a.b.c)
- Function call
- Array access (a[0])
- If
- Else If
- Else
- Predicate operator
- Is / Isnt alias of
== / !=
- For In
- Goroutine
-
gofmt to format the output
- One liner functions
- Math Operators
- Array type
- Pointer type
- Struct tags
- Parenthesis
- Reference and Dereference
- Increment/Decrement
- Struct instantiation
- Nil value
- Logical predicat operator (
|| / && or / and)
- Multiple return in func
- Multiple return values in assign
- Type assertion
- Tests
- Package
- Import
- Struct
- Top Level Function
- If/ElseIf/Else
- For
- NestedProperty
- GoRoutine
- Math Operation
- Reference/Dereference
- Increment/Decrement
- Struct instantiation
- Multiple return in func
- Multiple return values in assign