lib/rubrowser/parser/file.rb in rubrowser-2.10 vs lib/rubrowser/parser/file.rb in rubrowser-2.11
- old
+ new
@@ -17,10 +17,11 @@
@relations = []
end
def parse
return unless valid_file?(file)
+
constants = constants_from_file
@definitions = constants[:definitions]
@relations = constants[:relations]
rescue ::Parser::SyntaxError
@@ -104,21 +105,22 @@
def parse_array(arr, parents = [])
arr.map { |n| parse_block(n, parents) }
.reduce { |a, e| merge_constants(a, e) }
end
- def merge_constants(c1, c2)
- c1 ||= {}
- c2 ||= {}
+ def merge_constants(const1, const2)
+ const1 ||= {}
+ const2 ||= {}
{
- definitions: c1[:definitions].to_a + c2[:definitions].to_a,
- relations: c1[:relations].to_a + c2[:relations].to_a
+ definitions: const1[:definitions].to_a + const2[:definitions].to_a,
+ relations: const1[:relations].to_a + const2[:relations].to_a
}
end
def ast_consts_to_array(node, parents = [])
return parents unless valid_node?(node) &&
%I[const cbase].include?(node.type)
+
ast_consts_to_array(node.children.first, parents) + [node.children.last]
end
def empty_result
{}