It parses a sed script into an AST, then interprets that AST. sed is simple enough that such an interpretor is easy to write. e.g. each input line is only processed once, and in order
Maybe one of the more interesting parts is the testing of the parser using specification-based testing. First, define how to generate an arbitrary sed script (in its AST form). Haskell's QuickCheck will then generate 100 random sed scripts, and check that upon being pretty printed (to a sed script in its usual textual form), and then parsed, produces the original AST.
Specification-based testing is a nice complement to unit-based testing, that I'm beginning to rely more on, to avoid the tedium of writing so many unit tests.
The parser does not yet support nested sed expressions that contain more than one subexpression. The qualifier "suchThat (\xs -> length xs == 1)" at https://github.com/tomfitzhenry/hs-sed/blob/master/tests/Pre... documents this, and as a side-effect serves as a todo list [which I have since ignored for months :)].
It parses a sed script into an AST, then interprets that AST. sed is simple enough that such an interpretor is easy to write. e.g. each input line is only processed once, and in order
Maybe one of the more interesting parts is the testing of the parser using specification-based testing. First, define how to generate an arbitrary sed script (in its AST form). Haskell's QuickCheck will then generate 100 random sed scripts, and check that upon being pretty printed (to a sed script in its usual textual form), and then parsed, produces the original AST.
Specification-based testing is a nice complement to unit-based testing, that I'm beginning to rely more on, to avoid the tedium of writing so many unit tests.
The parser does not yet support nested sed expressions that contain more than one subexpression. The qualifier "suchThat (\xs -> length xs == 1)" at https://github.com/tomfitzhenry/hs-sed/blob/master/tests/Pre... documents this, and as a side-effect serves as a todo list [which I have since ignored for months :)].