[Haskell-beginners] Parsing 'A's and then ('A's or 'B's)
Alex Belanger
i.caught.air at gmail.com
Mon Jan 25 06:10:09 UTC 2016
If I understood properly,
Have you considered breaking the input into some sort of pattern mask then
validating it?
map (length . group) "AAABB" === [3,2]. Then you can do the same thing
grouping with the target [x, x, y] into [2, 1]. Then you can zip the lists
and ensure the numbers are all smaller than the other respectively. Also,
the lists themselves have the right lengths and order for their elements.
Examples of successful patterns:
[1,1]
AAA,BB
[1, 2]
AAA,B,B
[2,1]
A,AA,BB
AA,A,BB
[2,2]
A,AA,B,B
AA,A,B,B
Try with other examples I think this would work.
On Jan 24, 2016 4:57 PM, "Simon Jakobi" <simon.jakobi at googlemail.com> wrote:
> Hi Francesco,
>
> Thanks for your response!
>
>
>> if I understood your specification correctly, there would be multiple
>> ways to parse the string "AAA":
>>
>> - 3 'x' elements ("A", "A", "A")
>> - 2 'x' elements ("AA", "A")
>> - 2 'x' elements again (first one shorter) ("A", "AA")
>> - 1 'x' element ("AAA")
>>
>
> There would be even more ways because 'y', too, can represent one or more
> 'A's.
>
> Which of these four should we choose?Maybe "parse as many As as possible
>> without consuming the A followed by a series of B"?
>
>
> I don't think that there could be a general rule.
>
> For the string "AABB" and the sequence of symbols [x, y, y] there would be
> two possible parses:
>
> [x: "AA", y: "B", y: "B"]
> or
> [x: "A", y: "A", y: "BB"].
>
> I only care whether there are any valid parses.
>
> I've just tried to solve the problem with regular expressions (using
> pcre-light) and didn't come across the same problem. Is this due to
> attoparsec not being able to "backtrack" (not sure if this is the right
> term)? Is backtracking something that parsers generally are incapable of?
>
> Cheers,
> Simon
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160125/11fd5ab8/attachment-0001.html>
More information about the Beginners
mailing list