Skip to content

Commit

Permalink
Allow files without trailing newline
Browse files Browse the repository at this point in the history
  • Loading branch information
MDeiml committed Aug 5, 2022
1 parent c265d30 commit 4365f3a
Show file tree
Hide file tree
Showing 4 changed files with 30,288 additions and 29,970 deletions.
15 changes: 8 additions & 7 deletions tree-sitter-markdown/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ module.exports = grammar({
// parsed using normal tree-sitter rules.
//
// https://github.github.com/gfm/#thematic-breaks
thematic_break: $ => seq($._thematic_break, $._newline),
thematic_break: $ => seq($._thematic_break, choice($._newline, $._eof)),

// An ATX heading. This is currently handled by the external scanner but maybe could be
// parsed using normal tree-sitter rules.
Expand Down Expand Up @@ -144,12 +144,12 @@ module.exports = grammar({
_setext_heading1: $ => seq(
field('heading_content', $.paragraph),
$.setext_h1_underline,
$._newline
choice($._newline, $._eof),
),
_setext_heading2: $ => seq(
field('heading_content', $.paragraph),
$.setext_h2_underline,
$._newline
choice($._newline, $._eof),
),

// An indented code block. An indented code block is made up of indented chunks and blank
Expand Down Expand Up @@ -258,7 +258,7 @@ module.exports = grammar({
optional($._no_indented_chunk),
$.link_title
))),
choice($._newline, $._soft_line_break),
choice($._newline, $._soft_line_break, $._eof),
)),
_text_inline_no_link: $ => choice($._word, $._whitespace, common.punctuation_without($, ['[', ']'])),

Expand All @@ -280,12 +280,12 @@ module.exports = grammar({
// related to paragraphs ending does not grow.
//
// https://github.github.com/gfm/#paragraphs
paragraph: $ => seq(alias(repeat1(choice($._line, $._soft_line_break)), $.inline), $._newline),
paragraph: $ => seq(alias(repeat1(choice($._line, $._soft_line_break)), $.inline), choice($._newline, $._eof)),

// A blank line including the following newline.
//
// https://github.github.com/gfm/#blank-lines
_blank_line: $ => seq($._blank_line_start, $._newline),
_blank_line: $ => seq($._blank_line_start, choice($._newline, $._eof)),


// CONTAINER BLOCKS
Expand Down Expand Up @@ -414,7 +414,7 @@ module.exports = grammar({
$._newline,
$.pipe_table_delimiter_row,
repeat(seq($._pipe_table_newline, optional($.pipe_table_row))),
$._newline,
choice($._newline, $._eof),
)),

_pipe_table_newline: $ => seq(
Expand Down Expand Up @@ -570,6 +570,7 @@ module.exports = grammar({
// when trying to parse the `$._trigger_error` token in `$.link_title`.
$._error,
$._trigger_error,
$._eof,

$.minus_metadata,
$.plus_metadata,
Expand Down
86 changes: 74 additions & 12 deletions tree-sitter-markdown/src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1892,8 +1892,17 @@
"name": "_thematic_break"
},
{
"type": "SYMBOL",
"name": "_newline"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_newline"
},
{
"type": "SYMBOL",
"name": "_eof"
}
]
}
]
},
Expand Down Expand Up @@ -2141,8 +2150,17 @@
"name": "setext_h1_underline"
},
{
"type": "SYMBOL",
"name": "_newline"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_newline"
},
{
"type": "SYMBOL",
"name": "_eof"
}
]
}
]
},
Expand All @@ -2162,8 +2180,17 @@
"name": "setext_h2_underline"
},
{
"type": "SYMBOL",
"name": "_newline"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_newline"
},
{
"type": "SYMBOL",
"name": "_eof"
}
]
}
]
},
Expand Down Expand Up @@ -3387,6 +3414,10 @@
{
"type": "SYMBOL",
"name": "_soft_line_break"
},
{
"type": "SYMBOL",
"name": "_eof"
}
]
}
Expand Down Expand Up @@ -3573,8 +3604,17 @@
"value": "inline"
},
{
"type": "SYMBOL",
"name": "_newline"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_newline"
},
{
"type": "SYMBOL",
"name": "_eof"
}
]
}
]
},
Expand All @@ -3586,8 +3626,17 @@
"name": "_blank_line_start"
},
{
"type": "SYMBOL",
"name": "_newline"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_newline"
},
{
"type": "SYMBOL",
"name": "_eof"
}
]
}
]
},
Expand Down Expand Up @@ -4407,8 +4456,17 @@
}
},
{
"type": "SYMBOL",
"name": "_newline"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_newline"
},
{
"type": "SYMBOL",
"name": "_eof"
}
]
}
]
}
Expand Down Expand Up @@ -5319,6 +5377,10 @@
"type": "SYMBOL",
"name": "_trigger_error"
},
{
"type": "SYMBOL",
"name": "_eof"
},
{
"type": "SYMBOL",
"name": "minus_metadata"
Expand Down
Loading

0 comments on commit 4365f3a

Please sign in to comment.