module Novika::Quote
Overview
Includers are Novika quotes, which are known as strings in most other programming languages.
Quotes are optimized for the ASCII-only case. Also, they
treat single String::Grapheme
s separately from strings
of those, and cache grapheme counts here and there.
The slowest operations on quotes are #slice_at
and #at
over non- ASCII quotes. Both are currently O(N) in terms
of iterations only; they do a lot of other work besides
iteration as well.
When you are slow, being even slower doesn't matter that much anymore. This is the case with Novika.
And yes, quotes do rely on the experimental grapheme API.
Included Modules
Direct including types
Defined in:
novika/forms/quote.crConstant Summary
-
EFFECT_BOUND_TAKE =
12
-
Specifies how many characters to take from the left and right boundaries of the quote for a shorter representation in
#effect
. -
EFFECT_MAX_CHARS =
32
-
Specifies the maximum amount of characters to display before the quote gets cut off in
#effect
(seeForm#effect
). -
EMPTY =
StringQuote.new("", count: 0, ascii_only: true)
-
The empty quote.
Constructors
-
.new(string : String, count = string.grapheme_size, ascii = string.ascii_only?)
Creates a quote from string.
-
.new(grapheme : String::Grapheme)
Creates a quote from grapheme.
-
.new(char : Char)
Creates a quote from char.
Class Method Summary
Instance Method Summary
-
#==(other : Quote) : Bool
Returns whether this quote variant consists of the same graphemes as other.
-
#at(b : Int32, e : Int32) : Quote
Returns a subquote from b to e.
-
#at(index : Int32) : GraphemeQuote
Returns the grapheme at index as
Quote
, or dies. -
#at?(index : Int32) : GraphemeQuote | Nil
Returns the grapheme at index as
Quote
, or nil. -
#cached_count? : Int32 | Nil
Returns the cached count of graphemes in this quote variant.
-
#count : Int32
Returns the amount of graphemes in this quote variant.
-
#desc(io : IO)
Appends a string description of this form to io.
-
#each_occurrence_of(pattern : Form, &)
Yields occurrences of the given pattern in this quote.
-
#effect(io)
Generates and returns a description for the stack effect of this form.
-
#empty? : Bool
Returns whether this quote is empty.
-
#first_byte? : UInt8 | Nil
Returns the first byte (or nil) in this quote.
-
#fit(total : Int, ellipsis : _) : Quote
Ensures this quote is of total characters or less.
-
#ord? : Int32 | Nil
Returns the Unicode codepoint for the first character in this quote, or nil if this quote is empty.
-
#pad(total : Int, padder : _, side : PadSide) : Quote
Pads this quote with padder until it becomes total perceived characters long.
-
#replace_all(pattern : Quote, repl : Quote) : Quote
Replaces instances of pattern with repl.
-
#slice_at(slicept : Int32) : Tuple(Quote, Quote)
Slices this quote into two quotes at slicept.
-
#slice_at?(slicept : Int32) : Tuple(Quote, Quote) | Nil
Slices this quote into two quotes at slicept.
-
#stitch(other : Quote) : Quote
Stitches (concatenates) this and other quote variants, and returns the resulting quote.
-
#string : String
Converts this quote variant to
String
. -
#to_byteslice
Returns an immutable
Byteslice
representation of this quote. -
#to_quote : Quote
Returns this form's quote representation.
Instance methods inherited from module Novika::Form
a(type : T.class) : T forall T
a,
desc(io : IO)desc : String desc, die(details : String) die, effect(io)
effect effect, on_open(engine : Engine) : self on_open, on_parent_open(engine : Engine) : self on_parent_open, onto(block : Block) : self onto, sel(a, b) sel, to_quote : Quote to_quote
Instance methods inherited from module Novika::Schedulable
schedule(engine : Engine, stack : Block)
schedule,
schedule!(engine : Engine, stack : Block)
schedule!
Constructor Detail
Creates a quote from string.
count can be provided if the amount of graphemes in string is known.
Class Method Detail
Instance Method Detail
Returns whether this quote variant consists of the same graphemes as other.
Returns a subquote from b to e. Clamps b and e to bounds of this quote. Returns an empty quote if this quote is empty without regarding b and e.
Both ends are inclusive.
Returns the grapheme at index as Quote
, or nil.
Returns the cached count of graphemes in this quote variant. Returns nil if there is no cached count.
Appends a string description of this form to io.
Yields occurrences of the given pattern in this quote.
Generates and returns a description for the stack effect of this form.
For blocks and builtins, tries to extract a ( ... -- ... )
(but see EFFECT_PATTERN
) from their corresponding
comment. If could not extract or no comment, returns
'a block' for blocks and 'native code' for builtins.
Ensures this quote is of total characters or less. In case of overflow, truncates with ellipsis. If even ellipsis cannot fit, truncates ellipsis so that it is of total characters. Returns the resulting quote.
Returns the Unicode codepoint for the first character in this quote, or nil if this quote is empty.
Pads this quote with padder until it becomes total perceived characters long. The side where the padding should apply is specified by side. Returns the resulting quote.
Replaces instances of pattern with repl. Returns the resulting quote.
Slices this quote into two quotes at slicept. Returns the two resulting quotes. Dies if slicept is out of bounds.
Slices this quote into two quotes at slicept. Returns the two resulting quotes. Returns nil if slicept is out of bounds.
Stitches (concatenates) this and other quote variants, and returns the resulting quote.
Returns this form's quote representation.