Class: Typedocs::Parser
- Inherits:
-
Object
- Object
- Typedocs::Parser
- Defined in:
- lib/typedocs/parser.rb,
lib/typedocs/parser.rb,
lib/typedocs/parser/object_builder.rb
Defined Under Namespace
Classes: ASTBuilder, ObjectBuilder
Instance Method Summary collapse
Instance Method Details
#parse(klass, src, type = :root) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/typedocs/parser.rb', line 7 def parse(klass, src, type = :root) ast = Typedocs::Parser::ASTBuilder.new obj = Typedocs::Parser::ObjectBuilder.create_builder_for(klass) root = ast.public_send(type) result = begin obj.apply root.parse(src) rescue Parslet::ParseFailed => e raise e.cause.ascii_tree rescue ArgumentError => e error = StandardError.new("Parse error: Maybe parser's bug. Input=#{src.inspect}, Error = #{e}") error.set_backtrace e.backtrace raise error end if result.is_a?(Hash) raise "Parse error: Maybe parser's bug or unexpected argument(type: #{type.inspect}). Input=#{src.inspect}, Result=#{result.inspect}" end result end |