Skip to content

Commit 2c9ddba

Browse files
committed
Markdown: new parser
As requested in universal-ctags#1566 by @gwerbin. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
1 parent 43faa71 commit 2c9ddba

File tree

12 files changed

+293
-0
lines changed

12 files changed

+293
-0
lines changed

Tmain/list-fields-with-prefix.d/stdout-expected.txt

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ x UCTAGSxpath no NONE s-- no xpath for the
1111
- UCTAGStemplate no C++ s-- no template parameters
1212
- UCTAGSproperties no CUDA s-- no properties (static, inline, mutable,...)
1313
- UCTAGSassignment yes LdScript s-- no how a value is assigned to the symbol
14+
- UCTAGSsectionMarker no Markdown s-- no character used for declaring section(#, ##, =, or -)
1415
- UCTAGShome yes Passwd s-- no home directory
1516
- UCTAGSshell yes Passwd s-- no login shell
1617
- UCTAGSdecorators no Python s-- no decorators on functions and classes

Tmain/list-fields.d/stdout-expected.txt

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ z kind no NONE s-- no Include the "kind:" key in kind field (use k or K) in tags
2929
- template no C++ s-- no template parameters
3030
- properties no CUDA s-- no properties (static, inline, mutable,...)
3131
- assignment yes LdScript s-- no how a value is assigned to the symbol
32+
- sectionMarker no Markdown s-- no character used for declaring section(#, ##, =, or -)
3233
- home yes Passwd s-- no home directory
3334
- shell yes Passwd s-- no login shell
3435
- decorators no Python s-- no decorators on functions and classes

Units/simple-markdown.d/args.ctags

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--sort=no
2+
--fields-Markdown=+{sectionMarker}

Units/simple-markdown.d/expected.tags

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
a input.md /^# a$/;" c sectionMarker:#
2+
b input.md /^## b$/;" s sectionMarker:#
3+
c input.md /^### c$/;" S sectionMarker:#
4+
d input.md /^#### d$/;" t sectionMarker:#
5+
e input.md /^##### e$/;" T sectionMarker:#
6+
f input.md /^###### f$/;" u sectionMarker:#
7+
g input.md /^# g #$/;" c sectionMarker:##
8+
h input.md /^# h ##$/;" c sectionMarker:##
9+
i input.md /^## i #$/;" s sectionMarker:##
10+
j input.md /^## j ##$/;" s sectionMarker:##
11+
k input.md /^## k ###$/;" s sectionMarker:##
12+
l input.md /^### l #$/;" S sectionMarker:##
13+
m input.md /^### m ##$/;" S sectionMarker:##
14+
n input.md /^### n ###$/;" S sectionMarker:##
15+
o input.md /^### o ###$/;" S sectionMarker:##
16+
p input.md /^#### p #$/;" t sectionMarker:##
17+
q input.md /^#### q #####$/;" t sectionMarker:##
18+
r input.md /^##### r #$/;" T sectionMarker:##
19+
s input.md /^##### s ######$/;" T sectionMarker:##
20+
t input.md /^###### t #$/;" u sectionMarker:##
21+
u input.md /^###### u #######$/;" u sectionMarker:##
22+
A input.md /^A$/;" c sectionMarker:=
23+
B input.md /^B$/;" c sectionMarker:=
24+
C input.md /^C$/;" c sectionMarker:=
25+
D input.md /^D$/;" s sectionMarker:-
26+
E input.md /^E$/;" s sectionMarker:-
27+
F input.md /^F$/;" s sectionMarker:-

Units/simple-markdown.d/input.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# a
2+
3+
## b
4+
5+
### c
6+
7+
#### d
8+
9+
##### e
10+
11+
###### f
12+
13+
# g #
14+
# h ##
15+
16+
## i #
17+
## j ##
18+
## k ###
19+
20+
### l #
21+
### m ##
22+
### n ###
23+
### o ###
24+
25+
#### p #
26+
#### q #####
27+
28+
##### r #
29+
##### s ######
30+
31+
###### t #
32+
###### u #######
33+
34+
A
35+
=
36+
37+
B
38+
==
39+
40+
C
41+
===
42+
43+
D
44+
-
45+
46+
E
47+
--
48+
49+
F
50+
---
51+

docs/news.rst

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ The following parsers have been added:
5959
* JSON
6060
* GNU linker script(LdScript)
6161
* Man page *optlib*
62+
* Markdown *optlib*
6263
* Maven2 *libxml*
6364
* M4
6465
* ObjectiveC

main/parsers.h

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
M4Parser, \
8282
ManParser, \
8383
MakefileParser, \
84+
MarkdownParser, \
8485
MatLabParser, \
8586
MyrddinParser, \
8687
ObjcParser, \

makefiles/translator_input.mak

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ TRANSLATOR_INPUT = \
55
optlib/elm.ctags \
66
optlib/gdbinit.ctags \
77
optlib/man.ctags \
8+
optlib/markdown.ctags \
89
optlib/passwd.ctags \
910
optlib/pod.ctags \
1011
optlib/qemuhx.ctags \

optlib/markdown.c

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
* Generated by ./misc/optlib2c from optlib/markdown.ctags, Don't edit this manually.
3+
*/
4+
#include "general.h"
5+
#include "parse.h"
6+
#include "routines.h"
7+
8+
9+
static void initializeMarkdownParser (const langType language CTAGS_ATTR_UNUSED)
10+
{
11+
12+
addLanguageRegexTable (language, "main");
13+
addLanguageRegexTable (language, "sharp");
14+
15+
addLanguageTagMultiTableRegex (language, "main",
16+
"^#",
17+
"", "", "{tjump=sharp}{_advanceTo=0start}", NULL);
18+
addLanguageTagMultiTableRegex (language, "main",
19+
"^([^\n]+)[\n]=+[\n]",
20+
"\\1", "c", "{_field=sectionMarker:=}", NULL);
21+
addLanguageTagMultiTableRegex (language, "main",
22+
"^([^\n]+)[\n]-+[\n]",
23+
"\\1", "s", "{_field=sectionMarker:-}", NULL);
24+
addLanguageTagMultiTableRegex (language, "main",
25+
"^[^\n]+[\n]",
26+
"", "", "", NULL);
27+
addLanguageTagMultiTableRegex (language, "main",
28+
"^[\n]+",
29+
"", "", "", NULL);
30+
addLanguageTagMultiTableRegex (language, "main",
31+
"^[^\n]+",
32+
"", "", "", NULL);
33+
addLanguageTagMultiTableRegex (language, "sharp",
34+
"^#[ \t]+([^\n]+)([ \t]+#+)[\n]",
35+
"\\1", "c", "{_field=sectionMarker:##}{tjump=main}", NULL);
36+
addLanguageTagMultiTableRegex (language, "sharp",
37+
"^##[ \t]+([^\n]+)([ \t]+#+)[\n]",
38+
"\\1", "s", "{_field=sectionMarker:##}{tjump=main}", NULL);
39+
addLanguageTagMultiTableRegex (language, "sharp",
40+
"^###[ \t]+([^\n]+)([ \t]+#+)[\n]",
41+
"\\1", "S", "{_field=sectionMarker:##}{tjump=main}", NULL);
42+
addLanguageTagMultiTableRegex (language, "sharp",
43+
"^####[ \t]+([^\n]+)([ \t]+#+)[\n]",
44+
"\\1", "t", "{_field=sectionMarker:##}{tjump=main}", NULL);
45+
addLanguageTagMultiTableRegex (language, "sharp",
46+
"^#####[ \t]+([^\n]+)([ \t]+#+)[\n]",
47+
"\\1", "T", "{_field=sectionMarker:##}{tjump=main}", NULL);
48+
addLanguageTagMultiTableRegex (language, "sharp",
49+
"^######[ \t]+([^\n]+)([ \t]+#+)[\n]",
50+
"\\1", "u", "{_field=sectionMarker:##}{tjump=main}", NULL);
51+
addLanguageTagMultiTableRegex (language, "sharp",
52+
"^#[ \t]+([^\n]+)[\n]",
53+
"\\1", "c", "{_field=sectionMarker:#}{tjump=main}", NULL);
54+
addLanguageTagMultiTableRegex (language, "sharp",
55+
"^##[ \t]+([^\n]+)[\n]",
56+
"\\1", "s", "{_field=sectionMarker:#}{tjump=main}", NULL);
57+
addLanguageTagMultiTableRegex (language, "sharp",
58+
"^###[ \t]+([^\n]+)[\n]",
59+
"\\1", "S", "{_field=sectionMarker:#}{tjump=main}", NULL);
60+
addLanguageTagMultiTableRegex (language, "sharp",
61+
"^####[ \t]+([^\n]+)[\n]",
62+
"\\1", "t", "{_field=sectionMarker:#}{tjump=main}", NULL);
63+
addLanguageTagMultiTableRegex (language, "sharp",
64+
"^#####[ \t]+([^\n]+)[\n]",
65+
"\\1", "T", "{_field=sectionMarker:#}{tjump=main}", NULL);
66+
addLanguageTagMultiTableRegex (language, "sharp",
67+
"^######[ \t]+([^\n]+)[\n]",
68+
"\\1", "u", "{_field=sectionMarker:#}{tjump=main}", NULL);
69+
addLanguageTagMultiTableRegex (language, "sharp",
70+
"^[^\n]+[\n]",
71+
"", "", "{tjump=main}", NULL);
72+
addLanguageTagMultiTableRegex (language, "sharp",
73+
"^[\n]+",
74+
"", "", "{tjump=main}", NULL);
75+
addLanguageTagMultiTableRegex (language, "sharp",
76+
"^[^\n]+",
77+
"", "", "{tjump=main}", NULL);
78+
}
79+
80+
extern parserDefinition* MarkdownParser (void)
81+
{
82+
static const char *const extensions [] = {
83+
"md",
84+
NULL
85+
};
86+
87+
static const char *const aliases [] = {
88+
NULL
89+
};
90+
91+
static const char *const patterns [] = {
92+
NULL
93+
};
94+
95+
static kindDefinition MarkdownKindTable [] = {
96+
{
97+
true, 'c', "chapter", "chapsters",
98+
},
99+
{
100+
true, 's', "section", "sections",
101+
},
102+
{
103+
true, 'S', "subsection", "subsections",
104+
},
105+
{
106+
true, 't', "subsubsection", "subsubsections",
107+
},
108+
{
109+
true, 'T', "l4subsection", "level 4 subsections",
110+
},
111+
{
112+
true, 'u', "l5subsection", "level 5 subsections",
113+
},
114+
};
115+
static fieldDefinition MarkdownFieldTable [] = {
116+
{
117+
.enabled = false,
118+
.name = "sectionMarker",
119+
.description = "character used for declaring section(#, ##, =, or -)",
120+
},
121+
};
122+
123+
parserDefinition* const def = parserNew ("Markdown");
124+
125+
def->enabled = true;
126+
def->extensions = extensions;
127+
def->patterns = patterns;
128+
def->aliases = aliases;
129+
def->method = METHOD_NOT_CRAFTED|METHOD_REGEX;
130+
def->kindTable = MarkdownKindTable;
131+
def->kindCount = ARRAY_SIZE(MarkdownKindTable);
132+
def->fieldTable = MarkdownFieldTable;
133+
def->fieldCount = ARRAY_SIZE(MarkdownFieldTable);
134+
def->initialize = initializeMarkdownParser;
135+
136+
return def;
137+
}

optlib/markdown.ctags

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#
2+
#
3+
# Copyright (c) 2018, Red Hat, Inc.
4+
# Copyright (c) 2018, Masatake YAMATO
5+
#
6+
# Author: Masatake YAMATO <yamato@redhat.com>
7+
#
8+
# This program is free software; you can redistribute it and/or
9+
# modify it under the terms of the GNU General Public License
10+
# as published by the Free Software Foundation; either version 2
11+
# of the License, or (at your option) any later version.
12+
#
13+
# This program is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
# GNU General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU General Public License
19+
# along with this program; if not, write to the Free Software
20+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21+
# USA.
22+
#
23+
#
24+
25+
#
26+
# TODO: Tracking the scope
27+
#
28+
29+
--langdef=Markdown
30+
--map-Markdown=+.md
31+
32+
--kinddef-Markdown=c,chapter,chapsters
33+
--kinddef-Markdown=s,section,sections
34+
--kinddef-Markdown=S,subsection,subsections
35+
--kinddef-Markdown=t,subsubsection,subsubsections
36+
--kinddef-Markdown=T,l4subsection,level 4 subsections
37+
--kinddef-Markdown=u,l5subsection,level 5 subsections
38+
39+
--_fielddef-Markdown=sectionMarker,character used for declaring section(#, ##, =, or -)
40+
41+
--_tabledef-Markdown=main
42+
--_tabledef-Markdown=sharp
43+
44+
45+
--_mtable-regex-Markdown=main/^#///{tjump=sharp}{_advanceTo=0start}
46+
--_mtable-regex-Markdown=main/^([^\n]+)[\n]=+[\n]/\1/c/{_field=sectionMarker:=}
47+
--_mtable-regex-Markdown=main/^([^\n]+)[\n]-+[\n]/\1/s/{_field=sectionMarker:-}
48+
--_mtable-regex-Markdown=main/^[^\n]+[\n]//
49+
--_mtable-regex-Markdown=main/[\n]+//
50+
--_mtable-regex-Markdown=main/^[^\n]+//
51+
52+
53+
--_mtable-regex-Markdown=sharp/^#[ \t]+([^\n]+)([ \t]+#+)[\n]/\1/c/{_field=sectionMarker:##}{tjump=main}
54+
--_mtable-regex-Markdown=sharp/^##[ \t]+([^\n]+)([ \t]+#+)[\n]/\1/s/{_field=sectionMarker:##}{tjump=main}
55+
--_mtable-regex-Markdown=sharp/^###[ \t]+([^\n]+)([ \t]+#+)[\n]/\1/S/{_field=sectionMarker:##}{tjump=main}
56+
--_mtable-regex-Markdown=sharp/^####[ \t]+([^\n]+)([ \t]+#+)[\n]/\1/t/{_field=sectionMarker:##}{tjump=main}
57+
--_mtable-regex-Markdown=sharp/^#####[ \t]+([^\n]+)([ \t]+#+)[\n]/\1/T/{_field=sectionMarker:##}{tjump=main}
58+
--_mtable-regex-Markdown=sharp/^######[ \t]+([^\n]+)([ \t]+#+)[\n]/\1/u/{_field=sectionMarker:##}{tjump=main}
59+
--_mtable-regex-Markdown=sharp/^#[ \t]+([^\n]+)[\n]/\1/c/{_field=sectionMarker:#}{tjump=main}
60+
--_mtable-regex-Markdown=sharp/^##[ \t]+([^\n]+)[\n]/\1/s/{_field=sectionMarker:#}{tjump=main}
61+
--_mtable-regex-Markdown=sharp/^###[ \t]+([^\n]+)[\n]/\1/S/{_field=sectionMarker:#}{tjump=main}
62+
--_mtable-regex-Markdown=sharp/^####[ \t]+([^\n]+)[\n]/\1/t/{_field=sectionMarker:#}{tjump=main}
63+
--_mtable-regex-Markdown=sharp/^#####[ \t]+([^\n]+)[\n]/\1/T/{_field=sectionMarker:#}{tjump=main}
64+
--_mtable-regex-Markdown=sharp/^######[ \t]+([^\n]+)[\n]/\1/u/{_field=sectionMarker:#}{tjump=main}
65+
--_mtable-regex-Markdown=sharp/^[^\n]+[\n]//{tjump=main}
66+
--_mtable-regex-Markdown=sharp/[\n]+//{tjump=main}
67+
--_mtable-regex-Markdown=sharp/^[^\n]+//{tjump=main}

win32/ctags_vs2013.vcxproj

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
<ClCompile Include="..\optlib\elm.c" />
144144
<ClCompile Include="..\optlib\gdbinit.c" />
145145
<ClCompile Include="..\optlib\man.c" />
146+
<ClCompile Include="..\optlib\markdown.c" />
146147
<ClCompile Include="..\optlib\passwd.c" />
147148
<ClCompile Include="..\optlib\pod.c" />
148149
<ClCompile Include="..\optlib\puppetManifest.c" />

win32/ctags_vs2013.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@
183183
<ClCompile Include="..\optlib\man.c">
184184
<Filter>Source Files\optlib</Filter>
185185
</ClCompile>
186+
<ClCompile Include="..\optlib\markdown.c">
187+
<Filter>Source Files\optlib</Filter>
188+
</ClCompile>
186189
<ClCompile Include="..\optlib\passwd.c">
187190
<Filter>Source Files\optlib</Filter>
188191
</ClCompile>

0 commit comments

Comments
 (0)