<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">Le 2 févr. 2016 à 07:43, Patrick Gili &lt;<a href="mailto:gili.patrick.r@gili-labs.com" class="">gili.patrick.r@gili-labs.com</a>&gt; a écrit :</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Dany,<div class=""><br class=""></div><div class="">When you say "sub patterns", do you mean "capture groups"?</div></div></div></blockquote><div><br class=""></div><div><div>Looks like my sub-patterns/matches are in Perl parlance capture groups, but it seems that this may need support from the compiler. Tuple have fixed length (no support for variadic tuple), could not get arrays to work in switch case, enum cannot reuse same name with different set of associated value.</div><div></div></div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 1, 2016, at 10:43 PM, Dany St-Amant via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">Le 31 janv. 2016 à 22:39, Chris Lattner via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; a écrit :</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Jan 31, 2016, at 8:32 AM, Patrick Gili via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">There have been several threads that have discussed the notion of a regular expression literals. However, I didn't see anyone putting together a formal proposal, and hence I took the liberty to do so. I would appreciate discussion and comments on the proposal:</div></div></blockquote><div class=""><br class=""></div><div class="">I am +1 on the concept of adding regex literals to Swift, but -1 on this proposal.</div><div class=""><br class=""></div><div class="">Specifically, instead of introducing regex literals, I’d suggest that you investigate introducing regex’s to the pattern grammar, which is what Swift uses for matching already. &nbsp;Regex’s should be usable in the cases of a switch, for example. &nbsp;Similarly, they should be able to bind variables directly to sub patterns.</div></div></div></blockquote><div class=""><br class=""></div>I was seeing the sub patterns originally a bit like:</div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">switch</span>( string &lt;match-op&gt; regex) {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span> .matches(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">_</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"http"</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> port):</div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">&nbsp; </span></font><span style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);" class="">case</span><font face="Menlo" class=""><span style="font-size: 11px;" class=""> .matches(</span></font><span style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);" class="">_</span><font face="Menlo" class=""><span style="font-size: 11px;" class="">, </span></font><span style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);" class="">let</span><font face="Menlo" class=""><span style="font-size: 11px;" class=""> name, </span></font><span style="font-family: Menlo; font-size: 11px; color: rgb(209, 47, 27);" class="">"8080"</span><font face="Menlo" class=""><span style="font-size: 11px;" class="">):</span></font></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp;&nbsp;<span style="color: rgb(187, 44, 162);" class="">case</span>&nbsp;.matches(<span style="color: rgb(187, 44, 162);" class="">_</span>,&nbsp;<span style="color: rgb(209, 47, 27);" class="">"<a href="smb://smb/" class="">\\smb\</a>"</span>):</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div style="font-family: Helvetica; font-size: 12px;" class="">but the comment about the pattern grammar make me of:</div><div style="font-family: Helvetica; font-size: 12px;" class=""></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">switch</span>( string ) {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span> regexp1:&nbsp;<span style="color: rgb(187, 44, 162);" class="">if</span> ($0.<span style="color: rgb(39, 42, 216);" class="">1</span> = <span style="color: rgb(209, 47, 27);" class="">"http"</span>) { }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span> regexp2:</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div class="">Both have their uses</div><div class=""><br class=""></div><div class="">Dany</div><div class=""><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="">Further, I highly recommend checking out Perl 6’s regular expressions. &nbsp;They are a community that has had an obsessive passion for regular expressions, and in Perl 6 they were given the chance to reinvent the wheel based on what they learned. &nbsp;What they came up with is very powerful, and pretty good all around.</div><div class=""><br class=""></div><div class="">-Chris</div><div class=""><br class=""></div></div></div></blockquote></div><br class=""></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></body></html>