interpreter-in-go
“interprester-in-go” or InterinGo (for short) is a new interpreter language, come with LSP and highlighter for neovim. It can be run in 3 mode
- REPL mode: Which stand for read-evaluation-print-loop, similar to
python - File mode: Execute code as input from file
- Server mode: Which have a pretty UI for REPL on a HTTP Server
Why
To challenge my knowledge with go language and advanced (interpreter) concept. I also set up a http server to public InterinGo interpreter, that you can access evaluating the language right now.
Techstack:
Front-end
templfor html templatetailwind.cssfor stylinghtmxfor server REPL API accessjavascriptfor some dynamic UI rendering
Back-end:
golangstandard library for http-request/server handlingreadlinefor CLI
How to use
Build the program and get ./interingo file executable or download Released binary. You can run ./interingo -h to get help on runner flag directly (for TLDR folks). You can also using Docker, which already pull and build the code too
sudo docker run -it --entrypoint="interingo" nghiango1/interingo
Using bash session can be even better
sudo docker run -it --entrypoint="/bin/bash" nghiango1/interingo
REPL mode
Running ./interingo executable normaly
./interingo
And you should have been welcome with this
$ ./interingo
Hello <username>! This is the InterinGo programming language!
Type `help()` in commands for common guide
>>
File mode
This have the highest piority, so don’t expect server, or REPL running
Running ./interingo executable with -f flag.
./interingo -f <file-location>
Unknow what to do yet, use test code in ‘test/’ directory as your start point. Every file contain comment for expected output in the top to make sure you don’t get lost
./interingo -f test/return-01.iig
Server mode
As expected, who know what you got if they can’t just test it directly on the browser
Running ./interingo executable with -s flag
./interingo -s
You can also specify listen address with -l flag or it will default to 0.0.0.0:8080
./interingo -s -l 127.0.0.1:4000
Verbose output
Tell more infomation about Lexer, Parse, Evaluation process via REPL output
Start with the -v flag
$ ./interingo -v
Or using toggleVerbose()command in InterinGo REPL to enable/disable it
$ ./interingo
>> toggleVerbose()
The “interprester-in-go” language syntax:
You can go to server/docs/ or read live docs website
Build - Minimal REPL build
Prerequisite
TLDR:
go v1.24.1
tailwindcss v4.0.8
Ubuntu machine
Go: Prefered to use version manager
- Install go version manager
gvm
sudo apt-get install bison
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
cdusually not working, so better just delete it.
vi ~/.gvm/scripts/gvm-default
# Delete the last line of `gvm-default` file - Which change cd functionality
- Install latest (currently at v1.24.1) version from binary file and set it as default
gvm install go1.24.1 -B
gvm use go1.24.1 --default
Tailwindcss CLI: Following https://tailwindcss.com/docs/installation/tailwind-cli for installing guide. Currently the project using version v4.0.8
- Example install command, you can also download the binary file
tailwindcss-linux-x64directly from tailwind github release page
npm install tailwindcss @tailwindcss/cli
- Then setup correct cli tools path to
TAILWIND_CLIos environment. Bellow is the default in the make file (which will be used if the variable isnot set)
TAILWIND_CLI ?= tailwindcss-linux-x64
Nix/Nix-shell
Install nix-shell if you not using NixOS: Following guide from https://nix.dev/manual/nix/2.29/installation/index.html
curl -L https://nixos.org/nix/install | sh -s -- --daemon
Then all prerequired can be done using nix-shell from project root (which have shell.nix file). This will create a virtual (like python3-venv) shell with correct build tools version installed
nix-shell
Build
Build the code with
make build
Test
Test all module with
go test ./...
Build - Full build with Server front-end
All server source file is in /server/ directory, which need special handle for templ files - containing frontend code. This require extra build tool and generating code step. Makefile is add to help handle these process
Prerequire
Install go-lang latest version, currently go 1.22.0
gvm install go1.22.0 -B
gvm use go1.22.0 -default
Install templ tools, learn more in templ.guide. Make sure to setup go/bin into your environment.
go install github.com/a-h/templ/cmd/templ@latest
export PATH="$PATH:~/go/bin"
In case that you using Neovim with Mason, you can install templ directly from there (LSP templ). You will need setup mason bin to PATH instead
> $ which templ > /home/username/.local/share/nvim/mason/bin/templ > # ^^^^^^^^^ change this to your username > ``` Download latest `tailwind` CLI standalone tool from their [github](https://github.com/tailwindlabs/tailwindcss/releases/) and put it in to `PATH`. This should be add in `.profile` file ```sh wget https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64 cp tailwindcss-linux-x64 ~/.local/bin export PATH="$HOME/.local/bin:$PATH"
Install cmake
apt-get -y install make
Using Make tools
Build
I setup Makefile to handle CLI operation, use make build-run to rebuild and start the server
makeormake allormake help: Show all option commandmake build: Build/Rebuildtempltemplate files and generating tailwindcss stylesheetmake run: Run built the servermake build-run: Do both
Example
make
Dev mode
Golang doesn’t have watch mode, but templ and tailwindcss have it
make tailwind-watch: Tailwind watch mode - Auto rebuild when files changemake templ-watch: Templ watch mode - Auto rebuild when files changego run . -sormake go-run: Run the server without build
Build - LSP, Highlight
Docker ready neovim with full configuration is here
sudo docker build -t interingo .
sudo docker run -it interingo
or pull directly from docker hub
sudo docker run -it nghiango1/interingo
Using neovim quick guide
- Using
<space>fto format the file (comment isn’t properly parse by lsp server yet though) - Using
<space>pvto open the list of new file to choose and formating - Using
<F5><enter>to run the file with InterinGo REPL mode
LSP and Treesitter highlight can be overkill as it per need specific text editor configuration (some even need specific plugin/extension configuration). Currently, I only setup a Neovim config as Local, as provide them as a fully working component with one click install seem like an overkill. Following each correspond README.md to properly config and use them in neovim if you interested
I at least can provide some pictures to prove it work:
- In markdown file:
- In specific
*.iigfile extension: - In LSP auto format: