evincarofautumn / Toody

A two-dimensional parser combinator library.
MIT License
41 stars 1 forks source link

Add more tests & example use cases #1

Open evincarofautumn opened 7 years ago

evincarofautumn commented 7 years ago

A simple ASCII table extractor:

+-----+-----+-----+
| foo | bar | baz |
+-----+-----+-----+
| 123 | 456 | 789 |
+-----+-----+-----+

A Funciton interpreter:

                   ╓───╖
                   ║ ! ║
                   ╙─┬─╜   ┌───╖  ╔═══╗
               ┌─────┴─────┤ > ╟──╢ 2 ║
               │           ╘═╤═╝  ╚═══╝
 ╔════╗  ┌───╖ │             │
 ║ −1 ╟──┤ + ╟─┴─┐           │
 ╚════╝  ╘═╤═╝   │           │
         ┌─┴─╖   │    ╔═══╗  │
         │ ! ║   │    ║ 1 ║  │
         ╘═╤═╝   │    ╚═╤═╝  │
           │   ┌─┴─╖  ┌─┴─╖  │
           │   │ × ╟──┤ ? ╟──┘
           │   ╘═╤═╝  ╘═╤═╝
           └─────┘      │

2D ASCII math notation, extending the existing math notation test:

 2    2    2
a  + b  = c

       ________
      / 2
-b ± √ b  - 4ac
---------------
       2a
PappasBrent commented 3 years ago

How about parsing a video game map (I'm thinking a text-based game like Zork)?

Example, parsing a "house":

                [Front yard]
                |
                |
[office]--------[living room]----[kitchen]
                |
                |
                [bedroom]----[bathroom]

I'm currently writing my own 2D parser in Go (not published to GitHub yet) so I find this project interesting, especially since it's written in Haskell (which is truthfully somewhat beyond me haha).

evincarofautumn commented 3 years ago

How about parsing a video game map

@PappasBrent: That’s a nice idea!

I think that, in general, an interesting test case is one that is not only 2D, but also encodes some structure in the spatial relationships between things. I had thought that a map wouldn’t be an interesting example, because I was only thinking of map “tiles”, like this:

        front yard
office  living room  kitchen
        bedroom      bathroom

This could be just an array or CSV. But your example also uses space to describe connections between rooms, whereas mine would need additional data.

So a few other things come to mind:

written in Haskell (which is truthfully somewhat beyond me haha)

If you have any questions about the code, I’d be happy to help or give a brief overview. (It’s an incentive to write some docs as a side effect.)