I would like to parse several lists of commands indented or formated as array with Parsec
. As example, my lists will be formated like this:
Command1 arg1 arg2 Command1 arg1 arg2 Command1 arg1 arg2
Command2 arg1 Command3 arg1 arg2 arg3
Command3 arg1 arg2 arg3
Command4
Command3 arg1 arg2 arg3 Command2 arg1
Command4
Command4
Command5 arg1 Command2 arg1
These commands are supposed to be parsed column by column with state changes in the parser.
My idea is to gather the commands into separated list of string and parse these strings into a subparser (executed inside the main parser).
I inspected the API of the Parsec library but I didn't find a function to do that.
I considered using runParser
but this function only extract the results of the parser and not its state.
I also considered making a function inspired by runParsecT
and mkPT
to make my own parser, but the constructors ParsecT
or initialPos
are not available (not exported by the library)
Is it possible to run a subparser inside a parser with Parsec
?
If not, does a library such as megaparsec can solve my problem?
getState
and include the state in the result of the parser. – Julia Pathmegaparsec
does haverunParser'
which returns the state. – Julia Path