Improved strong/emph parsers to avoid exponential blowup. [jgm/peg-markdown]
See https://github.com/jgm/peg-markdown/commit/c59e682
This commit is contained in:
parent
f42048b731
commit
54cb06d41a
56
parser.leg
56
parser.leg
@ -529,45 +529,49 @@ 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
|
||||||
|
|
||||||
OneStarOpen = !StarLine '*' !Spacechar !Newline
|
EmphStar = '*'
|
||||||
OneStarClose = !Spacechar !Newline a:Inline '*' { $$ = a }
|
|
||||||
|
|
||||||
EmphStar = OneStarOpen
|
|
||||||
a:StartList
|
a:StartList
|
||||||
( !OneStarClose Inline { a = cons($$, a) } )*
|
( !'*' b:NonspaceInline { a = cons(b, a) }
|
||||||
OneStarClose { a = cons($$, a) }
|
| b:SpaceInline { a = cons(b, a) }
|
||||||
|
| b:StrongStar { a = cons(b, a) }
|
||||||
|
)+
|
||||||
|
'*'
|
||||||
{ $$ = p.mkList(EMPH, a) }
|
{ $$ = p.mkList(EMPH, a) }
|
||||||
|
|
||||||
OneUlOpen = !UlLine '_' !Spacechar !Newline
|
EmphUl = '_'
|
||||||
OneUlClose = !Spacechar !Newline a:Inline '_' !Alphanumeric { $$ = a }
|
|
||||||
|
|
||||||
EmphUl = OneUlOpen
|
|
||||||
a:StartList
|
a:StartList
|
||||||
( !OneUlClose Inline { a = cons($$, a) } )*
|
( !'_' b:NonspaceInline { a = cons(b, a) }
|
||||||
OneUlClose { a = cons($$, a) }
|
| b:SpaceInline { a = cons(b, a) }
|
||||||
|
| b:StrongUl { a = cons(b, a) }
|
||||||
|
)+
|
||||||
|
'_'
|
||||||
{ $$ = p.mkList(EMPH, a) }
|
{ $$ = p.mkList(EMPH, a) }
|
||||||
|
|
||||||
Strong = StrongStar | StrongUl
|
Strong = StrongStar | StrongUl
|
||||||
|
|
||||||
TwoStarOpen = !StarLine "**" !Spacechar !Newline
|
StrongStar = "**"
|
||||||
TwoStarClose = !Spacechar !Newline a:Inline "**" { $$ = a }
|
|
||||||
|
|
||||||
StrongStar = TwoStarOpen
|
|
||||||
a:StartList
|
a:StartList
|
||||||
( !TwoStarClose Inline { a = cons($$, a) } )*
|
( !"**" b:NonspaceInline { a = cons(b, a) }
|
||||||
TwoStarClose { a = cons($$, a) }
|
| b:SpaceInline { a = cons(b, a) }
|
||||||
|
)+
|
||||||
|
"**"
|
||||||
{ $$ = p.mkList(STRONG, a) }
|
{ $$ = p.mkList(STRONG, a) }
|
||||||
|
|
||||||
TwoUlOpen = !UlLine "__" !Spacechar !Newline
|
StrongUl = "__"
|
||||||
TwoUlClose = !Spacechar !Newline a:Inline "__" !Alphanumeric { $$ = a }
|
a:StartList
|
||||||
|
( !"__" b:NonspaceInline { a = cons(b, a) }
|
||||||
StrongUl = TwoUlOpen
|
| b:SpaceInline { a = cons(b, a) }
|
||||||
a:StartList
|
)+
|
||||||
( !TwoUlClose Inline { a = cons($$, a) } )*
|
"__"
|
||||||
TwoUlClose { a = cons($$, a) }
|
{ $$ = p.mkList(STRONG, a) }
|
||||||
{ $$ = p.mkList(STRONG, a) }
|
|
||||||
|
|
||||||
Image = '!' ( ExplicitLink | ReferenceLink )
|
Image = '!' ( ExplicitLink | ReferenceLink )
|
||||||
{ if $$.key == LINK {
|
{ if $$.key == LINK {
|
||||||
|
Loading…
Reference in New Issue
Block a user