Skip to content

Commit

Permalink
Merge pull request #521 from nevalang/nodes_comments_fix
Browse files Browse the repository at this point in the history
fix(parser): add support for comments inside components
  • Loading branch information
emil14 authored Mar 13, 2024
2 parents 162d058 + e583251 commit 3d0bca6
Show file tree
Hide file tree
Showing 8 changed files with 830 additions and 563 deletions.
21 changes: 21 additions & 0 deletions e2e/run_tests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func TestListWithNegInt(t *testing.T) {
}
}

// Check that compiler throws human-readable error when type arguments in Node are incompatible.
func TestIncompatCompTypeArg(t *testing.T) {
err := os.Chdir("./tests/incompat_comp_type_arg")
require.NoError(t, err)
Expand All @@ -134,5 +135,25 @@ func TestIncompatCompTypeArg(t *testing.T) {
string(out),
)

require.Equal(t, 0, cmd.ProcessState.ExitCode())
}

// Check program with comments is parsed without errors.
func TestComments(t *testing.T) {
err := os.Chdir("./tests/comments")
require.NoError(t, err)

defer os.Chdir(wd)

cmd := exec.Command("neva", "run", "main")

out, err := cmd.CombinedOutput()
require.NoError(t, err)
require.Equal(
t,
"<empty>\n",
string(out),
)

require.Equal(t, 0, cmd.ProcessState.ExitCode())
}
19 changes: 19 additions & 0 deletions e2e/tests/comments/main/main.neva
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// top-level comment 1
component Main(start) (stop) {
// comment inside component 1
nodes {
// comment inside nodes 1
Printer<any>
// comment inside nodes 2
}
// comment inside component 2
net {
// comment inside network 1
:start -> printer:data
// comment inside network 2
printer:sig -> :stop
// comment inside network
}
// comment inside component 3
}
// top-level comment 2
1 change: 1 addition & 0 deletions e2e/tests/comments/neva.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
neva: 0.10.0
2 changes: 1 addition & 1 deletion internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewApp( //nolint:funlen
},
{
Name: "new",
Usage: "Create new nevalang project",
Usage: "Create new Nevalang project",
Args: true,
Action: func(cCtx *cli.Context) error {
if path := cCtx.Args().First(); path != "" {
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/parser/generated/neva.interp

Large diffs are not rendered by default.

1,339 changes: 781 additions & 558 deletions internal/compiler/parser/generated/neva_parser.go

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions internal/compiler/parser/neva.g4
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,14 @@ groupCompStmt:
)* '}';
compDef: interfaceDef compBody? NEWLINE*;
compBody:
'{' NEWLINE* (compNodesDef NEWLINE*)? (compNetDef NEWLINE*)? '}';
'{' NEWLINE* (COMMENT NEWLINE*)* (compNodesDef NEWLINE*)? (
COMMENT NEWLINE*
)* (compNetDef NEWLINE*)? (COMMENT NEWLINE*)* '}';

// nodes
compNodesDef: 'nodes' NEWLINE* compNodesDefBody;
compNodesDefBody: '{' NEWLINE* (compNodeDef NEWLINE*)* '}';
compNodesDefBody:
'{' NEWLINE* ((compNodeDef | COMMENT) NEWLINE*)* '}';
compNodeDef: compilerDirectives? IDENTIFIER? nodeInst;
nodeInst: entityRef NEWLINE* typeArgs? NEWLINE* nodeDIArgs?;
nodeDIArgs: compNodesDefBody;
Expand Down
2 changes: 1 addition & 1 deletion pkg/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pkg

// Version is the current version of the language and stdlib
var Version = "0.10.5" //nolint:gochecknoglobals
var Version = "0.11.1" //nolint:gochecknoglobals

0 comments on commit 3d0bca6

Please sign in to comment.