Scala-native: Support for scala-native/re2s

Created on 11 Jan 2019  路  5Comments  路  Source: scala-native/scala-native

Unfortunately, scala-native is missing just a few Char/Array/etc methods needed to use re2s instead of the re2 dependency; switching to re2s would be a big win for setup and portability, since C++ libs are quite a challenge to compile and link directly.

If I try to link the following short program:

import re2s.RE2

object main {
  def main(args:Array[String]):Unit = {
    val request_pattern = new RE2("\\w+ \\w+ \\w+")
    val input = "foo bar baz"
    val result = request_pattern.match_(input)
    println(result)
  }
}

I get these link errors:

[error] cannot link: @java.lang.Character$::codePointAt_java.lang.CharSequence_i32_i32
[error] cannot link: @java.lang.Character$::codePointBefore_java.lang.CharSequence_i32_i32
[error] cannot link: @java.lang.StringBuilder::indexOf_java.lang.String_i32_i32
[error] cannot link: @java.util.ArrayList::listIterator_i32_java.util.ListIterator
[error] cannot link: @java.util.ArrayList::listIterator_java.util.ListIterator
[error] cannot link: @java.util.ArrayList::removeRange_i32_i32_unit
[error] cannot link: @java.util.ArrayList::subList_i32_i32_java.util.List
[error] cannot link: @java.util.List::toArray_scala.scalanative.runtime.ObjectArray_scala.scalanative.runtime.ObjectArray

Most of those would be pretty straightforward to implement; however, the unicode code-point logic might be a bit of a pain. We might consider handling ascii only for a first pass, and raising an exception if bytes > 127 are found, to keep the initial implementation simple.

javalib

Most helpful comment

Scala Native itself already has codePointAt and codePointBefore (herehttps://github.com/scala-native/scala-native/blob/01fbdf7cf6f1f9f62982eab30a35eeb2f7c735ca/javalib/src/main/scala/java/lang/Character.scala#L239-L279)), just for Array[Char] instead of CharSequence. You can just delegate the CharSequence ones to the Array[Char] ones, or copy-paste-and-adapt them. They're really not difficult.

All 5 comments

Scala Native itself already has codePointAt and codePointBefore (herehttps://github.com/scala-native/scala-native/blob/01fbdf7cf6f1f9f62982eab30a35eeb2f7c735ca/javalib/src/main/scala/java/lang/Character.scala#L239-L279)), just for Array[Char] instead of CharSequence. You can just delegate the CharSequence ones to the Array[Char] ones, or copy-paste-and-adapt them. They're really not difficult.

Thanks, I searched for it but must have missed typed somehow then I looked at Scala.js and didn't find it so that confirmed my mistake.

@rwhaling

I believe that this Issue was fixed by PR #1498, which has been merged (and seems to be working).

If that PR satisfies you, this Issue can be closed.

Thank you for kicking off the ball on this one. Its transitive closure resulted in a number of
fixes and soon-to-be fixes.

Bravo!

Was this page helpful?
0 / 5 - 0 ratings