Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: Update versions #162

Merged
merged 3 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions .github/workflows/cli.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
name: CI
on:
workflow_dispatch:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
pre_job:
name: Skip Duplicate Actions
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@v5
with:
skip_after_successful_duplicate: 'true'

test:
needs: pre_job
if: needs.pre_job.outputs.should_skip != 'true'
strategy:
fail-fast: false
matrix:
os : [ubuntu-latest]
scala: [2.12.15, 2.13.6]
scala: [2.12.20, 2.13.16]
platform: [jvm, js]
java : [8, 11]
java : [8, 21]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup
uses: olafurpg/setup-scala@v13
uses: coursier/setup-action@v1
with:
java-version: "adopt@1.${{ matrix.java }}"
jvm: "temurin:${{ matrix.java }}"
apps: sbt

- name: Cache
uses: coursier/cache-action@v5
uses: coursier/cache-action@v6

- name: Test JVM
if: matrix.platform == 'jvm'
Expand Down
41 changes: 10 additions & 31 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,36 +1,15 @@
*.class
*.log

# sbt specific
.cache/
.history/
.lib/
dist/*
target/
lib_managed/
src_managed/
project/boot/
project/plugins/project/
.bsp

# Scala-IDE specific
.scala_dependencies
.worksheet
# IDE and other personal preferences go to a global gitignore or .git/info/exclude

# Misc. analysis tools
.ensime
.ensime_cache
# Scala ecosystem
.bloop
.bsp
.metals
project/boot/
project/plugins/project/
target/

# Intellij
.idea/
*.iml
*.iws

# Mac
.DS_Store

# Auto-generated files
# Project
## generated files
.scalafix.conf
.scalafmt.conf
scalastyle-config.xml
*.log
5 changes: 0 additions & 5 deletions .jvmopts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
-Dfile.encoding=UTF8
-Xms1G
-Xmx13G
-XX:MaxPermSize=512M
-XX:ReservedCodeCacheSize=250M
-XX:+TieredCompilation
-XX:-UseGCOverheadLimit
# effectively adds GC to Perm space
-XX:+CMSClassUnloadingEnabled
# must be enabled for CMSClassUnloadingEnabled to work
-XX:+UseConcMarkSweepGC
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# kantan.regex

[![Build Status](https://travis-ci.org/nrinaudo/kantan.regex.svg?branch=master)](https://travis-ci.org/nrinaudo/kantan.regex)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.nrinaudo/kantan.regex_2.13/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.nrinaudo/kantan.regex_2.13)
[![Build Status](https://github.com/nrinaudo/kantan.regex/actions/workflows/cli.yml/badge.svg?branch=master)](https://github.com/nrinaudo/kantan.regex/actions/workflows/cli.yml?branch=master)
[![kantan.regex Scala version support](https://index.scala-lang.org/nrinaudo/kantan.regex/kantan.regex/latest-by-scala-version.svg?platform=jvm)](https://index.scala-lang.org/nrinaudo/kantan.regex/kantan.regex)
[![kantan.regex Scala version support](https://index.scala-lang.org/nrinaudo/kantan.regex/kantan.regex/latest-by-scala-version.svg?platform=sjs1)](https://index.scala-lang.org/nrinaudo/kantan.regex/kantan.regex)
[![Join the chat at https://gitter.im/nrinaudo/kantan.regex](https://img.shields.io/badge/gitter-join%20chat-52c435.svg)](https://gitter.im/nrinaudo/kantan.regex)

There are two main use-cases for regular expressions:
Expand Down
9 changes: 6 additions & 3 deletions cats/shared/src/main/scala/kantan/regex/cats/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@

package kantan.regex

import _root_.cats.{Eq, Functor}
import kantan.codecs.cats.{CommonInstances, DecoderInstances}
import _root_.cats.Eq
import _root_.cats.Functor
import kantan.codecs.cats.CommonInstances
import kantan.codecs.cats.DecoderInstances

package object cats extends DecoderInstances with CommonInstances {
// - Regex instances -------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------

implicit val regexFunctor: Functor[Regex] = new Functor[Regex] {
override def map[A, B](fa: Regex[A])(f: A => B) = fa.map(f)
override def map[A, B](fa: Regex[A])(f: A => B) =
fa.map(f)
}

// - Eq instances ----------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ package kantan.regex.cats
import cats.Eq
import cats.data.EitherT
import cats.instances.all._
import cats.laws.discipline.{MonadErrorTests, SemigroupKTests}
import cats.laws.discipline.MonadErrorTests
import cats.laws.discipline.SemigroupKTests
import cats.laws.discipline.SemigroupalTests.Isomorphisms
import kantan.regex.{DecodeError, GroupDecoder}
import kantan.regex.DecodeError
import kantan.regex.GroupDecoder
import kantan.regex.cats.arbitrary._
import kantan.regex.cats.equality._
import kantan.regex.laws.discipline.DisciplineSuite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ package kantan.regex.cats

import cats.Show
import cats.kernel.laws.discipline.EqTests
import kantan.regex.{CompileError, DecodeError, RegexError}
import kantan.regex.CompileError
import kantan.regex.DecodeError
import kantan.regex.RegexError
import kantan.regex.cats.arbitrary._
import kantan.regex.laws.discipline.DisciplineSuite

Expand Down
7 changes: 4 additions & 3 deletions cats/shared/src/test/scala/kantan/regex/cats/equality.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import kantan.regex.Regex

object equality extends kantan.codecs.cats.laws.discipline.EqInstances {

implicit def eqRegex[A: Eq]: Eq[Regex[A]] = Eq.by { regex => (str: String) =>
regex.eval(str).toList
}
implicit def eqRegex[A: Eq]: Eq[Regex[A]] =
Eq.by { regex => (str: String) =>
regex.eval(str).toList
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

package kantan.regex

import kantan.codecs.strings.StringDecoder

import java.text.DateFormat
import java.util.Date
import kantan.codecs.strings.StringDecoder

trait PlatformSpecificInstances {
def dateDecoder(format: DateFormat): GroupDecoder[Date] = codecs.fromString(StringDecoder.dateDecoder(format))
def dateDecoder(format: DateFormat): GroupDecoder[Date] =
codecs.fromString(StringDecoder.dateDecoder(format))
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package kantan.regex

import java.text.SimpleDateFormat
import java.util.{Date, Locale}
import kantan.codecs.strings.{StringCodec}
import kantan.codecs.strings.StringCodec
import kantan.regex.laws.discipline.{DisciplineSuite, GroupDecoderTests, MatchDecoderTests}
import kantan.regex.laws.discipline.arbitrary._

Expand Down
26 changes: 14 additions & 12 deletions core/shared/src/main/scala/kantan/regex/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import java.util.regex.Matcher
* fit all possible situations - one might imagine, for example, a scenario where a regular expression is created
* dynamically before being compiled.
*
* [[Compiler]] is provided for these cases where literals are not an option. The preferred way of using it is to
* make sure the corresponding [[kantan.regex.ops.CompilerOps syntax]] is in scope and use the `asRegex` method:
* [[Compiler]] is provided for these cases where literals are not an option. The preferred way of using it is to make
* sure the corresponding [[kantan.regex.ops.CompilerOps syntax]] is in scope and use the `asRegex` method:
* {{{
* // Obtain a regular expression as a string somehow.
* val regex: String = ???
Expand All @@ -49,7 +49,6 @@ trait Compiler[E] {
* compiler.compile[Int]("""\[(\d+)\]""", 1)
* }}}
*
*
* A [[[MatchDecoder MatchDecoder[A]]]] will be generated by calling
* [[MatchDecoder$.fromGroup[A](index:Int)* MatchDecoder.fromGroup]] with the specified `group` value.
*/
Expand All @@ -58,7 +57,8 @@ trait Compiler[E] {

/** Unsafe version of `compile`. */
@SuppressWarnings(Array("org.wartremover.warts.Throw"))
def unsafeCompile[A: MatchDecoder](expr: E): Regex[DecodeResult[A]] = compile(expr).fold(e => throw e, identity)
def unsafeCompile[A: MatchDecoder](expr: E): Regex[DecodeResult[A]] =
compile(expr).fold(e => throw e, identity)

/** Unsafe version of `compile`. */
@SuppressWarnings(Array("org.wartremover.warts.Throw"))
Expand All @@ -73,13 +73,15 @@ object Compiler {
*
* This is a convenience method and equivalent to calling `implicitly[Compiler[A]]`
*/
def apply[A](implicit ev: Compiler[A]): Compiler[A] = macro imp.summon[Compiler[A]]
def apply[A](implicit ev: Compiler[A]): Compiler[A] =
macro imp.summon[Compiler[A]]

/** Creates a new [[Compiler]] instance from a function that turns `A` into a `Pattern`. */
def fromPattern[A](f: A => CompileResult[Pattern]): Compiler[A] = new Compiler[A] {
override def compile[B: MatchDecoder](expr: A): CompileResult[Regex[DecodeResult[B]]] =
f(expr).map(p => Regex(p))
}
def fromPattern[A](f: A => CompileResult[Pattern]): Compiler[A] =
new Compiler[A] {
override def compile[B: MatchDecoder](expr: A): CompileResult[Regex[DecodeResult[B]]] =
f(expr).map(p => Regex(p))
}

/** Provides compilation for Scala Regexes. */
implicit val scalaRegex: Compiler[scala.util.matching.Regex] = fromPattern(r => CompileResult.success(r.pattern))
Expand All @@ -96,10 +98,10 @@ private class MatchIterator(val matcher: Matcher) extends Iterator[Match] {

// We need to get a first "matched" matcher for scala.js:
// https://github.com/scala-js/scala-js/issues/3280
var nextSeen = matcher.find()
val m = new Match(matcher)
var nextSeen: Boolean = matcher.find()
val m = new Match(matcher)

override def hasNext = {
override def hasNext: Boolean = {
if(!nextSeen) nextSeen = matcher.find()
nextSeen
}
Expand Down
12 changes: 8 additions & 4 deletions core/shared/src/main/scala/kantan/regex/DecodeResult.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ import kantan.codecs.ResultCompanion

/** Provides construction methods for [[DecodeResult]]. */
object DecodeResult extends ResultCompanion.WithDefault[DecodeError] {
override protected def fromThrowable(t: Throwable) = DecodeError.TypeError(t)
override protected def fromThrowable(t: Throwable): DecodeError.TypeError =
DecodeError.TypeError(t)

/** Creates a new [[kantan.regex.DecodeError.TypeError TypeError]] failure with the specified error message. */
def typeError(str: String): DecodeResult[Nothing] = failure(DecodeError.TypeError(str))
def typeError(str: String): DecodeResult[Nothing] =
failure(DecodeError.TypeError(str))

/** Creates a new [[kantan.regex.DecodeError.TypeError TypeError]] failure with the specified error. */
def typeError(e: Exception): DecodeResult[Nothing] = failure(DecodeError.TypeError(e))
def typeError(e: Exception): DecodeResult[Nothing] =
failure(DecodeError.TypeError(e))

/** Creates a new [[kantan.regex.DecodeError.NoSuchGroupId NoSuchgroupId]] failure for the specified group id. */
def noSuchGroupId(id: Int): DecodeResult[Nothing] = failure(DecodeError.NoSuchGroupId(id))
def noSuchGroupId(id: Int): DecodeResult[Nothing] =
failure(DecodeError.NoSuchGroupId(id))

/** Creates a new [[kantan.regex.DecodeError.EmptyGroup EmptyGroup]] failure. */
val emptyGroup: DecodeResult[Nothing] = failure(DecodeError.EmptyGroup)
Expand Down
4 changes: 3 additions & 1 deletion core/shared/src/main/scala/kantan/regex/Errors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package kantan.regex

import kantan.codecs.error.{Error, ErrorCompanion}
import kantan.codecs.error.Error
import kantan.codecs.error.ErrorCompanion

/** Root class for all regular expression related errors. */
sealed abstract class RegexError(msg: String) extends Error(msg)
Expand All @@ -29,6 +30,7 @@ object CompileError extends ErrorCompanion("an unspecified compile error occurre
sealed abstract class DecodeError(msg: String) extends RegexError(msg)

object DecodeError {
@SuppressWarnings(Array("org.wartremover.warts.ObjectThrowable"))
case object EmptyGroup extends DecodeError("an empty group was found")

@SuppressWarnings(Array("org.wartremover.warts.StringPlusAny"))
Expand Down
3 changes: 2 additions & 1 deletion core/shared/src/main/scala/kantan/regex/GroupDecoder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package kantan.regex

import kantan.codecs.{Decoder, DecoderCompanion}
import kantan.codecs.Decoder
import kantan.codecs.DecoderCompanion
import kantan.codecs.strings.StringDecoder

/** Provides instance creation and summoning methods for [[GroupDecoder]]. */
Expand Down
7 changes: 4 additions & 3 deletions core/shared/src/main/scala/kantan/regex/Match.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import scala.util.Try
/** Represents a single match in a regular expression evaluation.
*
* It's usually better not to interact with [[Match]] directly - more often than not, adapting existing instances of
* [[MatchDecoder]] is the better solution. When in a situation where you *must* deal with such values directly,
* it's important not to hold onto them: due to the way kantan.regex works internally, [[Match]] is mutable.
* [[MatchDecoder]] is the better solution. When in a situation where you *must* deal with such values directly, it's
* important not to hold onto them: due to the way kantan.regex works internally, [[Match]] is mutable.
*/
class Match private[regex] (private val matcher: Matcher) {

Expand All @@ -38,7 +38,8 @@ class Match private[regex] (private val matcher: Matcher) {
if(index < 0 || index > length) DecodeResult.noSuchGroupId(index)
else GroupDecoder[A].decode(Option(matcher.group(index)))

override def toString = matcher.toString
override def toString =
matcher.toString

/** Underlying pattern. */
def pattern(): Pattern =
Expand Down
Loading