Browse Source

[parser] allow JSX fragments too

Simon Krajewski 6 years ago
parent
commit
68fdc5a667
2 changed files with 6 additions and 2 deletions
  1. 2 2
      src/syntax/lexer.ml
  2. 4 0
      tests/unit/src/unitstd/InlineXml.unit.hx

+ 2 - 2
src/syntax/lexer.ml

@@ -283,7 +283,7 @@ let integer = [%sedlex.regexp? ('1'..'9', Star ('0'..'9')) | '0']
 (* https://www.w3.org/TR/xml/#sec-common-syn plus '$' for JSX *)
 (* https://www.w3.org/TR/xml/#sec-common-syn plus '$' for JSX *)
 let xml_name_start_char = [%sedlex.regexp? '$' | ':' | 'A'..'Z' | '_' | 'a'..'z' | 0xC0 .. 0xD6 | 0xD8 .. 0xF6 | 0xF8 .. 0x2FF | 0x370 .. 0x37D | 0x37F .. 0x1FFF | 0x200C .. 0x200D | 0x2070 .. 0x218F | 0x2C00 .. 0x2FEF | 0x3001 .. 0xD7FF | 0xF900 .. 0xFDCF | 0xFDF0 .. 0xFFFD | 0x10000 .. 0xEFFFF]
 let xml_name_start_char = [%sedlex.regexp? '$' | ':' | 'A'..'Z' | '_' | 'a'..'z' | 0xC0 .. 0xD6 | 0xD8 .. 0xF6 | 0xF8 .. 0x2FF | 0x370 .. 0x37D | 0x37F .. 0x1FFF | 0x200C .. 0x200D | 0x2070 .. 0x218F | 0x2C00 .. 0x2FEF | 0x3001 .. 0xD7FF | 0xF900 .. 0xFDCF | 0xFDF0 .. 0xFFFD | 0x10000 .. 0xEFFFF]
 let xml_name_char = [%sedlex.regexp? xml_name_start_char | '-' | '.' | '0'..'9' | 0xB7 | 0x0300 .. 0x036F | 0x203F .. 0x2040]
 let xml_name_char = [%sedlex.regexp? xml_name_start_char | '-' | '.' | '0'..'9' | 0xB7 | 0x0300 .. 0x036F | 0x203F .. 0x2040]
-let xml_name = [%sedlex.regexp? xml_name_start_char, Star xml_name_char]
+let xml_name = [%sedlex.regexp? Opt(xml_name_start_char, Star xml_name_char)]
 
 
 let rec skip_header lexbuf =
 let rec skip_header lexbuf =
 	match%sedlex lexbuf with
 	match%sedlex lexbuf with
@@ -603,6 +603,6 @@ let lex_xml p lexbuf =
 		lexbuf = lexbuf;
 		lexbuf = lexbuf;
 	} in
 	} in
 	try
 	try
-		not_xml ctx 0 true
+		not_xml ctx 0 (name <> "") (* don't allow self-closing fragments *)
 	with Exit ->
 	with Exit ->
 		error Unterminated_xml p
 		error Unterminated_xml p

+ 4 - 0
tests/unit/src/unitstd/InlineXml.unit.hx

@@ -19,6 +19,10 @@ unit.HelperMacros.pipeMarkupLiteral(<:xml></:xml>) == "<:xml></:xml>";
 unit.HelperMacros.pipeMarkupLiteral(<xml:xml></xml:xml>) == "<xml:xml></xml:xml>";
 unit.HelperMacros.pipeMarkupLiteral(<xml:xml></xml:xml>) == "<xml:xml></xml:xml>";
 unit.HelperMacros.pipeMarkupLiteral(<foo.Bar_barf3-gnieh:blargh></foo.Bar_barf3-gnieh:blargh>) == "<foo.Bar_barf3-gnieh:blargh></foo.Bar_barf3-gnieh:blargh>";
 unit.HelperMacros.pipeMarkupLiteral(<foo.Bar_barf3-gnieh:blargh></foo.Bar_barf3-gnieh:blargh>) == "<foo.Bar_barf3-gnieh:blargh></foo.Bar_barf3-gnieh:blargh>";
 
 
+// fragments
+unit.HelperMacros.pipeMarkupLiteral(<></>) == "<></>";
+unit.HelperMacros.pipeMarkupLiteral(<>abc</>) == "<>abc</>";
+
 // No check for string literal balancing
 // No check for string literal balancing
 unit.HelperMacros.pipeMarkupLiteral(<xml a=" </xml>) == "<xml a=\" </xml>";
 unit.HelperMacros.pipeMarkupLiteral(<xml a=" </xml>) == "<xml a=\" </xml>";
 unit.HelperMacros.pipeMarkupLiteral(<xml a=' </xml>) == "<xml a=' </xml>";
 unit.HelperMacros.pipeMarkupLiteral(<xml a=' </xml>) == "<xml a=' </xml>";