diff --git a/corpus/issues.txt b/corpus/issues.txt index e27ab5a..d5a2576 100644 --- a/corpus/issues.txt +++ b/corpus/issues.txt @@ -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))) diff --git a/src/tree_sitter_markdown/inline_context.cc b/src/tree_sitter_markdown/inline_context.cc index 94bcb27..1628e64 100644 --- a/src/tree_sitter_markdown/inline_context.cc +++ b/src/tree_sitter_markdown/inline_context.cc @@ -8,6 +8,7 @@ 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) { @@ -15,6 +16,7 @@ InlineContext::InlineContext(const InlineDelimiterList::Iterator 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(); } @@ -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(); } diff --git a/src/tree_sitter_markdown/inline_context.h b/src/tree_sitter_markdown/inline_context.h index 3dd3912..643a3ca 100644 --- a/src/tree_sitter_markdown/inline_context.h +++ b/src/tree_sitter_markdown/inline_context.h @@ -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; @@ -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); diff --git a/src/tree_sitter_markdown/inline_scan.cc b/src/tree_sitter_markdown/inline_scan.cc index 0eac075..e0442eb 100644 --- a/src/tree_sitter_markdown/inline_scan.cc +++ b/src/tree_sitter_markdown/inline_scan.cc @@ -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