Skip to content

Commit

Permalink
Parser: Fix operator parsing
Browse files Browse the repository at this point in the history
Closes #122
  • Loading branch information
piegamesde committed Mar 14, 2024
1 parent d24e159 commit 4db5814
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Nixfmt/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,20 @@ list = List <$> symbol TBrackOpen <*> items term <*> symbol TBrackClose

-- OPERATORS

opChars :: [Char]
opChars = "<>=+*/."

operator :: Token -> Parser Leaf
operator t = label "operator" $ try $ lexeme $
rawSymbol t <* notFollowedBy (oneOf opChars)
rawSymbol t <* notFollowedBy (oneOf (
-- Resolve ambiguities between operators which are prefixes of others
case t of
TPlus -> "+" :: [Char]
TMinus -> ">"
TMul -> "/"
TDiv -> "/*"
TLess -> "="
TGreater -> "="
TNot -> "="
_ -> ""
))

opCombiner :: Operator -> MPExpr.Operator Parser Expression
opCombiner Apply = MPExpr.InfixL $ return Application
Expand Down
3 changes: 3 additions & 0 deletions test/correct/operator-after-operator.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://github.com/NixOS/nixfmt/issues/122
(1+/**/1)
(1+.4)

0 comments on commit 4db5814

Please sign in to comment.