<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="">On Dec 20, 2016, at 2:11 AM, Jonathan Hull via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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="">Yes, I agree. I am excited to see what happens in phase 2.<div class=""><br class=""></div><div class="">What I am suggesting here is slightly different. Basically being able to use RegEx (with capture groups) as a shorthand for a type composed of base literals. For example: (StringLiteral, [IntegerLiteral]). Named capture groups could even map to a dictionary literal. I am using “RegEx goes Here” to represent RegEx in the examples below, but hopefully it will get it’s own literal type in Xcode (Imagine that replacing it here).</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func foo( _ param: “RegExGoesHere”) {…} //Definition uses a RegEx where the type would normally be</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>foo(“my parseable string") //Calling with a string literal</div><div class=""><br class=""></div><div class="">In this case, ‘param’ takes a string literal when called but the compiler converts it to a tuple of literals based on the regEx supplied and passes that tuple the function. The type/structure of the tuple is defined by the capture groups in the RegEx</div><div class=""><br class=""></div><div class="">The parameter above would only allow string literals to be passed in, and would give a compiler error if you tried to pass a variable or if the string didn’t conform to the supplied RegEx. To allow passing String variables you would have to add either ‘?’ or ‘!’ after the RegEx definition to handle the case where the value doesn’t conform.</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func foo( _ param: “RegExGoesHere”?) {…} //‘param' is nil if RegEx fails</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>foo(myStringVar) //Calling</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func bar( _ param: “RegExGoesHere”!) {…} //fatal error if RegEx fails</div><div class=""><br class=""></div><div class="">When a variable is passed, the RegEx is performed at runtime instead of compile time.</div><div class=""><br class=""></div><div class="">Once you have this, the syntax to add new literal types/initializers falls out virtually for free.</div></div></div></blockquote></div><br class=""><div class="">Is “RegExGoesHere” where the regex pattern goes, or where the string you’re trying to match goes? If it’s the latter, where does the pattern go? If it’s the former, where does the string you’re trying to match go?</div><div class=""><br class=""></div><div class="">Also, it’s worth noting that I don’t think you can just use Strings to hold arbitrary regular expressions… According to “Daveo” (not me) on stackoverflow (<a href="http://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url" class="">http://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url</a>), the regex for the regex for an URL is:</div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><span class="pun" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">[-</span><span class="pln" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">a</span><span class="pun" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">-</span><span class="pln" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">zA</span><span class="pun" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">-</span><span class="pln" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">Z0</span><span class="pun" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">-</span><span class="lit" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">9</span><span class="pun" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">@:%.</span><span class="pln" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">_\+</span><span class="pun" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">~#=]{</span><span class="lit" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">2</span><span class="pun" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">,</span><span class="lit" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">256</span><span class="pun" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">}</span><span class="pln" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">\.</span><span class="pun" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">[</span><span class="pln" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">a</span><span class="pun" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">-</span><span class="pln" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">z</span><span class="pun" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">]{</span><span class="lit" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">2</span><span class="pun" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">,</span><span class="lit" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">6</span><span class="pun" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">}</span><span class="pln" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">\b</span><span class="pun" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">([-</span><span class="pln" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">a</span><span class="pun" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">-</span><span class="pln" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">zA</span><span class="pun" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">-</span><span class="pln" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">Z0</span><span class="pun" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">-</span><span class="lit" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">9</span><span class="pun" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">@:%</span><span class="pln" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">_\+</span><span class="pun" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">.~#?&</span><span class="com" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">//</span><span class="com" style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit; font-size: 13px; margin: 0px; padding: 0px; border: 0px;">=]*)</span></div></blockquote><div class=""><span class="com" style="white-space: inherit; margin: 0px; padding: 0px; border: 0px;">But pasting this into a string literal gives several “Invalid escape sequence in literal” errors.</span></div><div class=""><span class="com" style="white-space: inherit; margin: 0px; padding: 0px; border: 0px;"><br class=""></span></div><div class=""><span class="com" style="white-space: inherit; margin: 0px; padding: 0px; border: 0px;">- Dave Sweeris</span></div></body></html>