Skip to content

Commit

Permalink
Renamed UrlInput to UrlFragment and made it visible in Soundness
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Oct 8, 2024
1 parent ac9a0d3 commit 5ec57c3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ import anticipation.*
import contextual.*
import spectacular.*

object UrlInput:
given Substitution[UrlInput, Text, "x"] = UrlInput.Textual(_)
given Substitution[UrlInput, Raw, "x"] = raw => UrlInput.RawTextual(raw.text)
given Substitution[UrlInput, Int, "80"] = UrlInput.Integral(_)
object UrlFragment:
def apply(value: Text): UrlFragment = UrlFragment.Textual(value)
def apply(value: Int): UrlFragment = UrlFragment.Integral(value)

given Substitution[UrlFragment, Text, "x"] = UrlFragment.Textual(_)
given Substitution[UrlFragment, Raw, "x"] = raw => UrlFragment.RawTextual(raw.text)
given Substitution[UrlFragment, Int, "80"] = UrlFragment.Integral(_)

given [ValueType](using encoder: Encoder[ValueType]) => Substitution[UrlInput, ValueType, "x"] =
value => UrlInput.Textual(encoder.encode(value))
given [ValueType](using encoder: Encoder[ValueType]) => Substitution[UrlFragment, ValueType, "x"] =
value => UrlFragment.Textual(encoder.encode(value))

enum UrlInput:
enum UrlFragment:
case Integral(value: Int)
case Textual(value: Text)
case RawTextual(value: Text)
10 changes: 5 additions & 5 deletions src/url/nettlesome.UrlInterpolator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import scala.quoted.*

import errorDiagnostics.empty

object UrlInterpolator extends contextual.Interpolator[UrlInput, Text, Url[Label]]:
object UrlInterpolator extends contextual.Interpolator[UrlFragment, Text, Url[Label]]:

def refined(context: Expr[StringContext], parts: Expr[Seq[Any]])(using Quotes)
: Expr[Url[Label]] =
Expand All @@ -47,8 +47,8 @@ object UrlInterpolator extends contextual.Interpolator[UrlInput, Text, Url[Label

def initial: Text = t""

def insert(state: Text, value: UrlInput): Text = value match
case UrlInput.Integral(port) =>
def insert(state: Text, value: UrlFragment): Text = value match
case UrlFragment.Integral(port) =>
if !state.ends(t":")
then throw InterpolationError(m"a port number must be specified after a colon")

Expand All @@ -58,7 +58,7 @@ object UrlInterpolator extends contextual.Interpolator[UrlInput, Text, Url[Label

state+port.show

case UrlInput.Textual(text) =>
case UrlFragment.Textual(text) =>
if !state.ends(t"/")
then throw InterpolationError(m"a substitution may only be made after a slash")

Expand All @@ -68,7 +68,7 @@ object UrlInterpolator extends contextual.Interpolator[UrlInput, Text, Url[Label

state+text.urlEncode

case UrlInput.RawTextual(text) =>
case UrlFragment.RawTextual(text) =>
if !state.ends(t"/")
then throw InterpolationError(m"a substitution may only be made after a slash")

Expand Down
2 changes: 1 addition & 1 deletion src/url/soundness+nettlesome-url.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

package soundness

export nettlesome.{url, email, host, Authority, Raw, Scheme, Url, UrlError, HttpUrl}
export nettlesome.{url, email, host, Authority, Raw, Scheme, Url, UrlError, HttpUrl, UrlFragment}

0 comments on commit 5ec57c3

Please sign in to comment.