Skip to content

Commit

Permalink
feat(pointfree-lang): update grammar (add line comments)
Browse files Browse the repository at this point in the history
- update readme
  • Loading branch information
postspectacular committed Apr 24, 2020
1 parent cca8574 commit a8cdbe8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
8 changes: 6 additions & 2 deletions packages/pointfree-lang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ an ES6 embedded DSL for concatenative programming:
yarn add @thi.ng/pointfree-lang
```

Package sizes (gzipped, pre-treeshake): ESM: 5.06 KB / CJS: 5.05 KB / UMD: 4.97 KB
Package sizes (gzipped, pre-treeshake): ESM: 5.13 KB / CJS: 5.13 KB / UMD: 5.04 KB

## Dependencies

Expand Down Expand Up @@ -317,7 +317,9 @@ comment](https://github.com/thi-ng/umbrella/tree/develop/packages/pointfree#abou
in preparation for future tooling additions.

Comments current cannot contain `(` or `)`, but can span multiple lines.
There's no special syntax for single line comments:

Since v1.4.0 line comments are supported, use the standard JS `//`
prefix and extend until the next newline char.

```
( multiline:
Expand All @@ -331,6 +333,8 @@ ______ ____ |__| _____/ |__/ ____\______ ____ ____
)
1 2 ( embedded single line ) 3
// single line comment
```

### Identifiers
Expand Down
11 changes: 10 additions & 1 deletion packages/pointfree-lang/src/grammar.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ NonWordExpr
= _ expr:(
LitQuote
/ Var
/ LineComment
/ Comment
/ Array
/ Obj
Expand Down Expand Up @@ -104,7 +105,7 @@ Sym
}

SymChars
= [*?$%&/\|~<>=_.+\-]
= [*?$%&#/\|~<>=_.+\-]

Var
= VarDeref
Expand Down Expand Up @@ -138,6 +139,14 @@ Comment
};
}

LineComment
= "//" body:$(!"\n" .)* "\n" {
return {
type: NodeType.COMMENT,
body: body.trim()
};
}

String
= "\"" body:$(!"\"" .)* "\"" {
return {type: NodeType.STRING, body };
Expand Down
2 changes: 1 addition & 1 deletion packages/pointfree-lang/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const endvar = (id: string) => (ctx: pf.StackContext) => {
* @param state -
*/
const visit = (node: ASTNode, ctx: pf.StackContext, state: VisitorState) => {
LOGGER.fine("visit", node.type, node, ctx[0].toString());
LOGGER.fine("visit", NodeType[node.type], node, ctx[0].toString());
switch (node.type) {
case NodeType.SYM:
return visitSym(node, ctx, state);
Expand Down
6 changes: 5 additions & 1 deletion packages/pointfree-lang/tpl.readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ comment](https://github.com/thi-ng/umbrella/tree/develop/packages/pointfree#abou
in preparation for future tooling additions.

Comments current cannot contain `(` or `)`, but can span multiple lines.
There's no special syntax for single line comments:

Since v1.4.0 line comments are supported, use the standard JS `//`
prefix and extend until the next newline char.

```
( multiline:
Expand All @@ -293,6 +295,8 @@ ______ ____ |__| _____/ |__/ ____\______ ____ ____
)
1 2 ( embedded single line ) 3
// single line comment
```

### Identifiers
Expand Down

0 comments on commit a8cdbe8

Please sign in to comment.