Class: Lisp::Format::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/carat/lisp-format.rb

Overview

Engine for the format Lexer and Parser. Given an input format string and an initial State, it lets the Parser create the directives and then simply iterates over them, Directive#execute:ing them each.

Instance Method Summary collapse

Constructor Details

#initialize(format, state) ⇒ Formatter

Create a Formatter from a String format and a State state.



413
414
415
# File 'lib/carat/lisp-format.rb', line 413

def initialize(format, state)
  @parser, @state = Parser.new(Lexer.new(format)), state
end

Instance Method Details

#runObject

Parse and run the result.



418
419
420
421
# File 'lib/carat/lisp-format.rb', line 418

def run
  Format.execute_directives(@state, @parser.parse)
  return @state.latest_output.to_s
end