Skip to content

Chaining of prefix and postfix operators #241

@jacobpake

Description

@jacobpake

A parser built via buildExprParser supports chaining of infix operators, but does not support chaining prefix and postfix operators.

Consider the following parser:

word :: String -> Parser String String
word s = string s <* whiteSpace

bool :: Parser String Boolean
bool = (word "True" >>= \_ -> pure true) <|> (word "False" >>= \_ -> pure false)

parser :: Parser String Boolean
parser = buildExprParser
  [ [ Prefix (word "not" >>= \_ -> pure not) ]
  , [ Infix (word "and" >>= \_ -> pure (&&)) AssocLeft ]
  ]
  bool

This successfully parses expressions like True and True and True, but fails to parse expressions such as not not True.

It would be nice if this was supported out-of-the-box, or if there is some way to enable it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions