@@ -45,44 +45,61 @@ public static function parse(Lexer $lexer)
4545 'children ' => $ children ,
4646 'selfClosing ' => true
4747 ];
48+ } else {
49+ throw new Exception (sprintf ('Self closing tag "%s" misses closing bracket. ' , $ identifier ));
4850 }
4951 }
5052
5153 if ($ lexer ->isClosingBracket ()) {
5254 $ lexer ->consume ();
55+ } else {
56+ throw new Exception (sprintf ('Tag "%s" did not end with closing bracket. ' , $ identifier ));
5357 }
5458
5559 $ children = Children::parse ($ lexer );
5660
57- while ($ lexer ->isWhitespace ()) {
58- $ lexer ->consume ();
59- }
60-
6161 if ($ lexer ->isOpeningBracket ()) {
6262 $ lexer ->consume ();
6363
6464 if ($ lexer ->isForwardSlash ()) {
6565 $ lexer ->consume ();
66+ } else {
67+ throw new Exception (sprintf (
68+ 'Opening-bracket for closing of tag "%s" was not followed by slash. ' ,
69+ $ identifier
70+ ));
6671 }
72+ } else {
73+ throw new Exception (sprintf (
74+ 'Opening-bracket for closing of tag "%s" expected. ' ,
75+ $ identifier
76+ ));
6777 }
6878
6979 $ closingIdentifier = Identifier::parse ($ lexer );
7080
81+ if ($ closingIdentifier !== $ identifier ) {
82+ throw new Exception (sprintf (
83+ 'Closing-tag identifier "%s" did not match opening-tag identifier "%s". ' ,
84+ $ closingIdentifier ,
85+ $ identifier
86+ ));
87+ }
88+
7189 if ($ lexer ->isClosingBracket ()) {
7290 $ lexer ->consume ();
73-
74- if ($ closingIdentifier === $ identifier ) {
75- return [
76- 'identifier ' => $ identifier ,
77- 'props ' => $ props ,
78- 'children ' => $ children ,
79- 'selfClosing ' => false
80- ];
81- }
91+ return [
92+ 'identifier ' => $ identifier ,
93+ 'props ' => $ props ,
94+ 'children ' => $ children ,
95+ 'selfClosing ' => false
96+ ];
97+ } else {
98+ throw new Exception (sprintf ('Closing tag "%s" did not end with closing-bracket. ' , $ identifier ));
8299 }
83100
84101 if ($ lexer ->isEnd ()) {
85- throw new Exception (sprintf ('Tag %s was is not closed ' , $ identifier ));
102+ throw new Exception (sprintf ('Tag "%s" was is not closed. ' , $ identifier ));
86103 }
87104 }
88105}
0 commit comments