class Dhall::TextLiteral
Public Class Methods
decode(*chunks)
click to toggle source
# File lib/dhall/binary.rb, line 204 def self.decode(*chunks) lead_text, *pairs = chunks chunks = [Text.new(value: lead_text)] + pairs.each_slice(2).flat_map do |(e, t)| [Dhall.decode(e), Text.new(value: t)] end chunks.length == 1 ? chunks.first : TextLiteral.new(chunks: chunks) end
for(*chunks)
click to toggle source
# File lib/dhall/ast.rb, line 1301 def self.for(*chunks) fixed = ([""] + chunks) .flat_map { |c| ["", c, ""] } .map { |c| c.is_a?(Expression) ? c : Text.new(value: c.to_s) } .chunk { |x| x.is_a?(Text) }.flat_map do |(is_text, group)| is_text ? group.reduce(&:<<) : group end fixed.length == 1 ? fixed.first : new(chunks: fixed) end
Public Instance Methods
as_json()
click to toggle source
# File lib/dhall/ast.rb, line 1321 def as_json [18, *chunks.map { |chunk| chunk.is_a?(Text) ? chunk.value : chunk.as_json }] end
end_empty?()
click to toggle source
# File lib/dhall/ast.rb, line 1317 def end_empty? chunks.last.empty? end
flatten()
click to toggle source
# File lib/dhall/normalize.rb, line 427 def flatten with(chunks: chunks.flat_map do |chunk| chunk.is_a?(TextLiteral) ? chunk.chunks : chunk end) end
normalize()
click to toggle source
Calls superclass method
Dhall::Expression#normalize
# File lib/dhall/normalize.rb, line 416 def normalize lit = TextLiteral.for(*super.flatten.chunks) if lit.is_a?(TextLiteral) && lit.chunks.length == 3 && lit.start_empty? && lit.end_empty? lit.chunks[1] else lit end end
start_empty?()
click to toggle source
# File lib/dhall/ast.rb, line 1313 def start_empty? chunks.first.empty? end