{"action":"created","issue":{"url":"https://api.github.com/repos/scala/scala/issues/7387","repository_url":"https://api.github.com/repos/scala/scala","labels_url":"https://api.github.com/repos/scala/scala/issues/7387/labels{/name}","comments_url":"https://api.github.com/repos/scala/scala/issues/7387/comments","events_url":"https://api.github.com/repos/scala/scala/issues/7387/events","html_url":"https://github.com/scala/scala/pull/7387","id":376883730,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI3OTkzODQz","number":7387,"title":"Provide a simple string matcher as the dual of the simple string interpolator","user":{"login":"lihaoyi","id":934140,"node_id":"MDQ6VXNlcjkzNDE0MA==","avatar_url":"https://avatars0.githubusercontent.com/u/934140?v=4","gravatar_id":"","url":"https://api.github.com/users/lihaoyi","html_url":"https://github.com/lihaoyi","followers_url":"https://api.github.com/users/lihaoyi/followers","following_url":"https://api.github.com/users/lihaoyi/following{/other_user}","gists_url":"https://api.github.com/users/lihaoyi/gists{/gist_id}","starred_url":"https://api.github.com/users/lihaoyi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lihaoyi/subscriptions","organizations_url":"https://api.github.com/users/lihaoyi/orgs","repos_url":"https://api.github.com/users/lihaoyi/repos","events_url":"https://api.github.com/users/lihaoyi/events{/privacy}","received_events_url":"https://api.github.com/users/lihaoyi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/scala/scala/milestones/67","html_url":"https://github.com/scala/scala/milestone/67","labels_url":"https://api.github.com/repos/scala/scala/milestones/67/labels","id":2719691,"node_id":"MDk6TWlsZXN0b25lMjcxOTY5MQ==","number":67,"title":"2.13.0-RC1","description":"Merge to 2.13.x. A PR should have scala/bug issue. No new PRs after Dec 15. Lead: @adriaanm\r\n\r\nRestricted to fixes directly improving the collections, their usage or the migration to 2.13.0. We will also consider fixes for important regressions since 2.12. An exception may be made for a small addition that cannot target 2.13.1 due to binary incompatibilities.","creator":{"login":"adriaanm","id":91083,"node_id":"MDQ6VXNlcjkxMDgz","avatar_url":"https://avatars2.githubusercontent.com/u/91083?v=4","gravatar_id":"","url":"https://api.github.com/users/adriaanm","html_url":"https://github.com/adriaanm","followers_url":"https://api.github.com/users/adriaanm/followers","following_url":"https://api.github.com/users/adriaanm/following{/other_user}","gists_url":"https://api.github.com/users/adriaanm/gists{/gist_id}","starred_url":"https://api.github.com/users/adriaanm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adriaanm/subscriptions","organizations_url":"https://api.github.com/users/adriaanm/orgs","repos_url":"https://api.github.com/users/adriaanm/repos","events_url":"https://api.github.com/users/adriaanm/events{/privacy}","received_events_url":"https://api.github.com/users/adriaanm/received_events","type":"User","site_admin":false},"open_issues":62,"closed_issues":190,"state":"open","created_at":"2017-08-23T23:45:52Z","updated_at":"2018-11-07T12:55:25Z","due_on":"2019-01-11T08:00:00Z","closed_at":null},"comments":11,"created_at":"2018-11-02T16:35:49Z","updated_at":"2018-11-07T13:16:55Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/scala/scala/pulls/7387","html_url":"https://github.com/scala/scala/pull/7387","diff_url":"https://github.com/scala/scala/pull/7387.diff","patch_url":"https://github.com/scala/scala/pull/7387.patch"},"body":"```scala\r\nval s\"Hello, $name\" = \"Hello, James\"\r\nprintln(name)  // \"James\"\r\n```\r\n```scala\r\nval s\"$greeting, $name\" = \"Hello, James\"\r\nprintln(greeting)  // \"Hello\"\r\nprintln(name)  // \"James\"\r\n```\r\n```scala\r\nval TimeSplitter = \"([0-9]+)[.:]([0-9]+)\".r\r\nval s\"The time is ${TimeSplitter(hours, mins)}\" = \"The time is 10.50\"\r\nprintln(hours) // 10\r\nprintln(mins) // 50\r\n```\r\nThis is slightly random, but I think it fits very well as a counterpart to the existing `s\"...\"` interpolator, has a very simple definition, has lived in the ammonite-ops library as the `r` interpolator for a long time, and I have generally found it very useful.\r\n\r\nIt supports simple globbing matches, without any fancy regex group-matching or whatever. This is a nice fit for the simple semantics of the existing `s` interpolator.\r\n\r\nI'm not 100% sure if the current delegate-to-regex implementation is sufficiently performant, but if people like the idea it shouldn't be hard to rewrite it as a NFA state machine with O(length-of-string) asymptotic performance.\r\n\r\nOne subtlety is that in the case of ambiguity, the regex prefers giving the characters to earlier matches rather than later matches\r\n\r\n```scala\r\nscala> val s\"$a-$b-$c-$d\" = \"1-2-3-4-5-6-7-8-9\"\r\na: String = 1-2-3-4-5-6\r\nb: String = 7\r\nc: String = 8\r\nd: String = 9\r\n``` \r\n\r\nThis is somewhat arbitrary, but something I'm personally fine with. This is for simple matches; for anything complex or ambiguous, you can use a full regex.\r\n\r\nFancier regex matching, e.g. using regex-syntax in the literal parts of the string or regex capturing groups to the bound variables, is out of scope for this PR. Maybe it can be done separately, but even if it does appear I think there's value in a simple matcher that people can use without worrying about needing to escape their `.`s and other regex special-characters.\r\n\r\nNotably, this *cannot* be implemented in user-land right now as an extension method on `StringContext`, because the presence of the `s` method stops the extension method from being picked up.\r\n\r\nWhat do people think? If it seems plausible that we could get this into the standard library, I'll be happy to add a few unit tests and do whatever polish is necessary."},"comment":{"url":"https://api.github.com/repos/scala/scala/issues/comments/436619116","html_url":"https://github.com/scala/scala/pull/7387#issuecomment-436619116","issue_url":"https://api.github.com/repos/scala/scala/issues/7387","id":436619116,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNjYxOTExNg==","user":{"login":"lihaoyi","id":934140,"node_id":"MDQ6VXNlcjkzNDE0MA==","avatar_url":"https://avatars0.githubusercontent.com/u/934140?v=4","gravatar_id":"","url":"https://api.github.com/users/lihaoyi","html_url":"https://github.com/lihaoyi","followers_url":"https://api.github.com/users/lihaoyi/followers","following_url":"https://api.github.com/users/lihaoyi/following{/other_user}","gists_url":"https://api.github.com/users/lihaoyi/gists{/gist_id}","starred_url":"https://api.github.com/users/lihaoyi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lihaoyi/subscriptions","organizations_url":"https://api.github.com/users/lihaoyi/orgs","repos_url":"https://api.github.com/users/lihaoyi/repos","events_url":"https://api.github.com/users/lihaoyi/events{/privacy}","received_events_url":"https://api.github.com/users/lihaoyi/received_events","type":"User","site_admin":false},"created_at":"2018-11-07T13:16:55Z","updated_at":"2018-11-07T13:16:55Z","author_association":"NONE","body":"huh not sure why the test is failing in scala/scala master when it passes in scala 2.12.7; is there some easy command to run just that test?"}}
{"actor":{"display_login":"lihaoyi"}}