فهرست منبع

[lexer] sync inline xml tag identifiers

closes #7558
Simon Krajewski 6 سال پیش
والد
کامیت
09466b7c09
3فایلهای تغییر یافته به همراه20 افزوده شده و 3 حذف شده
  1. 4 2
      src/syntax/lexer.ml
  2. 9 0
      tests/unit/src/unit/HelperMacros.hx
  3. 7 1
      tests/unit/src/unitstd/InlineXml.unit.hx

+ 4 - 2
src/syntax/lexer.ml

@@ -280,6 +280,8 @@ let idtype = [%sedlex.regexp? Star '_', 'A'..'Z', Star ('_' | 'a'..'z' | 'A'..'Z
 
 let integer = [%sedlex.regexp? ('1'..'9', Star ('0'..'9')) | '0']
 
+let xml_ident = [%sedlex.regexp? Opt('$'), (ident | idtype)]
+
 let rec skip_header lexbuf =
 	match%sedlex lexbuf with
 	| 0xfeff -> skip_header lexbuf
@@ -549,7 +551,7 @@ and not_xml ctx depth in_open =
 		store lexbuf;
 		not_xml ctx depth in_open
 	(* closing tag *)
-	| '<','/',ident,'>' ->
+	| '<','/',xml_ident,'>' ->
 		let s = lexeme lexbuf in
 		Buffer.add_string buf s;
 		(* If it matches our document close tag, finish or decrease depth. *)
@@ -559,7 +561,7 @@ and not_xml ctx depth in_open =
 		end else
 			not_xml ctx depth false
 	(* opening tag *)
-	| '<',ident ->
+	| '<',xml_ident ->
 		let s = lexeme lexbuf in
 		Buffer.add_string buf s;
 		(* If it matches our document open tag, increase depth and set in_open to true. *)

+ 9 - 0
tests/unit/src/unit/HelperMacros.hx

@@ -93,4 +93,13 @@ class HelperMacros {
 				error("Markup literal expected", e.pos);
 		}
 	}
+
+	static public macro function pipeMarkupLiteralUnprocessed(e:Expr) {
+		return switch (e) {
+			case macro @:markup $v{(s:String)}:
+				macro $v{s};
+			case _:
+				error("Markup literal expected", e.pos);
+		}
+	}
 }

+ 7 - 1
tests/unit/src/unitstd/InlineXml.unit.hx

@@ -27,4 +27,10 @@ unit.HelperMacros.pipeMarkupLiteral(<xml a=~/ </xml>) == "<xml a=~/ </xml>";
 // format
 var count = 33;
 unit.HelperMacros.pipeMarkupLiteral(<xml>$count + $count = ${count*2}</xml>) == unit.HelperMacros.pipeMarkupLiteral(<xml>33 + 33 = 66</xml>);
-unit.HelperMacros.pipeMarkupLiteral(<xml>$count + <xml>$count</xml> = ${count*2}</xml>) == unit.HelperMacros.pipeMarkupLiteral(<xml>33 + <xml>33</xml> = 66</xml>);
+unit.HelperMacros.pipeMarkupLiteral(<xml>$count + <xml>$count</xml> = ${count*2}</xml>) == unit.HelperMacros.pipeMarkupLiteral(<xml>33 + <xml>33</xml> = 66</xml>);
+
+// dollar
+unit.HelperMacros.pipeMarkupLiteralUnprocessed(<$xml></$xml>) == "<$xml></$xml>";
+
+// uppercase
+unit.HelperMacros.pipeMarkupLiteral(<Xml></Xml>) == "<Xml></Xml>";