@@ -457,24 +457,45 @@ class Parser {
457457 if ( #if hscriptPos tokens .length != 0 #else ! tokens .isEmpty () #end )
458458 throw " assert" ;
459459 if ( readPos == start + ident .length + 1 ) {
460+ var startTag = " <" + ident ;
460461 var endTag = " </" + ident + " >" ;
461- var end = input .indexOf (endTag , readPos );
462- if ( end < 0 ) {
463- endTag = ' />' ;
464- end = input .indexOf (endTag , readPos );
465- }
466- if ( end >= 0 ) {
467- readPos = end + endTag .length ;
468- char = - 1 ;
469- start -- ;
470- var end = readPos - 1 ;
471- #if hscriptPos
472- tokenMin = start + offset ;
473- tokenMax = end + offset ;
474- #end
475- var str = input .substr (start ,end - start + 1 );
476- return mk (EMeta (" :markup" ,[],mk (EConst (CString (str )))));
462+ var endTag2 = " />" ;
463+ var end = - 1 ;
464+ var count = 1 , curPos = readPos ;
465+ var r_nextTag = ~/ <[A-Za-z0-9 _] + / ;
466+ while ( count > 0 ) {
467+ end = input .indexOf (endTag , curPos + 1 );
468+ if ( end >= 0 )
469+ end + = endTag .length ;
470+ var end2 = input .indexOf (endTag2 , curPos + 1 );
471+ if ( end2 > 0 && (end < 0 || end2 < end ) ) {
472+ var nextTag = - 1 ;
473+ if ( r_nextTag .matchSub (input , curPos + 1 ) )
474+ nextTag = r_nextTag .matchedPos ().pos ;
475+ if ( nextTag < 0 || end2 < nextTag )
476+ end = end2 + endTag2 .length ;
477+ }
478+ if ( end < 0 )
479+ error (ECustom (" Unclosed " + startTag + " >" ), curPos , curPos + startTag .length + 1 );
480+ var prev = input .indexOf (startTag , curPos + 1 );
481+ if ( prev < 0 || prev > end ) {
482+ count -- ;
483+ curPos = end - 1 ;
484+ } else {
485+ count ++ ;
486+ curPos = prev ;
487+ }
477488 }
489+ readPos = end ;
490+ char = - 1 ;
491+ start -- ;
492+ var end = readPos - 1 ;
493+ #if hscriptPos
494+ tokenMin = start + offset ;
495+ tokenMax = end + offset ;
496+ #end
497+ var str = input .substr (start ,end - start + 1 );
498+ return mk (EMeta (" :markup" ,[],mk (EConst (CString (str )))));
478499 }
479500 }
480501 return unexpected (tk );
0 commit comments