Skip to content

Commit

Permalink
Markdown: new parser
Browse files Browse the repository at this point in the history
As requested in universal-ctags#1566 by @gwerbin.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Apr 24, 2018
1 parent 174253f commit 0793bfc
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 0 deletions.
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 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
137 changes: 137 additions & 0 deletions optlib/markdown.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* 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",
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;
}
67 changes: 67 additions & 0 deletions optlib/markdown.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#
#
# Copyright (c) 2018, Red Hat, Inc.
# Copyright (c) 2018, Masatake YAMATO
#
# Author: Masatake YAMATO <yamato@redhat.com>
#
# 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

--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

0 comments on commit 0793bfc

Please sign in to comment.