Hi
I'm looking for a way of pattern matching the "geometry" of an array, the order in which the elements appear, not the contents of each element directly.
Let me outline what I mean by some examples. Given the target array:
array('T_STRING','T_VARIABLE','ASSIGN','T_STRING','LPAREN','T_VARIABLE','COMMA','T_VARIABLE','RPAREN');
//as a matter of fact, these would be the tokens for the PHP code "foo $var = Foo($arg1,$arg2)'
Then the following "pattern" would match, returning the 0-based indexes of the matches, as well as the indexes of the groupings, just like preg_match_all() would do for strings:
array('T_STRING', '?', '(', 'T_VARIABLE', 'ASSIGN' ')', '?',
'T_STRING', 'LPAREN', '(', 'T_VARIABLE', 'COMMA', '?', ')', '?', 'RPAREN');
This is only a simplified PoC, the way I intend to use it is much more complicated, and I don't want to use the full parser generator from PEAR (the lemon port to PHP), which would be overkill.
Are you aware of a function (possibly not an internal PHP function) or project which does just that?
Thank you.