Parser

name.rayrobdod.stringContextParserCombinator.Parser
See theParser companion object
final class Parser[Expr[_], Type[_], A]

Parses an interpolated string expression into some value

Type parameters

A

the type of the parsed result

Expr

the macro-level expression type

Type

the macro-level type type

Attributes

Companion
object
Source
Parser.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Grouped members

parse

def extract(sc: StringContext, value: A)(implicit ev: Id[Any] =:= Expr[Any], ev2: ClassTag[Any] =:= Type[Any]): Option[Seq[Any]]

Extract subexpressions from the given value according to the given StringContext

Extract subexpressions from the given value according to the given StringContext

Attributes

Source
Parser.scala
final def extractor[UnexprA](sc: Expr[StringContext])(using Quotes, Type[UnexprA], Expr[UnexprA] <:< A, Expr[Boolean] =:= Expr[Boolean], Type[Boolean] =:= Type[Boolean]): Expr[Unapply[UnexprA]]

Parses a StringContext into an extractor

Parses a StringContext into an extractor

Attributes

Example
def valueImpl(sc:Expr[scala.StringContext])(using Quotes):Expr[Unapply[Result]] = {
 val myParser:Extractor[Expr[Result]] = ???
 myParser.extractor(sc)
}
extension (inline sc:scala.StringContext)
 inline def value:Unapply[Result] =
   ${valueImpl('sc)}
Inherited from:
VersionSpecificParser (hidden)
Source
VersionSpecificParser.scala
def interpolate(sc: StringContext, args: List[Any])(implicit ev: Any <:< Expr[Any]): A

Processes an immediate string context and its arguments into a value

Processes an immediate string context and its arguments into a value

Attributes

Source
Parser.scala
final def interpolate(sc: Expr[StringContext], args: Expr[Seq[Any]])(using q: Quotes, ev: Expr[Any] <:< Expr[Any]): A

Parses a StringContext and its arguments into a value

Parses a StringContext and its arguments into a value

Attributes

Example
def valueImpl(sc:Expr[scala.StringContext],
       args:Expr[Seq[Any]])(using Quotes):Expr[Result] = {
 val myParser:Interpolator[Expr[Result]] = ???
 myParser.interpolate(sc, args)
}
extension (inline sc:scala.StringContext)
 inline def value(inline args:Any*):Result =
   ${valueImpl('sc, 'args)}
Inherited from:
VersionSpecificParser (hidden)
Source
VersionSpecificParser.scala

Result Changing Combinators

def contramap[Z](contrafn: Z => A): Extractor[Expr, Type, Z]

Returns an extractor which invokes this extractor after mapping the input value using contrafn

Returns an extractor which invokes this extractor after mapping the input value using contrafn

Attributes

Source
Parser.scala
def imap[Z](cofn: A => Z, contrafn: Z => A): Parser[Expr, Type, Z]

Attributes

Source
Parser.scala
def map[Z](cofn: A => Z): Interpolator[Expr[Any], Z]

Returns an interpolator which invokes this parser, then modifies a successful result according to fn

Returns an interpolator which invokes this parser, then modifies a successful result according to fn

Attributes

Source
Parser.scala
def void: Parser[Expr, Type, Unit]

Returns a parser which discards its result while interpolating and ignores its input value while extracting

Returns a parser which discards its result while interpolating and ignores its input value while extracting

Attributes

Source
Parser.scala
def widenWith[Z](cofn: A => Z, contrafn: PartialExprFunction[Expr, Z, A]): Parser[Expr, Type, Z]

Returns an parser which is the pair of an Interpolator#map and an Extractor#widenWith

Returns an parser which is the pair of an Interpolator#map and an Extractor#widenWith

Attributes

Source
Parser.scala

Sequencing Combinators

def andThen[B, Z](rhs: Parser[Expr, Type, B])(implicit ev: BiSequenced[A, B, Z]): Parser[Expr, Type, Z]

Returns a parser which invokes this parser, and upon success invokes the other parser.

Returns a parser which invokes this parser, and upon success invokes the other parser.

Type parameters

Z

the result parser's parsed value type

Value parameters

ev

A descriptor of how to combine two values into one value

rhs

the parser to call after this one

Attributes

Source
Parser.scala
def flatMap[ExprZ <: Expr[Any], Z](cofn: A => Interpolator[ExprZ, Z]): Interpolator[ExprZ, Z]

Attributes

Source
Parser.scala

Branching Combinators

def orElse[B, Z](rhs: Parser[Expr, Type, B])(implicit ev: BiEithered[Expr, A, B, Z]): Parser[Expr, Type, Z]

Returns a parser which invokes this parser, and then:

Returns a parser which invokes this parser, and then:

  • If this parser run succeeded, return this internal's success
  • If this parser failed and consumed input, return this parser's failure
  • If this parser failed but did not consume input, run the other parser and return the other parser's result

Type parameters

Z

the result parser's parsed value type

Value parameters

ev

A descriptor of how to treat either value as one value

rhs

the parser to call after this one

Attributes

Source
Parser.scala

Repeating Combinators

def optionally[Z](strategy: RepeatStrategy)(implicit ev: BiOptionally[Expr, A, Z]): Parser[Expr, Type, Z]

Returns a parser which invokes this parser and provides a value whether this parser succeeded or failed

Returns a parser which invokes this parser and provides a value whether this parser succeeded or failed

Type parameters

Z

the result parser's parsed value type

Value parameters

ev

A descriptor of how to mark present or absent values

strategy

whether the optionally will attempt to match as much or as little as possible, and whether it will backtrack. Default is RepeatStrategy.Possessive

Attributes

Source
Parser.scala
def repeat[Z](min: Int, max: Int, delimiter: Parser[Expr, Type, Unit], strategy: RepeatStrategy)(implicit ev: BiRepeated[Expr, A, Z]): Parser[Expr, Type, Z]

Returns a parser which invokes this parser repeatedly and returns the aggregated result

Returns a parser which invokes this parser repeatedly and returns the aggregated result

Type parameters

Z

the result parser's parsed value type

Value parameters

delimiter

a parser describing separators between each repeat. Defaults to a parser that always succeeds and consumes no input.

ev

A descriptor of how to combine the repeated values into one value

max

the maximum number of repeats to consume

min

the minimum number of repeats to be considered successful

strategy

whether the repeat will attempt to match as much or as little as possible, and whether it will backtrack. Default is RepeatStrategy.Possessive

Attributes

Source
Parser.scala

Error Enriching Combinators

def opaque(description: String): Parser[Expr, Type, A]

Returns a parser which invokes this parser, but has the given description upon failure

Returns a parser which invokes this parser, but has the given description upon failure

Attributes

Source
Parser.scala

Other Combinators

def attempt: Parser[Expr, Type, A]

Returns a parser which invokes this parser, but treats the result of a failed parse as if it does not consume input

Returns a parser which invokes this parser, but treats the result of a failed parse as if it does not consume input

Attributes

Source
Parser.scala
def hide: Parser[Expr, Type, A]

Returns a parser which invokes this parser, but does not show the expected value in failure messages

Returns a parser which invokes this parser, but does not show the expected value in failure messages

Attributes

Source
Parser.scala

convert

def toExtractor: Extractor[Expr, Type, A]

Returns an Extractor that builds an extractor like this parser would

Returns an Extractor that builds an extractor like this parser would

Attributes

Source
Parser.scala
def toInterpolator: Interpolator[Expr[Any], A]

Returns an Interpolator that interpolates like this parser would

Returns an Interpolator that interpolates like this parser would

Attributes

Source
Parser.scala