1

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?

Zoltan Hernyak
  • 989
  • 1
  • 14
  • 35

1 Answers1

0

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);  

output:

aa
cc
dd

Try it

M.Hassan
  • 10,282
  • 5
  • 65
  • 84