Class: TL1::AST::Literal

Inherits:
Node
  • Object
show all
Defined in:
lib/tl1/ast.rb

Overview

A literal string. Not included in parsing output, but must match.

Instance Attribute Summary

Attributes inherited from Node

#fields

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#<=>, #as_json, #to_json

Constructor Details

#initialize(fields) ⇒ Literal

Returns a new instance of Literal.



221
222
223
# File 'lib/tl1/ast.rb', line 221

def initialize(fields)
  @fields = fields.to_str
end

Class Method Details

.parse(source) ⇒ Object



217
218
219
# File 'lib/tl1/ast.rb', line 217

def self.parse(source)
  new(source)
end

Instance Method Details

#formatObject



225
226
227
# File 'lib/tl1/ast.rb', line 225

def format(*)
  fields
end

#parse(source) ⇒ Object



229
230
231
232
# File 'lib/tl1/ast.rb', line 229

def parse(source, **)
  return if source == format
  raise "Message literal does not match format literal #{format.inspect}"
end