object combinator
This module contains pre-made combinators that are very useful for a variety of purposes, specialised to cats
.
In particular, it contains functionality found normally in parsley.combinator
, but returning the cats
NonEmptyList
instead of a regular Scala List
.
- Source
- combinator.scala
- Since
1.2.0
- Alphabetic
- By Inheritance
- combinator
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def endBy1[A](p: Parsley[A], sep: => Parsley[_]): Parsley[NonEmptyList[A]]
This combinator parses one or more occurrences of
p
, separated and ended bysep
.This combinator parses one or more occurrences of
p
, separated and ended bysep
.Parses
p
followed bysep
one or more times. The results of thep
's,x1
throughxn
, are returned asNonEmptyList.of(x1, .., xn)
. Ifp
orsep
fails having consumed input, the whole parser fails.- p
the parser whose results are collected into a list.
- sep
the delimiter that must be parsed between every
p
.- returns
a parser that parses
p
delimited bysep
, returning the non-empty list ofp
's results.
scala> ... scala> val args = endBy1(int, string(";\n")) scala> args.parse("7;\n3;\n2") val res0 = Failure(..) scala> args.parse("") val res1 = Failure(..) scala> args.parse("1;\n") val res2 = Success(NonEmptyList.of(1)) scala> args.parse("1;\n2;\n") val res3 = Success(NonEmptyList.of(1, 2))
- Since
1.2.0
Example: - final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def sepBy1[A](p: Parsley[A], sep: => Parsley[_]): Parsley[NonEmptyList[A]]
This combinator parses one or more occurrences of
p
, separated bysep
.This combinator parses one or more occurrences of
p
, separated bysep
.First parses a
p
. Then parsessep
followed byp
until there are no moresep
s. The results of thep
's,x1
throughxn
, are returned asNonEmptyList.of(x1, .., xn)
. Ifp
orsep
fails having consumed input, the whole parser fails. Requires at least onep
to have been parsed.- p
the parser whose results are collected into a list.
- sep
the delimiter that must be parsed between every
p
.- returns
a parser that parses
p
delimited bysep
, returning the non-empty list ofp
's results.
scala> ... scala> val args = sepBy1(int, string(", ")) scala> args.parse("7, 3, 2") val res0 = Success(NonEmptyList.of(7, 3, 2)) scala> args.parse("") val res1 = Failure(..) scala> args.parse("1") val res2 = Success(NonEmptyList.of(1)) scala> args.parse("1, 2, ") val res3 = Failure(..) // no trailing comma allowed
- Since
1.2.0
Example: - def sepEndBy1[A](p: Parsley[A], sep: => Parsley[_]): Parsley[NonEmptyList[A]]
This combinator parses one or more occurrences of
p
, separated and optionally ended bysep
.This combinator parses one or more occurrences of
p
, separated and optionally ended bysep
.First parses a
p
. Then parsessep
followed byp
until there are no more: if a finalsep
exists, this is parsed. The results of thep
's,x1
throughxn
, are returned asNonEmptyList.of(x1, .., xn)
. Ifp
orsep
fails having consumed input, the whole parser fails. Requires at least onep
to have been parsed.- p
the parser whose results are collected into a list.
- sep
the delimiter that must be parsed between every
p
.- returns
a parser that parses
p
delimited bysep
, returning the non-empty list ofp
's results.
scala> ... scala> val args = sepEndBy1(int, string(";\n")) scala> args.parse("7;\n3;\n2") val res0 = Success(NonEmptyList.of(7, 3, 2)) scala> args.parse("") val res1 = Failure(..) scala> args.parse("1") val res2 = Success(NonEmptyList.of(1)) scala> args.parse("1;\n2;\n") val res3 = Success(NonEmptyList.of(1, 2))
- Since
1.2.0
Example: - def some[A](p: Parsley[A]): Parsley[NonEmptyList[A]]
This combinator repeatedly parses a given parser one or more times, collecting the results into a list.
This combinator repeatedly parses a given parser one or more times, collecting the results into a list.
Parses a given parser,
p
, repeatedly until it fails. Ifp
failed having consumed input, this combinator fails. Otherwise whenp
fails without consuming input, this combinator will return all of the results,x1
throughxn
(withn >= 1
), in a non-empty list:NonEmptyList.of(x1, .., xn)
. Ifp
was not successful at least one time, this combinator fails.- p
the parser to execute multiple times.
- returns
a parser that parses
p
until it fails, returning the non-empty list of all the successful results.
scala> import parsley.character.string scala> import parsley.cats.combinator.some scala> val p = some(string("ab")) scala> p.parse("") val res0 = Failure(..) scala> p.parse("ab") val res1 = Success(NonEmptyList.of("ab")) scala> p.parse("abababab") val res2 = Success(NonEmptyList.of("ab", "ab", "ab", "ab")) scala> p.parse("aba") val res3 = Failure(..)
- Since
1.2.0
Example: - def someTill[A](p: Parsley[A], end: Parsley[_]): Parsley[NonEmptyList[A]]
This combinator repeatedly parses a given parser one or more times, until the
end
parser succeeds, collecting the results into a list.This combinator repeatedly parses a given parser one or more times, until the
end
parser succeeds, collecting the results into a list.First ensures that trying to parse
end
fails, then tries to parsep
. If it succeed then it will repeatedly: try to parseend
, if it fails without consuming input, then parsesp
, which must succeed. Whenend
does succeed, this combinator will return all of the results generated byp
,x1
throughxn
(withn >= 1
), in a non-empty list:NonEmptyList.of(x1, .., xn)
. The parserp
must succeed at least once beforeend
succeeds.- p
the parser to execute multiple times.
- end
the parser that stops the parsing of
p
.- returns
a parser that parses
p
untilend
succeeds, returning the non-empty list of all the successful results.
This can be useful for scanning comments:
scala> import parsley.character.{string, item, endOfLine} scala> import parsley.cats.combinator.someTill scala> val comment = string("//") *> someTill(item, endOfLine) scala> p.parse("//hello world") val res0 = Failure(..) scala> p.parse("//hello world\n") val res1 = Success(NonEmptyList.of('h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd')) scala> p.parse("//\n") val res2 = Failure(..) scala> p.parse("//a\n") val res3 = Success(NonEmptyList.of('a'))
- Since
1.3.0
Example: - final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
Deprecated Value Members
- def someUntil[A](p: Parsley[A], end: Parsley[_]): Parsley[NonEmptyList[A]]
This combinator repeatedly parses a given parser one or more times, until the
end
parser succeeds, collecting the results into a list.This combinator repeatedly parses a given parser one or more times, until the
end
parser succeeds, collecting the results into a list.First ensures that trying to parse
end
fails, then tries to parsep
. If it succeed then it will repeatedly: try to parseend
, if it fails without consuming input, then parsesp
, which must succeed. Whenend
does succeed, this combinator will return all of the results generated byp
,x1
throughxn
(withn >= 1
), in a non-empty list:NonEmptyList.of(x1, .., xn)
. The parserp
must succeed at least once beforeend
succeeds.- p
the parser to execute multiple times.
- end
the parser that stops the parsing of
p
.- returns
a parser that parses
p
untilend
succeeds, returning the non-empty list of all the successful results.
- Annotations
- @deprecated
- Deprecated
(Since version 1.3.0) This combinator will be removed in 2.0.0, use someTill instead
This can be useful for scanning comments:
scala> import parsley.character.{string, item, endOfLine} scala> import parsley.cats.combinator.someUntil scala> val comment = string("//") *> someUntil(item, endOfLine) scala> p.parse("//hello world") val res0 = Failure(..) scala> p.parse("//hello world\n") val res1 = Success(NonEmptyList.of('h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd')) scala> p.parse("//\n") val res2 = Failure(..) scala> p.parse("//a\n") val res3 = Success(NonEmptyList.of('a'))
- Since
1.2.0
Example: