lib/csl/parser.rb in csl-1.0.0.pre10 vs lib/csl/parser.rb in csl-1.0.0.pre11
- old
+ new
@@ -35,11 +35,11 @@
rescue
nil
end
def parse!(source, scope = Node)
- root = parser[source].children.detect { |child| !comment?(child) }
+ root = parser[source].children.detect { |child| !skip?(child) }
parse_tree root, scope
end
private
@@ -60,12 +60,12 @@
[n.to_sym, a.respond_to?(:value) ? a.value : a.to_s]
}.flatten]
end
def parse_tree(node, scope = Node)
- return nil if node.nil?
-
+ return nil if node.nil?
+
root = parse_node node, scope
scope = specialize_scope(root, scope)
node.children.each do |child|
root << parse_tree(child, scope) unless comment?(child)
@@ -81,25 +81,27 @@
child = node.children[0]
child && child.respond_to?(:text?) && child.text? && child.text
end
end
- def comment?(node)
- node.respond_to?(:comment?) && node.comment? ||
- node.respond_to?(:node_type) && [:comment, :xmldecl].include?(node.node_type)
- end
+ def comment?(node)
+ node.respond_to?(:comment?) && node.comment? ||
+ node.respond_to?(:node_type) &&
+ [:comment, :xmldecl, :processing_instruction, 7].include?(node.node_type)
+ end
+ alias skip? comment?
- def specialize_scope(root, scope = Node)
- case root
- when Style
- Style
- when Locale
- Locale
- when Info
- Info
- else
- scope
- end
- end
+ def specialize_scope(root, scope = Node)
+ case root
+ when Style
+ Style
+ when Locale
+ Locale
+ when Info
+ Info
+ else
+ scope
+ end
+ end
end
end
\ No newline at end of file