class Ven::Reader
- Ven::Reader
- Reference
- Object
Overview
A reader based on Pratt's parsing algorithm.
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
-
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
-
#before(type : String, unit : -> T = ->led) forall T
Expects type after calling unit.
- #context : Context::Reader
-
#die(message : String)
Given the explanation message, dies of ParseError.
-
#eoi?
Returns whether this token is a valid statement delimiter.
-
#expect(*restrictions : String)
Reads a word if one of the restrictions matches the current word's type.
-
#is_led?(only pick : Parselet::Led.class)
Returns whether this word is a led.
-
#is_led?
Returns whether this word is a led.
-
#is_nud?(only pick : Parselet::Nud.class)
Returns whether this word is a nud.
-
#is_nud?
Returns whether this word is a nud.
-
#is_stmt?
Returns whether this word is a statement.
- #keyword(trigger : String)
-
#led(level = Precedence::ZERO.value) : Quote
Parses a led expression with precedence level.
- #led=(led : Hash(String, Ven::Parselet::Led))
- #nud : Hash(String, Ven::Parselet::Nud)
- #nud=(nud : Hash(String, Ven::Parselet::Nud))
-
#prepare
Initializes this reader so it is capable of reading base Ven.
-
#program(&)
Parses the program (i.e., zero or more statements followed by EOF).
-
#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.
-
#statement : Quote
Parses a single statament.
- #to_s(io)
- #word : {type: String, lexeme: String, line: UInt32}
-
#word!(restriction : String)
Reads a word if the type of the current word is restriction.
-
#word!
Returns the current word and consumes the next one.
Constructor Detail
Instance Method Detail
Reads a word if one of the restrictions matches the current word's type. Dies of parse error otherwise.
Returns whether this word is a led. pick may be provided to check only certain parselet classes.
Returns whether this word is a led. pick may be provided to check only certain parselet classes.
Returns whether this word is a nud. pick may be provided to check only certain parselet classes.
Returns whether this word is a nud. pick may be provided to check only certain parselet classes.
Parses a led expression with precedence level.
Parses the program (i.e., zero or more statements followed by EOF). Each statement is yielded to the block.
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
.