hafriedlander / php-peg

PEG (parsing expression grammar) compiler for PHP
Other
191 stars 53 forks source link

Some problems with rules that include variables #9

Open ksmolyanin opened 13 years ago

ksmolyanin commented 13 years ago

There are some problems with rules that include variables. Example: user_structure: tag_begin pws tag_name:simple_name save_tag_name:"" (rws attribute:user_attribute (rws attribute:user_attribute)*)? (rws tag_stub | (pws tag_end content:template_content? tag_begin pws end_tag_mark pws "$tag_name" pws tag_end)) function save_tag_name (&$res, $sub) { $res['content'][] = '{}'; $res['content'][] = $res['tag_name']['text']; } function attribute (&$res, $sub) { $res['content'][] = $sub['content']; } function content (&$res, $sub) { $res['content'][] = array ( '"', 'content', $sub['content'] ); } Here is impossible to declate function "tag_name" to save the tag name because this name is used as variable at the end of the rule. If I declare function tag_name (&$res, $sub) then variable $tag_name doesn't match!

Another bug is appeared if use variable "name" instead of variable "tag_name". With "name" it doesn't work at all! Probably it is because parser tree in $res already has member "name" .. but who knows about this?