Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Nicolas Rinaudo
@nrinaudo
ah hang on, no, it is
(and so we're clear: all the documentation's code is actually compiled and executed, so if it's in the doc, you know it's correct. I'm really proud of that)
ok, so I just re-read that example, and it was a mistake on my part to use ordered in the documentation. I should have used decoder. I'll create an issue
rubenpieters
@rubenpieters
thats pretty cool
Nicolas Rinaudo
@nrinaudo
is it clear what MatchDecoder.decoder does, and that it supports any arity from 1 to 22, or do you need some help?
rubenpieters
@rubenpieters
yes that is clear, but since it takes implicit groupdecoders it wont work when I will put multiple case class in it, is that right?
Nicolas Rinaudo
@nrinaudo
(just got pulled in on a meeting)
rubenpieters
@rubenpieters
ok nevermind the previous comment, I understand a bit better what it does now, the .decoder thing is a nice solution for the user to specify the order of things he wants to do
Nicolas Rinaudo
@nrinaudo
or build nested case class structures
rubenpieters
@rubenpieters
yep
Nicolas Rinaudo
@nrinaudo
I assumed that was your workaround :)
rubenpieters
@rubenpieters
Well currently the workaround is that I split the string and parse those elements separately in the case classes I want. I'm not sure the .decoder would work since in total there are more than 22 fields
Nicolas Rinaudo
@nrinaudo
ah, I see
Nicolas Rinaudo
@nrinaudo
Alright, so kantan.codecs now has support for java 8 times. I need to tidy it up somewhat, but it should now be trivial to bring it to kantan.regex
rubenpieters
@rubenpieters
Ok cool thanks
Nicolas Rinaudo
@nrinaudo
0.1.6-SNAPSHOT is being published just now, with support for java8 dates. I've yet to write the documentation, but importing kantan.regex.java8._ will bring default instances in scope
if the default java formats are not what you're after, you can declare your own decoders through instantDecoder, localDateTimeDecoder, .... which all take a DateFormat as a parameter
rubenpieters
@rubenpieters
Ill try to take a look at that tomortow
Nicolas Rinaudo
@nrinaudo
no hurry. I need to bring support to kantan.xpath and kantan.csv, and write the documentation, before a proper release anyway
plus, you already have a working solution which is essentially the same code, so it's not like you have a burning need to upgrade
rubenpieters
@rubenpieters
thats true
Nicolas Rinaudo
@nrinaudo
@/all official artifacts for 0.1.6 are now available on maven central.
johannes karoff
@cornerman
hi there! is it possible to concatenate two existing Regex into one Regex, which parses a tuple of the individual results?
Nicolas Rinaudo
@nrinaudo
Not directly, because two regexes mean two evaluations which is not supported by the decoder mechanism
On the other hand, you can use the decoding mechanism to yield two results, then manually conpose them into a tuple using flatmap
johannes karoff
@cornerman
@nrinaudo thanks for the response! how would i go about doing that? :)
Nicolas Rinaudo
@nrinaudo
sorry, missed your message.
So the principle is fairly straightforward - each evaluation yields an Either[Error, A], so you could write something like:
for {
  i <- str.evalRegex[Int](regex1)
  b <- str.evalRegex[Boolean](regex2)
} yield (i, b)
where regex1 and regex2 are the two regular expressions you with to compose and strthe string you wish to apply them to
@cornerman let me know if this isn't clear enough. If you were to give me a concrete use case, I could probably wip up some quick code to show you
johannes karoff
@cornerman
@nrinaudo ah got you. thats what you meant with decoding mechanism :)
my use-case is parsing a url-like structure. so I have a website, where i need to interpret the url (or more specifically the hash part of the url). so i have something similar to query parameters or key-value pairs like something=false&list=1,2,3&nothing=. so depending on the key, i need to interpret the rhs differently.
i was using fastparse previously to have a grammer for the options in the url. so i could write a parser for each option and then combine them in one grammar. that was nice. but is very slow on startup in scala.js.
johannes karoff
@cornerman
what i am doing now: i take the url and first match Map[String ->String] with a simple regex for k=v. and then i parse each entry in the map. so in the example, i would have then a regex for something, list and nothing.
so, it works now :)
johannes karoff
@cornerman
on another note: when i was using a star in my regex, e.g. (\w+)(:\d+)*. and then compiled a Regex[(String,String)] or Regex[(String,Seq[String])], I always got an error about an "empty group". I then went for (\w+)(:\d+)*? and used Regex[(String, Option[String])]. what can i do about this?
Nicolas Rinaudo
@nrinaudo
@cornerman Not sure about your use case for URI parsing, I would probably use a dedicated library for that as URI parameter parsing isn't as trivial as it might seem at first glance
johannes karoff
@cornerman
@nrinaudo in general i agree but it is not really a url. we have a SPA app running in the browser, which writes its current options to the hash-part of the url. the options are key-value pairs and similar to an url with regards to being a sequence of key-value pairs separated by & and =. so a dedicated uri parsing library would not really fit.
Nicolas Rinaudo
@nrinaudo
and as for your example, I'll need to see your code, because I don't think I understand what you're saying:
"abc:123".evalRegex[(String, String)](rx"(\w+)(:\d+)*").next
res1: kantan.regex.DecodeResult[(String, String)] = Right((abc,:123))
johannes karoff
@cornerman
yes, your example works, but if you have no match for (:\d+)*, it does not work:
"abc".evalRegex[(String, String)](rx"(\w+)(:\d+)*").next
res1: kantan.regex.DecodeResult[(String, String)] = Left(EmptyGroup: an empty group was found)
Nicolas Rinaudo
@nrinaudo
well yeah - the second group is not matched
so you get a match with a single group, which is what this is telling you
you have basically two choices there:
  • make the second group optional
  • make slightly more complicated groups (this would also allow you to ignore the :, which I'm assuming is desirable but I might be wrong)
johannes karoff
@cornerman
but semantically an empty string is a match for something* in a regex, isn't it?
Nicolas Rinaudo
@nrinaudo
you don't have an empty string. You have nothing
wait, what do you think the : means in your regex?
is that a separator, or did you think it means "non-capturing group"?
johannes karoff
@cornerman
no, just a separator
Nicolas Rinaudo
@nrinaudo
right
johannes karoff
@cornerman
i was under the impression, i could have a Regex[(String, Option[String])] from a *. just like from a ?. because both can yield an empty result