Various small parser cleanups.

This commit is contained in:
Yorick Peterse 2014-04-25 00:07:53 +02:00
parent ecf6851711
commit 83ff0e6656
1 changed files with 8 additions and 21 deletions

View File

@ -102,23 +102,16 @@ rule
| T_ELEM_START T_ELEM_NS T_ELEM_NAME { [val[1], val[2]] } | T_ELEM_START T_ELEM_NS T_ELEM_NAME { [val[1], val[2]] }
; ;
element_start element
: element_open attributes : element_open attributes expressions T_ELEM_END
{ {
Element.new( element = Element.new(
:namespace => val[0][0], :namespace => val[0][0],
:name => val[0][1], :name => val[0][1],
:attributes => val[1] :attributes => val[1]
) )
}
;
element element.children = val[2].flatten
: element_start expressions T_ELEM_END
{
element = val[0]
element.children = val[1].flatten
link_children(element) link_children(element)
@ -133,7 +126,7 @@ rule
{ {
attrs = {} attrs = {}
val[0].flatten.each do |pair| val[0].each do |pair|
attrs = attrs.merge(pair) attrs = attrs.merge(pair)
end end
@ -143,22 +136,16 @@ rule
; ;
attributes_ attributes_
: attributes_ attribute { val } : attributes_ attribute { val.flatten }
| attribute { val } | attribute { val }
; ;
attribute attribute
# foo # foo
: T_ATTR : T_ATTR { {val[0] => nil} }
{
{val[0] => nil}
}
# foo="bar" # foo="bar"
| T_ATTR T_STRING | T_ATTR T_STRING { {val[0] => val[1]} }
{
{val[0] => val[1]}
}
; ;
# XML declarations # XML declarations