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:
Michael Teichgräber 2013-01-23 22:35:43 +01:00
parent 6bfe7a1a46
commit e5cc35f577
2 changed files with 9 additions and 21 deletions

View File

@ -529,27 +529,19 @@ UlOrStarLine = (UlLine | StarLine) { $$ = p.mkString(yytext) }
StarLine = < "****" '*'* > | < Spacechar '*'+ &Spacechar > StarLine = < "****" '*'* > | < Spacechar '*'+ &Spacechar >
UlLine = < "____" '_'* > | < 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 Emph = EmphStar | EmphUl
EmphStar = '*' EmphStar = '*' &Nonspacechar
a:StartList a:StartList
( !'*' b:NonspaceInline { a = cons(b, a) } ( !'*' b:Inline { a = cons(b, a) }
| b:SpaceInline { a = cons(b, a) }
| b:StrongStar { a = cons(b, a) } | b:StrongStar { a = cons(b, a) }
)+ )+
'*' '*'
{ $$ = p.mkList(EMPH, a) } { $$ = p.mkList(EMPH, a) }
EmphUl = '_' EmphUl = '_' &Nonspacechar
a:StartList a:StartList
( !'_' b:NonspaceInline { a = cons(b, a) } ( !'_' b:Inline { a = cons(b, a) }
| b:SpaceInline { a = cons(b, a) }
| b:StrongUl { a = cons(b, a) } | b:StrongUl { a = cons(b, a) }
)+ )+
'_' '_'
@ -557,19 +549,15 @@ EmphUl = '_'
Strong = StrongStar | StrongUl Strong = StrongStar | StrongUl
StrongStar = "**" StrongStar = "**" &Nonspacechar
a:StartList a:StartList
( !"**" b:NonspaceInline { a = cons(b, a) } ( !"**" b:Inline { a = cons(b, a) })+
| b:SpaceInline { a = cons(b, a) }
)+
"**" "**"
{ $$ = p.mkList(STRONG, a) } { $$ = p.mkList(STRONG, a) }
StrongUl = "__" StrongUl = "__" &Nonspacechar
a:StartList a:StartList
( !"__" b:NonspaceInline { a = cons(b, a) } ( !"__" b:Inline { a = cons(b, a) })+
| b:SpaceInline { a = cons(b, a) }
)+
"__" "__"
{ $$ = p.mkList(STRONG, a) } { $$ = p.mkList(STRONG, a) }

2
portid
View File

@ -1 +1 @@
195 196