microparsec/internals

Lets

anyChar: Parser[char] = satisfy(constant true, ["any character"])
A Parser that matches any character.   Source Edit

Procs

proc peekCh(state: ParseState): ParseResult[Option[char]] {...}{.
    raises: [IOError, OSError], tags: [ReadIOEffect].}

A Parser that matches any character, to perform lookahead. Returns None if end of input has been reached. Does not consume any input.

This is currently called peekCh to avoid conflict with other function, but that will change in the future.

Note: Because this parser does not fail, do not use it with combinators such as many, because such parsers loop until a failure occurs. Careless use will thus result in an infinite loop.

  Source Edit
proc peekChF(state: ParseState): ParseResult[char] {...}{.raises: [IOError, OSError],
    tags: [ReadIOEffect].}

A Parser that matches any character, to perform lookahead. Does not consume any input, but will fail if end of input has been reached.

This is currently called peekCh to avoid conflict with other function, but that will change in the future.

  Source Edit

Funcs

func satisfy(p: char -> bool; expected: openArray[string] = []): Parser[char] {...}{.
    inline, raises: [], tags: [].}

Create a Parser that succeeds for any character for which a predicate returns true. Returns the character that is actually parsed.

This can be used to build more complex Parsers.

  Source Edit
func skip(p: char -> bool; expected: openArray[string] = []): Parser[void] {...}{.
    inline, raises: [], tags: [].}
Create a Parser that succeeds for any character for which a predicate returns true.   Source Edit
func satisfyWith[T](f: char -> T; p: T -> bool; expected: openArray[string] = []): Parser[
    T] {...}{.inline.}
Create a Parser that transforms a character, and succeeds if a predicate returns true on the transformed value. The parser returns the transformed character that was parsed.   Source Edit
func ch(c: char): Parser[char] {...}{.inline, raises: [], tags: [].}

Create a Parser that matches a specific character.

Note: This function is called char in Parsec, but this conflicts with the type char in Nim. As such, its name might change any time soon if I find a better one.

  Source Edit
func notChar(c: char): Parser[char] {...}{.inline, raises: [], tags: [].}
Create a Parser that matches any character except the given one.   Source Edit
func match[T](parser: Parser[T]): Parser[(string, T)] {...}{.inline.}
A Parser that returns both the result of a parse and the portion of the input that was consumed while it was being parsed.   Source Edit