Skip to content

Commit

Permalink
add nested syntax support
Browse files Browse the repository at this point in the history
  • Loading branch information
ravsii committed Sep 17, 2023
1 parent c8c9afc commit 904701e
Show file tree
Hide file tree
Showing 7 changed files with 1,624 additions and 572 deletions.
33 changes: 8 additions & 25 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,18 @@ module.exports = grammar({
$.connection_identifier,
$.sub_identifier
)),
optional($.label),
optional(choice(/\n+/, ";")),
optional($.label_block),
optional(choice(/\n+\s*/, ";")),
)),

label_block: $ => choice(
seq(":", $.label),
seq(":", $.container),
),

container: $ => seq("{", repeat($.expression), "}"),

label: _ => seq(":", choice(
// seq("|", /.+/, "|"),
/.+/,
)),

// shape_body: $ => prec.right(seq(
// "{",
// /\s*/,
// repeat(seq(/\s*/, $.shape_param)),
// /\s*/,
// "}"
// )),

// shape_param: $ => seq(
// $.identifier,
// /\s*/,
// ":",
// optional(/\s+/),
// $.param_value,
// optional($.param_body),
// ),

// param_body: $ => seq("{", /.+/, "}"),
label: _ => /.+/,

// building blocks

Expand Down
55 changes: 46 additions & 9 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"members": [
{
"type": "SYMBOL",
"name": "label"
"name": "label_block"
},
{
"type": "BLANK"
Expand All @@ -151,7 +151,7 @@
"members": [
{
"type": "PATTERN",
"value": "\\n+"
"value": "\\n+\\s*"
},
{
"type": "STRING",
Expand All @@ -167,24 +167,61 @@
]
}
},
"label": {
"type": "SEQ",
"label_block": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ":"
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ":"
},
{
"type": "SYMBOL",
"name": "label"
}
]
},
{
"type": "CHOICE",
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": ".+"
"type": "STRING",
"value": ":"
},
{
"type": "SYMBOL",
"name": "container"
}
]
}
]
},
"container": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "expression"
}
},
{
"type": "STRING",
"value": "}"
}
]
},
"label": {
"type": "PATTERN",
"value": ".+"
},
"identifier": {
"type": "PREC_RIGHT",
"value": 0,
Expand Down
47 changes: 44 additions & 3 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
"named": true,
"fields": {}
},
{
"type": "container",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "expression",
"named": true
}
]
}
},
{
"type": "expression",
"named": true,
Expand All @@ -25,7 +40,7 @@
"named": true
},
{
"type": "label",
"type": "label_block",
"named": true
},
{
Expand All @@ -51,9 +66,23 @@
}
},
{
"type": "label",
"type": "label_block",
"named": true,
"fields": {}
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "container",
"named": true
},
{
"type": "label",
"named": true
}
]
}
},
{
"type": "source_file",
Expand Down Expand Up @@ -121,6 +150,10 @@
"type": "down",
"named": false
},
{
"type": "label",
"named": true
},
{
"type": "left",
"named": false
Expand All @@ -132,5 +165,13 @@
{
"type": "up",
"named": false
},
{
"type": "{",
"named": false
},
{
"type": "}",
"named": false
}
]
Loading

0 comments on commit 904701e

Please sign in to comment.