Skip to content

Commit

Permalink
feat(grammar): add keyword extension
Browse files Browse the repository at this point in the history
  • Loading branch information
6cdh committed Aug 2, 2023
1 parent db5c4eb commit 43044ab
Show file tree
Hide file tree
Showing 7 changed files with 2,495 additions and 2,203 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -23,7 +23,7 @@ current status:
* [ ] Extensions
* [x] `{}` as replacement for `()` or `[]`
* [x] extend symbols which can start with digits, period, ... etc as long as it's not a number
* [ ] keyword `#:symbol`
* [x] keyword `#:symbol`
* [ ] escape sequence in string `\` + any character
* [ ] characters `#\bel`, `#\ls`, `#\nel`, `#\rubout`, `#\vt`

Expand Down
24 changes: 24 additions & 0 deletions corpus/ext.scm
@@ -0,0 +1,24 @@
===
list
===

{define x 1}

---
(program
(list
(symbol)
(symbol)
(number)))

===
keyword
===

#:abc
#:1abc

---
(program
(keyword)
(keyword))
25 changes: 18 additions & 7 deletions grammar.js
Expand Up @@ -115,6 +115,14 @@ const r7rs = {
"|")
};

const hidden_node = {
symbol:
token(
choice(
repeat1(common.symbol_element),
r7rs.symbol)),
};

module.exports = grammar({
name: "scheme",

Expand Down Expand Up @@ -170,7 +178,9 @@ module.exports = grammar({
$.syntax,
$.quasisyntax,
$.unsyntax,
$.unsyntax_splicing),
$.unsyntax_splicing,

$.keyword),

// simple datum {{{

Expand Down Expand Up @@ -212,12 +222,13 @@ module.exports = grammar({
r6rs.escape_sequence,
r7rs.escape_sequence)),

symbol: _ =>
PREC.symbol(
token(
choice(
repeat1(common.symbol_element),
r7rs.symbol))),
symbol: _ => PREC.symbol(hidden_node.symbol),

keyword: _ =>
token(
seq(
"#:",
hidden_node.symbol)),

// simple datum }}}

Expand Down
3 changes: 3 additions & 0 deletions nodes.md
Expand Up @@ -12,6 +12,8 @@ This page contains all visible nodes in yaml format.
- escape_sequence # escape sequence in string, for example, \n in "abc\n"
- number
- symbol # identifier
- keyword # #:identifier

- list # things surrounded by () or [] or {}
- quote # '
- quasiquote # `
Expand All @@ -21,6 +23,7 @@ This page contains all visible nodes in yaml format.
- unquote_splicing # ,@
- unsyntax # #,
- unsyntax_splicing # #,@

- vector
- byte_vector
```
Expand Down
68 changes: 68 additions & 0 deletions src/grammar.json
Expand Up @@ -200,6 +200,10 @@
{
"type": "SYMBOL",
"name": "unsyntax_splicing"
},
{
"type": "SYMBOL",
"name": "keyword"
}
]
},
Expand Down Expand Up @@ -12205,6 +12209,70 @@
}
}
},
"keyword": {
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "#:"
},
{
"type": "TOKEN",
"content": {
"type": "CHOICE",
"members": [
{
"type": "REPEAT1",
"content": {
"type": "PATTERN",
"value": "[^ \\r\\n\\t\\f\\v\\p{Zs}\\p{Zl}\\p{Zp}#;\"'`,(){}\\[\\]\\\\|]"
}
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "|"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[^|\\\\]+"
},
{
"type": "PATTERN",
"value": "\\\\[xX][0-9a-fA-F]+;"
},
{
"type": "PATTERN",
"value": "\\\\[abtnr]"
},
{
"type": "STRING",
"value": "\\|"
}
]
}
},
{
"type": "STRING",
"value": "|"
}
]
}
]
}
}
]
}
},
"list": {
"type": "CHOICE",
"members": [
Expand Down
56 changes: 56 additions & 0 deletions src/node-types.json
Expand Up @@ -46,6 +46,10 @@
"type": "directive",
"named": true
},
{
"type": "keyword",
"named": true
},
{
"type": "list",
"named": true
Expand Down Expand Up @@ -133,6 +137,10 @@
"type": "directive",
"named": true
},
{
"type": "keyword",
"named": true
},
{
"type": "list",
"named": true
Expand Down Expand Up @@ -247,6 +255,10 @@
"type": "directive",
"named": true
},
{
"type": "keyword",
"named": true
},
{
"type": "list",
"named": true
Expand Down Expand Up @@ -339,6 +351,10 @@
"type": "directive",
"named": true
},
{
"type": "keyword",
"named": true
},
{
"type": "list",
"named": true
Expand Down Expand Up @@ -426,6 +442,10 @@
"type": "directive",
"named": true
},
{
"type": "keyword",
"named": true
},
{
"type": "list",
"named": true
Expand Down Expand Up @@ -513,6 +533,10 @@
"type": "directive",
"named": true
},
{
"type": "keyword",
"named": true
},
{
"type": "list",
"named": true
Expand Down Expand Up @@ -600,6 +624,10 @@
"type": "directive",
"named": true
},
{
"type": "keyword",
"named": true
},
{
"type": "list",
"named": true
Expand Down Expand Up @@ -707,6 +735,10 @@
"type": "directive",
"named": true
},
{
"type": "keyword",
"named": true
},
{
"type": "list",
"named": true
Expand Down Expand Up @@ -794,6 +826,10 @@
"type": "directive",
"named": true
},
{
"type": "keyword",
"named": true
},
{
"type": "list",
"named": true
Expand Down Expand Up @@ -881,6 +917,10 @@
"type": "directive",
"named": true
},
{
"type": "keyword",
"named": true
},
{
"type": "list",
"named": true
Expand Down Expand Up @@ -968,6 +1008,10 @@
"type": "directive",
"named": true
},
{
"type": "keyword",
"named": true
},
{
"type": "list",
"named": true
Expand Down Expand Up @@ -1055,6 +1099,10 @@
"type": "directive",
"named": true
},
{
"type": "keyword",
"named": true
},
{
"type": "list",
"named": true
Expand Down Expand Up @@ -1142,6 +1190,10 @@
"type": "directive",
"named": true
},
{
"type": "keyword",
"named": true
},
{
"type": "list",
"named": true
Expand Down Expand Up @@ -1281,6 +1333,10 @@
"type": "escape_sequence",
"named": true
},
{
"type": "keyword",
"named": true
},
{
"type": "{",
"named": false
Expand Down

0 comments on commit 43044ab

Please sign in to comment.