[Haskell-cafe] parsing Haskell expressions

Johannes Waldmann johannes.waldmann at htwk-leipzig.de
Fri Apr 24 13:54:40 UTC 2020


Dear Cafe,


for a language that has (subset-of) Haskell expression syntax,
but different global declaration syntax, we are using parseExp
from haskell-src-exts. I have two question on this.

I am asking here because
https://github.com/haskell-suite/haskell-src-exts#maintenance
says that it's no longer active.


(1) can we make parseExp self-delimiting? The type is

parseExp :: String -> ParseResult (Exp SrcSpanInfo)

but I'd want "maximum munch" and the part that was not eaten,
as in   :: String -> ParseResult (.. , String)

I tried     parseExp "x } foo bar"
ParseFailed (SrcLoc "<unknown>.hs" 1 3) "Unexpected }"

so I could extract the error location, and then re-parse that prefix.
That's feels a bit strange.


(2) perhaps we don't need (1) if we do the chunking
on the outside. E.g., we run a lexer and look for delimiters
(keywords of the host language that then are forbidden in
inner expressions). We want to use
lexTokenStream :: String -> ParseResult [Loc Token]
and then I'd want  parseExp' :: [Token] -> ...

Else, we'd have to reconstruct the slice of the original input,
which again, feels a bit strange and (because) it duplicates work.


It is suggested to use
http://hackage.haskell.org/package/ghc-lib-parser
instead.

Would this help with the above? But then of course

(3) is there a transition strategy (e.g., wrapper modules)?


Thanks - J.W.


NB: this is the issue from the project's tracker:
https://gitlab.imn.htwk-leipzig.de/waldmann/cyp/issues/45


More information about the Haskell-Cafe mailing list