diff --git a/Units/parser-markdown.r/backquote.d/args.ctags b/Units/parser-markdown.r/backquote.d/args.ctags new file mode 100644 index 0000000000..5ee5f79f70 --- /dev/null +++ b/Units/parser-markdown.r/backquote.d/args.ctags @@ -0,0 +1 @@ +--sort=no diff --git a/Units/parser-markdown.r/backquote.d/expected.tags b/Units/parser-markdown.r/backquote.d/expected.tags new file mode 100644 index 0000000000..2f534165e0 --- /dev/null +++ b/Units/parser-markdown.r/backquote.d/expected.tags @@ -0,0 +1 @@ +A input.md /^# A$/;" c diff --git a/Units/parser-markdown.r/backquote.d/input.md b/Units/parser-markdown.r/backquote.d/input.md new file mode 100644 index 0000000000..5dd98997c1 --- /dev/null +++ b/Units/parser-markdown.r/backquote.d/input.md @@ -0,0 +1,3 @@ + `O` +# A + diff --git a/Units/parser-markdown.r/frontmatter.d/input.md b/Units/parser-markdown.r/frontmatter.d/input.md index 149fb2c260..125e9fdc82 100644 --- a/Units/parser-markdown.r/frontmatter.d/input.md +++ b/Units/parser-markdown.r/frontmatter.d/input.md @@ -6,6 +6,7 @@ tags: ['code','python'] menu: main: parent: 'code' +layout: default --- # About this input diff --git a/Units/parser-markdown.r/simple-markdown.d/expected.tags b/Units/parser-markdown.r/simple-markdown.d/expected.tags index 05b74f5fd9..b73edfcb2b 100644 --- a/Units/parser-markdown.r/simple-markdown.d/expected.tags +++ b/Units/parser-markdown.r/simple-markdown.d/expected.tags @@ -21,10 +21,17 @@ t input.md /^###### t #$/;" u l4subsection:h""k""o""q""s end:59 sectionMarker:## u input.md /^###### u #######$/;" u l4subsection:h""k""o""q""s end:61 sectionMarker:## A input.md /^A$/;" c end:64 sectionMarker:= B input.md /^B$/;" c end:74 sectionMarker:= -C input.md /^C$/;" c end:105 sectionMarker:= +C input.md /^C$/;" c end:128 sectionMarker:= D input.md /^D$/;" s chapter:C end:100 sectionMarker:- E input.md /^E$/;" s chapter:C end:103 sectionMarker:- -F input.md /^F$/;" s chapter:C end:105 sectionMarker:- +F input.md /^F$/;" s chapter:C end:106 sectionMarker:- +G input.md /^ G$/;" s chapter:C end:109 sectionMarker:- +H input.md /^ H$/;" s chapter:C end:112 sectionMarker:- +I input.md /^ I$/;" s chapter:C end:128 sectionMarker:- +C\\# input.md /^# C\\#$/;" c end:146 sectionMarker:# +J input.md /^J$/;" s chapter:C\\# end:133 sectionMarker:- +K input.md /^K$/;" s chapter:C\\# end:136 sectionMarker:- +L input.md /^L$/;" s chapter:C\\# end:146 sectionMarker:- x input.md /^function x$/;" f y input.md /^function y$/;" f z input.md /^z()$/;" f diff --git a/Units/parser-markdown.r/simple-markdown.d/input.md b/Units/parser-markdown.r/simple-markdown.d/input.md index 9580ed43aa..6029222370 100644 --- a/Units/parser-markdown.r/simple-markdown.d/input.md +++ b/Units/parser-markdown.r/simple-markdown.d/input.md @@ -103,3 +103,44 @@ E F --- + + G +- + + H +- + + I +- + + indented +- + + indented_with_tab +- + + indented_with_space_and_tab +- + +text +- ignored +- + +# C\# + +J + - + +K + - + +L + - + +ignored + - + +```foo``` + +> quoted +--- diff --git a/Units/parser-markdown.r/xml-comment.d/args.ctags b/Units/parser-markdown.r/xml-comment.d/args.ctags new file mode 100644 index 0000000000..5ee5f79f70 --- /dev/null +++ b/Units/parser-markdown.r/xml-comment.d/args.ctags @@ -0,0 +1 @@ +--sort=no diff --git a/Units/parser-markdown.r/xml-comment.d/expected.tags b/Units/parser-markdown.r/xml-comment.d/expected.tags new file mode 100644 index 0000000000..7153ca7c19 --- /dev/null +++ b/Units/parser-markdown.r/xml-comment.d/expected.tags @@ -0,0 +1 @@ +EXTRACT ME 1 input.md /^# EXTRACT ME 1$/;" c diff --git a/Units/parser-markdown.r/xml-comment.d/input.md b/Units/parser-markdown.r/xml-comment.d/input.md new file mode 100644 index 0000000000..e431eb962b --- /dev/null +++ b/Units/parser-markdown.r/xml-comment.d/input.md @@ -0,0 +1,7 @@ + + + + +# EXTRACT ME 1 diff --git a/docs/news.rst b/docs/news.rst index 166659ab41..486a52cd05 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -429,7 +429,7 @@ The following parsers have been added: * GNU linker script(LdScript) * LEX *optlib* * Man page *optlib* -* Markdown *optlib* +* Markdown * Maven2 *libxml* * MesonBuild (Meson) *optlib* * MesonOptions *optlib+script* diff --git a/main/nestlevel.c b/main/nestlevel.c index d3403f78f1..3ce87df09c 100644 --- a/main/nestlevel.c +++ b/main/nestlevel.c @@ -29,7 +29,7 @@ */ extern NestingLevels *nestingLevelsNewFull(size_t userDataSize, - void (* deleteUserData)(NestingLevel *)) + void (* deleteUserData)(NestingLevel *, void *)) { NestingLevels *nls = xCalloc (1, NestingLevels); nls->userDataSize = userDataSize; @@ -42,7 +42,7 @@ extern NestingLevels *nestingLevelsNew(size_t userDataSize) return nestingLevelsNewFull (userDataSize, NULL); } -extern void nestingLevelsFree(NestingLevels *nls) +extern void nestingLevelsFreeFull(NestingLevels *nls, void *ctxData) { int i; NestingLevel *nl; @@ -51,7 +51,7 @@ extern void nestingLevelsFree(NestingLevels *nls) { nl = NL_NTH(nls, i); if (nls->deleteUserData) - nls->deleteUserData (nl); + nls->deleteUserData (nl, ctxData); nl->corkIndex = CORK_NIL; } if (nls->levels) eFree(nls->levels); @@ -89,13 +89,13 @@ extern NestingLevel *nestingLevelsTruncate(NestingLevels *nls, int depth, int co } -extern void nestingLevelsPop(NestingLevels *nls) +extern void nestingLevelsPopFull(NestingLevels *nls, void *ctxData) { NestingLevel *nl = nestingLevelsGetCurrent(nls); Assert (nl != NULL); if (nls->deleteUserData) - nls->deleteUserData (nl); + nls->deleteUserData (nl, ctxData); nl->corkIndex = CORK_NIL; nls->n--; } diff --git a/main/nestlevel.h b/main/nestlevel.h index 18ac9927e7..c70c5e7e4e 100644 --- a/main/nestlevel.h +++ b/main/nestlevel.h @@ -35,7 +35,9 @@ struct NestingLevels int n; /* number of levels in use */ int allocated; size_t userDataSize; - void (* deleteUserData) (NestingLevel *); + /* The second argument is given via nestinglevelsPopFull + * or nestinglevelFreeFull */ + void (* deleteUserData) (NestingLevel *, void *); }; /* @@ -43,11 +45,13 @@ struct NestingLevels */ extern NestingLevels *nestingLevelsNew(size_t userDataSize); extern NestingLevels *nestingLevelsNewFull(size_t userDataSize, - void (* deleteUserData)(NestingLevel *)); -extern void nestingLevelsFree(NestingLevels *nls); + void (* deleteUserData)(NestingLevel *, void *)); +#define nestingLevelsFree(NLS) nestingLevelsFreeFull(NLS, NULL) +extern void nestingLevelsFreeFull(NestingLevels *nls, void *ctxData); extern NestingLevel *nestingLevelsPush(NestingLevels *nls, int corkIndex); extern NestingLevel * nestingLevelsTruncate(NestingLevels *nls, int depth, int corkIndex); -extern void nestingLevelsPop(NestingLevels *nls); +#define nestingLevelsPop(NLS) nestingLevelsPopFull(NLS, NULL) +extern void nestingLevelsPopFull(NestingLevels *nls, void *ctxData); #define nestingLevelsGetCurrent(NLS) nestingLevelsGetNthParent((NLS), 0) extern NestingLevel *nestingLevelsGetNthFromRoot(const NestingLevels *nls, int n); extern NestingLevel *nestingLevelsGetNthParent(const NestingLevels *nls, int n); diff --git a/optlib/markdown.c b/optlib/markdown.c deleted file mode 100644 index a8134e48d2..0000000000 --- a/optlib/markdown.c +++ /dev/null @@ -1,537 +0,0 @@ -/* - * Generated by ./misc/optlib2c from optlib/markdown.ctags, Don't edit this manually. - */ -#include "general.h" -#include "parse.h" -#include "routines.h" -#include "field.h" -#include "xtag.h" - - -typedef enum { - K_CHAPTER, - K_SECTION, - K_SUBSECTION, - K_SUBSUBSECTION, - K_L4SUBSECTION, - K_L5SUBSECTION, -} MarkdownKind; - - -static void initializeMarkdownParser (const langType language) -{ - addLanguageOptscriptToHook (language, SCRIPT_HOOK_PRELUDE, - "{{ % group:int SCOPEPOPWITHADJUSTMENT -\n" - " /scopePopWithAdjustment {\n" - " _scopetop {\n" - " % group:int index:int\n" - " dup 3 -1 roll\n" - " % index:int index:int group:int\n" - " _matchloc end:\n" - " % index:int\n" - " dup :end\n" - " % index:int endline:int true\n" - " % or index:int false\n" - " {\n" - " dup 1 gt {\n" - " 1 sub end:\n" - " } { pop } ifelse\n" - " } if\n" - " _scopepop\n" - " } if\n" - " } def\n" - "}}"); - - addLanguageRegexTable (language, "frontmatter"); - addLanguageRegexTable (language, "main"); - addLanguageRegexTable (language, "main_sharp"); - addLanguageRegexTable (language, "chapter"); - addLanguageRegexTable (language, "chapter_sharp"); - addLanguageRegexTable (language, "section"); - addLanguageRegexTable (language, "section_sharp"); - addLanguageRegexTable (language, "subsection"); - addLanguageRegexTable (language, "subsection_sharp"); - addLanguageRegexTable (language, "subsubsection"); - addLanguageRegexTable (language, "subsubsection_sharp"); - addLanguageRegexTable (language, "l4subsection"); - addLanguageRegexTable (language, "l4subsection_sharp"); - addLanguageRegexTable (language, "l5subsection"); - addLanguageRegexTable (language, "l5subsection_sharp"); - addLanguageRegexTable (language, "emptyLine"); - addLanguageRegexTable (language, "gfmLeave"); - addLanguageRegexTable (language, "rest"); - addLanguageRegexTable (language, "code"); - addLanguageRegexTable (language, "codeblockBacktick"); - addLanguageRegexTable (language, "codeblockTildes"); - - addLanguageTagMultiTableRegex (language, "frontmatter", - "^(---[\n]).*(---[\n])", - "", "", "{tjump=main}", NULL); - addLanguageTagMultiTableRegex (language, "frontmatter", - "^(;;;[\n]).*(;;;[\n])", - "", "", "{tjump=main}", NULL); - addLanguageTagMultiTableRegex (language, "frontmatter", - "^(\\+\\+\\+[\n]).*(\\+\\+\\+[\n])", - "", "", "{tjump=main}", NULL); - addLanguageTagMultiTableRegex (language, "frontmatter", - "^.", - "", "", "{_advanceTo=0start}{tjump=main}", NULL); - addLanguageTagMultiTableRegex (language, "main", - "^#", - "", "", "{_advanceTo=0start}{tjump=main_sharp}", NULL); - addLanguageTagMultiTableRegex (language, "main", - "^([\t ]*)[\n]+", - "", "", "", NULL); - addLanguageTagMultiTableRegex (language, "main", - "^[ \t]*````*[ \t]*([a-zA-Z0-9][-#+a-zA-Z0-9]*)?[^`\n]*[\n]", - "", "", "{tenter=codeblockBacktick}{_guest=\\1,0end,}", NULL); - addLanguageTagMultiTableRegex (language, "main", - "^[ \t]*~~~~*[ \t]*([a-zA-Z0-9][-#+a-zA-Z0-9]*)?[^~\n]*[\n]", - "", "", "{tenter=codeblockTildes}{_guest=\\1,0end,}", NULL); - addLanguageTagMultiTableRegex (language, "main", - "^([^\n]+)[\n]=+[\n]", - "\\1", "c", "{_field=sectionMarker:=}{scope=push}{tenter=chapter}", NULL); - addLanguageTagMultiTableRegex (language, "main", - "^([^\n]+)[\n]-+[\n]", - "\\1", "s", "{_field=sectionMarker:-}{scope=push}{tenter=section}", NULL); - addLanguageTagMultiTableRegex (language, "main", - "^[^\n]*[\n]+", - "", "", "", NULL); - addLanguageTagMultiTableRegex (language, "main", - "^[^\n]*", - "", "", "{tquit}", NULL); - addLanguageTagMultiTableRegex (language, "main_sharp", - "^#[ \t]+([^\n]+)([ \t]+#+)[\n]*", - "\\1", "c", "{_field=sectionMarker:##}{scope=push}{tenter=chapter,main}", NULL); - addLanguageTagMultiTableRegex (language, "main_sharp", - "^#[ \t]+([^\n]+)[\n]*", - "\\1", "c", "{_field=sectionMarker:#}{scope=push}{tenter=chapter,main}", NULL); - addLanguageTagMultiTableRegex (language, "main_sharp", - "^##[ \t]+([^\n]+)([ \t]+#+)[\n]*", - "\\1", "s", "{_field=sectionMarker:##}{scope=push}{tenter=section,main}", NULL); - addLanguageTagMultiTableRegex (language, "main_sharp", - "^##[ \t]+([^\n]+)[\n]*", - "\\1", "s", "{_field=sectionMarker:#}{scope=push}{tenter=section,main}", NULL); - addLanguageTagMultiTableRegex (language, "main_sharp", - "^###[ \t]+([^\n]+)([ \t]+#+)[\n]*", - "\\1", "S", "{_field=sectionMarker:##}{scope=push}{tenter=subsection,main}", NULL); - addLanguageTagMultiTableRegex (language, "main_sharp", - "^###[ \t]+([^\n]+)[\n]*", - "\\1", "S", "{_field=sectionMarker:#}{scope=push}{tenter=subsection,main}", NULL); - addLanguageTagMultiTableRegex (language, "main_sharp", - "^####[ \t]+([^\n]+)([ \t]+#+)[\n]*", - "\\1", "t", "{_field=sectionMarker:##}{scope=push}{tenter=subsubsection,main}", NULL); - addLanguageTagMultiTableRegex (language, "main_sharp", - "^####[ \t]+([^\n]+)[\n]*", - "\\1", "t", "{_field=sectionMarker:#}{scope=push}{tenter=subsubsection,main}", NULL); - addLanguageTagMultiTableRegex (language, "main_sharp", - "^#####[ \t]+([^\n]+)([ \t]+#+)[\n]*", - "\\1", "T", "{_field=sectionMarker:##}{scope=push}{tenter=l4subsection,main}", NULL); - addLanguageTagMultiTableRegex (language, "main_sharp", - "^#####[ \t]+([^\n]+)[\n]*", - "\\1", "T", "{_field=sectionMarker:#}{scope=push}{tenter=l4subsection,main}", NULL); - addLanguageTagMultiTableRegex (language, "main_sharp", - "^######[ \t]+([^\n]+)([ \t]+#+)[\n]*", - "\\1", "u", "{_field=sectionMarker:##}{scope=push}{tenter=l5subsection,main}", NULL); - addLanguageTagMultiTableRegex (language, "main_sharp", - "^######[ \t]+([^\n]+)[\n]*", - "\\1", "u", "{_field=sectionMarker:#}{scope=push}{tenter=l5subsection,main}", NULL); - addLanguageTagMultiTableRegex (language, "main_sharp", - "^.", - "", "", "{tjump=main}", NULL); - addLanguageTagMultiTableRegex (language, "chapter", - "^#", - "", "", "{_advanceTo=0start}{tjump=chapter_sharp}", NULL); - addLanguageTagMultiTableRegex (language, "chapter", - "^([\t ]*)[\n]+", - "", "", "", NULL); - addLanguageTagMultiTableRegex (language, "chapter", - "^([^\n]+)[\n]-+[\n]", - "\\1", "s", "{_field=sectionMarker:-}{scope=push}{tenter=section}", NULL); - addLanguageTagMultiTableRegex (language, "chapter", - "^([^\n]+)[\n]=+[\n]", - "", "", "{tleave}{_advanceTo=0start}" - "{{\n" - " 1 scopePopWithAdjustment\n" - "}}", NULL); - addLanguageTagMultiTableRegex (language, "chapter", - "^[ \t]*````*[ \t]*([a-zA-Z0-9][-#+a-zA-Z0-9]*)?[^`\n]*[\n]", - "", "", "{tenter=codeblockBacktick}{_guest=\\1,0end,}", NULL); - addLanguageTagMultiTableRegex (language, "chapter", - "^[ \t]*~~~~*[ \t]*([a-zA-Z0-9][-#+a-zA-Z0-9]*)?[^~\n]*[\n]", - "", "", "{tenter=codeblockTildes}{_guest=\\1,0end,}", NULL); - addLanguageTagMultiTableRegex (language, "chapter", - "^[^\n]*[\n]+", - "", "", "", NULL); - addLanguageTagMultiTableRegex (language, "chapter", - "^[^\n]*", - "", "", "{tquit}", NULL); - addLanguageTagMultiTableRegex (language, "chapter_sharp", - "^(^#{1,1}[ \t]+[^\n]+)", - "", "", "{tleave}{_advanceTo=0start}" - "{{\n" - " 1 scopePopWithAdjustment\n" - "}}", NULL); - addLanguageTagMultiTableRegex (language, "chapter_sharp", - "^##[ \t]+([^\n]+)([ \t]+#+)[\n]*", - "\\1", "s", "{_field=sectionMarker:##}{scope=push}{tenter=section,chapter}", NULL); - addLanguageTagMultiTableRegex (language, "chapter_sharp", - "^##[ \t]+([^\n]+)[\n]*", - "\\1", "s", "{_field=sectionMarker:#}{scope=push}{tenter=section,chapter}", NULL); - addLanguageTagMultiTableRegex (language, "chapter_sharp", - "^###[ \t]+([^\n]+)([ \t]+#+)[\n]*", - "\\1", "S", "{_field=sectionMarker:##}{scope=push}{tenter=subsection,chapter}", NULL); - addLanguageTagMultiTableRegex (language, "chapter_sharp", - "^###[ \t]+([^\n]+)[\n]*", - "\\1", "S", "{_field=sectionMarker:#}{scope=push}{tenter=subsection,chapter}", NULL); - addLanguageTagMultiTableRegex (language, "chapter_sharp", - "^####[ \t]+([^\n]+)([ \t]+#+)[\n]*", - "\\1", "t", "{_field=sectionMarker:##}{scope=push}{tenter=subsubsection,chapter}", NULL); - addLanguageTagMultiTableRegex (language, "chapter_sharp", - "^####[ \t]+([^\n]+)[\n]*", - "\\1", "t", "{_field=sectionMarker:#}{scope=push}{tenter=subsubsection,chapter}", NULL); - addLanguageTagMultiTableRegex (language, "chapter_sharp", - "^#####[ \t]+([^\n]+)([ \t]+#+)[\n]*", - "\\1", "T", "{_field=sectionMarker:##}{scope=push}{tenter=l4subsection,chapter}", NULL); - addLanguageTagMultiTableRegex (language, "chapter_sharp", - "^#####[ \t]+([^\n]+)[\n]*", - "\\1", "T", "{_field=sectionMarker:#}{scope=push}{tenter=l4subsection,chapter}", NULL); - addLanguageTagMultiTableRegex (language, "chapter_sharp", - "^######[ \t]+([^\n]+)([ \t]+#+)[\n]*", - "\\1", "u", "{_field=sectionMarker:##}{scope=push}{tenter=l5subsection,chapter}", NULL); - addLanguageTagMultiTableRegex (language, "chapter_sharp", - "^######[ \t]+([^\n]+)[\n]*", - "\\1", "u", "{_field=sectionMarker:#}{scope=push}{tenter=l5subsection,chapter}", NULL); - addLanguageTagMultiTableRegex (language, "chapter_sharp", - "^.", - "", "", "{tjump=chapter}", NULL); - addLanguageTagMultiTableRegex (language, "section", - "^#", - "", "", "{_advanceTo=0start}{tjump=section_sharp}", NULL); - addLanguageTagMultiTableRegex (language, "section", - "^([\t ]*)[\n]+", - "", "", "", NULL); - addLanguageTagMultiTableRegex (language, "section", - "^([^\n]+)[\n](=+|-+)[\n]", - "", "", "{tleave}{_advanceTo=0start}" - "{{\n" - " 1 scopePopWithAdjustment\n" - "}}", NULL); - addLanguageTagMultiTableRegex (language, "section", - "^[ \t]*````*[ \t]*([a-zA-Z0-9][-#+a-zA-Z0-9]*)?[^`\n]*[\n]", - "", "", "{tenter=codeblockBacktick}{_guest=\\1,0end,}", NULL); - addLanguageTagMultiTableRegex (language, "section", - "^[ \t]*~~~~*[ \t]*([a-zA-Z0-9][-#+a-zA-Z0-9]*)?[^~\n]*[\n]", - "", "", "{tenter=codeblockTildes}{_guest=\\1,0end,}", NULL); - addLanguageTagMultiTableRegex (language, "section", - "^[^\n]*[\n]+", - "", "", "", NULL); - addLanguageTagMultiTableRegex (language, "section", - "^[^\n]*", - "", "", "{tquit}", NULL); - addLanguageTagMultiTableRegex (language, "section_sharp", - "^(^#{1,2}[ \t]+[^\n]+)", - "", "", "{tleave}{_advanceTo=0start}" - "{{\n" - " 1 scopePopWithAdjustment\n" - "}}", NULL); - addLanguageTagMultiTableRegex (language, "section_sharp", - "^###[ \t]+([^\n]+)([ \t]+#+)[\n]*", - "\\1", "S", "{_field=sectionMarker:##}{scope=push}{tenter=subsection,section}", NULL); - addLanguageTagMultiTableRegex (language, "section_sharp", - "^###[ \t]+([^\n]+)[\n]*", - "\\1", "S", "{_field=sectionMarker:#}{scope=push}{tenter=subsection,section}", NULL); - addLanguageTagMultiTableRegex (language, "section_sharp", - "^####[ \t]+([^\n]+)([ \t]+#+)[\n]*", - "\\1", "t", "{_field=sectionMarker:##}{scope=push}{tenter=subsubsection,section}", NULL); - addLanguageTagMultiTableRegex (language, "section_sharp", - "^####[ \t]+([^\n]+)[\n]*", - "\\1", "t", "{_field=sectionMarker:#}{scope=push}{tenter=subsubsection,section}", NULL); - addLanguageTagMultiTableRegex (language, "section_sharp", - "^#####[ \t]+([^\n]+)([ \t]+#+)[\n]*", - "\\1", "T", "{_field=sectionMarker:##}{scope=push}{tenter=l4subsection,section}", NULL); - addLanguageTagMultiTableRegex (language, "section_sharp", - "^#####[ \t]+([^\n]+)[\n]*", - "\\1", "T", "{_field=sectionMarker:#}{scope=push}{tenter=l4subsection,section}", NULL); - addLanguageTagMultiTableRegex (language, "section_sharp", - "^######[ \t]+([^\n]+)([ \t]+#+)[\n]*", - "\\1", "u", "{_field=sectionMarker:##}{scope=push}{tenter=l5subsection,section}", NULL); - addLanguageTagMultiTableRegex (language, "section_sharp", - "^######[ \t]+([^\n]+)[\n]*", - "\\1", "u", "{_field=sectionMarker:#}{scope=push}{tenter=l5subsection,section}", NULL); - addLanguageTagMultiTableRegex (language, "section_sharp", - "^.", - "", "", "{tjump=section}", NULL); - addLanguageTagMultiTableRegex (language, "subsection", - "^#", - "", "", "{_advanceTo=0start}{tjump=subsection_sharp}", NULL); - addLanguageTagMultiTableRegex (language, "subsection", - "^([\t ]*)[\n]+", - "", "", "", NULL); - addLanguageTagMultiTableRegex (language, "subsection", - "^([^\n]+)[\n](=+|-+)[\n]", - "", "", "{tleave}{_advanceTo=0start}" - "{{\n" - " 1 scopePopWithAdjustment\n" - "}}", NULL); - addLanguageTagMultiTableRegex (language, "subsection", - "^[ \t]*````*[ \t]*([a-zA-Z0-9][-#+a-zA-Z0-9]*)?[^`\n]*[\n]", - "", "", "{tenter=codeblockBacktick}{_guest=\\1,0end,}", NULL); - addLanguageTagMultiTableRegex (language, "subsection", - "^[ \t]*~~~~*[ \t]*([a-zA-Z0-9][-#+a-zA-Z0-9]*)?[^~\n]*[\n]", - "", "", "{tenter=codeblockTildes}{_guest=\\1,0end,}", NULL); - addLanguageTagMultiTableRegex (language, "subsection", - "^[^\n]*[\n]+", - "", "", "", NULL); - addLanguageTagMultiTableRegex (language, "subsection", - "^[^\n]*", - "", "", "{tquit}", NULL); - addLanguageTagMultiTableRegex (language, "subsection_sharp", - "^(^#{1,3}[ \t]+[^\n]+)", - "", "", "{tleave}{_advanceTo=0start,subsection}" - "{{\n" - " 1 scopePopWithAdjustment\n" - "}}", NULL); - addLanguageTagMultiTableRegex (language, "subsection_sharp", - "^####[ \t]+([^\n]+)([ \t]+#+)[\n]*", - "\\1", "t", "{_field=sectionMarker:##}{scope=push}{tenter=subsubsection,subsection}", NULL); - addLanguageTagMultiTableRegex (language, "subsection_sharp", - "^####[ \t]+([^\n]+)[\n]*", - "\\1", "t", "{_field=sectionMarker:#}{scope=push}{tenter=subsubsection,subsection}", NULL); - addLanguageTagMultiTableRegex (language, "subsection_sharp", - "^#####[ \t]+([^\n]+)([ \t]+#+)[\n]*", - "\\1", "T", "{_field=sectionMarker:##}{scope=push}{tenter=l4subsection,subsection}", NULL); - addLanguageTagMultiTableRegex (language, "subsection_sharp", - "^#####[ \t]+([^\n]+)[\n]*", - "\\1", "T", "{_field=sectionMarker:#}{scope=push}{tenter=l4subsection,subsection}", NULL); - addLanguageTagMultiTableRegex (language, "subsection_sharp", - "^######[ \t]+([^\n]+)([ \t]+#+)[\n]*", - "\\1", "u", "{_field=sectionMarker:##}{scope=push}{tenter=l5subsection,subsection}", NULL); - addLanguageTagMultiTableRegex (language, "subsection_sharp", - "^######[ \t]+([^\n]+)[\n]*", - "\\1", "u", "{_field=sectionMarker:#}{scope=push}{tenter=l5subsection,subsection}", NULL); - addLanguageTagMultiTableRegex (language, "subsection_sharp", - "^.", - "", "", "{tjump=subsection}", NULL); - addLanguageTagMultiTableRegex (language, "subsubsection", - "^#", - "", "", "{_advanceTo=0start}{tjump=subsubsection_sharp}", NULL); - addLanguageTagMultiTableRegex (language, "subsubsection", - "^([\t ]*)[\n]+", - "", "", "", NULL); - addLanguageTagMultiTableRegex (language, "subsubsection", - "^([^\n]+)[\n](=+|-+)[\n]", - "", "", "{tleave}{_advanceTo=0start}" - "{{\n" - " 1 scopePopWithAdjustment\n" - "}}", NULL); - addLanguageTagMultiTableRegex (language, "subsubsection", - "^[ \t]*````*[ \t]*([a-zA-Z0-9][-#+a-zA-Z0-9]*)?[^`\n]*[\n]", - "", "", "{tenter=codeblockBacktick}{_guest=\\1,0end,}", NULL); - addLanguageTagMultiTableRegex (language, "subsubsection", - "^[ \t]*~~~~*[ \t]*([a-zA-Z0-9][-#+a-zA-Z0-9]*)?[^~\n]*[\n]", - "", "", "{tenter=codeblockTildes}{_guest=\\1,0end,}", NULL); - addLanguageTagMultiTableRegex (language, "subsubsection", - "^[^\n]*[\n]+", - "", "", "", NULL); - addLanguageTagMultiTableRegex (language, "subsubsection", - "^[^\n]*", - "", "", "{tquit}", NULL); - addLanguageTagMultiTableRegex (language, "subsubsection_sharp", - "^(^#{1,4}[ \t]+[^\n]+)", - "", "", "{tleave}{_advanceTo=0start}" - "{{\n" - " 1 scopePopWithAdjustment\n" - "}}", NULL); - addLanguageTagMultiTableRegex (language, "subsubsection_sharp", - "^#####[ \t]+([^\n]+)([ \t]+#+)[\n]*", - "\\1", "T", "{_field=sectionMarker:##}{scope=push}{tenter=l4subsection,subsubsection}", NULL); - addLanguageTagMultiTableRegex (language, "subsubsection_sharp", - "^#####[ \t]+([^\n]+)[\n]*", - "\\1", "T", "{_field=sectionMarker:#}{scope=push}{tenter=l4subsection,subsubsection}", NULL); - addLanguageTagMultiTableRegex (language, "subsubsection_sharp", - "^######[ \t]+([^\n]+)([ \t]+#+)[\n]*", - "\\1", "u", "{_field=sectionMarker:##}{scope=push}{tenter=l5subsection,subsubsection}", NULL); - addLanguageTagMultiTableRegex (language, "subsubsection_sharp", - "^######[ \t]+([^\n]+)[\n]*", - "\\1", "u", "{_field=sectionMarker:#}{scope=push}{tenter=l5subsection,subsubsection}", NULL); - addLanguageTagMultiTableRegex (language, "subsubsection_sharp", - "^.", - "", "", "{tjump=subsubsection}", NULL); - addLanguageTagMultiTableRegex (language, "l4subsection", - "^#", - "", "", "{_advanceTo=0start}{tjump=l4subsection_sharp}", NULL); - addLanguageTagMultiTableRegex (language, "l4subsection", - "^([\t ]*)[\n]+", - "", "", "", NULL); - addLanguageTagMultiTableRegex (language, "l4subsection", - "^([^\n]+)[\n](=+|-+)[\n]", - "", "", "{tleave}{_advanceTo=0start}" - "{{\n" - " 1 scopePopWithAdjustment\n" - "}}", NULL); - addLanguageTagMultiTableRegex (language, "l4subsection", - "^[ \t]*````*[ \t]*([a-zA-Z0-9][-#+a-zA-Z0-9]*)?[^`\n]*[\n]", - "", "", "{tenter=codeblockBacktick}{_guest=\\1,0end,}", NULL); - addLanguageTagMultiTableRegex (language, "l4subsection", - "^[ \t]*~~~~*[ \t]*([a-zA-Z0-9][-#+a-zA-Z0-9]*)?[^~\n]*[\n]", - "", "", "{tenter=codeblockTildes}{_guest=\\1,0end,}", NULL); - addLanguageTagMultiTableRegex (language, "l4subsection", - "^[^\n]*[\n]+", - "", "", "", NULL); - addLanguageTagMultiTableRegex (language, "l4subsection", - "^[^\n]*", - "", "", "{tquit}", NULL); - addLanguageTagMultiTableRegex (language, "l4subsection_sharp", - "^(^#{1,5}[ \t]+[^\n]+)", - "", "", "{tleave}{_advanceTo=0start}" - "{{\n" - " 1 scopePopWithAdjustment\n" - "}}", NULL); - addLanguageTagMultiTableRegex (language, "l4subsection_sharp", - "^######[ \t]+([^\n]+)([ \t]+#+)[\n]*", - "\\1", "u", "{_field=sectionMarker:##}{scope=push}{tenter=l5subsection,l4subsection}", NULL); - addLanguageTagMultiTableRegex (language, "l4subsection_sharp", - "^######[ \t]+([^\n]+)[\n]*", - "\\1", "u", "{_field=sectionMarker:#}{scope=push}{tenter=l5subsection,l4subsection}", NULL); - addLanguageTagMultiTableRegex (language, "l4subsection_sharp", - "^.", - "", "", "{tjump=l4subsection}", NULL); - addLanguageTagMultiTableRegex (language, "l5subsection", - "^#", - "", "", "{_advanceTo=0start}{tjump=l5subsection_sharp}", NULL); - addLanguageTagMultiTableRegex (language, "l5subsection", - "^([\t ]*)[\n]+", - "", "", "", NULL); - addLanguageTagMultiTableRegex (language, "l5subsection", - "^([^\n]+)[\n](=+|-+)[\n]", - "", "", "{tleave}{_advanceTo=0start}" - "{{\n" - " 1 scopePopWithAdjustment\n" - "}}", NULL); - addLanguageTagMultiTableRegex (language, "l5subsection", - "^[ \t]*````*[ \t]*([a-zA-Z0-9][-#+a-zA-Z0-9]*)?[^`\n]*[\n]", - "", "", "{tenter=codeblockBacktick}{_guest=\\1,0end,}", NULL); - addLanguageTagMultiTableRegex (language, "l5subsection", - "^[ \t]*~~~~*[ \t]*([a-zA-Z0-9][-#+a-zA-Z0-9]*)?[^~\n]*[\n]", - "", "", "{tenter=codeblockTildes}{_guest=\\1,0end,}", NULL); - addLanguageTagMultiTableRegex (language, "l5subsection", - "^[^\n]*[\n]+", - "", "", "", NULL); - addLanguageTagMultiTableRegex (language, "l5subsection", - "^[^\n]*", - "", "", "{tquit}", NULL); - addLanguageTagMultiTableRegex (language, "l5subsection_sharp", - "^#{1,6}[ \t]+([^\n]+)", - "", "", "{tleave}{_advanceTo=0start}" - "{{\n" - " 1 scopePopWithAdjustment\n" - "}}", NULL); - addLanguageTagMultiTableRegex (language, "l5subsection_sharp", - "^.", - "", "", "{tjump=l5subsection}", NULL); - addLanguageTagMultiTableRegex (language, "emptyLine", - "^([\t ]*)[\n]+", - "", "", "", NULL); - addLanguageTagMultiTableRegex (language, "gfmLeave", - "^([\t ]*)[\n]+", - "", "", "", NULL); - addLanguageTagMultiTableRegex (language, "gfmLeave", - "^([^\n]+)[\n](=+|-+)[\n]", - "", "", "{tleave}{_advanceTo=0start}" - "{{\n" - " 1 scopePopWithAdjustment\n" - "}}", NULL); - addLanguageTagMultiTableRegex (language, "rest", - "^[^\n]*[\n]+", - "", "", "", NULL); - addLanguageTagMultiTableRegex (language, "rest", - "^[^\n]*", - "", "", "{tquit}", NULL); - addLanguageTagMultiTableRegex (language, "code", - "^[ \t]*````*[ \t]*([a-zA-Z0-9][-#+a-zA-Z0-9]*)?[^`\n]*[\n]", - "", "", "{tenter=codeblockBacktick}{_guest=\\1,0end,}", NULL); - addLanguageTagMultiTableRegex (language, "code", - "^[ \t]*~~~~*[ \t]*([a-zA-Z0-9][-#+a-zA-Z0-9]*)?[^~\n]*[\n]", - "", "", "{tenter=codeblockTildes}{_guest=\\1,0end,}", NULL); - addLanguageTagMultiTableRegex (language, "codeblockBacktick", - "^[ \t]*````*[ \t]*[\n]", - "", "", "{tleave}{_guest=,,0start}", NULL); - addLanguageTagMultiTableRegex (language, "codeblockBacktick", - "^[^\n]*[\n]+", - "", "", "", NULL); - addLanguageTagMultiTableRegex (language, "codeblockBacktick", - "^[^\n]*", - "", "", "{tquit}", NULL); - addLanguageTagMultiTableRegex (language, "codeblockTildes", - "^[ \t]*~~~~*[ \t]*[\n]", - "", "", "{tleave}{_guest=,,0start}", NULL); - addLanguageTagMultiTableRegex (language, "codeblockTildes", - "^[^\n]*[\n]+", - "", "", "", NULL); - addLanguageTagMultiTableRegex (language, "codeblockTildes", - "^[^\n]*", - "", "", "{tquit}", NULL); -} - -extern parserDefinition* MarkdownParser (void) -{ - static const char *const extensions [] = { - "md", - "markdown", - NULL - }; - - static const char *const aliases [] = { - NULL - }; - - static const char *const patterns [] = { - NULL - }; - - static kindDefinition MarkdownKindTable [] = { - { - true, 'c', "chapter", "chapsters", - }, - { - true, 's', "section", "sections", - }, - { - true, 'S', "subsection", "subsections", - }, - { - true, 't', "subsubsection", "subsubsections", - }, - { - true, 'T', "l4subsection", "level 4 subsections", - }, - { - true, 'u', "l5subsection", "level 5 subsections", - }, - }; - static fieldDefinition MarkdownFieldTable [] = { - { - .enabled = false, - .name = "sectionMarker", - .description = "character used for declaring section(#, ##, =, or -)", - }, - }; - - parserDefinition* const def = parserNew ("Markdown"); - - def->enabled = true; - def->extensions = extensions; - def->patterns = patterns; - def->aliases = aliases; - def->method = METHOD_NOT_CRAFTED|METHOD_REGEX; - def->useCork = CORK_QUEUE; - def->kindTable = MarkdownKindTable; - def->kindCount = ARRAY_SIZE(MarkdownKindTable); - def->fieldTable = MarkdownFieldTable; - def->fieldCount = ARRAY_SIZE(MarkdownFieldTable); - def->defaultScopeSeparator = "\"\""; - def->initialize = initializeMarkdownParser; - - return def; -} diff --git a/optlib/markdown.ctags b/optlib/markdown.ctags deleted file mode 100644 index 1486dfb5d6..0000000000 --- a/optlib/markdown.ctags +++ /dev/null @@ -1,271 +0,0 @@ -# -# -# Copyright (c) 2018, Red Hat, Inc. -# Copyright (c) 2018, Masatake YAMATO -# -# Author: Masatake YAMATO -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -# USA. -# -# - ---langdef=Markdown ---map-Markdown=+.md ---map-Markdown=+.markdown - ---_scopesep-Markdown=*/*:"" - ---kinddef-Markdown=c,chapter,chapsters ---kinddef-Markdown=s,section,sections ---kinddef-Markdown=S,subsection,subsections ---kinddef-Markdown=t,subsubsection,subsubsections ---kinddef-Markdown=T,l4subsection,level 4 subsections ---kinddef-Markdown=u,l5subsection,level 5 subsections - ---_fielddef-Markdown=sectionMarker,character used for declaring section(#, ##, =, or -) - - ---_prelude-Markdown={{ - % group:int SCOPEPOPWITHADJUSTMENT - - /scopePopWithAdjustment { - _scopetop { - % group:int index:int - dup 3 -1 roll - % index:int index:int group:int - _matchloc end: - % index:int - dup :end - % index:int endline:int true - % or index:int false - { - dup 1 gt { - 1 sub end: - } { pop } ifelse - } if - _scopepop - } if - } def -}} - ---_tabledef-Markdown=frontmatter ---_tabledef-Markdown=main ---_tabledef-Markdown=main_sharp ---_tabledef-Markdown=chapter ---_tabledef-Markdown=chapter_sharp ---_tabledef-Markdown=section ---_tabledef-Markdown=section_sharp ---_tabledef-Markdown=subsection ---_tabledef-Markdown=subsection_sharp ---_tabledef-Markdown=subsubsection ---_tabledef-Markdown=subsubsection_sharp ---_tabledef-Markdown=l4subsection ---_tabledef-Markdown=l4subsection_sharp ---_tabledef-Markdown=l5subsection ---_tabledef-Markdown=l5subsection_sharp - ---_tabledef-Markdown=emptyLine ---_tabledef-Markdown=gfmLeave ---_tabledef-Markdown=rest ---_tabledef-Markdown=code - -# Handle GFM style codeblock in this table. -# https://github.github.com/gfm/#fenced-code-blocks ---_tabledef-Markdown=codeblockBacktick ---_tabledef-Markdown=codeblockTildes - - ---_mtable-regex-Markdown=emptyLine/^([\t ]*)[\n]+// - ---_mtable-extend-Markdown=gfmLeave+emptyLine ---_mtable-regex-Markdown=gfmLeave/^([^\n]+)[\n](=+|-+)[\n]//{tleave}{_advanceTo=0start}{{ - 1 scopePopWithAdjustment -}} - ---_mtable-regex-Markdown=rest/^[^\n]*[\n]+// ---_mtable-regex-Markdown=rest/^[^\n]*//{tquit} - ---_mtable-regex-Markdown=code/^[ \t]*````*[ \t]*([a-zA-Z0-9][-#+a-zA-Z0-9]*)?[^`\n]*[\n]//{tenter=codeblockBacktick}{_guest=\1,0end,} ---_mtable-regex-Markdown=code/^[ \t]*~~~~*[ \t]*([a-zA-Z0-9][-#+a-zA-Z0-9]*)?[^~\n]*[\n]//{tenter=codeblockTildes}{_guest=\1,0end,} - -# -# Frontmatter -# -# https://gohugo.io/content-management/front-matter/ -# - -# YAML area ---_mtable-regex-Markdown=frontmatter/(---[\n]).*(---[\n])//{tjump=main} - -# JSON area ---_mtable-regex-Markdown=frontmatter/(;;;[\n]).*(;;;[\n])//{tjump=main} - -# TOML area ---_mtable-regex-Markdown=frontmatter/(\+\+\+[\n]).*(\+\+\+[\n])//{tjump=main} - -# No frontmatter ---_mtable-regex-Markdown=frontmatter/.//{_advanceTo=0start}{tjump=main} - - -# -# Main -# ---_mtable-regex-Markdown=main_sharp/^#[ \t]+([^\n]+)([ \t]+#+)[\n]*/\1/c/{_field=sectionMarker:##}{scope=push}{tenter=chapter,main} ---_mtable-regex-Markdown=main_sharp/^#[ \t]+([^\n]+)[\n]*/\1/c/{_field=sectionMarker:#}{scope=push}{tenter=chapter,main} ---_mtable-regex-Markdown=main_sharp/^##[ \t]+([^\n]+)([ \t]+#+)[\n]*/\1/s/{_field=sectionMarker:##}{scope=push}{tenter=section,main} ---_mtable-regex-Markdown=main_sharp/^##[ \t]+([^\n]+)[\n]*/\1/s/{_field=sectionMarker:#}{scope=push}{tenter=section,main} ---_mtable-regex-Markdown=main_sharp/^###[ \t]+([^\n]+)([ \t]+#+)[\n]*/\1/S/{_field=sectionMarker:##}{scope=push}{tenter=subsection,main} ---_mtable-regex-Markdown=main_sharp/^###[ \t]+([^\n]+)[\n]*/\1/S/{_field=sectionMarker:#}{scope=push}{tenter=subsection,main} ---_mtable-regex-Markdown=main_sharp/^####[ \t]+([^\n]+)([ \t]+#+)[\n]*/\1/t/{_field=sectionMarker:##}{scope=push}{tenter=subsubsection,main} ---_mtable-regex-Markdown=main_sharp/^####[ \t]+([^\n]+)[\n]*/\1/t/{_field=sectionMarker:#}{scope=push}{tenter=subsubsection,main} ---_mtable-regex-Markdown=main_sharp/^#####[ \t]+([^\n]+)([ \t]+#+)[\n]*/\1/T/{_field=sectionMarker:##}{scope=push}{tenter=l4subsection,main} ---_mtable-regex-Markdown=main_sharp/^#####[ \t]+([^\n]+)[\n]*/\1/T/{_field=sectionMarker:#}{scope=push}{tenter=l4subsection,main} ---_mtable-regex-Markdown=main_sharp/^######[ \t]+([^\n]+)([ \t]+#+)[\n]*/\1/u/{_field=sectionMarker:##}{scope=push}{tenter=l5subsection,main} ---_mtable-regex-Markdown=main_sharp/^######[ \t]+([^\n]+)[\n]*/\1/u/{_field=sectionMarker:#}{scope=push}{tenter=l5subsection,main} ---_mtable-regex-Markdown=main_sharp/.//{tjump=main} - ---_mtable-regex-Markdown=main/^#//{_advanceTo=0start}{tjump=main_sharp} ---_mtable-extend-Markdown=main+emptyLine ---_mtable-extend-Markdown=main+code ---_mtable-regex-Markdown=main/^([^\n]+)[\n]=+[\n]/\1/c/{_field=sectionMarker:=}{scope=push}{tenter=chapter} ---_mtable-regex-Markdown=main/^([^\n]+)[\n]-+[\n]/\1/s/{_field=sectionMarker:-}{scope=push}{tenter=section} ---_mtable-extend-Markdown=main+rest - - -# -# Chapter -# ---_mtable-regex-Markdown=chapter_sharp/(^#{1,1}[ \t]+[^\n]+)//{tleave}{_advanceTo=0start}{{ - 1 scopePopWithAdjustment -}} ---_mtable-regex-Markdown=chapter_sharp/^##[ \t]+([^\n]+)([ \t]+#+)[\n]*/\1/s/{_field=sectionMarker:##}{scope=push}{tenter=section,chapter} ---_mtable-regex-Markdown=chapter_sharp/^##[ \t]+([^\n]+)[\n]*/\1/s/{_field=sectionMarker:#}{scope=push}{tenter=section,chapter} ---_mtable-regex-Markdown=chapter_sharp/^###[ \t]+([^\n]+)([ \t]+#+)[\n]*/\1/S/{_field=sectionMarker:##}{scope=push}{tenter=subsection,chapter} ---_mtable-regex-Markdown=chapter_sharp/^###[ \t]+([^\n]+)[\n]*/\1/S/{_field=sectionMarker:#}{scope=push}{tenter=subsection,chapter} ---_mtable-regex-Markdown=chapter_sharp/^####[ \t]+([^\n]+)([ \t]+#+)[\n]*/\1/t/{_field=sectionMarker:##}{scope=push}{tenter=subsubsection,chapter} ---_mtable-regex-Markdown=chapter_sharp/^####[ \t]+([^\n]+)[\n]*/\1/t/{_field=sectionMarker:#}{scope=push}{tenter=subsubsection,chapter} ---_mtable-regex-Markdown=chapter_sharp/^#####[ \t]+([^\n]+)([ \t]+#+)[\n]*/\1/T/{_field=sectionMarker:##}{scope=push}{tenter=l4subsection,chapter} ---_mtable-regex-Markdown=chapter_sharp/^#####[ \t]+([^\n]+)[\n]*/\1/T/{_field=sectionMarker:#}{scope=push}{tenter=l4subsection,chapter} ---_mtable-regex-Markdown=chapter_sharp/^######[ \t]+([^\n]+)([ \t]+#+)[\n]*/\1/u/{_field=sectionMarker:##}{scope=push}{tenter=l5subsection,chapter} ---_mtable-regex-Markdown=chapter_sharp/^######[ \t]+([^\n]+)[\n]*/\1/u/{_field=sectionMarker:#}{scope=push}{tenter=l5subsection,chapter} ---_mtable-regex-Markdown=chapter_sharp/.//{tjump=chapter} - ---_mtable-regex-Markdown=chapter/^#//{_advanceTo=0start}{tjump=chapter_sharp} ---_mtable-extend-Markdown=chapter+emptyLine ---_mtable-regex-Markdown=chapter/^([^\n]+)[\n]-+[\n]/\1/s/{_field=sectionMarker:-}{scope=push}{tenter=section} ---_mtable-regex-Markdown=chapter/^([^\n]+)[\n]=+[\n]//{tleave}{_advanceTo=0start}{{ - 1 scopePopWithAdjustment -}} ---_mtable-extend-Markdown=chapter+code ---_mtable-extend-Markdown=chapter+rest - -# -# Section -# ---_mtable-regex-Markdown=section_sharp/(^#{1,2}[ \t]+[^\n]+)//{tleave}{_advanceTo=0start}{{ - 1 scopePopWithAdjustment -}} ---_mtable-regex-Markdown=section_sharp/^###[ \t]+([^\n]+)([ \t]+#+)[\n]*/\1/S/{_field=sectionMarker:##}{scope=push}{tenter=subsection,section} ---_mtable-regex-Markdown=section_sharp/^###[ \t]+([^\n]+)[\n]*/\1/S/{_field=sectionMarker:#}{scope=push}{tenter=subsection,section} ---_mtable-regex-Markdown=section_sharp/^####[ \t]+([^\n]+)([ \t]+#+)[\n]*/\1/t/{_field=sectionMarker:##}{scope=push}{tenter=subsubsection,section} ---_mtable-regex-Markdown=section_sharp/^####[ \t]+([^\n]+)[\n]*/\1/t/{_field=sectionMarker:#}{scope=push}{tenter=subsubsection,section} ---_mtable-regex-Markdown=section_sharp/^#####[ \t]+([^\n]+)([ \t]+#+)[\n]*/\1/T/{_field=sectionMarker:##}{scope=push}{tenter=l4subsection,section} ---_mtable-regex-Markdown=section_sharp/^#####[ \t]+([^\n]+)[\n]*/\1/T/{_field=sectionMarker:#}{scope=push}{tenter=l4subsection,section} ---_mtable-regex-Markdown=section_sharp/^######[ \t]+([^\n]+)([ \t]+#+)[\n]*/\1/u/{_field=sectionMarker:##}{scope=push}{tenter=l5subsection,section} ---_mtable-regex-Markdown=section_sharp/^######[ \t]+([^\n]+)[\n]*/\1/u/{_field=sectionMarker:#}{scope=push}{tenter=l5subsection,section} ---_mtable-regex-Markdown=section_sharp/.//{tjump=section} - ---_mtable-regex-Markdown=section/^#//{_advanceTo=0start}{tjump=section_sharp} ---_mtable-extend-Markdown=section+gfmLeave ---_mtable-extend-Markdown=section+code ---_mtable-extend-Markdown=section+rest - - -# -# Subsection -# ---_mtable-regex-Markdown=subsection_sharp/(^#{1,3}[ \t]+[^\n]+)//{tleave}{_advanceTo=0start,subsection}{{ - 1 scopePopWithAdjustment -}} ---_mtable-regex-Markdown=subsection_sharp/^####[ \t]+([^\n]+)([ \t]+#+)[\n]*/\1/t/{_field=sectionMarker:##}{scope=push}{tenter=subsubsection,subsection} ---_mtable-regex-Markdown=subsection_sharp/^####[ \t]+([^\n]+)[\n]*/\1/t/{_field=sectionMarker:#}{scope=push}{tenter=subsubsection,subsection} ---_mtable-regex-Markdown=subsection_sharp/^#####[ \t]+([^\n]+)([ \t]+#+)[\n]*/\1/T/{_field=sectionMarker:##}{scope=push}{tenter=l4subsection,subsection} ---_mtable-regex-Markdown=subsection_sharp/^#####[ \t]+([^\n]+)[\n]*/\1/T/{_field=sectionMarker:#}{scope=push}{tenter=l4subsection,subsection} ---_mtable-regex-Markdown=subsection_sharp/^######[ \t]+([^\n]+)([ \t]+#+)[\n]*/\1/u/{_field=sectionMarker:##}{scope=push}{tenter=l5subsection,subsection} ---_mtable-regex-Markdown=subsection_sharp/^######[ \t]+([^\n]+)[\n]*/\1/u/{_field=sectionMarker:#}{scope=push}{tenter=l5subsection,subsection} ---_mtable-regex-Markdown=subsection_sharp/.//{tjump=subsection} - ---_mtable-regex-Markdown=subsection/^#//{_advanceTo=0start}{tjump=subsection_sharp} ---_mtable-extend-Markdown=subsection+gfmLeave ---_mtable-extend-Markdown=subsection+code ---_mtable-extend-Markdown=subsection+rest - - -# -# SubSubsection -# ---_mtable-regex-Markdown=subsubsection_sharp/(^#{1,4}[ \t]+[^\n]+)//{tleave}{_advanceTo=0start}{{ - 1 scopePopWithAdjustment -}} ---_mtable-regex-Markdown=subsubsection_sharp/^#####[ \t]+([^\n]+)([ \t]+#+)[\n]*/\1/T/{_field=sectionMarker:##}{scope=push}{tenter=l4subsection,subsubsection} ---_mtable-regex-Markdown=subsubsection_sharp/^#####[ \t]+([^\n]+)[\n]*/\1/T/{_field=sectionMarker:#}{scope=push}{tenter=l4subsection,subsubsection} ---_mtable-regex-Markdown=subsubsection_sharp/^######[ \t]+([^\n]+)([ \t]+#+)[\n]*/\1/u/{_field=sectionMarker:##}{scope=push}{tenter=l5subsection,subsubsection} ---_mtable-regex-Markdown=subsubsection_sharp/^######[ \t]+([^\n]+)[\n]*/\1/u/{_field=sectionMarker:#}{scope=push}{tenter=l5subsection,subsubsection} ---_mtable-regex-Markdown=subsubsection_sharp/.//{tjump=subsubsection} - ---_mtable-regex-Markdown=subsubsection/^#//{_advanceTo=0start}{tjump=subsubsection_sharp} ---_mtable-extend-Markdown=subsubsection+gfmLeave ---_mtable-extend-Markdown=subsubsection+code ---_mtable-extend-Markdown=subsubsection+rest - - -# -# L4subsection -# ---_mtable-regex-Markdown=l4subsection_sharp/(^#{1,5}[ \t]+[^\n]+)//{tleave}{_advanceTo=0start}{{ - 1 scopePopWithAdjustment -}} ---_mtable-regex-Markdown=l4subsection_sharp/^######[ \t]+([^\n]+)([ \t]+#+)[\n]*/\1/u/{_field=sectionMarker:##}{scope=push}{tenter=l5subsection,l4subsection} ---_mtable-regex-Markdown=l4subsection_sharp/^######[ \t]+([^\n]+)[\n]*/\1/u/{_field=sectionMarker:#}{scope=push}{tenter=l5subsection,l4subsection} ---_mtable-regex-Markdown=l4subsection_sharp/.//{tjump=l4subsection} - ---_mtable-regex-Markdown=l4subsection/^#//{_advanceTo=0start}{tjump=l4subsection_sharp} ---_mtable-extend-Markdown=l4subsection+gfmLeave ---_mtable-extend-Markdown=l4subsection+code ---_mtable-extend-Markdown=l4subsection+rest - - -# -# L5subsection -# ---_mtable-regex-Markdown=l5subsection_sharp/^#{1,6}[ \t]+([^\n]+)//{tleave}{_advanceTo=0start}{{ - 1 scopePopWithAdjustment -}} ---_mtable-regex-Markdown=l5subsection_sharp/.//{tjump=l5subsection} - ---_mtable-regex-Markdown=l5subsection/^#//{_advanceTo=0start}{tjump=l5subsection_sharp} ---_mtable-extend-Markdown=l5subsection+gfmLeave ---_mtable-extend-Markdown=l5subsection+code ---_mtable-extend-Markdown=l5subsection+rest - - -# -# Codeblock -# ---_mtable-regex-Markdown=codeblockBacktick/^[ \t]*````*[ \t]*[\n]//{tleave}{_guest=,,0start} ---_mtable-extend-Markdown=codeblockBacktick+rest - ---_mtable-regex-Markdown=codeblockTildes/^[ \t]*~~~~*[ \t]*[\n]//{tleave}{_guest=,,0start} ---_mtable-extend-Markdown=codeblockTildes+rest diff --git a/parsers/markdown.c b/parsers/markdown.c new file mode 100644 index 0000000000..f8b664a3a3 --- /dev/null +++ b/parsers/markdown.c @@ -0,0 +1,345 @@ +/* + * + * Copyright (c) 2007-2011, Nick Treleaven + * Copyright (c) 2012, Lex Trotman + * Copyright (c) 2021, Jiri Techet + * + * This source code is released for free distribution under the terms of the + * GNU General Public License version 2 or (at your option) any later version. + * + * This module contains functions for generating tags for markdown files. + * + * This parser was based on the asciidoc parser. + */ + +/* + * INCLUDE FILES + */ +#include "general.h" /* must always come first */ + +#include +#include + +#include "debug.h" +#include "entry.h" +#include "parse.h" +#include "read.h" +#include "vstring.h" +#include "nestlevel.h" +#include "routines.h" +#include "promise.h" +#include "htable.h" + +/* + * DATA DEFINITIONS + */ +typedef enum { + K_CHAPTER = 0, + K_SECTION, + K_SUBSECTION, + K_SUBSUBSECTION, + K_LEVEL4SECTION, + K_LEVEL5SECTION, + K_SECTION_COUNT, +} markdownKind; + +static kindDefinition MarkdownKinds[] = { + { true, 'c', "chapter", "chapters"}, + { true, 's', "section", "sections" }, + { true, 'S', "subsection", "level 2 sections" }, + { true, 't', "subsubsection", "level 3 sections" }, + { true, 'T', "l4subsection", "level 4 sections" }, + { true, 'u', "l5subsection", "level 5 sections" }, +}; + +static fieldDefinition MarkdownFields [] = { + { + .enabled = false, + .name = "sectionMarker", + .description = "character used for declaring section(#, ##, =, or -)", + }, +}; + +typedef enum { + F_MARKER, +} markdownField; + +static NestingLevels *nestingLevels = NULL; + +/* +* FUNCTION DEFINITIONS +*/ + +static NestingLevel *getNestingLevel (const int kind, unsigned long adjustmentWhenPop) +{ + NestingLevel *nl; + tagEntryInfo *e; + unsigned long line = getInputLineNumber (); + + line = (line > adjustmentWhenPop)? (line - adjustmentWhenPop): 0; + + while (1) + { + nl = nestingLevelsGetCurrent (nestingLevels); + e = getEntryOfNestingLevel (nl); + if ((nl && (e == NULL)) || (e && (e->kindIndex >= kind))) + nestingLevelsPopFull (nestingLevels, HT_UINT_TO_PTR ((unsigned int)line)); + else + break; + } + return nl; +} + + +static int makeMarkdownTag (const vString* const name, const int kind, const bool twoLine) +{ + int r = CORK_NIL; + + if (vStringLength (name) > 0) + { + const NestingLevel *const nl = getNestingLevel (kind, twoLine? 2: 1); + tagEntryInfo *parent = getEntryOfNestingLevel (nl); + tagEntryInfo e; + + initTagEntry (&e, vStringValue (name), kind); + + if (twoLine) + { + /* we want the line before the '---' underline chars */ + const unsigned long line = getInputLineNumber (); + Assert (line > 0); + if (line > 0) + { + e.lineNumber--; + e.filePosition = getInputFilePositionForLine (line - 1); + } + } + + if (parent && (parent->kindIndex < kind)) + e.extensionFields.scopeIndex = nl->corkIndex; + + r = makeTagEntry (&e); + } + return r; +} + + +static int makeSectionMarkdownTag (const vString* const name, const int kind, const char *marker) +{ + int r = makeMarkdownTag (name, kind, marker[0] != '#'); + attachParserFieldToCorkEntry (r, MarkdownFields [F_MARKER].ftype, marker); + + nestingLevelsPush (nestingLevels, r); + return r; +} + + +static vString *getHeading (const int kind, const unsigned char *line, + const int lineLen, bool *delimited) +{ + int pos = 0; + int start = kind + 1; + int end = lineLen - 1; + vString *name = vStringNew (); + + Assert (kind >= 0 && kind < K_SECTION_COUNT); + Assert (lineLen > start); + + *delimited = false; + while (isspace (line[pos])) ++pos; + while (line[end] == line[pos] && end - 1 >= 0 && line[end - 1] != '\\') + { + --end; + *delimited = true; + } + while (isspace (line[start])) ++start; + while (isspace (line[end])) --end; + + if (start <= end) + vStringNCatS (name, (const char*)(&(line[start])), end - start + 1); + + return name; +} + + +static int getFirstCharPos (const unsigned char *line, int lineLen, bool *indented) +{ + int indent = 0; + int i; + for (i = 0; i < lineLen && isspace (line[i]); i++) + indent += line[i] == '\t' ? 4 : 1; + *indented = indent >= 4; + return i; +} + + +static void fillEndField (NestingLevel *nl, void *ctxData) +{ + tagEntryInfo *e = getEntryOfNestingLevel (nl); + if (e) + { + unsigned long line = (unsigned long)(HT_PTR_TO_UINT (ctxData)); + e->extensionFields.endLine = line; + } +} + + +static void findMarkdownTags (void) +{ + vString *prevLine = vStringNew (); + vString *codeLang = vStringNew (); + const unsigned char *line; + char inCodeChar = 0; + long startSourceLineNumber = 0; + long startLineNumber = 0; + bool inPreambule = false; + bool inComment = false; + + nestingLevels = nestingLevelsNewFull (0, fillEndField); + + while ((line = readLineFromInputFile ()) != NULL) + { + int lineLen = strlen ((const char*) line); + bool lineProcessed = false; + bool indented; + int pos = getFirstCharPos (line, lineLen, &indented); + int lineNum = getInputLineNumber (); + + if (lineNum == 1 || inPreambule) + { + if (line[pos] == '-' && line[pos + 1] == '-' && line[pos + 2] == '-') + inPreambule = !inPreambule; + } + + if (inPreambule) + continue; + + /* fenced code block */ + if (line[pos] == '`' || line[pos] == '~') + { + char c = line[pos]; + char otherC = c == '`' ? '~' : '`'; + int nSame; + for (nSame = 1; line[nSame] == line[pos]; ++nSame); + + if (inCodeChar != otherC && nSame >= 3) + { + inCodeChar = inCodeChar ? 0 : c; + if (inCodeChar == c && strstr ((const char *)(line + pos + nSame), "```") != NULL) + inCodeChar = 0; + else if (inCodeChar) + { + startSourceLineNumber = getSourceLineNumber (); + startLineNumber = getInputLineNumber (); + vStringClear (codeLang); + vStringCatS (codeLang, (const char *)(line + pos + nSame)); + vStringStripLeading (codeLang); + vStringStripTrailing (codeLang); + } + else + { + long endLineNumber = getInputLineNumber () - 1; + if (codeLang->size > 0) + makePromise (vStringValue (codeLang), startLineNumber, 0, + endLineNumber, 0, startSourceLineNumber); + } + + lineProcessed = true; + } + } + /* XML comment start */ + else if (lineLen >= pos + 4 && line[pos] == '<' && line[pos + 1] == '!' && + line[pos + 2] == '-' && line[pos + 3] == '-') + { + if (strstr ((const char *)(line + pos + 4), "-->") == NULL) + inComment = true; + lineProcessed = true; + } + /* XML comment end */ + else if (inComment && strstr ((const char *)(line + pos), "-->")) + { + inComment = false; + lineProcessed = true; + } + + /* code block or comment */ + if (inCodeChar || inComment) + lineProcessed = true; + + /* code block using indent */ + else if (indented) + lineProcessed = true; + + /* if it's a title underline, or a delimited block marking character */ + else if (line[pos] == '=' || line[pos] == '-' || line[pos] == '#' || line[pos] == '>') + { + int nSame; + for (nSame = 1; line[nSame] == line[pos]; ++nSame); + + /* quote */ + if (line[pos] == '>') + ; /* just to make sure lineProcessed = true so it won't be in a heading */ + /* is it a two line title */ + else if (line[pos] == '=' || line[pos] == '-') + { + char marker[2] = { line[pos], '\0' }; + int kind = line[pos] == '=' ? K_CHAPTER : K_SECTION; + bool whitespaceTerminated = true; + + for (int i = pos + nSame; i < lineLen; i++) + { + if (!isspace (line[i])) + { + whitespaceTerminated = false; + break; + } + } + + vStringStripLeading (prevLine); + vStringStripTrailing (prevLine); + if (whitespaceTerminated && vStringLength (prevLine) > 0) + makeSectionMarkdownTag (prevLine, kind, marker); + } + /* otherwise is it a one line title */ + else if (line[pos] == '#' && nSame <= K_SECTION_COUNT && isspace (line[nSame])) + { + int kind = nSame - 1; + bool delimited = false; + vString *name = getHeading (kind, line, lineLen, &delimited); + if (vStringLength (name) > 0) + makeSectionMarkdownTag (name, kind, delimited ? "##" : "#"); + vStringDelete (name); + } + + lineProcessed = true; + } + + vStringClear (prevLine); + if (!lineProcessed) + vStringCatS (prevLine, (const char*) line); + } + vStringDelete (prevLine); + vStringDelete (codeLang); + { + unsigned int line = (unsigned int)getInputLineNumber (); + nestingLevelsFreeFull (nestingLevels, HT_UINT_TO_PTR (line)); + } +} + +extern parserDefinition* MarkdownParser (void) +{ + parserDefinition* const def = parserNew ("Markdown"); + static const char *const extensions [] = { "md", "markdown", NULL }; + + def->enabled = true; + def->extensions = extensions; + def->useCork = CORK_QUEUE; + def->kindTable = MarkdownKinds; + def->kindCount = ARRAY_SIZE (MarkdownKinds); + def->fieldTable = MarkdownFields; + def->fieldCount = ARRAY_SIZE (MarkdownFields); + def->defaultScopeSeparator = "\"\""; + def->parser = findMarkdownTags; + + return def; +} diff --git a/parsers/ruby.c b/parsers/ruby.c index 2aab8d94d7..2b2fd2594a 100644 --- a/parsers/ruby.c +++ b/parsers/ruby.c @@ -695,7 +695,7 @@ static void attachMixinField (int corkIndex, stringList *mixinSpec) vStringValue (mixinField)); } -static void deleteBlockData (NestingLevel *nl) +static void deleteBlockData (NestingLevel *nl, void *data CTAGS_ATTR_UNUSED) { struct blockData *bdata = nestingLevelGetUserData (nl); diff --git a/source.mak b/source.mak index 146c1da8bb..49ed3458e2 100644 --- a/source.mak +++ b/source.mak @@ -185,7 +185,6 @@ OPTLIB2C_INPUT = \ optlib/kconfig.ctags \ optlib/lex.ctags \ optlib/man.ctags \ - optlib/markdown.ctags \ optlib/meson.ctags \ optlib/mesonOptions.ctags \ optlib/passwd.ctags \ @@ -309,6 +308,7 @@ PARSER_SRCS = \ parsers/lua.c \ parsers/m4.c \ parsers/make.c \ + parsers/markdown.c \ parsers/matlab.c \ parsers/myrddin.c \ parsers/nsis.c \ diff --git a/win32/ctags_vs2013.vcxproj b/win32/ctags_vs2013.vcxproj index 3d8c728a5b..68c5767b42 100644 --- a/win32/ctags_vs2013.vcxproj +++ b/win32/ctags_vs2013.vcxproj @@ -240,7 +240,6 @@ - @@ -316,6 +315,7 @@ + diff --git a/win32/ctags_vs2013.vcxproj.filters b/win32/ctags_vs2013.vcxproj.filters index 859aeeed70..d75b65f6d0 100644 --- a/win32/ctags_vs2013.vcxproj.filters +++ b/win32/ctags_vs2013.vcxproj.filters @@ -243,9 +243,6 @@ Source Files\optlib - - Source Files\optlib - Source Files\optlib @@ -471,6 +468,9 @@ Source Files\parsers + + Source Files\parsers + Source Files\parsers