talang

package module
v0.0.0-...-38ca351 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2021 License: MIT Imports: 10 Imported by: 1

README

Travis Codecov GoDoc go-report

Talang

Talang is a custom programming language, specifically a lisp-dialect, implemented in Go, that we developed and use internally at Talon.One.

Motivation

The motivation behind developing our own custom language is that the very nature of what our customers are doing in the core of our product is a form of programming. We needed a language to represent these "programs" with certain characteristics:

  • Easy to parse, interpret and manipulate
  • Easy to represent in JSON
  • Safe runtime properties (Talang has no recursion, no infinite loops)
  • Type-safe expressions

No existing language would fit these requirements and was also easy to integrate.

How do we use Talang at Talon.One?

Within our product, we let our customers write their own sets of what we call "Rules". These are concluded of two main types of expressions:

  • Conditions: representing predicates which evaluate to a boolean reault
  • Effects: representing expressions which return side effects handled by the promotions

We needed a way to give our customers the flexibility and control when composing such "Rules".

At the core of our product we developed a processing engine which takes these predefined Rules, gives them an execution context, and evaluates them. The return result(s) from this engine then returned to our customers to process / work with.

Why would you need it?

Talang is a very simple, fast and flexible language which is very easy to represents in JSON objects. When you desire a language, customizable, expandable, with no compiling time and fast evaluation time - Talang can be a very good choice for your requirements.

Usage

Get the package:

$ go get github.com/talon-one/talang

Then import it and use the Interpreter:

interp := talang.MustNewInterpreter()
result, err := interp.LexAndEvaluate(`(+ 1 2)`)
if err != nil {
	panic(err)
}
fmt.Println(result.Stringify()) // 3

You can refer to the examples folder for more examples and usages.

Here you can see a list of the embedded function in the language.

Playing Around

Check out our brand new playground at https://talang-land.talon.one/.

Or alternatively, get our CLI locally and play with Talang in your consolse!

Contributing

We have collected notes on how to contribute to this project in CONTRIBUTING.md.

License

Talang is released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lex

func Lex(str string) (*token.TaToken, error)

func MustLex

func MustLex(str string) *token.TaToken

func MustParse

func MustParse(str string) *token.TaToken

func Parse

func Parse(str string) (*token.TaToken, error)

Types

type Interpreter

type Interpreter struct {
	interpreter.Interpreter
}

func MustNewInterpreter

func MustNewInterpreter() *Interpreter

func NewInterpreter

func NewInterpreter() (*Interpreter, error)

func (*Interpreter) Evaluate

func (interp *Interpreter) Evaluate(b *token.TaToken) error

func (*Interpreter) LexAndEvaluate

func (interp *Interpreter) LexAndEvaluate(str string) (*token.TaToken, error)

func (*Interpreter) MustEvaluate

func (interp *Interpreter) MustEvaluate(b *token.TaToken)

func (*Interpreter) MustLexAndEvaluate

func (interp *Interpreter) MustLexAndEvaluate(str string) *token.TaToken

Directories

Path Synopsis
cmd
corefn
cmp
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL