class Ven::Reader
- Ven::Reader
- Reference
- Object
Overview
A reader capable of parsing Ven.
puts Ven::Reader.read("2 + 2")
Included Modules
Defined in:
ven/read.crConstant 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
-
.new(source : String, file : String = "untitled", context : Ven::Suite::Context::Reader = Context::Reader.new)
Makes a reader.
Class Method Summary
-
.read(source : String, file = "untitled", context = Context::Reader.new)
Makes an instance of
Reader
, immediately reads source and disposes the instance. -
.read(source, file = "untitled", context = Context::Reader.new, &)
Makes an instance of
Reader
, immediately reads source and disposes the instance.
Instance Method Summary
-
#before(type : String, unit : -> T = ->led) forall T
Expects type after calling unit.
-
#before(after : -> Bool, unit = ->led)
Calls after after calling unit.
-
#context : Ven::Suite::Context::Reader
Returns this reader's context.
-
#die(message : String)
Given an explanation message, message, dies of
ReadError
. -
#distinct? : Distinct | Nil
Tries to read a 'distinct' statement.
-
#eoi?
Returns whether the current word is one of the end-of-input words.
-
#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.
-
#exposes : Array(Distinct)
Tries to read a group of 'expose' statements separated by semicolons.
-
#is_led?(only pick : Parselet::Led.class) : Bool
Returns whether the current word is a led parselet of type pick.
-
#is_led?
Returns whether the current word is a led parselet.
-
#is_nud?(only pick : Parselet::Nud.class) : Bool
Returns whether the current word is a nud parselet of type pick.
-
#is_nud?
Returns whether the current word is a nud parselet.
-
#is_stmt?
Returns whether the current word is a statement parselet.
-
#led(level : Precedence = Precedence::ZERO) : Quote
Reads a led expression on precedence level level (see
Precedence
). -
#prepare
Prepares this reader so it is able to read Ven.
-
#read(&)
Reads the source, yielding each top-level statement to the block.
-
#read
Reads the source into an Array of
Quote
s. -
#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.
-
#statement : Quote
Reads a statement followed by a semicolon (if needed).
- #to_s(io)
-
#word : {type: String, lexeme: String, line: Int32}
Returns the current word.
-
#word!(type : String)
Returns the current word and consumes the next one, but only if the current word is of type type.
-
#word!
Returns the current word and consumes the next one.
Constructor Detail
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
Class Method Detail
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
.
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
.
Instance Method Detail
Expects type after calling unit. Returns whatever unit returns.
Calls after after calling unit. If after returned
false, dies of ReadError
.
Tries to read a 'distinct' statement.
Returns the path of the distinct if found one, or nil if did not.
"distinct" PATH (";" | EOI)
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.
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)}
Returns whether the current word is a led parselet of type pick.
Returns whether the current word is a nud parselet of type pick.
Reads a led expression on precedence level level (see Precedence
).
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.
Reads the source into an Array of Quote
s.
Returns that array.
Raises if this reader is dirty.
NOTE expose
and distinct
are not read by this method.
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.
Reads a statement followed by a semicolon (if needed).
Semicolons are optional before #eoi?
words.
Returns the current word and consumes the next one, but only if the current word is of type type. Returns nil otherwise.