Skip to content

Commit

Permalink
fix: no "assertion failed" caused by right parenthesis in link defini…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
ikatyang committed Jan 17, 2021
1 parent 1c0dbdc commit 19d63b0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
17 changes: 17 additions & 0 deletions corpus/issues.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,20 @@ ss_*.
(document
(paragraph
(text)))

================================================================================
#14 - Assertion failed caused by right parenthesis in link definition
================================================================================
[x]: x
)

--------------------------------------------------------------------------------

(document
(link_reference_definition
(link_label
(text))
(link_destination
(text)))
(paragraph
(text)))
3 changes: 3 additions & 0 deletions src/tree_sitter_markdown/inline_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ bool InlineContext::is_vld_pst() const { return pst_ != PST_INVALID; }
bool InlineContext::has_asr() const { return has_asr_; }
bool InlineContext::has_usc() const { return has_usc_; }
bool InlineContext::has_del() const { return has_del_; }
bool InlineContext::has_cln() const { return has_cln_; }
LexedLength InlineContext::btk_len() const { return btk_len_; }

InlineContext::InlineContext(const InlineDelimiterList::Iterator dlm_itr) {
dlm_itr_ = dlm_itr;
has_asr_ = dlm_itr->sym() == SYM_ASR_BGN;
has_usc_ = dlm_itr->sym() == SYM_USC_BGN;
has_del_ = dlm_itr->sym() == SYM_DEL_BGN;
has_cln_ = dlm_itr->sym() == SYM_LNK_REF_DEF_CLN;
btk_len_ = dlm_itr->sym() == SYM_COD_SPN_BGN ? dlm_itr->len() : 0;
upd_pst();
}
Expand All @@ -23,6 +25,7 @@ InlineContext::InlineContext(const InlineDelimiterList::Iterator dlm_itr, const
has_asr_ = prt_ctx.has_asr_ || dlm_itr->sym() == SYM_ASR_BGN;
has_usc_ = prt_ctx.has_usc_ || dlm_itr->sym() == SYM_USC_BGN;
has_del_ = prt_ctx.has_del_ || dlm_itr->sym() == SYM_DEL_BGN;
has_cln_ = prt_ctx.has_cln_ || dlm_itr->sym() == SYM_LNK_REF_DEF_CLN;
btk_len_ = prt_ctx.btk_len_ || (dlm_itr->sym() == SYM_COD_SPN_BGN ? dlm_itr->len() : 0);
upd_pst();
}
Expand Down
2 changes: 2 additions & 0 deletions src/tree_sitter_markdown/inline_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct InlineContext {
bool has_asr_;
bool has_usc_;
bool has_del_;
bool has_cln_;
LexedLength btk_len_;
public:
InlineDelimiterList::Iterator dlm_itr() const;
Expand All @@ -22,6 +23,7 @@ struct InlineContext {
bool has_asr() const;
bool has_usc() const;
bool has_del() const;
bool has_cln() const;
LexedLength btk_len() const;

InlineContext(const InlineDelimiterList::Iterator delimiter_iterator);
Expand Down
2 changes: 1 addition & 1 deletion src/tree_sitter_markdown/inline_scan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ bool scn_inl_rng(Lexer &lxr, InlineDelimiterList &inl_dlms, InlineContextStack &

bool scn_inl_rpr(Lexer &lxr, InlineDelimiterList &inl_dlms, InlineContextStack &inl_ctx_stk, BlockDelimiterList &blk_dlms, BlockContextStack &blk_ctx_stk, const InlineDelimiterList::Iterator &nxt_inl_dlm_itr) {
if (lxr.lka_chr() != ')') return false;
if (VLD(SYM_LNK_INL_END)) {
if (VLD(SYM_LNK_INL_END) && !inl_ctx_stk.back().has_cln()) {
if (
inl_ctx_stk.back().dlm_itr()->sym() == SYM_LNK_DST_END_MKR
|| inl_ctx_stk.back().dlm_itr()->sym() == SYM_LNK_TIT_END_MKR
Expand Down

0 comments on commit 19d63b0

Please sign in to comment.