@@ -564,7 +564,7 @@ impl Parser {
564564
565565 TemplateLanguage :: constructs ( & self . template_language )
566566 . into_iter ( )
567- . any ( |c | self . peek_str ( c . 0 ) )
567+ . any ( |construct | self . peek_regex ( & construct . 0 ) )
568568 }
569569
570570 fn parse_template_expression ( & mut self ) -> TemplateExpression {
@@ -573,7 +573,7 @@ impl Parser {
573573
574574 let construct = TemplateLanguage :: constructs ( & self . template_language )
575575 . into_iter ( )
576- . find ( |c | self . peek_str ( c . 0 ) )
576+ . find ( |construct | self . peek_regex ( & construct . 0 ) )
577577 . unwrap_or_else ( || panic ! ( "No matching construct found for input" ) ) ;
578578
579579 let mut quote = None ;
@@ -602,8 +602,8 @@ impl Parser {
602602 }
603603 }
604604
605- if quote. is_none ( ) && self . peek_str ( construct. 2 ) {
606- self . consume_str ( construct. 2 ) ;
605+ if quote. is_none ( ) && self . peek_regex ( & construct. 2 ) {
606+ self . consume_regex ( & construct. 2 ) ;
607607 break ;
608608 }
609609
@@ -657,6 +657,27 @@ impl Parser {
657657 true
658658 }
659659
660+ fn peek_regex ( & self , regex : & regex:: Regex ) -> bool {
661+ let remaining_input: String = self . input [ self . cursor ..] . iter ( ) . collect ( ) ;
662+ regex. is_match ( & remaining_input)
663+ }
664+
665+ fn consume_regex ( & mut self , regex : & regex:: Regex ) {
666+ let remaining_input: String = self . input [ self . cursor ..] . iter ( ) . collect ( ) ;
667+ if let Some ( regex_match) = regex. find ( & remaining_input) {
668+ assert_eq ! (
669+ regex_match. start( ) ,
670+ 0 ,
671+ "Regex did not match at the current position"
672+ ) ;
673+ for _ in 0 ..regex_match. end ( ) {
674+ self . advance ( ) ;
675+ }
676+ } else {
677+ panic ! ( "Regex did not match the input" ) ;
678+ }
679+ }
680+
660681 fn peek_any ( & self , list : & [ & str ] ) -> bool {
661682 for & s in list {
662683 if self . peek_str ( s) {
0 commit comments