Add documentation for `ParcAssertDemo.hs`.
Chris Pressey
8 months ago
72 | 72 | combinator can be used to apply arithmetic operators like `+` and `*` |
73 | 73 | when parsing an arithmetic expression. |
74 | 74 | |
75 | ### `ParcAssert.hs` | |
76 | ||
77 | With what we have so far, if we merely accumulate state as we parse, | |
78 | we can parse only context-free languages. | |
79 | ||
80 | But if we enable the parser to succeed or fail based on some predicate | |
81 | applied to the parsing state, we can parse context-sensitive languages. | |
82 | ||
83 | (Actually, if we don't restrict ourselves to sufficiently simple | |
84 | predicates, we can parse languages quite beyond the context-sensitive | |
85 | range. For example, we could use a predicate which checks if the | |
86 | string passed to it is a valid sentence in Presburger arithmetic. | |
87 | Formulating a set of parser combinators which actually (and provably) | |
88 | is limited to parsing context-sensitive languages seems like a hard | |
89 | (maybe open) problem.) | |
90 | ||
91 | [`ParcAssertDemo.hs`](ParcAssertDemo.hs) uses `ParcSt2St` and adds a | |
92 | combinator called `assert` that takes such a predicate on the parsing | |
93 | state, and produces a parser which succeeds only when that predicate | |
94 | is true on the current parsing state, failing otherwise. | |
95 | ||
96 | The demo module gives an example of a parser for a classic | |
97 | context-free language: strings of the form `a`^_n_ `b`^_n_ `c`^_n_. | |
98 | ||
75 | 99 | ### ... and more? |
76 | 100 | |
77 | 101 | With luck, there will be further experiments added here over time. |