Skip to content

Commit

Permalink
rename project to avoid name clash with the existing Otto JS interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
xrstf committed Nov 21, 2023
1 parent 7c2d98e commit 91c7964
Show file tree
Hide file tree
Showing 85 changed files with 269 additions and 270 deletions.
6 changes: 3 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# SPDX-License-Identifier: MIT

builds:
- dir: cmd/otti
binary: otti
- dir: cmd/rudi
binary: rudi
env:
# goreleaser does not work with CGO, it could also complicate
# usage by users in CI/CD systems like Terraform Cloud where
Expand Down Expand Up @@ -32,7 +32,7 @@ builds:
goarch: '386'
archives:
- format: tar.gz
name_template: 'otti_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
name_template: 'rudi_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
wrap_in_directory: true
strip_parent_binary_folder: true
format_overrides:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ all: clean generate build test

.PHONY: generate
generate:
pigeon pkg/lang/grammar/otto.peg > pkg/lang/parser/generated.go
pigeon pkg/lang/grammar/rudi.peg > pkg/lang/parser/generated.go

.PHONY: clean
clean:
Expand All @@ -27,7 +27,7 @@ clean:
.PHONY: build
build:
mkdir -p _build
cd cmd/otti && go build $(GO_BUILD_FLAGS) -o ../../_build .
cd cmd/rudi && go build $(GO_BUILD_FLAGS) -o ../../_build .

.PHONY: test
test:
Expand Down
49 changes: 24 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,47 @@
# Otto
# Rudi

<p align="center">
<img src="https://img.shields.io/github/v/release/xrstf/otto" alt="last stable release">
<img src="https://img.shields.io/github/v/release/xrstf/rudi" alt="last stable release">

<a href="https://goreportcard.com/report/go.xrstf.de/otto">
<img src="https://goreportcard.com/badge/go.xrstf.de/otto" alt="go report card">
<a href="https://goreportcard.com/report/go.xrstf.de/rudi">
<img src="https://goreportcard.com/badge/go.xrstf.de/rudi" alt="go report card">
</a>

<a href="https://pkg.go.dev/go.xrstf.de/otto">
<img src="https://pkg.go.dev/badge/go.xrstf.de/otto" alt="godoc">
<a href="https://pkg.go.dev/go.xrstf.de/rudi">
<img src="https://pkg.go.dev/badge/go.xrstf.de/rudi" alt="godoc">
</a>
</p>

Otto is a Lisp-based, embeddable programming language that focuses on transforming data structures
like those available in JSON (numbers, bools, objects, vectors etc.). A statement in Otto looks like
Rudi is a Lisp-based, embeddable programming language that focuses on transforming data structures
like those available in JSON (numbers, bools, objects, vectors etc.). A statement in Rudi looks like

```lisp
(set .foo[0] (+ (len .users) 42))
```

Otto has been named after the legendary German comedian
[Otto Waalkes](https://en.wikipedia.org/wiki/Otto_Waalkes).
Rudi has been named after my grandfather.

## Installation

Otto is primarily meant to be embedded into other Go programs, but a standalone CLI application,
_Otti_, is also available to test your scripts with. Otti can be installed using Git & Go:
Rudi is primarily meant to be embedded into other Go programs, but a standalone CLI application,
_Rudi_, is also available to test your scripts with. Rudi can be installed using Git & Go:

```bash
git clone https://github.com/xrstf/otto
cd otto
git clone https://github.com/xrstf/rudi
cd rudi
make build
```

Alternatively, you can download the [latest release](https://github.com/xrstf/otto/releases/latest)
Alternatively, you can download the [latest release](https://github.com/xrstf/rudi/releases/latest)
from GitHub.

## Usage

Otti has extensive help built right into it, try running `otti help` to get started.
Rudi has extensive help built right into it, try running `rudi help` to get started.

## Embedding

Otto is well suited to be embedded into Go applications. A clean and simple API makes it a breeze:
Rudi is well suited to be embedded into Go applications. A clean and simple API makes it a breeze:

```go
package main
Expand All @@ -51,33 +50,33 @@ import (
"fmt"
"log"

"go.xrstf.de/otto"
"go.xrstf.de/rudi"
)

const script = `(+ $myvar 42 .foo)`

func main() {
// setup the set of variables available by default in the script
vars := otto.NewVariables().
vars := rudi.NewVariables().
Set("myvar", 42)

// Likewise, setup the functions available (note that this includes functions like "if" and "and",
// so running with an empty function set is generally not advisable).
funcs := otto.NewBuiltInFunctions()
funcs := rudi.NewBuiltInFunctions()

// Otto programs are meant to manipulate a document (path expressions like ".foo" resolve within
// Rudi programs are meant to manipulate a document (path expressions like ".foo" resolve within
// that document). The document can be anything, but is most often a JSON object.
documentData := map[string]any{"foo": 9000}
document, err := otto.NewDocument(documentData)
document, err := rudi.NewDocument(documentData)
if err != nil {
log.Fatalf("Cannot use %v as the document: %v", documentData, err)
}

// combine document, variables and functions into an execution context
ctx := otto.NewContext(document, funcs, vars)
ctx := rudi.NewContext(document, funcs, vars)

// parse the script (the name is used when generating error strings)
program, err := otto.ParseScript("myscript", script)
program, err := rudi.ParseScript("myscript", script)
if err != nil {
log.Fatalf("The script is invalid: %v", err)
}
Expand All @@ -86,7 +85,7 @@ func main() {
// this returns an evaluated value, which is the result of the last expression that was evaluated,
// plus a new context, which contains for example newly set runtime variables; in many cases the
// new context is not that important and you'd focus on the evaluated value.
newCtx, evaluated, err := otto.RunProgram(ctx, program)
newCtx, evaluated, err := rudi.RunProgram(ctx, program)
if err != nil {
log.Fatalf("Failed to evaluate script: %v", err)
}
Expand Down
33 changes: 0 additions & 33 deletions cmd/otti/util/otto.go

This file was deleted.

20 changes: 10 additions & 10 deletions cmd/otti/cmd/console/command.go → cmd/rudi/cmd/console/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
"strings"

"github.com/chzyer/readline"
"go.xrstf.de/otto"
cmdtypes "go.xrstf.de/otto/cmd/otti/types"
"go.xrstf.de/otto/cmd/otti/util"
"go.xrstf.de/otto/docs"
"go.xrstf.de/otto/pkg/eval/types"
"go.xrstf.de/rudi"
cmdtypes "go.xrstf.de/rudi/cmd/rudi/types"
"go.xrstf.de/rudi/cmd/rudi/util"
"go.xrstf.de/rudi/docs"
"go.xrstf.de/rudi/pkg/eval/types"
)

//go:embed help.md
Expand Down Expand Up @@ -61,12 +61,12 @@ func Run(opts *cmdtypes.Options, args []string) error {
return fmt.Errorf("failed to read inputs: %w", err)
}

ctx, err := util.SetupOttoContext(files)
ctx, err := util.SetupRudiContext(files)
if err != nil {
return fmt.Errorf("failed to setup context: %w", err)
}

fmt.Println("Welcome to Otti 🐘")
fmt.Println("Welcome to Rudi 🐘")
fmt.Println("Type `help` fore more information, `exit` or Ctrl-C to exit.")
fmt.Println("")

Expand All @@ -84,7 +84,7 @@ func Run(opts *cmdtypes.Options, args []string) error {

newCtx, stop, err := processInput(ctx, helpTopics, opts, line)
if err != nil {
parseErr := &otto.ParseError{}
parseErr := &rudi.ParseError{}
if errors.As(err, parseErr) {
fmt.Println(parseErr.Snippet())
fmt.Println(parseErr)
Expand Down Expand Up @@ -119,12 +119,12 @@ func processInput(ctx types.Context, helpTopics []docs.Topic, opts *cmdtypes.Opt
}

// parse input
program, err := otto.ParseScript("(repl)", input)
program, err := rudi.ParseScript("(repl)", input)
if err != nil {
return ctx, false, err
}

newCtx, evaluated, err := otto.RunProgram(ctx, program)
newCtx, evaluated, err := rudi.RunProgram(ctx, program)
if err != nil {
return ctx, false, err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/otti/cmd/script/help.md → cmd/rudi/cmd/console/help.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Welcome to the Otto interpreter :)
# Welcome to the Rudi interpreter :)

You can enter one of

* A path expression, like `.foo` or `.foo[0].bar` to access the global document.
* An expression like (+ .foo 42) to compute data by functions; see the topics
below or the Otto website for a complete list of available functions.
below or the Rudi website for a complete list of available functions.
* A scalar JSON value, like `3` or `[1 2 3]`, which will simply return that
exact value with no further side effects. Not super useful usually.

Expand All @@ -14,7 +14,7 @@ Additionally, the following commands can be used:

* help – Show this help text.
* help TOPIC – Show help for a specific topic.
* exit – Exit Otti immediately.
* exit – Exit Rudi immediately.

## Help Topics

Expand Down
6 changes: 3 additions & 3 deletions cmd/otti/cmd/help/command.go → cmd/rudi/cmd/help/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"strings"

"github.com/spf13/pflag"
"go.xrstf.de/otto/cmd/otti/types"
"go.xrstf.de/otto/cmd/otti/util"
"go.xrstf.de/otto/docs"
"go.xrstf.de/rudi/cmd/rudi/types"
"go.xrstf.de/rudi/cmd/rudi/util"
"go.xrstf.de/rudi/docs"
)

//go:embed help.md
Expand Down
20 changes: 10 additions & 10 deletions cmd/otti/cmd/help/help.md → cmd/rudi/cmd/help/help.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# The Otto interpreter :)
# The Rudi interpreter :)

Otti is a command line interpreter for the Otto programming language. Otti can
Rudi is a command line interpreter for the Rudi programming language. Rudi can
read multiple JSON/YAML files and then apply JSON paths or scripts to them. For
quicker development, an interactive REPL is also available.

## Modes

Otti can run in one of two modes:
Rudi can run in one of two modes:

* **Interactive Mode** is enabled by passing `--interactive` (or `-i`). This will
start a REPL session where Otto scripts are read from stdin and evaluated
start a REPL session where Rudi scripts are read from stdin and evaluated
against the loaded files.
* **Script Mode** is used the an Otto script is passed either as the first
argument or read from a file defined by `--script`. In this mode Otti will
* **Script Mode** is used the an Rudi script is passed either as the first
argument or read from a file defined by `--script`. In this mode Rudi will
run all statements from the script and print the resulting value, then it exits.

Examples:

* `otti '.foo' myfile.json`
* `otti '(set .foo "bar") (set .users 42) .' myfile.json`
* `otti --script convert.otto myfile.json`
* `rudi '.foo' myfile.json`
* `rudi '(set .foo "bar") (set .users 42) .' myfile.json`
* `rudi --script convert.rudi myfile.json`

## File Handling

Expand All @@ -31,5 +31,5 @@ for `set` for more information).

## Help

Help is available by using `help` as the first argument to Otto. This can be
Help is available by using `help` as the first argument to Rudi. This can be
followed by a topic, like `help if`.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"os"
"strings"

"go.xrstf.de/otto"
"go.xrstf.de/otto/cmd/otti/types"
"go.xrstf.de/otto/cmd/otti/util"
"go.xrstf.de/otto/pkg/debug"
"go.xrstf.de/rudi"
"go.xrstf.de/rudi/cmd/rudi/types"
"go.xrstf.de/rudi/cmd/rudi/util"
"go.xrstf.de/rudi/pkg/debug"

"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -43,7 +43,7 @@ func Run(opts *types.Options, args []string) error {
}

// parse the script
program, err := otto.ParseScript(scriptName, script)
program, err := rudi.ParseScript(scriptName, script)
if err != nil {
return fmt.Errorf("invalid script: %w", err)
}
Expand All @@ -64,13 +64,13 @@ func Run(opts *types.Options, args []string) error {
}

// setup the evaluation context
ctx, err := util.SetupOttoContext(files)
ctx, err := util.SetupRudiContext(files)
if err != nil {
return fmt.Errorf("failed to setup context: %w", err)
}

// evaluate the script
_, evaluated, err := otto.RunProgram(ctx, program)
_, evaluated, err := rudi.RunProgram(ctx, program)
if err != nil {
return fmt.Errorf("failed to evaluate script: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/otti/cmd/console/help.md → cmd/rudi/cmd/script/help.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Welcome to the Otto interpreter :)
# Welcome to the Rudi interpreter :)

You can enter one of

* A path expression, like `.foo` or `.foo[0].bar` to access the global document.
* An expression like (+ .foo 42) to compute data by functions; see the topics
below or the Otto website for a complete list of available functions.
below or the Rudi website for a complete list of available functions.
* A scalar JSON value, like `3` or `[1 2 3]`, which will simply return that
exact value with no further side effects. Not super useful usually.

Expand All @@ -14,7 +14,7 @@ Additionally, the following commands can be used:

* help – Show this help text.
* help TOPIC – Show help for a specific topic.
* exit – Exit Otti immediately.
* exit – Exit Rudi immediately.

## Help Topics

Expand Down
Loading

0 comments on commit 91c7964

Please sign in to comment.