Friday 15 January 2010

parsing - How to use PetitParser to match the expression inside a dart string? -


I want to use PetitParserDart to parse the embed expression inside a DART string.

Prepare some objects:

  class user {string name; } Var user1 = new user () ..name = "mike"; Var user2 = new user () ..name = "jeff"; Var user3 = new user () ..name = "john}}}"; Var user = [user1, user2, user3];   

long string:

  var s = "" Hello, this is an embedded dart expression below: $ {users.where ((U) = & Gt; u.name! = 'Jeff}}}}}}}}' '. Where ((U) {come back u.name! =' {{{John '}) .map ((u) => gt; ; U.name) .toList ()} It is very complex. "" "  

You can see that there is a $ {} inside the string, And its content is very complex.

I am trying to use such PetTiperser code:

  def ("expr_in_string", string ('$ {'). Ref ('expr') .char ('}')); Def ("express", ????);   

But I do not know how to define the expr rule in it can be { or } , So I can not just use anyIn ('{}'). Neg () .

What should I do now? I think it would be a very complex rule.

I do not think you all can possibly parse more or less complete dart expression without the grammar string . You can either write approximation (as you did in your answer) or try to use the expression of dart grammar coming up with examples. In either case the grammar is complex as a result, because what you try to match is complex.

No comments:

Post a Comment