简体   繁体   中英

Sprache - combination of parsers

Using Sprache I have parsers, A,B,C,D which matches with different input parts, and selects (returns) different class instances. In my input there are a lot of parts in a random order, eq. "abaabccbdbabddba". I need to select all 'a'-s and 'b'-s and so on - order is irrelevant:

  from a_list in A.Many()
  from b_list in B.Many()
  from c_list in C.Many()
  from d_list in D.Many()

won't work this way. How can I describe this situation (best way) in Sprache?

Old questions since 6 years with no answer. The next code may help someone:

  var segment=
                from start in Parse.Letter.Once()
                let a =start.First()
                from rest in Parse.Chars(a).Many()
                select start.Concat(rest);            
            var allSegments = segment.Many();
        
        //test
            var text = "abaabccbdbabddba";         
            var result=allSegments.Parse(text);  

Try it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM