Class: Lisp::Format::Directives::FreshLine

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

Overview

Represents the ~% (Freshline) directive. This outputs a new-line (?n) character a given number of times, depending on if it is already at the first output column or not.

Instance Attribute Summary

Attributes inherited from Directive

#pos

Instance Method Summary collapse

Methods inherited from Directive

#initialize, #join

Constructor Details

This class inherits a constructor from Lisp::Format::Directives::Directive

Instance Method Details

#execute(state) ⇒ Object

Outputs a new-line character a given number of times depending on if it is already at the first output column or not. If it is it outputs it the given number minus one (1). The full form is

~n&

with the following interpretations

n (1)

number of times to output the specific character (maybe minus one).



1304
1305
1306
1307
1308
1309
# File 'lib/carat/lisp-format.rb', line 1304

def execute(state)
  n = param(0, state, 1)
  return if n.zero?
  state.output(?\n) if state._col > 0
  (n - 1).times do state.output(?\n) end
end