Matchers

io.github.edadma.pattern_matcher.Matchers
trait Matchers[Input <: CharReader]

Provides methods for coding character pattern matchers.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Type members

Classlikes

case class Match[R](result: R, next: Input) extends MatcherResult[R]

Represents a successful match.

Represents a successful match.

Type parameters

R

type of result value

Value parameters

next

next character of input

result

result value of the match

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class MatcherResult[R]
class Object
trait Matchable
class Any
Show all
abstract class Matcher[+R] extends Input => MatcherResult[R]

Abstract matcher. A matcher is a function that maps character input to a result value.

Abstract matcher. A matcher is a function that maps character input to a result value.

Type parameters

R

type of result value

Attributes

Supertypes
trait Input => MatcherResult[R]
class Object
trait Matchable
class Any
abstract class MatcherResult[+R]

Abstract class for Matcher results

Abstract class for Matcher results

Type parameters

R

type of result value

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Match[R]
class Mismatch
case class Mismatch(msg: String, next: Input) extends MatcherResult[Nothing]

Represents an unsuccessful match.

Represents an unsuccessful match.

Value parameters

next

character at which the mismatch occurred

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class MatcherResult[Nothing]
class Object
trait Matchable
class Any
Show all
case class ~[+A, +B](a: A, b: B)

Case class for return sequence matcher results that can be pattern matched.

Case class for return sequence matcher results that can be pattern matched.

Type parameters

A

type of left result value

B

type of right result value

Value parameters

a

left result value

b

right result value

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Value members

Concrete methods

def affect(affect: CharReader => Unit): Matcher[Unit]
def anyOf(cs: Char*): Matcher[Char]

Returns a matcher that will match any of a list of characters.

Returns a matcher that will match any of a list of characters.

Value parameters

cs

argument list of characters

Attributes

Returns

a matcher that only matches a character from a list

def backStringLit: Matcher[String]
def capture[S](name: String, m: => Matcher[S]): Matcher[S]
def char: Matcher[Char]

Returns a matcher that always succeeds as long as there is input remaining, matching one character.

Returns a matcher that always succeeds as long as there is input remaining, matching one character.

Attributes

Returns

a matcher with the next input character as its result value, failing if there is no more input

def clear(): Unit

Clears capture groups.

Clears capture groups.

Attributes

def delimiter: Matcher[String]
def digit: Matcher[Char]

Returns a digit character matcher.

Returns a digit character matcher.

Attributes

def digits: Matcher[String]
def doubleStringLit: Matcher[String]
def elem(pred: Char => Boolean, msg: String): Matcher[Char]

Returns a matcher that matches the current input character if it is a member of a class of characters.

Returns a matcher that matches the current input character if it is a member of a class of characters.

Value parameters

pred

predicate that determines if the current input character matches

Attributes

Returns

a matcher for matching character classes

def eoi: Matcher[Unit]

Returns a zero-length matcher that succeeds at the end of input.

Returns a zero-length matcher that succeeds at the end of input.

Attributes

Returns

a matcher that succeeds at the end of input, fails otherwise.

def fail(msg: String): Matcher[Nothing]

Returns a matcher that always fails.

Returns a matcher that always fails.

Attributes

Returns

a matcher that always fails with a result containing the current point in the input stream

def floatLit: Matcher[Double]
def group(name: String): Option[(Input, Input)]

Returns capture group.

Returns capture group.

Value parameters

name

the name of the capture group to return

Attributes

Returns

a capture group with is a pair of input objects: the first is the first character in the group, the second is the next input character after the end of the group.

def guard[S](m: => Matcher[S]): Matcher[S]

Returns a matcher whose result is the same as the given matcher, but without consuming any input.

Returns a matcher whose result is the same as the given matcher, but without consuming any input.

Type parameters

S

the type of the result value

Value parameters

m

the given matcher

Attributes

Returns

the new matcher

def hexdigit: Matcher[Char]

Returns a hex digit character matcher.

Returns a hex digit character matcher.

Attributes

def ident: Matcher[String]
def identChar(c: Char): Boolean
def identOrReserved: Matcher[String]
def integerLit: Matcher[Int]
def letter: Matcher[Char]

Returns a letter character matcher.

Returns a letter character matcher.

Attributes

def letterOrDigit: Matcher[Char]

Returns a letter or digit character matcher.

Returns a letter or digit character matcher.

Attributes

def lookbehind(pred: Char => Boolean, msg: String): Matcher[Char]

Returns a zero-length matcher that succeeds if the previous input character is a member of a character class.

Returns a zero-length matcher that succeeds if the previous input character is a member of a character class.

Value parameters

pred

predicate that determines inclusion in a character class

Attributes

def lower: Matcher[Char]

Returns a lower case character matcher.

Returns a lower case character matcher.

Attributes

def matchall[R](m: Matcher[R]): Matcher[R]
def matched[S](m: => Matcher[S]): Matcher[(Input, Input)]
def noneOf(cs: Char*): Matcher[Char]

Returns a matcher that will matcher any character not in a list of characters.

Returns a matcher that will matcher any character not in a list of characters.

Value parameters

cs

argument list of characters

Attributes

Returns

a matcher that only matches a character not on a list

def not[S](m: => Matcher[S]): Matcher[Unit]

Returns a matcher that negates the result of the given matcher. No input is consumed.

Returns a matcher that negates the result of the given matcher. No input is consumed.

Type parameters

S

the type of the result value of the given matcher

Value parameters

m

the matcher whose result is negated

Attributes

Returns

the new matcher

def notElem(pred: Char => Boolean, msg: String): Matcher[Char]
def opt[S](m: => Matcher[S]): Matcher[Option[S]]

Returns a matcher that allows a matcher to succeed optionally.

Returns a matcher that allows a matcher to succeed optionally.

Type parameters

S

the type of the optional result value

Value parameters

m

the matcher to apply to the input.

Attributes

Returns

a matcher with an optional result value

def pos: Matcher[Input]
def rep[S](m: => Matcher[S]): Matcher[List[S]]
def rep1[S](m: => Matcher[S]): Matcher[List[S]]
def rep1sep[T, U](m: => Matcher[T], sep: => Matcher[U]): Matcher[List[T]]
def repsep[T, U](m: => Matcher[T], sep: => Matcher[U]): Matcher[List[T]]
def repu[S](m: => Matcher[S]): Matcher[Unit]
def singleStringLit: Matcher[String]
def soi: Matcher[Unit]

Returns a zero-length matcher that succeeds at the start of input.

Returns a zero-length matcher that succeeds at the start of input.

Attributes

Returns

a matcher that succeeds at the start of input, fails otherwise.

def space: Matcher[Char]

Returns a space character matcher.

Returns a space character matcher.

Attributes

def str(s: String): Matcher[String]

Returns a matcher to match against a string.

Returns a matcher to match against a string.

For example

 def bracketed: Matcher[List[Char]] = "[[" ~> rep(not("]]") ~> char) <~ "]]"

Value parameters

s

the string to match

Attributes

Returns

a matcher that matches against a string, with that string as its result value if it succeeds

def string[S](m: => Matcher[S]): Matcher[String]
def substring(name: String): Option[String]

Returns the substring from a capture group.

Returns the substring from a capture group.

Value parameters

name

the name of the capture group

Attributes

def succeed[R](r: => R): Matcher[R]

Returns a matcher that always succeeds.

Returns a matcher that always succeeds.

Type parameters

R

the type of result value

Value parameters

r

the result value

Attributes

Returns

a matcher that always succeeds with a result value

def t[S](m: => Matcher[S]): Matcher[S]
def tap[S](name: String)(m: => Matcher[S]): Matcher[S]
def upper: Matcher[Char]

Returns an upper case character matcher.

Returns an upper case character matcher.

Attributes

def whitespace: Matcher[Unit]

Concrete fields

val delimiters: HashSet[String]

The set of delimiters

The set of delimiters

Attributes

val reserved: HashSet[String]

The set of reserved identifiers

The set of reserved identifiers

Attributes

Implicits

Implicits

implicit def ch(c: Char): Matcher[Char]

Returns a matcher for a specific character. This combinator is an implicit function so that character literals can be lifted to the corresponding character matcher.

Returns a matcher for a specific character. This combinator is an implicit function so that character literals can be lifted to the corresponding character matcher.

For example

 def tag: Matcher[String] = '<' ~> (letter|'_') ~ rep(letter|digit|'-'|'_'|'.') <~ '>'

Value parameters

c

the character to be matched

Attributes

Returns

the character matcher

implicit def keyword(s: String): Matcher[String]