Skip to content

Commit 8cf6aaf

Browse files
cscheidclaude
andcommitted
Fix pipe table parsing with code spans containing pipes (#29)
Added code span recognition to pipe table cell parsing. The block grammar now properly handles backtick code spans like `|` within table cells by repeating the inline grammar's code span parsing logic in the block context. Changes: - Added CODE_SPAN_START and CODE_SPAN_CLOSE external tokens to block grammar - Implemented parse_code_span() in block scanner with lookahead for matching delimiters - Added _pipe_table_code_span rule to parse code spans within table cells - Updated scanner state serialization to track code span delimiter length 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent dfdcca9 commit 8cf6aaf

File tree

5 files changed

+9826
-8591
lines changed

5 files changed

+9826
-8591
lines changed

crates/tree-sitter-qmd/tree-sitter-markdown/grammar.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,21 +454,34 @@ module.exports = grammar({
454454
),
455455
),
456456

457+
// Code span within pipe table cells - simplified version that only handles backticks
458+
_pipe_table_code_span: $ => seq(
459+
$._code_span_start,
460+
repeat(choice(
461+
$._word,
462+
$._whitespace,
463+
common.punctuation_without($, []),
464+
)),
465+
$._code_span_close,
466+
),
467+
457468
_pipe_table_cell_contents: $ => prec.right(
458469
seq(
459470
choice(
460471
$._word,
461-
$._display_math_state_track_marker,
462-
$._inline_math_state_track_marker,
472+
$._display_math_state_track_marker,
473+
$._inline_math_state_track_marker,
463474
$._backslash_escape,
475+
$._pipe_table_code_span,
464476
common.punctuation_without($, ['|']),
465477
),
466478
repeat(choice(
467479
$._word,
468-
$._display_math_state_track_marker,
469-
$._inline_math_state_track_marker,
480+
$._display_math_state_track_marker,
481+
$._inline_math_state_track_marker,
470482
$._whitespace,
471483
$._backslash_escape,
484+
$._pipe_table_code_span,
472485
common.punctuation_without($, ['|']),
473486
)))),
474487

@@ -569,6 +582,10 @@ module.exports = grammar({
569582
// special tokens to allow external scanner serialization to happen
570583
$._display_math_state_track_marker,
571584
$._inline_math_state_track_marker,
585+
586+
// code span delimiters for parsing pipe table cells
587+
$._code_span_start,
588+
$._code_span_close,
572589
],
573590
precedences: $ => [
574591
[$._setext_heading1, $._block],

crates/tree-sitter-qmd/tree-sitter-markdown/src/grammar.json

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5347,6 +5347,185 @@
53475347
}
53485348
]
53495349
},
5350+
"_pipe_table_code_span": {
5351+
"type": "SEQ",
5352+
"members": [
5353+
{
5354+
"type": "SYMBOL",
5355+
"name": "_code_span_start"
5356+
},
5357+
{
5358+
"type": "REPEAT",
5359+
"content": {
5360+
"type": "CHOICE",
5361+
"members": [
5362+
{
5363+
"type": "SYMBOL",
5364+
"name": "_word"
5365+
},
5366+
{
5367+
"type": "SYMBOL",
5368+
"name": "_whitespace"
5369+
},
5370+
{
5371+
"type": "SEQ",
5372+
"members": [
5373+
{
5374+
"type": "CHOICE",
5375+
"members": [
5376+
{
5377+
"type": "STRING",
5378+
"value": "!"
5379+
},
5380+
{
5381+
"type": "STRING",
5382+
"value": "\""
5383+
},
5384+
{
5385+
"type": "STRING",
5386+
"value": "#"
5387+
},
5388+
{
5389+
"type": "STRING",
5390+
"value": "$"
5391+
},
5392+
{
5393+
"type": "STRING",
5394+
"value": "%"
5395+
},
5396+
{
5397+
"type": "STRING",
5398+
"value": "&"
5399+
},
5400+
{
5401+
"type": "STRING",
5402+
"value": "'"
5403+
},
5404+
{
5405+
"type": "STRING",
5406+
"value": "("
5407+
},
5408+
{
5409+
"type": "STRING",
5410+
"value": ")"
5411+
},
5412+
{
5413+
"type": "STRING",
5414+
"value": "*"
5415+
},
5416+
{
5417+
"type": "STRING",
5418+
"value": "+"
5419+
},
5420+
{
5421+
"type": "STRING",
5422+
"value": ","
5423+
},
5424+
{
5425+
"type": "STRING",
5426+
"value": "-"
5427+
},
5428+
{
5429+
"type": "STRING",
5430+
"value": "."
5431+
},
5432+
{
5433+
"type": "STRING",
5434+
"value": "/"
5435+
},
5436+
{
5437+
"type": "STRING",
5438+
"value": ":"
5439+
},
5440+
{
5441+
"type": "STRING",
5442+
"value": ";"
5443+
},
5444+
{
5445+
"type": "STRING",
5446+
"value": "<"
5447+
},
5448+
{
5449+
"type": "STRING",
5450+
"value": "="
5451+
},
5452+
{
5453+
"type": "STRING",
5454+
"value": ">"
5455+
},
5456+
{
5457+
"type": "STRING",
5458+
"value": "?"
5459+
},
5460+
{
5461+
"type": "STRING",
5462+
"value": "@"
5463+
},
5464+
{
5465+
"type": "STRING",
5466+
"value": "["
5467+
},
5468+
{
5469+
"type": "STRING",
5470+
"value": "\\"
5471+
},
5472+
{
5473+
"type": "STRING",
5474+
"value": "]"
5475+
},
5476+
{
5477+
"type": "STRING",
5478+
"value": "^"
5479+
},
5480+
{
5481+
"type": "STRING",
5482+
"value": "_"
5483+
},
5484+
{
5485+
"type": "STRING",
5486+
"value": "`"
5487+
},
5488+
{
5489+
"type": "STRING",
5490+
"value": "{"
5491+
},
5492+
{
5493+
"type": "STRING",
5494+
"value": "|"
5495+
},
5496+
{
5497+
"type": "STRING",
5498+
"value": "}"
5499+
},
5500+
{
5501+
"type": "STRING",
5502+
"value": "~"
5503+
}
5504+
]
5505+
},
5506+
{
5507+
"type": "CHOICE",
5508+
"members": [
5509+
{
5510+
"type": "SYMBOL",
5511+
"name": "_last_token_punctuation"
5512+
},
5513+
{
5514+
"type": "BLANK"
5515+
}
5516+
]
5517+
}
5518+
]
5519+
}
5520+
]
5521+
}
5522+
},
5523+
{
5524+
"type": "SYMBOL",
5525+
"name": "_code_span_close"
5526+
}
5527+
]
5528+
},
53505529
"_pipe_table_cell_contents": {
53515530
"type": "PREC_RIGHT",
53525531
"value": 0,
@@ -5372,6 +5551,10 @@
53725551
"type": "SYMBOL",
53735552
"name": "_backslash_escape"
53745553
},
5554+
{
5555+
"type": "SYMBOL",
5556+
"name": "_pipe_table_code_span"
5557+
},
53755558
{
53765559
"type": "SEQ",
53775560
"members": [
@@ -5545,6 +5728,10 @@
55455728
"type": "SYMBOL",
55465729
"name": "_backslash_escape"
55475730
},
5731+
{
5732+
"type": "SYMBOL",
5733+
"name": "_pipe_table_code_span"
5734+
},
55485735
{
55495736
"type": "SEQ",
55505737
"members": [
@@ -5921,6 +6108,14 @@
59216108
{
59226109
"type": "SYMBOL",
59236110
"name": "_inline_math_state_track_marker"
6111+
},
6112+
{
6113+
"type": "SYMBOL",
6114+
"name": "_code_span_start"
6115+
},
6116+
{
6117+
"type": "SYMBOL",
6118+
"name": "_code_span_close"
59246119
}
59256120
],
59266121
"inline": [],

0 commit comments

Comments
 (0)