i'm trying capture string combination of a's , b's ending b. in other words:
local patt = s'ab'^0 * p'b' matching aaab , bbabb not aaa or bba. above not match anything. because s'ab'^0 greedy , matches final b? think , can't think of alternatives except perhaps resorting lpeg.cmt seems overkill. maybe not, know how match such pattern? saw this question problem solution there stop @ first end marker (i.e. 'cat' there, 'b' here) , in case need accept middle 'b's.
p.s. i'm trying match expression outermost rule function call. e.g.
func(); func(x)(y); func_arr[z](); all match but
exp; func()[1]; 4 + 5; do not. rest of grammar works , i'm pretty sure boils down same issue completeness, grammar i'm working looks like:
top_expr = v'primary_expr' * v'postfix_op'^0 * v'func_call_op' * p';'; postfix_op = v'func_call_op' + v'index_op'; and v'postfix_op'^0 eats func_call_op i'm expecting @ end.
yes, there no backtracking, you've correctly identified problem. think solution list valid postfix_op expressions; i'd change v'func_call_op' + v'index_op' v'func_call_op'^0 * v'index_op' , change final v'func_call_op' v'func_call_op'^1 allow several function calls @ end.
update: suggested in comments, solution a/b problem (p'b'^0 * p'a')^0 * p'b'^1.
Comments
Post a Comment