Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown parser #1727

Merged
merged 3 commits into from
Apr 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Tmain/list-fields-with-prefix.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ x UCTAGSxpath no NONE s-- no xpath for the
- UCTAGStemplate no C++ s-- no template parameters
- UCTAGSproperties no CUDA s-- no properties (static, inline, mutable,...)
- UCTAGSassignment yes LdScript s-- no how a value is assigned to the symbol
- UCTAGSsectionMarker no Markdown s-- no character used for declaring section(#, ##, =, or -)
- UCTAGShome yes Passwd s-- no home directory
- UCTAGSshell yes Passwd s-- no login shell
- UCTAGSdecorators no Python s-- no decorators on functions and classes
Expand Down
1 change: 1 addition & 0 deletions Tmain/list-fields.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ z kind no NONE s-- no Include the "kind:" key in kind field (use k or K) in tags
- template no C++ s-- no template parameters
- properties no CUDA s-- no properties (static, inline, mutable,...)
- assignment yes LdScript s-- no how a value is assigned to the symbol
- sectionMarker no Markdown s-- no character used for declaring section(#, ##, =, or -)
- home yes Passwd s-- no home directory
- shell yes Passwd s-- no login shell
- decorators no Python s-- no decorators on functions and classes
Expand Down
2 changes: 2 additions & 0 deletions Units/simple-markdown.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--sort=no
--fields-Markdown=+{sectionMarker}
27 changes: 27 additions & 0 deletions Units/simple-markdown.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
a input.md /^# a$/;" c sectionMarker:#
b input.md /^## b$/;" s sectionMarker:#
c input.md /^### c$/;" S sectionMarker:#
d input.md /^#### d$/;" t sectionMarker:#
e input.md /^##### e$/;" T sectionMarker:#
f input.md /^###### f$/;" u sectionMarker:#
g input.md /^# g #$/;" c sectionMarker:##
h input.md /^# h ##$/;" c sectionMarker:##
i input.md /^## i #$/;" s sectionMarker:##
j input.md /^## j ##$/;" s sectionMarker:##
k input.md /^## k ###$/;" s sectionMarker:##
l input.md /^### l #$/;" S sectionMarker:##
m input.md /^### m ##$/;" S sectionMarker:##
n input.md /^### n ###$/;" S sectionMarker:##
o input.md /^### o ###$/;" S sectionMarker:##
p input.md /^#### p #$/;" t sectionMarker:##
q input.md /^#### q #####$/;" t sectionMarker:##
r input.md /^##### r #$/;" T sectionMarker:##
s input.md /^##### s ######$/;" T sectionMarker:##
t input.md /^###### t #$/;" u sectionMarker:##
u input.md /^###### u #######$/;" u sectionMarker:##
A input.md /^A$/;" c sectionMarker:=
B input.md /^B$/;" c sectionMarker:=
C input.md /^C$/;" c sectionMarker:=
D input.md /^D$/;" s sectionMarker:-
E input.md /^E$/;" s sectionMarker:-
F input.md /^F$/;" s sectionMarker:-
51 changes: 51 additions & 0 deletions Units/simple-markdown.d/input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# a

## b

### c

#### d

##### e

###### f

# g #
# h ##

## i #
## j ##
## k ###

### l #
### m ##
### n ###
### o ###

#### p #
#### q #####

##### r #
##### s ######

###### t #
###### u #######

A
=

B
==

C
===

D
-

E
--

F
---

1 change: 1 addition & 0 deletions Units/simple-passwd.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--map-passwd=+.passwd
2 changes: 2 additions & 0 deletions Units/simple-passwd.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin input.passwd /^bin:x:1:1:bin:\/bin:\/sbin\/nologin$/;" u home:/bin shell:/sbin/nologin
root input.passwd /^root:x:0:0:root:\/root:\/bin\/bash$/;" u home:/root shell:/bin/bash
2 changes: 2 additions & 0 deletions Units/simple-passwd.d/input.passwd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
1 change: 1 addition & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ The following parsers have been added:
* JSON
* GNU linker script(LdScript)
* Man page *optlib*
* Markdown *optlib*
* Maven2 *libxml*
* M4
* ObjectiveC
Expand Down
1 change: 1 addition & 0 deletions main/parsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
M4Parser, \
ManParser, \
MakefileParser, \
MarkdownParser, \
MatLabParser, \
MyrddinParser, \
ObjcParser, \
Expand Down
1 change: 1 addition & 0 deletions makefiles/translator_input.mak
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ TRANSLATOR_INPUT = \
optlib/elm.ctags \
optlib/gdbinit.ctags \
optlib/man.ctags \
optlib/markdown.ctags \
optlib/passwd.ctags \
optlib/pod.ctags \
optlib/qemuhx.ctags \
Expand Down
138 changes: 138 additions & 0 deletions optlib/markdown.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* Generated by ./misc/optlib2c from optlib/markdown.ctags, Don't edit this manually.
*/
#include "general.h"
#include "parse.h"
#include "routines.h"


static void initializeMarkdownParser (const langType language CTAGS_ATTR_UNUSED)
{

addLanguageRegexTable (language, "main");
addLanguageRegexTable (language, "sharp");

addLanguageTagMultiTableRegex (language, "main",
"^#",
"", "", "{tjump=sharp}{_advanceTo=0start}", NULL);
addLanguageTagMultiTableRegex (language, "main",
"^([^\n]+)[\n]=+[\n]",
"\\1", "c", "{_field=sectionMarker:=}", NULL);
addLanguageTagMultiTableRegex (language, "main",
"^([^\n]+)[\n]-+[\n]",
"\\1", "s", "{_field=sectionMarker:-}", NULL);
addLanguageTagMultiTableRegex (language, "main",
"^[^\n]+[\n]",
"", "", "", NULL);
addLanguageTagMultiTableRegex (language, "main",
"^[\n]+",
"", "", "", NULL);
addLanguageTagMultiTableRegex (language, "main",
"^[^\n]+",
"", "", "", NULL);
addLanguageTagMultiTableRegex (language, "sharp",
"^#[ \t]+([^\n]+)([ \t]+#+)[\n]",
"\\1", "c", "{_field=sectionMarker:##}{tjump=main}", NULL);
addLanguageTagMultiTableRegex (language, "sharp",
"^##[ \t]+([^\n]+)([ \t]+#+)[\n]",
"\\1", "s", "{_field=sectionMarker:##}{tjump=main}", NULL);
addLanguageTagMultiTableRegex (language, "sharp",
"^###[ \t]+([^\n]+)([ \t]+#+)[\n]",
"\\1", "S", "{_field=sectionMarker:##}{tjump=main}", NULL);
addLanguageTagMultiTableRegex (language, "sharp",
"^####[ \t]+([^\n]+)([ \t]+#+)[\n]",
"\\1", "t", "{_field=sectionMarker:##}{tjump=main}", NULL);
addLanguageTagMultiTableRegex (language, "sharp",
"^#####[ \t]+([^\n]+)([ \t]+#+)[\n]",
"\\1", "T", "{_field=sectionMarker:##}{tjump=main}", NULL);
addLanguageTagMultiTableRegex (language, "sharp",
"^######[ \t]+([^\n]+)([ \t]+#+)[\n]",
"\\1", "u", "{_field=sectionMarker:##}{tjump=main}", NULL);
addLanguageTagMultiTableRegex (language, "sharp",
"^#[ \t]+([^\n]+)[\n]",
"\\1", "c", "{_field=sectionMarker:#}{tjump=main}", NULL);
addLanguageTagMultiTableRegex (language, "sharp",
"^##[ \t]+([^\n]+)[\n]",
"\\1", "s", "{_field=sectionMarker:#}{tjump=main}", NULL);
addLanguageTagMultiTableRegex (language, "sharp",
"^###[ \t]+([^\n]+)[\n]",
"\\1", "S", "{_field=sectionMarker:#}{tjump=main}", NULL);
addLanguageTagMultiTableRegex (language, "sharp",
"^####[ \t]+([^\n]+)[\n]",
"\\1", "t", "{_field=sectionMarker:#}{tjump=main}", NULL);
addLanguageTagMultiTableRegex (language, "sharp",
"^#####[ \t]+([^\n]+)[\n]",
"\\1", "T", "{_field=sectionMarker:#}{tjump=main}", NULL);
addLanguageTagMultiTableRegex (language, "sharp",
"^######[ \t]+([^\n]+)[\n]",
"\\1", "u", "{_field=sectionMarker:#}{tjump=main}", NULL);
addLanguageTagMultiTableRegex (language, "sharp",
"^[^\n]+[\n]",
"", "", "{tjump=main}", NULL);
addLanguageTagMultiTableRegex (language, "sharp",
"^[\n]+",
"", "", "{tjump=main}", NULL);
addLanguageTagMultiTableRegex (language, "sharp",
"^[^\n]+",
"", "", "{tjump=main}", 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->kindTable = MarkdownKindTable;
def->kindCount = ARRAY_SIZE(MarkdownKindTable);
def->fieldTable = MarkdownFieldTable;
def->fieldCount = ARRAY_SIZE(MarkdownFieldTable);
def->initialize = initializeMarkdownParser;

return def;
}
68 changes: 68 additions & 0 deletions optlib/markdown.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#
#
# Copyright (c) 2018, Red Hat, Inc.
# Copyright (c) 2018, Masatake YAMATO
#
# Author: Masatake YAMATO <[email protected]>
#
# 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.
#
#

#
# TODO: Tracking the scope
#

--langdef=Markdown
--map-Markdown=+.md
--map-Markdown=+.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 -)

--_tabledef-Markdown=main
--_tabledef-Markdown=sharp


--_mtable-regex-Markdown=main/^#///{tjump=sharp}{_advanceTo=0start}
--_mtable-regex-Markdown=main/^([^\n]+)[\n]=+[\n]/\1/c/{_field=sectionMarker:=}
--_mtable-regex-Markdown=main/^([^\n]+)[\n]-+[\n]/\1/s/{_field=sectionMarker:-}
--_mtable-regex-Markdown=main/^[^\n]+[\n]//
--_mtable-regex-Markdown=main/[\n]+//
--_mtable-regex-Markdown=main/^[^\n]+//


--_mtable-regex-Markdown=sharp/^#[ \t]+([^\n]+)([ \t]+#+)[\n]/\1/c/{_field=sectionMarker:##}{tjump=main}
--_mtable-regex-Markdown=sharp/^##[ \t]+([^\n]+)([ \t]+#+)[\n]/\1/s/{_field=sectionMarker:##}{tjump=main}
--_mtable-regex-Markdown=sharp/^###[ \t]+([^\n]+)([ \t]+#+)[\n]/\1/S/{_field=sectionMarker:##}{tjump=main}
--_mtable-regex-Markdown=sharp/^####[ \t]+([^\n]+)([ \t]+#+)[\n]/\1/t/{_field=sectionMarker:##}{tjump=main}
--_mtable-regex-Markdown=sharp/^#####[ \t]+([^\n]+)([ \t]+#+)[\n]/\1/T/{_field=sectionMarker:##}{tjump=main}
--_mtable-regex-Markdown=sharp/^######[ \t]+([^\n]+)([ \t]+#+)[\n]/\1/u/{_field=sectionMarker:##}{tjump=main}
--_mtable-regex-Markdown=sharp/^#[ \t]+([^\n]+)[\n]/\1/c/{_field=sectionMarker:#}{tjump=main}
--_mtable-regex-Markdown=sharp/^##[ \t]+([^\n]+)[\n]/\1/s/{_field=sectionMarker:#}{tjump=main}
--_mtable-regex-Markdown=sharp/^###[ \t]+([^\n]+)[\n]/\1/S/{_field=sectionMarker:#}{tjump=main}
--_mtable-regex-Markdown=sharp/^####[ \t]+([^\n]+)[\n]/\1/t/{_field=sectionMarker:#}{tjump=main}
--_mtable-regex-Markdown=sharp/^#####[ \t]+([^\n]+)[\n]/\1/T/{_field=sectionMarker:#}{tjump=main}
--_mtable-regex-Markdown=sharp/^######[ \t]+([^\n]+)[\n]/\1/u/{_field=sectionMarker:#}{tjump=main}
--_mtable-regex-Markdown=sharp/^[^\n]+[\n]//{tjump=main}
--_mtable-regex-Markdown=sharp/[\n]+//{tjump=main}
--_mtable-regex-Markdown=sharp/^[^\n]+//{tjump=main}
1 change: 1 addition & 0 deletions win32/ctags_vs2013.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
<ClCompile Include="..\optlib\elm.c" />
<ClCompile Include="..\optlib\gdbinit.c" />
<ClCompile Include="..\optlib\man.c" />
<ClCompile Include="..\optlib\markdown.c" />
<ClCompile Include="..\optlib\passwd.c" />
<ClCompile Include="..\optlib\pod.c" />
<ClCompile Include="..\optlib\puppetManifest.c" />
Expand Down
3 changes: 3 additions & 0 deletions win32/ctags_vs2013.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@
<ClCompile Include="..\optlib\man.c">
<Filter>Source Files\optlib</Filter>
</ClCompile>
<ClCompile Include="..\optlib\markdown.c">
<Filter>Source Files\optlib</Filter>
</ClCompile>
<ClCompile Include="..\optlib\passwd.c">
<Filter>Source Files\optlib</Filter>
</ClCompile>
Expand Down