Hello!
I am quite new to Elm and 1 week ago I was tasked to create a parser in Elm that takes in a string
“& (A, B)” and parses it into: And (Var “A”) (Var “B”). This is quite trivial to me, as we have only been doing much simpler operations and parsing in Elm. The assignment is a huge step ahead of my current knowledge and after reading and researching for like 7 hours straight today, I realized that this would be nearly impossible given my current ability. I am sitting at almost no progress, so really, any advice/suggestions would be greatly appreciated. I have already looked at the Parser library, but I didn’t see anything for custom types/custom variables. Thank you in advance!
Interestingly, I just published a package for parsing a different style of boolean logic expression yesterday. I did use elm/parser for the parsing, but I have found that it can take some time to ramp up on how to use the library.
What I found particularly helpful were the examples in the parser repo, in particular the math example.
It might also help to start with creating types for your parser output if you haven’t already.
I know that’s not much, but maybe it can help you get started enough to narrow your focus to smaller more specific problems. For me, that’s often key to making progress.
Not sure what it is that you need. But I decided to learn more about the elm/parser during Advent of Code 2021.
Eg: on day 4: elm-aoc-template/Day4.elm at 2021-perty · perty/elm-aoc-template · GitHub
Also days 2,5,6,8,10,12,13 and 14 - I find import Parser
.
Hi, I would recommend elm-community parser:
https://package.elm-lang.org/packages/andre-dietrich/parser-combinators/latest/Combine
This is “pretty” easy to use and there are some examples included:
I also used it for testing and build a package that generates random strings based on regex expressions:
https://package.elm-lang.org/packages/andre-dietrich/elm-random-regex/latest/
and basically you require something like this:
and_expression =
string "and"
|> parenthesis (
expression
|> map Tuple.pair
|> ignore (string ",")
|> andMap expression
)
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.