Class: ToFactory::Parsing::Syntax

Inherits:
Object
  • Object
show all
Defined in:
lib/to_factory/parsing/syntax.rb

Direct Known Subclasses

NewSyntax, OldSyntax

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contents) ⇒ Syntax

Returns a new instance of Syntax.



8
9
10
# File 'lib/to_factory/parsing/syntax.rb', line 8

def initialize(contents)
  @contents = contents
end

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



6
7
8
# File 'lib/to_factory/parsing/syntax.rb', line 6

def contents
  @contents
end

Instance Method Details

#factoriesObject



25
26
27
28
29
30
31
# File 'lib/to_factory/parsing/syntax.rb', line 25

def factories
  if multiple_factories?
    factories_sexp[1..-1]
  else
    [factories_sexp]
  end
end

#factories_sexpObject



33
34
35
# File 'lib/to_factory/parsing/syntax.rb', line 33

def factories_sexp
  header? ?  sexp[3] : sexp
end

#multiple_factories?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/to_factory/parsing/syntax.rb', line 12

def multiple_factories?
  factories_sexp[0] == :block
end

#name_from(sexp) ⇒ Object



37
38
39
# File 'lib/to_factory/parsing/syntax.rb', line 37

def name_from(sexp)
  sexp[1][3][1]
end

#parseObject



16
17
18
19
20
21
22
23
# File 'lib/to_factory/parsing/syntax.rb', line 16

def parse
  factories.map do |x|
    Representation.new(name_from(x), parent_from(x), to_ruby(x))
  end

rescue Racc::ParseError, StringScanner::Error => e
  raise ParseException.new("Original exception: #{e.message}\n #{e.backtrace}\nToFactory Error parsing \n#{@contents}\n o")
end