class Ven::Reader

Overview

A reader capable of parsing Ven.

puts Ven::Reader.read("2 + 2")

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

Built-in keywords.

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

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(source : String, file : String = "untitled", context : Ven::Suite::Context::Reader = Context::Reader.new) #

Makes a reader.

source (the only required argument) is for the source code, file is for the filename, and context is for the reader context.

NOTE Instances of Reader should be disposed after the first use.

puts Reader.new("1 + 1").read

[View source]

Class Method Detail

def self.read(source : String, file = "untitled", context = Context::Reader.new) #

Makes an instance of Reader, immediately reads source and disposes the instance.

source (the only required argument) is for the source code; file is for the filename; context is for the reader context.

Ignores valid expose and distinct.

See #read.


[View source]
def self.read(source, file = "untitled", context = Context::Reader.new, &) #

Makes an instance of Reader, immediately reads source and disposes the instance.

source (the only required argument) is for the source code; file is for the filename; context is for the reader context.

Ignores valid expose and distinct.

See #read.


[View source]

Instance Method Detail

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

Expects type after calling unit. Returns whatever unit returns.


[View source]
def before(after : -> Bool, unit = ->led) #

Calls after after calling unit. If after returned false, dies of ReadError.


[View source]

Returns this reader's context.


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

Given an explanation message, message, dies of ReadError.


[View source]
def distinct? : Distinct | Nil #

Tries to read a 'distinct' statement.

Returns the path of the distinct if found one, or nil if did not.

"distinct" PATH (";" | EOI)


[View source]
def eoi? #

Returns whether the current word is one of the end-of-input words.


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

Returns the current word and consumes the next one, but only if the current word is of one of the given types. Dies of ReadError otherwise.


[View source]
def exposes : Array(Distinct) #

Tries to read a group of 'expose' statements separated by semicolons. Returns an array of each of those exposes' paths. If read no expose statements, returns and empty array.

{"expose" PATH (";" | EOI)}


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

Returns whether the current word is a led parselet of type pick.


[View source]
def is_led? #

Returns whether the current word is a led parselet.


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

Returns whether the current word is a nud parselet of type pick.


[View source]
def is_nud? #

Returns whether the current word is a nud parselet.


[View source]
def is_stmt? #

Returns whether the current word is a statement parselet.


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

Reads a led expression on precedence level level (see Precedence).


[View source]
def prepare #

Prepares this reader so it is able to read Ven.


[View source]
def read(&) #

Reads the source, yielding each top-level statement to the block.

Returns nothing.

Raises if this reader is dirty.

NOTE expose and distinct are not read by this method.


[View source]
def read #

Reads the source into an Array of Quotes.

Returns that array.

Raises if this reader is dirty.

NOTE expose and distinct are not read by this method.


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

Calls unit repeatedly; assembles the results of each call in an Array, and returns that array on termination.

Expects sep after each call to unit. Terminates on stop.


[View source]
def statement : Quote #

Reads a statement followed by a semicolon (if needed).

Semicolons are optional before #eoi? words.


[View source]
def to_s(io) #

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

Returns the current word.


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

Returns the current word and consumes the next one, but only if the current word is of type type. Returns nil otherwise.


[View source]
def word! #

Returns the current word and consumes the next one.


[View source]