diff --git a/README.md b/README.md index 62cbc48..7895b17 100644 --- a/README.md +++ b/README.md @@ -6,36 +6,47 @@ An interpreted, expression-oriented language where everything evaluates to strin ### Installation -You need Go to build the official interpreter from this repository. +You need Go to build the official interpreter from this repository. +Run `go get github.com/skius/stringlang/cmd/stringlang` to install the CLI on your machine. -Run `go get github.com/skius/stringlang/cmd/stringlang` to install the interpreter on your machine. You can then -run it using `stringlang ...` +### CLI + +Run StringLang programs using `stringlang ...`, +or alternatively run the StringLang REPL by running `stringlang` with no arguments. ### Running from code To interpret StringLang code from your Go program, all you need is the following: + ```go package main -import "github.com/skius/stringlang" + +import ( + "github.com/skius/stringlang" + "os" + "strconv" +) func main() { - stringlang := `"Replace me with the " + "source code of your StringLang program"` - expr, err := stringlang.Parse(stringlang) - if err != nil { - panic(err) - } - // The built-in functions your StringLang program will have access to - funcs := []map[string]func([]string)string{ - "length": func (as []string) string { return len(as[0]) }, - // Add more built-in functions here - } - // Arguments to your StringLang program - args := os.Args - ctx := NewContext(args, funcs) - result := expr.Eval(ctx) + source := `"Replace me with the " + "source code of your StringLang program"` + expr, err := stringlang.Parse([]byte(source)) + if err != nil { + panic(err) + } + // The built-in functions your StringLang program will have access to + funcs := map[string]func([]string) string{ + "length": func(as []string) string { return strconv.Itoa(len(as[0])) }, + // Add more built-in functions here + } + // Arguments to your StringLang program + args := os.Args + ctx := stringlang.NewContext(args, funcs) + result := expr.Eval(ctx) } ``` +See the CLI's [main.go](cmd/stringlang/main.go) for a more advanced example. + ### Contributing Feel free to open Issues and Pull Requests! The language specification and interpreter is by no means final.