Discussion:
[Ur] Parsing text files
Fabrice Leal
2018-09-17 20:11:51 UTC
Permalink
Hi!
I wanted to parse a text file with a non trivial syntax (
https://en.wikipedia.org/wiki/Portable_Game_Notation) and was wondering
what would be the best way to achieve this. The best option seems to be
maybe FFI with C or haskell ... would it be too crazy to do this with plain
urweb?

---
Fabrice Leal
Adam Chlipala
2018-09-17 20:31:04 UTC
Permalink
Post by Fabrice Leal
I wanted to parse a text file with a non trivial syntax
(https://en.wikipedia.org/wiki/Portable_Game_Notation) and was
wondering what would be the best way to achieve this. The best option
seems to be maybe FFI with C or haskell ... would it be too crazy to
do this with plain urweb?
I don't see what would be wrong with parsing in Ur/Web directly. That's
how I've always done parsing in Ur/Web apps.
Fabrice Leal
2018-09-17 21:09:41 UTC
Permalink
That's fair, I'll give it a try :)
Post by Fabrice Leal
Hi!
I wanted to parse a text file with a non trivial syntax (
https://en.wikipedia.org/wiki/Portable_Game_Notation) and was wondering
what would be the best way to achieve this. The best option seems to be
maybe FFI with C or haskell ... would it be too crazy to do this with plain
urweb?
---
Fabrice Leal
--
---
Fabrice Leal
Benjamin Barenblat
2018-09-17 21:18:22 UTC
Permalink
Post by Fabrice Leal
I wanted to parse a text file with a non trivial syntax (
https://en.wikipedia.org/wiki/Portable_Game_Notation) and was wondering
what would be the best way to achieve this. The best option seems to be
maybe FFI with C or haskell ... would it be too crazy to do this with plain
urweb?
I experimented a bit with reimplementing Parsec
(https://hackage.haskell.org/package/parsec) in Ur. The basic idea isn't
too complex - you build a monad that hangs on to four continuations (one
for each of {"parse succeeded", "parse failed"} x {"consumed input",
"consumed no input"}), and it's pretty easy to implement all the
combinators you want in terms of it. I implemented a few combinators
before I realized I really only needed regexes, so I switched to that
(https://git.benjamin.barenblat.name/urweb-regex/).

Anyway, point is, a pure Ur implementation should work, and you should
consider using my regex library for any regular-language bits. :) I
haven't pushed to it in a few years, but it does still build and work. I
actually have some pending changes to it that I'm hoping to push soon -
I'm getting rid of the Boost dependency and making the Autoconf a bit
more robust. Let me know if you're interested in those changes; I can
try to hurry them up.

Loading...