Skip to content
This repository has been archived by the owner on Feb 10, 2021. It is now read-only.

Injecting macros #28

Open
andre-dietrich opened this issue Feb 27, 2018 · 2 comments
Open

Injecting macros #28

andre-dietrich opened this issue Feb 27, 2018 · 2 comments

Comments

@andre-dietrich
Copy link

andre-dietrich commented Feb 27, 2018

Hi,
I am building a simple parser for an extended Markdown format. One thing I try to include is macro support, which are stored within the state as Dict String String, with name and code to inject. Instead of running multiple string replacements, I would like to add the code in front of the current input stream, if the macro pattern is detected, and then go on with straight forward parsing ...

Is the "primitive" function the appropriate method and if so, how can I use it?

Kind regards,

André

@andre-dietrich
Copy link
Author

Hi,

found a solution. Could you please add the following function? Using this, it is possible to modify the InputStream at parsing time. I use it to define macros, that change the parser state and if a macro pattern is detected also the input stream.

{-| Modify the parser's InputStream.
-}
modifyStream : (String -> String) -> Parser s ()
modifyStream f =
Parser <|
\state stream ->
app (succeed ()) state { stream | input = f stream.input }

@stil4m
Copy link
Contributor

stil4m commented Mar 2, 2018

Could you provide a pull request with a unit test?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants