hafriedlander / php-peg

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

Group names inside rules sometimes don't work as expected #8

Open ksmolyanin opened 13 years ago

ksmolyanin commented 13 years ago

Group names inside rules sometimes don't work as expected because they do not share params with other parts of the rule. Example: unknown_attribute: name:simple_name pws ":" pws value:(expression | identifier) function name (&$res, $sub) { $res['content'][] = '"'; $res['content'][] = $sub['text']; } function value (&$res, $sub) { //$res['content'][] = $sub['text']; // <-- thist works good, but I don't need it $res['content'][] = $sub['content']; // <-- this doesn't work because it doesn't know what is $sub['content'] } There is workaround: unknown_attribute: name:simple_name pws ":" pws (value:expression | value:identifier) function name (&$res, $sub) { $res['content'][] = '"'; $res['content'][] = $sub['text']; } function value (&$res, $sub) { $res['content'][] = $sub['content']; } Pay attention to "value:" name in both examples