Skip to content

Commit

Permalink
You can now write comments with a //
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncabot committed Mar 19, 2024
1 parent 6352197 commit 7a9c566
Show file tree
Hide file tree
Showing 9 changed files with 765 additions and 715 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ All variables are `float64` values.
get("some-value") # => 123
```

## Comments

You can add single-line coments by prefixing a line with `//`.

```jabl
// This is a comment
```

# Interpreter

The JABL interpreter is a simple program that reads a story and executes it. It is written in Go and can be run from the command line or compiled to WASM and invoked from Javascript.
Expand Down
1 change: 1 addition & 0 deletions internal/jabl/jabl.y
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ stmt:
| IF '(' boolExpr ')' block { $$ = &ifStmt{cond: $3, block: $5} }
| IF '(' boolExpr ')' block ELSE block { $$ = &ifStmt{cond: $3, block: $5, other: $7} }
| SET '(' strExpr ',' numExpr ')' { $$ = &fnStmt{fn: SET, expr: $3, expr2: $5} }
| '/' '/' STRING { $$ = &commentStmt{comment: $3} }
;

strExpr:
Expand Down
4 changes: 4 additions & 0 deletions internal/jabl/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ type seqStmt struct {
rest stmt
}

type commentStmt struct {
comment string
}

type fnStmt struct {
fn int
expr expr
Expand Down
190 changes: 97 additions & 93 deletions internal/jabl/parser.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions internal/jabl/testdata/examples/comments/code.jabl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
// print something good
print("Hello World")
}
5 changes: 5 additions & 0 deletions internal/jabl/testdata/examples/comments/result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"output": "Hello World\n",
"choices": null,
"transition": ""
}
1 change: 1 addition & 0 deletions internal/jabl/testdata/examples/comments/state_after.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions internal/jabl/testdata/examples/comments/state_before.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Loading

0 comments on commit 7a9c566

Please sign in to comment.