module Pars::Parse

Overview

Tools for creating commonly useful Parser instances.

Extended Modules

Defined in:

pars/parse.cr

Instance Method Summary

Macro Summary

Instance Method Detail

def alphanumeric #

[View source]
def byte(byte : UInt8) : Parser(UInt8) #

Parser that matches for a specific byte at the parse head.


[View source]
def byte : Parser(UInt8) #

Parser that return the byte vaue at the parse head.


[View source]
def byte_if(expected = nil, &block : UInt8 -> Bool) : Parser(UInt8) #

Parser that return the context head if it satisfies block.

expected can be optionally specified for providing a human friendly ParseError on fail.


[View source]
def bytes(bytes : Bytes) : Parser(Bytes) #

Creates a Parser(Bytes) that looks at the current parse position and expects a series of bytes to be consecutively present.


[View source]
def char(char : Char) : Parser(Char) #

Parser that matches for a specific char at the parse head.


[View source]
def char : Parser(Char) #

Parser that returns the parse head as a Char.


[View source]
def char_if(expected = nil, &block : Char -> Bool) : Parser(Char) #

Parser that return the context head if it satisfies block.

expected can be optionally specified for providing a human friendly ParseError on fail.


[View source]
def cond(value : T, expected : T | String | Nil = nil, &block : T -> Bool) : Parser(T) forall T #

Parser that succeeds with value if block evaluates to true when passed the value.

In most cases this should not be used externally and is instead a tool for composing parsers.


[View source]
def const(value : T) : Parser(T) forall T #

Always succeeds with value and does not consume any input.


[View source]
def decimal #

Parses a fractional number as a String.


[View source]
def digit #

Parses a digit as a character.


[View source]
def eq(value : T) : Parser(T) forall T #

Parser that tests equivalence to value at the parse head.

If equivalent value itself is returned and the parse head progresses.


[View source]
def integer #

Parses an integer as a String.


[View source]
def letter #

Parses a character in the alphabet regardless of case.


[View source]
def list(item : Parser(A), delimiter : Parser(B)) : Parser(Array(A)) forall A, B #

Creates a Parser(Array(T)) that will continue to parse with parser delimited by delimter until an error with either occurs.


[View source]
def lowercase #

Parses a character of the lowercase alphabet.


[View source]
def no_char_of(string_or_list : String | Enumerable(Char)) : Parser(Char) #

Functions identically to Parse.one_char_of, but reverses the expected input. If the current character is present in s, then the parse fails.


[View source]
def non_empty_list(item : Parser(A), delimiter : Parser(B)) : Parser(Array(A)) forall A, B #

[View source]
def number #

Parses a number as a String.


[View source]
def one_char_of(string_or_list : String | Enumerable(Char)) : Parser(Char) #

Creates a Parser(Char) that looks at the current parse position and expects the current character to be present in the string s.


[View source]
def string(string : String) : Parser(String) #

Creates a Parser(String) that looks at the current parse position and expects the array of characters in the string s (s.chars) to be consecutively present.


[View source]
def uppercase #

Parses a character of the uppercase alphabet.


[View source]
def whitespace #

[View source]
def word #

Parses a full word of at least one character.


[View source]

Macro Detail

macro do(body) #

Provides a notation for building complex parsers that combine the result of a number of component parsers.


[View source]