chris613
2020-2-17 14:14:12

So, im working on an application for managing recipes. Eventually (at this point its just planning) ill want to parse ingredients lists. e.g. 1 egg 4 grams blue cheese 300g plain flour sort of thing.

my question is: (and sort of just looking for opinions at this point) with Racket being language orientated, is there a benefit to implimenting a “laguage” for this ? or would it be better to fiddle about with parsac in irder to “extract” structured data from the input?


chris613
2020-2-17 14:16:28

the main benefit i can think of, is that if i implement a “language” then i should be able to “syntax highlight” and feedback to the user wich bits of the input the computer has successful parsed & included vs which parts have been ignored


chris613
2020-2-17 14:17:20

or maybe even eventually have sort of compiler checks that can verify the usage of ingredients in the recipe directions


philip.mcgrath
2020-2-17 17:01:49

I think this is not an either/or choice. If you decide to make a language, you will need a parser to turn raw bytes of input into an abstract syntax tree: in Racket world we call that a “reader.” You can make such a parser with parsac, megaparsac, parser-tools/lex, or any other library, or write one by hand. If you treat the ingredients as “just” data, you’re going to have to do the same thing. The infrastructure for syntax highlighting (color:text<%> 1) doesn’t depend on the text being a “language,” either, though it does integrate with #lang. So this is a decision you can defer for a while.


philip.mcgrath
2020-2-17 17:03:04

On the other hand, if your users are programmers, maybe you could specify a language for writing ingredients and avoid heuristics for free-form text.


chris613
2020-2-17 19:31:54

thanks for the input :smile: