@@ -1452,9 +1452,22 @@ impl<'i> Parser<'i> {
14521452 . unwrap ( ) ; // is_function() already checked
14531453 let text = & content[ 0 ..paren] ;
14541454
1455- // Validate that the entire text is a valid identifier
1456- let target = validate_identifier ( text)
1457- . ok_or ( ParsingError :: InvalidFunction ( self . offset , text. len ( ) ) ) ?;
1455+ let target = validate_identifier ( text) ;
1456+
1457+ if target. is_none ( ) {
1458+ if text. contains ( ' ' ) || text. contains ( '<' ) || text. contains ( '>' ) {
1459+ let width = if let Some ( tilde_pos) = content. find ( '~' ) {
1460+ tilde_pos. min ( content. len ( ) )
1461+ } else {
1462+ content. len ( )
1463+ } ;
1464+ return Err ( ParsingError :: InvalidCodeBlock ( self . offset , width) ) ;
1465+ } else {
1466+ return Err ( ParsingError :: InvalidFunction ( self . offset , text. len ( ) ) ) ;
1467+ }
1468+ }
1469+
1470+ let target = target. unwrap ( ) ;
14581471
14591472 self . advance ( text. len ( ) ) ;
14601473 let parameters = self . read_parameters ( ) ?;
@@ -1558,7 +1571,25 @@ impl<'i> Parser<'i> {
15581571
15591572 fn read_binding_expression ( & mut self ) -> Result < Expression < ' i > , ParsingError > {
15601573 // Parse the expression before the ~ operator
1561- let expression = self . take_until ( & [ '~' ] , |inner| inner. read_expression ( ) ) ?;
1574+ let expression = self . take_until ( & [ '~' ] , |inner| {
1575+ let start_pos = inner. offset ;
1576+ let expression = inner. read_expression ( ) ?;
1577+
1578+ // Check for leftover content, erroring if present
1579+ inner. trim_whitespace ( ) ;
1580+ if inner
1581+ . source
1582+ . is_empty ( )
1583+ {
1584+ Ok ( expression)
1585+ } else {
1586+ let width = inner. offset - start_pos
1587+ + inner
1588+ . source
1589+ . len ( ) ;
1590+ Err ( ParsingError :: InvalidCodeBlock ( start_pos, width) )
1591+ }
1592+ } ) ?;
15621593
15631594 // Consume the ~ operator
15641595 self . advance ( 1 ) ; // consume '~'
0 commit comments