pChar

fun <U : Any> pChar(character: Char, ignoreCase: Boolean = false): Parser<Char, Char, U>

Returns a Parser that consumes exactly one Char equal to character, and fails if the next character is different or the input is exhausted.

This is a thin wrapper around pSatisfy with a strict equality predicate.

Type parameters

  • U — the user context type threaded through unchanged. Use Unit when no context is needed.

Example

val openBrace: Parser<Char, Char, Unit> = pChar('{')

val input = ParserInput.of("{...}".toList(), Unit)
when (val result = openBrace(input)) {
is Success -> println("Matched: ${result.value}") // '{'
is Failure -> println(result.message)
}

Return

a Parser that succeeds with character on a match, or fails with a diagnostic message from pSatisfy.

Parameters

character

the exact character to match.

See also