abooij / haskell-xkbcommon

Haskell bindings for libxkbcommon
MIT License
7 stars 6 forks source link

"Irrefutable pattern" Error #10

Open georgewsinger opened 5 years ago

georgewsinger commented 5 years ago

After constructing a stack.yaml and running stack build:

/home/george/hsroots/haskell-xkbcommon/Text/XkbCommon/KeycodeList.hs:1:1: error:
    Exception when trying to run compile-time code:
      /home/george/hsroots/haskell-xkbcommon/Language/Preprocessor/Cpphs/MacroPass.hs:(96,9)-(97,68): Irrefutable pattern failed for pattern Cmd (Just hd) : _

    Code: runIO genKeycodes >>= return
  |
1 | {-# LANGUAGE TemplateHaskell #-}
abooij commented 5 years ago

It looks like this is due to an upstream bug: malcolmwallace/cpphs#16.

As a workaround, perhaps you can force an older version of cpphs by simply using an old stackage version.

frozencemetery commented 5 years ago

cpphs appears to be unmaintained (see linked bug). If there's no workaround, I'd suggest migrating to a different tool instead.

abooij commented 5 years ago

@frozencemetery Perhaps that's a good idea. However, I have no good overview of how this package is actually being used, and by which packages. I suspect most of the code is never used. If we can get an overview of this, then we are in a position to clean up this package a little bit. Perhaps it should be split up.

frozencemetery commented 5 years ago

@abooij by "this package", do you mean cpphs or haskell-xkbcommon?

If the former: cpphs is directly used by haskell-xkbcommon . My understanding is a little rocky here, but I think it's used by all the .hsc files.

If the latter: haskell-xkbcommon is your package. I don't know whether there's a way to query rdeps in haskell-land, but if you're considering breaking changes, you could either make them (and be okay reverting), or just fork to a new name. Not sure how you'd get this information otherwise.

I'm just here because I'd like waymonad to build, and resolving this issue (or removing the waymonad dep on haskell-xkbcommon) is required for that as far as I can tell.

abooij commented 5 years ago

@frozencemetery, I meant how haskell-xkbcommon is used. Looking at waymonad, at first glance it looks like haskell-xkbcommon is used as intended, or at least it's not just using 3 lines of code. Importantly, it uses Text.XkbCommon.KeysymPatterns, which is generated using cpphs. Specifically, Text.XkbCommon.ParseDefines reads certain C header files, and picks out the #defines using cpphs. It may be necessary to follow #includes when parsing the given C header file (I believe there was an issue about this), which kinda complicates the parsing.

Having done all this parsing, it simply reads a bunch of #defines, filters out a bunch, and outputs corresponding Haskell values for them.

It should certainly be possible to do this without using cpphs, either by some raw String manipulation, or using a parser library such as Megaparsec. PRs are welcome.