Almost Operational Coding Language is my attempt at creating a programming language, including the tools around it, that is usable enough to solve Advent of Code 2024.
For the language to be almost operational it should have:
- an interpreter,
- syntax highlighting,
- basic LSP.
Rust is required to build the interpreter.
- Clone this repository:
git clone https://github.com/viddrobnic/aoc-lang.git
- Build and install the interpreter:
cd aoc-lang cargo install --path .
- Run some code:
aoc-lang examples/hello_world.aoc
Syntax highlighting is implemented with tree sitter. I am using neovim as my editor (btw) and this is the standard way of doing it. If you are using some other editor, you are on your own...
- Add the aoc tree sitter parser to your config:
local parser_config = require('nvim-treesitter.parsers').get_parser_configs() parser_config.aoc = { install_info = { url = 'https://github.com/viddrobnic/aoc-lang.git', files = { 'tree-sitter-aoc/src/parser.c' }, }, filetype = 'aoc', }
- Open neovim and install the parser
:TSInstall aoc
- Configure automatic aoc file type detection:
vim.filetype.add({ extension = { aoc = 'aoc', }, })
- Add highlighting queries by copying
this file
from the repo to
~/.config/nvim/queries/aoc/
- Restart neovim and open an
.aoc
file :)
Language server can be started by running aoc-lang lsp
. If you are using
neovim with lspconfig, you can
configure the LSP by adding the following configuration:
local configs = require 'lspconfig.configs'
if not configs.aoc then
configs.aoc = {
default_config = {
name = 'AOC LSP',
cmd = { '/path/to/aoc-lang', 'lsp' },
root_dir = lspconfig.util.root_pattern('.git'),
filetypes = { 'aoc' },
},
}
end
lspconfig.aoc.setup {
capabilities = capabilities,
on_attach = on_attach,
}
The language server should get started automatically when you open a .aoc
file.
AoC language supports the following features:
- integers
- floats
- booleans
- strings
- characters
- arrays
- hash maps
- arithmetic operations (
+
,-
,*
,/
,%
) - bit-wise operations (
&
,|
,!
) - comparison operations (
<
,>
,<=
,>=
,==
,!=
) - logical operations (
!
,&
,|
) - variables
- multi variable assignment (
[a, b] = [10, 20]
) - if/else statements
- while loop
- for loop
- break
- continue
- functions
- comments
- stdin, stdout
- imports
- error reporting with line numbers
For more detailed overview of the syntax, see examples
directory,
which contains examples of code with comments.
AoC LSP has the following features:
- diagnostics
- go to definition
- list references
- highlight
- hover
- list document symbols
- auto-complete suggestions