Skip to content

Commit

Permalink
Merge pull request #699 from nevalang/dash-delim-syntax
Browse files Browse the repository at this point in the history
Dash delim syntax
  • Loading branch information
emil14 authored Sep 21, 2024
2 parents 4a86048 + 16b66d4 commit f3603f5
Show file tree
Hide file tree
Showing 108 changed files with 1,891 additions and 1,953 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.23'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v6
with:
version: v1.54.0
version: v1.60
only-new-issues: true
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
build_and_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: setup go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.23'
- name: build
run: go build -v ./...
- name: install
Expand Down
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"name": "ANTLR",
"type": "antlr-debug",
"request": "launch",
"input": "${workspaceFolder}/internal/compiler/parser/tests/happypath/027_compiler_directives.neva",
// "input": "${workspaceFolder}/internal/compiler/parser/tests/happypath/027_compiler_directives.neva",
"input": "${workspaceFolder}/examples/hello_world/main.neva",
"grammar": "${workspaceFolder}/internal/compiler/parser/neva.g4",
"startRule": "prog",
"printParseTree": true,
Expand Down
30 changes: 30 additions & 0 deletions docs/formatting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# General

Don't try to be as short as possible (and don't try to be as verbose as possible). Seek balance instead. Readability is king. Code that is understandable at a glance is good code. There are multiple ways to write the same thing, sometimes shorter, sometimes longer. You should choose the most appropriate form for each specific usecase.

# Nodes

write nodes in one line if

- < 80 chars
- no aliases

good

```neva
flow Main(start) (stop) {
Foo, Bar, Baz, Bax
---
:start -> foo -> bar -> baz -> bax -> :stop
}
```

bad

```neva
flow Main(start) (stop) {
f Foo, Bar, Baz, Bax
---
:start -> foo -> bar -> baz -> bax -> :stop
}
```
23 changes: 11 additions & 12 deletions e2e/99_bottles_verbose/main/main.neva
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// https://www.99-bottles-of-beer.net

flow Main(start) (stop) {
nodes { Switch<int>, next PrintNext2Lines }

Switch<int>
next PrintNext2Lines
---
:start -> (99 -> next:n)

next:n -> switch:data
Expand All @@ -13,12 +14,10 @@ flow Main(start) (stop) {
}

flow PrintNext2Lines(n int) (n int) {
nodes {
decr Decr<int>
first PrintFirstLine
second PrintSecondLine
}

decr Decr<int>
first PrintFirstLine
second PrintSecondLine
---
:n -> first:n
first:n -> decr:data
decr:res -> second:n
Expand All @@ -32,8 +31,8 @@ const firstLine2 string = '1 bottle of beer on the wall, 1 bottle of beer.'
const firstLine3 string = 'No more bottles of beer on the wall, no more bottles of beer.'

flow PrintFirstLine(n int) (n int) {
nodes { Switch<int>, Println, Printf, Lock<int> }

Switch<int>, Println, Printf, Lock<int>
---
:n -> [switch:data, lock:data]
0 -> switch:case[0]
1 -> switch:case[1]
Expand All @@ -56,8 +55,8 @@ const secondLine3 string = 'Take one down and pass it around, no more bottles of
const secondLine4 string = 'Go to the store and buy some more, 99 bottles of beer on the wall.'

flow PrintSecondLine(n int) (n int) {
nodes { Switch<int>, Lock<int>, Printf, Println }

Switch<int>, Lock<int>, Printf, Println
---
:n -> [switch:data, lock:data]
-1 -> switch:case[0]
0 -> switch:case[1]
Expand Down
22 changes: 11 additions & 11 deletions e2e/99_bottles_with_chain/main/main.neva
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// https://www.99-bottles-of-beer.net

flow Main(start) (stop) {
nodes { Switch<int>, next PrintNext2Lines }

Switch<int>
next PrintNext2Lines
---
:start -> (99 -> next:n -> switch:data)
-1 -> switch:case[0] -> :stop
switch:else -> next:n
}

flow PrintNext2Lines(n int) (n int) {
nodes {
decr Decr<int>
first PrintFirstLine
second PrintSecondLine
}
decr Decr<int>
first PrintFirstLine
second PrintSecondLine
---
:n -> first:n -> decr:data
decr:res -> second:n -> :n
}
Expand All @@ -25,8 +25,8 @@ const firstLine2 string = '1 bottle of beer on the wall, 1 bottle of beer.'
const firstLine3 string = 'No more bottles of beer on the wall, no more bottles of beer.'

flow PrintFirstLine(n int) (n int) {
nodes { Switch<int>, Println, Printf, Lock<int> }

Switch<int>, Println, Printf, Lock<int>
---
:n -> [switch:data, lock:data]

0 -> switch:case[0] -> ($firstLine3 -> println:data)
Expand All @@ -48,8 +48,8 @@ const secondLine3 string = 'Take one down and pass it around, no more bottles of
const secondLine4 string = 'Go to the store and buy some more, 99 bottles of beer on the wall.'

flow PrintSecondLine(n int) (n int) {
nodes { Switch<int>, Lock<int>, Printf, Println }

Switch<int>, Lock<int>, Printf, Println
---
:n -> [switch:data, lock:data]

-1 -> switch:case[0] -> ($secondLine4 -> println:data)
Expand Down
16 changes: 7 additions & 9 deletions e2e/add_nums_from_stdin_naive/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import {
}

flow Main(start any) (stop any) {
nodes {
scanner1 io.Scanln
scanner2 io.Scanln
parser1 strconv.ParseNum<int>
parser2 strconv.ParseNum<int>
adder ReducePort<int> { Add<int> }
println Println<int>
}

scanner1 io.Scanln
scanner2 io.Scanln
parser1 strconv.ParseNum<int>
parser2 strconv.ParseNum<int>
adder ReducePort<int> { Add<int> }
println Println<int>
---
:start -> scanner1:sig
scanner1:data-> parser1:data
parser1:res -> [adder:port[0], scanner2:sig]
Expand Down
18 changes: 8 additions & 10 deletions e2e/add_nums_from_stdin_with_default_any/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@ import {
}

flow Main(start) (stop) {
nodes { Aux, Println }

Aux, Println
---
:start -> aux:sig
[aux:res, aux:err] -> println:data
println:sig -> :stop
}

flow Aux(sig) (res int, err error) {
nodes {
reader1 IntReader
reader2 IntReader
adder ReducePort<int> { Add<int> }
}

reader1 IntReader
reader2 IntReader
adder ReducePort<int> { Add<int> }
---
:sig -> reader1:sig
reader1:num -> [adder:port[0], reader2:sig]
[reader1:err, reader2:err] -> :err
Expand All @@ -26,8 +24,8 @@ flow Aux(sig) (res int, err error) {
}

flow IntReader(sig any) (num int, err error) {
nodes { io.Scanln, strconv.ParseNum<int> }

io.Scanln, strconv.ParseNum<int>
---
:sig -> scanln:sig
scanln:data -> parseNum:data
parseNum:res -> :num
Expand Down
16 changes: 7 additions & 9 deletions e2e/add_nums_from_stdin_with_err_handling/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import {
}

flow Main(start any) (stop any) {
nodes {
scanner1 io.Scanln
scanner2 io.Scanln
parser1 strconv.ParseNum<int>
parser2 strconv.ParseNum<int>
adder ReducePort<int> { Add<int> }
println Println<any>
}

scanner1 io.Scanln
scanner2 io.Scanln
parser1 strconv.ParseNum<int>
parser2 strconv.ParseNum<int>
adder ReducePort<int> { Add<int> }
println Println<any>
---
:start -> scanner1:sig
scanner1:data -> parser1:data
parser1:err -> println:data
Expand Down
18 changes: 8 additions & 10 deletions e2e/add_nums_from_stdin_with_multuple_senders/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@ import {
}

flow Main(start) (stop) {
nodes { Aux, Println<any> }

Aux, Println<any>
---
:start -> aux:sig
[aux:res, aux:err] -> println:data
println:sig -> :stop
}

flow Aux(sig) (res int, err error) {
nodes {
reader1 IntReader
reader2 IntReader
adder ReducePort<int> { Add<int> }
}

reader1 IntReader
reader2 IntReader
adder ReducePort<int> { Add<int> }
---
:sig -> reader1:sig
reader1:num -> [adder:port[0], reader2:sig]
[reader1:err, reader2:err] -> :err
Expand All @@ -26,8 +24,8 @@ flow Aux(sig) (res int, err error) {
}

flow IntReader(sig any) (num int, err error) {
nodes { io.Scanln, strconv.ParseNum<int> }

io.Scanln, strconv.ParseNum<int>
---
:sig -> scanln:sig
scanln:data -> parseNum:data
parseNum:res -> :num
Expand Down
18 changes: 8 additions & 10 deletions e2e/add_nums_from_stdin_with_sub_components/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@ import {
}

flow Main(start any) (stop any) {
nodes { Aux, Println<any> }

Aux, Println<any>
---
:start -> aux:sig
aux:res -> println:data
aux:err -> println:data
println:sig -> :stop
}

flow Aux(sig any) (res int, err error) {
nodes {
reader1 IntReader
reader2 IntReader
adder ReducePort<int> { Add<int> }
}

reader1 IntReader
reader2 IntReader
adder ReducePort<int> { Add<int> }
---
:sig -> reader1:sig
reader1:num -> [adder:port[0], reader2:sig]
reader1:err -> :err
Expand All @@ -28,8 +26,8 @@ flow Aux(sig any) (res int, err error) {
}

flow IntReader(sig any) (num int, err error) {
nodes { io.Scanln, strconv.ParseNum<int> }

io.Scanln, strconv.ParseNum<int>
---
:sig -> scanln:sig
scanln:data -> parseNum:data
parseNum:res -> :num
Expand Down
10 changes: 5 additions & 5 deletions e2e/add_nums_verbose/main/main.neva
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
flow Main(start any) (stop any) {
nodes {
adder Add<int>
sequencer StreamPort<int>
println Println<int>
}
adder Add<int>
sequencer StreamPort<int>
println Println<int>

---

:start -> [
(1 -> sequencer:port[0]),
Expand Down
8 changes: 4 additions & 4 deletions e2e/add_nums_with_bridge/main/main.neva
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
flow Main(start any) (stop any) {
nodes {
adder ReducePort<int> { Add<int> }
println Println<int>
}
adder ReducePort<int> { Add<int> }
println Println<int>

---

:start -> [
(1 -> adder:port[0]),
Expand Down
3 changes: 2 additions & 1 deletion e2e/bare_iter_over_list/main/main.neva
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const lst list<int> = [50, 30, 20, 100]

flow Main(start) (stop) {
nodes { Println<stream<int>>, Iter<int>, If }
Println<stream<int>>, Iter<int>, If
---
:start -> ($lst -> iter -> println.last -> if)
if:then -> :stop
}
9 changes: 4 additions & 5 deletions e2e/comments/main/main.neva
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// top-level comment 1
flow Main(start) (stop) {
// comment inside flow 1
nodes {
// comment inside nodes 1
Println<any>
// comment inside nodes 2
}
// comment inside nodes 1
Println<any>
// comment inside nodes 2
---
// comment inside flow 2
:start -> println:data
println:sig -> :stop
Expand Down
3 changes: 2 additions & 1 deletion e2e/compare_ints/main/main.neva
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
flow Main(start) (stop) {
nodes { Println, Gt<int>,If}
Println, Gt<int>, If
---
:start -> [
(10 -> gt:compared),
(50 -> gt:actual)
Expand Down
Loading

0 comments on commit f3603f5

Please sign in to comment.