agdarsec icon indicating copy to clipboard operation
agdarsec copied to clipboard

Lift a parser working on a subset of the tokens

Open gallais opened this issue 5 years ago • 0 comments

It would be nice to have:

reLex : (check : q -> Maybe p) ->  ∀[ Parser P v ] ->  ∀[ Parser Q v ]

where P and Q are essentially the same parameters except that P has p as the token type while Q has q, which is larger.

My current use case: I want the user to provide a parser munching characters but I'd like to use it in a context where a lexer has been run and some special characters have been recognised as special. So I have:

data TOK = A | B | C Char

and I'd like reLex to run a modified view that takes check into account so that the client's anyTok only succeeds if the TOK has the shape C c.

gallais avatar Nov 07 '20 11:11 gallais