Skip to content

Commit

Permalink
feat: add support for anchor declarations and definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
vhyrro committed Nov 9, 2021
1 parent 51fdb9e commit 1a74d6c
Show file tree
Hide file tree
Showing 5 changed files with 194,344 additions and 189,345 deletions.
28 changes: 17 additions & 11 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ module.exports = grammar({
$.anchor_declaration_begin,
$.anchor_declaration_text,
$.anchor_declaration_end,
$.anchor_definition_begin,
$.anchor_definition_location,
$.anchor_definition_text,
$.anchor_definition_end,

$.ranged_tag_prefix,
$.ranged_tag_end_prefix,
Expand Down Expand Up @@ -198,7 +194,7 @@ module.exports = grammar({
alias($.space, "_space"),
$.link,
$.anchor_declaration,
// $.anchor_definition,
$.anchor_definition,
$.escape_sequence,
$._attached_modifier,
),
Expand Down Expand Up @@ -491,16 +487,26 @@ module.exports = grammar({

anchor_declaration: $ =>
seq(
$.anchor_declaration_begin,
$.anchor_declaration_text,
$.anchor_declaration_end,
alias($.anchor_declaration_begin, "_begin"),
field("text", $.anchor_declaration_text),
alias($.anchor_declaration_end, "_end"),
),

anchor_definition: $ =>
seq(
prec(2, seq(
$.anchor_declaration,
// other stuff here
),
alias($.link_begin, "_begin"),
choice(
$.link_location,
seq(
$.link_file,
optional(
$.link_location,
)
)
),
alias($.link_end, "_end"),
)),

unordered_link1: $ =>
prec.right(1,
Expand Down
112 changes: 83 additions & 29 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@
"type": "SYMBOL",
"name": "anchor_declaration"
},
{
"type": "SYMBOL",
"name": "anchor_definition"
},
{
"type": "SYMBOL",
"name": "escape_sequence"
Expand Down Expand Up @@ -1069,27 +1073,93 @@
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "anchor_declaration_begin"
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "anchor_declaration_begin"
},
"named": false,
"value": "_begin"
},
{
"type": "SYMBOL",
"name": "anchor_declaration_text"
"type": "FIELD",
"name": "text",
"content": {
"type": "SYMBOL",
"name": "anchor_declaration_text"
}
},
{
"type": "SYMBOL",
"name": "anchor_declaration_end"
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "anchor_declaration_end"
},
"named": false,
"value": "_end"
}
]
},
"anchor_definition": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "anchor_declaration"
}
]
"type": "PREC",
"value": 2,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "anchor_declaration"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "link_begin"
},
"named": false,
"value": "_begin"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "link_location"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "link_file"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "link_location"
},
{
"type": "BLANK"
}
]
}
]
}
]
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "link_end"
},
"named": false,
"value": "_end"
}
]
}
},
"unordered_link1": {
"type": "PREC_RIGHT",
Expand Down Expand Up @@ -5868,22 +5938,6 @@
"type": "SYMBOL",
"name": "anchor_declaration_end"
},
{
"type": "SYMBOL",
"name": "anchor_definition_begin"
},
{
"type": "SYMBOL",
"name": "anchor_definition_location"
},
{
"type": "SYMBOL",
"name": "anchor_definition_text"
},
{
"type": "SYMBOL",
"name": "anchor_definition_end"
},
{
"type": "SYMBOL",
"name": "ranged_tag_prefix"
Expand Down
38 changes: 27 additions & 11 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"type": "anchor_declaration",
"named": true
},
{
"type": "anchor_definition",
"named": true
},
{
"type": "bold",
"named": true
Expand Down Expand Up @@ -74,21 +78,37 @@
{
"type": "anchor_declaration",
"named": true,
"fields": {
"text": {
"multiple": false,
"required": true,
"types": [
{
"type": "anchor_declaration_text",
"named": true
}
]
}
}
},
{
"type": "anchor_definition",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "anchor_declaration_begin",
"type": "anchor_declaration",
"named": true
},
{
"type": "anchor_declaration_end",
"type": "link_file",
"named": true
},
{
"type": "anchor_declaration_text",
"type": "link_location",
"named": true
}
]
Expand Down Expand Up @@ -2447,6 +2467,10 @@
"type": "anchor_declaration",
"named": true
},
{
"type": "anchor_definition",
"named": true
},
{
"type": "bold",
"named": true
Expand Down Expand Up @@ -4514,14 +4538,6 @@
"type": "_uppercase",
"named": false
},
{
"type": "anchor_declaration_begin",
"named": true
},
{
"type": "anchor_declaration_end",
"named": true
},
{
"type": "anchor_declaration_text",
"named": true
Expand Down
Loading

0 comments on commit 1a74d6c

Please sign in to comment.