Class: Lisp::Format::Directives::Factory

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

Overview

Factory for directives. Formatting directives should be created using singleton methods in this class.

Constant Summary collapse

@@directives =
{
  ?A  => [Ascii,		4,  [],		 0],
  ?S  => [SExpression,		4,  [],		 0],
  ?D  => [Decimal,		4,  [],		 0],
  ?B  => [Binary,		4,  [],		 0],
  ?O  => [Octal,		4,  [],		 0],
  ?X  => [Hexadecimal,		4,  [],		 0],
  ?R  => [Radix,		5,  [],		 0],
  ?P  => [Plural,		0,  [],		 0],
  ?C  => [Character,		0,  [],		 0],
  ?F  => [FFFP,			5,  [?:],	 0],
  ?E  => [ExpFP,		7,  [?:],	 0],
  ?G  => [GeneralFP,		7,  [?:],	 0],
  ?$  => [DollarFP,		4,  [],		 0],
  ?%  => [NewLine,		1,  [?:, ?@],	 0],
  ?&  => [FreshLine,		1,  [?:, ?@],	 0],
  ?|  => [NewPage,		1,  [?:, ?@],	 0],
  ?~  => [Tilde,		0,  [?:, ?@],	 0],
  ?\n => [SkipWhitespace,	0,  [[?:, ?@]],	 0],
  ?T  => [Tabulate,		2,  [],		 0],
  ?*  => [ArgJump,		1,  [[?:, ?@]],	 0],
  ??  => [Indirection,		0,  [?:],	 0],
  ?(  => [BeginCaseConversion,	0,  [],		 0],
  ?)  => [EndCaseConversion,	0,  [?:, ?@],	 0],
  ?[  => [BeginConditional,	1,  [[?:, ?@]],	 1],
  ?;  => [ClauseSeparator,	0,  [?@],	 0],
  ?]  => [EndConditional,	0,  [?@],	-1],
  ?{  => [BeginIteration,	1,  [],		 1],
  ?}  => [EndIteration,		0,  [?:, ?@],	-1],
}

Class Method Summary collapse

Class Method Details

.build(params, modifiers, directive, top, pos) ⇒ Object

Create a directive given a set of paramaters, modifiers, the character representing the directive, possible owning directive, and position in the format string.



1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
# File 'lib/carat/lisp-format.rb', line 1747

def self.build(params, modifiers, directive, top, pos)
  @@directives.include? directive or
    raise UnknownDirectiveError.new(pos), 'unknown format directive'
  idx = directive.chr.upcase[0]
  params.size <= @@directives[idx][1] or
    raise ParameterError.new(pos),
      'too many parameters given, expected no more than ' +
      @@directives[idx][1].to_s
  @@directives[idx][2].each do |illegal|
    if illegal.is_a? Array and (modifiers == illegal or
      modifiers.reverse == illegal)
      raise ModifierError.new(pos),
        'cannot specify both : and @ modifiers'
    elsif modifiers.include? illegal
      raise ModifierError.new(pos),
        'cannot specify the ' + mod.chr + 'modifier'
    end
  end
  return [
    @@directives[idx][0].new(params, modifiers, top, pos),
    @@directives[idx][3]
  ]
end