Rewrote Emph/Strong parsers to avoid exponential blowup. [jgm/peg-markdown]
See https://github.com/jgm/peg-markdown/commit/39dfc1c
This commit is contained in:
parent
6bfe7a1a46
commit
e5cc35f577
28
parser.leg
28
parser.leg
@ -529,27 +529,19 @@ UlOrStarLine = (UlLine | StarLine) { $$ = p.mkString(yytext) }
|
||||
StarLine = < "****" '*'* > | < Spacechar '*'+ &Spacechar >
|
||||
UlLine = < "____" '_'* > | < Spacechar '_'+ &Spacechar >
|
||||
|
||||
SpaceInline = a:StartList
|
||||
( (b:Space | b:Endline) { a = cons(b, a) } )+
|
||||
c:Inline { a = cons(c, a); $$ = p.mkList(LIST, a) }
|
||||
|
||||
NonspaceInline = !Spacechar !Newline Inline
|
||||
|
||||
Emph = EmphStar | EmphUl
|
||||
|
||||
EmphStar = '*'
|
||||
EmphStar = '*' &Nonspacechar
|
||||
a:StartList
|
||||
( !'*' b:NonspaceInline { a = cons(b, a) }
|
||||
| b:SpaceInline { a = cons(b, a) }
|
||||
( !'*' b:Inline { a = cons(b, a) }
|
||||
| b:StrongStar { a = cons(b, a) }
|
||||
)+
|
||||
'*'
|
||||
{ $$ = p.mkList(EMPH, a) }
|
||||
|
||||
EmphUl = '_'
|
||||
EmphUl = '_' &Nonspacechar
|
||||
a:StartList
|
||||
( !'_' b:NonspaceInline { a = cons(b, a) }
|
||||
| b:SpaceInline { a = cons(b, a) }
|
||||
( !'_' b:Inline { a = cons(b, a) }
|
||||
| b:StrongUl { a = cons(b, a) }
|
||||
)+
|
||||
'_'
|
||||
@ -557,19 +549,15 @@ EmphUl = '_'
|
||||
|
||||
Strong = StrongStar | StrongUl
|
||||
|
||||
StrongStar = "**"
|
||||
StrongStar = "**" &Nonspacechar
|
||||
a:StartList
|
||||
( !"**" b:NonspaceInline { a = cons(b, a) }
|
||||
| b:SpaceInline { a = cons(b, a) }
|
||||
)+
|
||||
( !"**" b:Inline { a = cons(b, a) })+
|
||||
"**"
|
||||
{ $$ = p.mkList(STRONG, a) }
|
||||
|
||||
StrongUl = "__"
|
||||
StrongUl = "__" &Nonspacechar
|
||||
a:StartList
|
||||
( !"__" b:NonspaceInline { a = cons(b, a) }
|
||||
| b:SpaceInline { a = cons(b, a) }
|
||||
)+
|
||||
( !"__" b:Inline { a = cons(b, a) })+
|
||||
"__"
|
||||
{ $$ = p.mkList(STRONG, a) }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user