Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Module: XMonad.Util.Parser #659

Merged
merged 4 commits into from
Dec 17, 2021
Merged

New Module: XMonad.Util.Parser #659

merged 4 commits into from
Dec 17, 2021

Conversation

slotThe
Copy link
Member

@slotThe slotThe commented Nov 30, 2021

Description

Inspired in part by the first draft of #651 (where the need for it arose again, which was not helped by ReadPs lack of discoverability), this is a parser combinator module for xmonad; based on ReadP, but hopefully a bit more intuitive to use. This is especially with regards to how other combinator libraries work, as well as the interplay with normal Control.Applicative functions. Plus, Semigroup and Monoid instances :)

Commits

New module: XMonad.Util.Parser

This module provides a parser combinator library based on base's ReadP,
which aims to function more like other popular combinator libraries like
attoparsec and megaparsec.

In particular, the Alternative and Monoid instances are left-biased now,
so combinators like many and optional from Control.Applicative work
in a more intuitive manner. Further, some functions (like endBy1)
only return the "most successful" parse, instead of returning all of
them. We can now get away with providing a single parsing result
instead of ReadP's list of results (as such, parsers need to be
disambiguated earlier instead of trimming the list down after parsing).

X.P.OrgMode: Use X.U.Parser

Since we now have an "internal" parser library in xmonad, use it. This
allows us to get rid of some hacks in this module that were needed
because of ReadP's parsing behaviour.

X.U.EZConfig: Use X.U.Parser

Using X.U.Parser works almost as a drop-in replacement for ReadP here.
In some places (like parseSpecial) we need to be a little bit more
careful when constructing the parser, but this is offset a much simpler
readKeySequence.

X.U.EZConfig: Add simple unit tests

Add very basic unit tests for EZConfig to see if it can parse all of the
keys (and key combinations) that it promises to parse.

The long-term goal here should be to write a pretty-printer for EZConfig
and to check whether that's a proper inverse (either in the normal sense
or in the inverse semigroup sense), as the tests for X.P.OrgMode do.

Checklist

  • I've read CONTRIBUTING.md

  • I've considered how to best test these changes (property, unit,
    manually, ...) and concluded:

      - Some tests for EZConfig are included (hopefully to be expanded later on),
      - X.P.OrgMode passes its existing tests.
    
  • I updated the CHANGES.md file

@slotThe slotThe marked this pull request as ready for review November 30, 2021 08:51
XMonad/Util/Parser.hs Outdated Show resolved Hide resolved
This module provides a parser combinator library based on base's ReadP,
which aims to function more like other popular combinator libraries like
attoparsec and megaparsec.

In particular, the Alternative and Monoid instances are left-biased now,
so combinators like `many` and `optional` from Control.Applicative work
in a more intuitive manner.  Further, some functions (like `endBy1`)
only return the "most successful" parse, instead of returning all of
them.  We can now get away with providing a single parsing result
instead of ReadP's list of results (as such, parsers need to be
disambiguated earlier instead of trimming the list down after parsing).
Since we now have an "internal" parser library in xmonad, use it.  This
allows us to get rid of some hacks in this module that were needed
because of ReadP's parsing behaviour.
Using X.U.Parser works almost as a drop-in replacement for ReadP here.
In some places (like `parseSpecial`) we need to be a little bit more
careful when constructing the parser, but this is offset a much simpler
`readKeySequence`.
Add very basic unit tests for EZConfig to see if it can parse all of the
keys (and key combinations) that it promises to parse.

The long-term goal here should be to write a pretty-printer for EZConfig
and to check whether that's a proper inverse (either in the normal sense
or in the inverse semigroup sense), as the tests for X.P.OrgMode do.
@slotThe slotThe merged commit 0010735 into xmonad:master Dec 17, 2021
@slotThe slotThe deleted the x.u.parser branch October 25, 2022 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants