Skip to content

Commit

Permalink
write a little docs and rebrand to piperscipt
Browse files Browse the repository at this point in the history
  • Loading branch information
oysandvik94 committed Aug 9, 2024
1 parent c2dd64c commit 7e6e004
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 24 deletions.
53 changes: 31 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
# Lasagnalang
# PiperScript

This project is an interpreter for the language Lasagnalang.
This project is an interpreter for the language PiperScript.

It is intented as a learning exercise based on the book [Writing An Interpreter
in Go](https://interpreterbook.com/). At the current state the intepreter is
adapted from the Go to Rust, with the goal of learning more about interpreters
and Rust. At a later stage I hope to create a
[LSP](https://microsoft.github.io/language-server-protocol/) for Lasagnalang,
as well as implementing some more novel idea for the language.
adapted from Go to Rust, with the goal of learning more about interpreters
and Rust.

Lasagnalang may look something like this:
PiperScript looks something like this:

```
foo: 5
let foo: "hei"
let bar: fn(x):
return x + "ok"
~
if foo == 5:
foo + 10
if bar == foo:
print(bar)
else:
1 + 1
print(foo)
~
add: fn(x, y): return x + y~
let adder: fn(x):
return fn(y): return x + y ~
~
add 5 1
let array: [2, 5, 6]
print(array[2])
complex: fn(x, y, k):
foo: add x y
return k(foo)
~
let hash: {"mee", 5, "boo", 1}
print(hash["mee"])
power: fn(x): return x * x~
let one: 1
print(hash["mee"] / 8 * (array[1] + one))
complex 5 3 power // 64
res: complex 5 3 power
print(last(array))
push(array, 5)
```

There is nothing interesting or worthwhile about the language, the project is
entirely about the exercise of creating an interpreter.
## Additonal documentation

See the following readme's for more technical docs:

- [Interpreter](crates/interpreter/README.md)
- [LSP](crates/son_of_anton/README.md)
- [Formatter](crates/piperfmt/README.md)
24 changes: 24 additions & 0 deletions crates/interpreter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Interpreter

The interpreter is currently a tree-walking interpreter.

## Parsing

The main entry point is in `parser.rs`, see `Parser` structs new function.

The parser holds a lexer, that walks the source code and produces
tokens for the parser.

The parser is a [Pratt Parser](https://matklad.github.io/2020/04/13/simple-but-powerful-pratt-parsing.html), also known as
recursive descent parsing.

The parser produces human readable "compile-time" errors.

## Evaluating

Currently a tree-walking interpreter. Will be rewritten to
byte-code interpreter soon.

Main entry point is in `eval.rs`, see `eval::eval()`

Evaluator produces runtime errors.
8 changes: 8 additions & 0 deletions crates/piperfmt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Piperfmt

Early version of formatter, will build upon slowly.

Strategy will be storing tokens together with statements/expressions,
and formatting based on those tokens.

The formatter will be 100% opinionated.
2 changes: 1 addition & 1 deletion crates/repl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::io::{stdin, stdout, Write};
use interpreter::eval::{self, objects::Environment, EvaledProgram};

pub fn execute_repl() -> Result<(), std::io::Error> {
println!("Welcome to lasagnalang, try and write some code:");
println!("Welcome to piperscript, try and write some code:");
let repl_scope = &mut Environment::new_env_reference();

loop {
Expand Down
28 changes: 28 additions & 0 deletions crates/son_of_anton/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Son of Anton

Son of Anton is PiperScrips LSP implementation.

See the [specification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/)

Server is a JSON-RPC server over stdin and stdout.

To install:
`cargo install --package son_of_anton`

To use in i.e. neovim:

```lua
local root_dir = vim.fs.dirname(vim.fs.find({ ".git" }, { upward = true })[1])
local client = vim.lsp.start({
name = "anton",
cmd = { "son_of_anton" },
root_dir = root_dir,
})
vim.lsp.buf_attach_client(0, client)
```

## Features

Currently supports these capabilites:

- Intitialize
1 change: 0 additions & 1 deletion crates/son_of_anton/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut anton = SonOfAnton::from(io::stdout());

loop {
// Block until there is input to read
let mut buffer = String::new();
reader.read_line(&mut buffer)?;

Expand Down

0 comments on commit 7e6e004

Please sign in to comment.