class Ven::Reader

Overview

A reader based on Pratt's parsing algorithm.

Included Modules

Defined in:

ven/read.cr

Constant Summary

KEYWORDS = ["_", "&_", "nud", "not", "is", "in", "if", "else", "fun", "given", "loop", "next", "queue", "ensure", "expose", "distinct", "box", "and", "or", "return", "dies", "to"] of ::String

A list of keywords protected by the reader.

RX_IGNORE = /^(#{Ven.regex_for(:IGNORE)})/
RX_NUMBER = /^(#{Ven.regex_for(:NUMBER)})/
RX_REGEX = /^(#{Ven.regex_for(:REGEX)})/
RX_SPECIAL = /^(#{Ven.regex_for(:SPECIAL)})/
RX_STRING = /^(#{Ven.regex_for(:STRING)})/
RX_SYMBOL = /^(#{Ven.regex_for(:SYMBOL)})/

Constructors

Instance Method Summary

Constructor Detail

def self.new(context : Ven::Suite::Context::Reader, file : String, src : String) #

[View source]

Instance Method Detail

def before(type : String, unit : -> T = ->led) forall T #

Expects type after calling unit.


[View source]
def context : Context::Reader #

[View source]
def die(message : String) #

Given the explanation message, dies of ParseError.


[View source]
def eoi? #

Returns whether this token is a valid statement delimiter.


[View source]
def expect(*restrictions : String) #

Reads a word if one of the restrictions matches the current word's type. Dies of parse error otherwise.


[View source]
def is_led?(only pick : Parselet::Led.class) #

Returns whether this word is a led. pick may be provided to check only certain parselet classes.


[View source]
def is_led? #

Returns whether this word is a led. pick may be provided to check only certain parselet classes.


[View source]
def is_nud?(only pick : Parselet::Nud.class) #

Returns whether this word is a nud. pick may be provided to check only certain parselet classes.


[View source]
def is_nud? #

Returns whether this word is a nud. pick may be provided to check only certain parselet classes.


[View source]
def is_stmt? #

Returns whether this word is a statement.


[View source]
def keyword(trigger : String) #

[View source]
def led(level = Precedence::ZERO.value) : Quote #

Parses a led expression with precedence level.


[View source]
def led=(led : Hash(String, Ven::Parselet::Led)) #

[View source]
def nud : Hash(String, Ven::Parselet::Nud) #

[View source]
def nud=(nud : Hash(String, Ven::Parselet::Nud)) #

[View source]
def prepare #

Initializes this reader so it is capable of reading base Ven.


[View source]
def program(&) #

Parses the program (i.e., zero or more statements followed by EOF). Each statement is yielded to the block.


[View source]
def repeat(stop : String | Nil = nil, sep : String | Nil = nil, unit : -> T = ->led) forall T #

Calls unit repeatedly, remembering what each call results in, and returns an Array of the results. Expects a sep after each unit. Terminates at stop.

NOTE either stop or sep, and unit may be omitted; unit defaults to a #led.


[View source]
def statement : Quote #

Parses a single statament.


[View source]
def to_s(io) #

[View source]
def word : {type: String, lexeme: String, line: UInt32} #

[View source]
def word!(restriction : String) #

Reads a word if the type of the current word is restriction.


[View source]
def word! #

Returns the current word and consumes the next one.


[View source]