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"] of ::String

A list of keywords protected by the reader.

Constructors

Instance Method Summary

Constructor Detail

def self.new #

[View source]

Instance Method Detail

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

Expects type after calling unit.


[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 | Nil = nil) #

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 | Nil = nil) #

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 keywords : Array(String) #

[View source]
def keywords=(keywords : Array(String)) #

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

Parses a led expression with precedence level.


[View source]
def led?(only pick : Parselet::Led.class | Nil = nil) #

Returns an array of leds that are of .class only. If given no only, or only is nil, returns all leds.


[View source]
def module(&) #

Performs a module-level parse (zero or more statements followed by EOF). Each statement is yielded to block.


[View source]
def nud?(only pick : Parselet::Nud.class | Nil = nil) #

Returns an array of nuds that are of .class only. If given no only, or only is nil, returns all nuds.


[View source]
def prepare #

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


[View source]
def read(filename : String, source : String, &block : Quote -> _) #

Reads the source under the filename.


[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 reset(file : String = "<unknown>", src : String = "") #

Resets


[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! #

Consumes a fresh word and returns the former word.


[View source]
def world : Ven::World #

[View source]
def world=(world : Ven::World) #

[View source]