forked from NimbusKit/markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
markdown.grammar
72 lines (61 loc) · 2.72 KB
/
markdown.grammar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
%option case-insensitive
%option reentrant
/*
match unicode characters as one rule instead of each byte.
http://stackoverflow.com/questions/10252777/making-lex-to-read-utf-8-doesnt-work?lq=1
*/
u2a [\xC2-\xDF][\x80-\xBF]
u2b \xE0[\xA0-\xBF][\x80-\xBF]
u3a [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}
u3b \xED[\x80-\x9F][\x80-\xBF]
u4a \xF0[\x90-\xBF][\x80-\xBF]{2}
u4b [\xF1-\xF3][\x80-\xBF]{3}
u4c \xF4[\x80-\x8F][\x80-\xBF]{2}
utf_8 {u2a}|{u2b}|{u3a}|{u3b}|{u4a}|{u4b}|{u4c}
h [0-9a-f]
nonascii [\200-\377]
unicode \\{h}{1,6}[ \t\r\n\f]?
escape {unicode}|\\[ -~\200-\377]
nmchar [a-z0-9-]|{nonascii}|{escape}
em1 \*[^(\n|\*)]+\*
strong1 \*\*[^\*]*\*\*
strongem1 \*\*\*[^\*]*\*\*\*
em2 _[^_]*_
strong2 __[^_]*__
strongem2 ___[^_]*___
header1 ^#{1,6}.*
header2 .+\n[=-]+\n
bulletstart ^[-\+*]+[ ]
blockquote ^>+
codeline [ ]
protocol (http|ftp)s?\:\/\/
subdomain {nmchar}\.
urlpath [\/]|{nmchar}+
protourl {protocol}[^ \n]+
optprotourl {protocol}?{subdomain}*{nmchar}+\.{nmchar}+{urlpath}*?
href \[.+\]\(.+\)
em {em1}|{em2}
strong {strong1}|{strong2}
strongem {strongem1}|{strongem2}
strikethrough ~~.*?~~
url {protourl}|{optprotourl}
w [ \t\r\n\f]*
nl \n|\r\n|\r|\f
%%
{em} {markdownConsume(yytext, MARKDOWNEM, yyscanner);}
{strong} {markdownConsume(yytext, MARKDOWNSTRONG, yyscanner);}
{strongem} {markdownConsume(yytext, MARKDOWNSTRONGEM, yyscanner);}
{strikethrough} {markdownConsume(yytext, MARKDOWNSTRIKETHROUGH, yyscanner);}
{header1} {markdownConsume(yytext, MARKDOWNHEADER, yyscanner);}
{header2} {markdownConsume(yytext, MARKDOWNMULTILINEHEADER, yyscanner);}
{url} {markdownConsume(yytext, MARKDOWNURL, yyscanner);}
{href} {markdownConsume(yytext, MARKDOWNHREF, yyscanner);}
{bulletstart} {markdownConsume(yytext, MARKDOWNBULLETSTART, yyscanner);}
{blockquote} {markdownConsume(yytext, MARKDOWNBLOCKQUOTE, yyscanner);}
[ ]{2,}$ {markdownConsume(yytext, MARKDOWNNEWLINE, yyscanner);}
[\n]{2,} {markdownConsume(yytext, MARKDOWNPARAGRAPH, yyscanner);}
[ \n\t\f] {markdownConsume(yytext, MARKDOWNUNKNOWN, yyscanner);}
{utf_8} {markdownConsume(yytext, MARKDOWNUNKNOWN, yyscanner);}
. {markdownConsume(yytext, MARKDOWNUNKNOWN, yyscanner);}
%%
int markdownwrap(yyscan_t yyscanner){return 1;}