Skip to content

Commit

Permalink
Merge pull request #20 from 1Kinoti/main
Browse files Browse the repository at this point in the history
add support for table annotations
  • Loading branch information
fdncred committed Jul 7, 2023
2 parents f46cfce + feaaebf commit 66be448
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 236 deletions.
9 changes: 4 additions & 5 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ module.exports = grammar({
$._declaration,
// NOTE:
// in a script, this is not a legal top level item, this is
// only here to cover `config.nu` and `env.nu` which are what
// this parser will mostly be used for i think
// only here to cover `config.nu` and `env.nu`
prec(-1, $._statement),
))
),
Expand Down Expand Up @@ -155,7 +154,7 @@ module.exports = grammar({
PUNC().colon,
field("type", choice(
$.list_type,
$.record_type,
$.collection_type,
$.flat_type,
)),
field("completion", optional($.param_cmd)),
Expand All @@ -168,14 +167,14 @@ module.exports = grammar({

flat_type: $ => field("flat_type", FLAT_TYPES()),

record_type: $ => {
collection_type: $ => {
const key = field("key", choice(
$.identifier,
alias($.val_string, $.identifier),
));

return seq(
"record",
choice("record", "table"),
seq(
token.immediate(BRACK().open_angle),
repeat(seq(
Expand Down
4 changes: 2 additions & 2 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@
"list" @type.enum
["<" ">"] @punctuation.bracket
)
(record_type
"record" @type.enum
(collection_type
["record" "table"] @type.enum
"<" @punctuation.bracket
key: (_) @variable.parameter
["," ":"] @punctuation.delimiter
Expand Down
19 changes: 14 additions & 5 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
{
"type": "PATTERN",
"value": ".*"
"value": ".*\\n"
}
]
},
Expand Down Expand Up @@ -677,7 +677,7 @@
},
{
"type": "SYMBOL",
"name": "record_type"
"name": "collection_type"
},
{
"type": "SYMBOL",
Expand Down Expand Up @@ -874,12 +874,21 @@
]
}
},
"record_type": {
"collection_type": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "record"
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "record"
},
{
"type": "STRING",
"value": "table"
}
]
},
{
"type": "SEQ",
Expand Down
58 changes: 29 additions & 29 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,32 @@
}
}
},
{
"type": "collection_type",
"named": true,
"fields": {
"key": {
"multiple": true,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "flat_type",
"named": true
}
]
}
},
{
"type": "command",
"named": true,
Expand Down Expand Up @@ -2959,15 +2985,15 @@
"required": true,
"types": [
{
"type": "flat_type",
"type": "collection_type",
"named": true
},
{
"type": "list_type",
"type": "flat_type",
"named": true
},
{
"type": "record_type",
"type": "list_type",
"named": true
}
]
Expand Down Expand Up @@ -3470,32 +3496,6 @@
}
}
},
{
"type": "record_type",
"named": true,
"fields": {
"key": {
"multiple": true,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "flat_type",
"named": true
}
]
}
},
{
"type": "redirection",
"named": true,
Expand Down
Loading

0 comments on commit 66be448

Please sign in to comment.