Class: ToFactory::Parsing::Syntax
- Inherits:
-
Object
- Object
- ToFactory::Parsing::Syntax
- Defined in:
- lib/to_factory/parsing/syntax.rb
Instance Attribute Summary collapse
-
#contents ⇒ Object
Returns the value of attribute contents.
Instance Method Summary collapse
- #factories ⇒ Object
- #factories_sexp ⇒ Object
-
#initialize(contents) ⇒ Syntax
constructor
A new instance of Syntax.
- #multiple_factories? ⇒ Boolean
- #name_from(sexp) ⇒ Object
- #parse ⇒ Object
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
#contents ⇒ Object
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
#factories ⇒ Object
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_sexp ⇒ Object
33 34 35 |
# File 'lib/to_factory/parsing/syntax.rb', line 33 def factories_sexp header? ? sexp[3] : sexp end |
#multiple_factories? ⇒ 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 |
#parse ⇒ Object
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.}\n #{e.backtrace}\nToFactory Error parsing \n#{@contents}\n o") end |