Use non-associative for ‘or’ selector

When an expression looks like this:

  a.b or (0 == 0)

The precedence wasn’t being applied correctly in the pretty printer.
The parenthesis were left off so that the pretty printer produced,

  a.b or 0 == 0

While they look similar, without the parenthesis the expression would
take (a.b or 0) as one expression. This caused an error in the
Pretty/Parse Property tests. Disabling associativity for the (0 == 0)
part fixed this.

Fixes #305
This commit is contained in:
Matthew Bauer 2018-07-31 17:47:24 -04:00
parent bf507a5df0
commit 5709d52d60

View file

@ -205,7 +205,8 @@ exprFNixDoc = \case
NSelect r attr o ->
(if isJust o then leastPrecedence else flip mkNixDoc selectOp) $
wrapPath selectOp r <> dot <> prettySelector attr <> ordoc
where ordoc = maybe empty (((space <> text "or") <+>) . wrapParens selectOp) o
where
ordoc = maybe empty (((space <> text "or") <+>) . wrapParens appOpNonAssoc) o
NHasAttr r attr ->
mkNixDoc (wrapParens hasAttrOp r <+> text "?" <+> prettySelector attr) hasAttrOp
NEnvPath p -> simpleExpr $ text ("<" ++ p ++ ">")