-
We have a basic markup format our app uses. It contains links, times, etc. But it also contains some parts which are dynamic, such as mentioned user names just like we have in GitHub. I want to be able to call
Would you suggest rebuilding a parser each time such as |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Traditionally the parsing and resolution would be done separately. That means you create a generic parser that would extract all user-names and then in a second step you would check that list against your list of valid usernames. That said, with PetitParser creating dynamic parsers is very cheap. There is nothing that speaks against creating something like this: Parser<Token<String>> getUserNamesParser(List<String> usernames) => usernames
.map((username) => '@$username'.toParser())
.toChoiceParser()
.token(); If you parser is large and complex and you don't want to create everything from scratch each time, you could even modify the existing one: Keep a settable reference that you update whenever your list of users changes (or before each time you parse). |
Beta Was this translation helpful? Give feedback.
-
Thanks! To follow-up here, I ended up creating a generic parser every time things change and it was fast, so I didn't end up going with a settable reference. |
Beta Was this translation helpful? Give feedback.
Traditionally the parsing and resolution would be done separately. That means you create a generic parser that would extract all user-names and then in a second step you would check that list against your list of valid usernames.
That said, with PetitParser creating dynamic parsers is very cheap. There is nothing that speaks against creating something like this:
If you parser is large and complex and you don't want to create everything from scratch each time, you could even modify the existing one: Keep a settable reference that …