Skip to content

Commit

Permalink
Remove direction from Operator
Browse files Browse the repository at this point in the history
  • Loading branch information
jfmengels committed Aug 3, 2024
1 parent 0fc4e6b commit eff82e1
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 44 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
- Renamed `Integer` to `IntegerLiteral`
- Renamed `Hex` to `HexLiteral`
- Renamed `ListExpr` to `ListLiteral`
- Renamed `OperatorApplication` to `Operation`
- `OperatorApplication`
- Renamed `OperatorApplication` to `Operation`
- Removed the `InfixDirection` field
- `OperatorApplication String InfixDirection (Node Expression) (Node Expression)` -> `Operation String (Node Expression) (Node Expression)`
- Renamed `isOperatorApplication` to `isOperation`
- Renamed `RecordExpr` to `Record`
- Renamed `CaseExpression` to `Case`
Expand Down
13 changes: 6 additions & 7 deletions src/Elm/Parser/Expression.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Elm.Parser.Tokens as Tokens
import Elm.Parser.TypeAnnotation as TypeAnnotation
import Elm.Syntax.DestructurePattern exposing (DestructurePattern)
import Elm.Syntax.Expression as Expression exposing (Case, Expression(..), LetDeclaration(..), RecordSetter)
import Elm.Syntax.Infix as Infix
import Elm.Syntax.Node as Node exposing (Node(..))
import Elm.Syntax.Range exposing (Location)
import Elm.Syntax.Signature exposing (Signature)
Expand Down Expand Up @@ -1195,7 +1194,7 @@ applyExtensionRight extensionRight ((Node { start } left) as leftNode) =
extendRightOperation.expression
in
Node { start = start, end = end }
(Operation extendRightOperation.symbol extendRightOperation.direction leftNode right)
(Operation extendRightOperation.symbol leftNode right)


abovePrecedence0 : Parser (WithComments ExtensionRight)
Expand Down Expand Up @@ -1273,7 +1272,7 @@ infixLeft precedence possibilitiesForPrecedence symbol =
possibilitiesForPrecedence
(Parser.symbol symbol)
(\right ->
ExtendRightByOperation { symbol = symbol, direction = Infix.Left, expression = right }
ExtendRightByOperation { symbol = symbol, expression = right }
)


Expand All @@ -1283,7 +1282,7 @@ infixNonAssociative precedence possibilitiesForPrecedence symbol =
possibilitiesForPrecedence
(Parser.symbol symbol)
(\right ->
ExtendRightByOperation { symbol = symbol, direction = Infix.Non, expression = right }
ExtendRightByOperation { symbol = symbol, expression = right }
)


Expand All @@ -1296,7 +1295,7 @@ infixRight precedence possibilitiesForPrecedenceMinus1 symbol =
possibilitiesForPrecedenceMinus1
(Parser.symbol symbol)
(\right ->
ExtendRightByOperation { symbol = symbol, direction = Infix.Right, expression = right }
ExtendRightByOperation { symbol = symbol, expression = right }
)


Expand All @@ -1323,7 +1322,7 @@ infixLeftSubtraction precedence possibilitiesForPrecedence =
)
)
(\right ->
ExtendRightByOperation { symbol = "-", direction = Infix.Left, expression = right }
ExtendRightByOperation { symbol = "-", expression = right }
)


Expand Down Expand Up @@ -1362,6 +1361,6 @@ postfix precedence operator apply =


type ExtensionRight
= ExtendRightByOperation { symbol : String, direction : Infix.InfixDirection, expression : Node Expression }
= ExtendRightByOperation { symbol : String, expression : Node Expression }
| ExtendRightByApplication (Node Expression)
| ExtendRightByRecordAccess (Node String)
5 changes: 2 additions & 3 deletions src/Elm/Syntax/Expression.elm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Although it is a easy and simple language, you can express a lot! See the `Expre

import Elm.Syntax.DestructurePattern exposing (DestructurePattern)
import Elm.Syntax.Documentation exposing (Documentation)
import Elm.Syntax.Infix exposing (InfixDirection)
import Elm.Syntax.ModuleName exposing (ModuleName)
import Elm.Syntax.Node as Node exposing (Node(..))
import Elm.Syntax.Pattern exposing (Pattern)
Expand Down Expand Up @@ -111,7 +110,7 @@ type Expression
| FunctionOrValue ModuleName String
| PrefixOperator String
| FunctionCall (Node Expression) (Node Expression) (List (Node Expression))
| Operation String InfixDirection (Node Expression) (Node Expression)
| Operation String (Node Expression) (Node Expression)
| If (Node Expression) (Node Expression) (Node Expression)
| TupleExpression (List (Node Expression))
| Let LetBlock
Expand Down Expand Up @@ -222,7 +221,7 @@ isCase e =
isOperation : Expression -> Bool
isOperation e =
case e of
Operation _ _ _ _ ->
Operation _ _ _ ->
True

_ ->
Expand Down
8 changes: 0 additions & 8 deletions tests/Elm/Parser/DeclarationsTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Elm.Parser.ParserWithCommentsTestUtil as ParserWithCommentsUtil exposing
import Elm.Syntax.Declaration as Declaration exposing (..)
import Elm.Syntax.DestructurePattern exposing (DestructurePattern(..))
import Elm.Syntax.Expression as Expression exposing (..)
import Elm.Syntax.Infix as Infix exposing (InfixDirection(..))
import Elm.Syntax.Node exposing (Node(..))
import Elm.Syntax.Pattern exposing (..)
import Elm.Syntax.StringLiteralType exposing (StringLiteralType(..))
Expand Down Expand Up @@ -148,7 +147,6 @@ foo = bar"""
, expression =
Node { start = { row = 1, column = 9 }, end = { row = 1, column = 14 } }
(Operation "+"
Infix.Left
(Node { start = { row = 1, column = 9 }, end = { row = 1, column = 10 } } (FunctionOrValue [] "x"))
(Node { start = { row = 1, column = 13 }, end = { row = 1, column = 14 } } (IntegerLiteral 1))
)
Expand Down Expand Up @@ -318,7 +316,6 @@ foo = bar"""
( Node { start = { row = 3, column = 5 }, end = { row = 3, column = 14 } } (NamedPattern { moduleName = [], name = "Increment" } [])
, Node { start = { row = 4, column = 7 }, end = { row = 4, column = 16 } }
(Operation "+"
Left
(Node { start = { row = 4, column = 7 }, end = { row = 4, column = 12 } } (FunctionOrValue [] "model"))
(Node { start = { row = 4, column = 15 }, end = { row = 4, column = 16 } } (IntegerLiteral 1))
)
Expand All @@ -327,7 +324,6 @@ foo = bar"""
[ ( Node { start = { row = 6, column = 5 }, end = { row = 6, column = 14 } } (NamedPattern { moduleName = [], name = "Decrement" } [])
, Node { start = { row = 7, column = 7 }, end = { row = 7, column = 16 } }
(Operation "-"
Left
(Node { start = { row = 7, column = 7 }, end = { row = 7, column = 12 } } (FunctionOrValue [] "model"))
(Node { start = { row = 7, column = 15 }, end = { row = 7, column = 16 } } (IntegerLiteral 1))
)
Expand Down Expand Up @@ -493,11 +489,9 @@ foo = bar"""
, expression =
Node { start = { row = 1, column = 31 }, end = { row = 1, column = 83 } }
(Operation "<|"
Right
(Node { start = { row = 1, column = 31 }, end = { row = 1, column = 36 } } (FunctionOrValue [] "curry"))
(Node { start = { row = 1, column = 40 }, end = { row = 1, column = 83 } }
(Operation ">>"
Right
(Node { start = { row = 1, column = 40 }, end = { row = 1, column = 56 } }
(TupleExpression
[ Node { start = { row = 1, column = 41 }, end = { row = 1, column = 55 } }
Expand Down Expand Up @@ -552,7 +546,6 @@ foo = bar"""
(NamedPattern { moduleName = [], name = "Increment" } [])
, Node { start = { row = 4, column = 7 }, end = { row = 4, column = 16 } }
(Operation "+"
Left
(Node { start = { row = 4, column = 7 }, end = { row = 4, column = 12 } } (FunctionOrValue [] "model"))
(Node { start = { row = 4, column = 15 }, end = { row = 4, column = 16 } } (IntegerLiteral 1))
)
Expand All @@ -562,7 +555,6 @@ foo = bar"""
(NamedPattern { moduleName = [], name = "Decrement" } [])
, Node { start = { row = 7, column = 7 }, end = { row = 7, column = 16 } }
(Operation "-"
Left
(Node { start = { row = 7, column = 7 }, end = { row = 7, column = 12 } } (FunctionOrValue [] "model"))
(Node { start = { row = 7, column = 15 }, end = { row = 7, column = 16 } } (IntegerLiteral 1))
)
Expand Down
18 changes: 0 additions & 18 deletions tests/Elm/Parser/ExpressionTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Elm.Parser.Expression exposing (expression)
import Elm.Parser.ParserWithCommentsTestUtil as ParserWithCommentsUtil
import Elm.Syntax.DestructurePattern exposing (DestructurePattern(..))
import Elm.Syntax.Expression exposing (Expression(..))
import Elm.Syntax.Infix as Infix exposing (InfixDirection(..))
import Elm.Syntax.Node exposing (Node(..))
import Elm.Syntax.StringLiteralType exposing (StringLiteralType(..))
import Expect
Expand Down Expand Up @@ -97,7 +96,6 @@ all =
(TupleExpression
[ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 11 } }
(Operation "*"
Left
(Node { start = { row = 1, column = 2 }, end = { row = 1, column = 4 } }
(Negation (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 4 } } (IntegerLiteral 1)))
)
Expand All @@ -122,7 +120,6 @@ all =
|> expectAst
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 10 } } <|
Operation "+"
Infix.Left
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 6 } } <| FunctionOrValue [] "model")
(Node { start = { row = 1, column = 9 }, end = { row = 1, column = 10 } } <| IntegerLiteral 1)
)
Expand Down Expand Up @@ -430,7 +427,6 @@ all =
|> expectAst
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } }
(Operation "-"
Left
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 2 } } (IntegerLiteral 2))
(Node { start = { row = 1, column = 3 }, end = { row = 1, column = 4 } } (IntegerLiteral 1))
)
Expand Down Expand Up @@ -465,7 +461,6 @@ all =
(TupleExpression
[ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 8 } }
(Operation "-"
Left
(Node { start = { row = 1, column = 3 }, end = { row = 1, column = 4 } } (FunctionOrValue [] "x"))
(Node { start = { row = 1, column = 7 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "y"))
)
Expand All @@ -480,22 +475,18 @@ all =
|> expectAst
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 29 } }
(Operation "=="
Non
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 18 } }
(Operation "+"
Left
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 3 } }
(Negation (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 3 } } (IntegerLiteral 1)))
)
(Node { start = { row = 1, column = 6 }, end = { row = 1, column = 18 } }
(Operation "*"
Left
(Node { start = { row = 1, column = 6 }, end = { row = 1, column = 9 } }
(Negation (Node { start = { row = 1, column = 7 }, end = { row = 1, column = 9 } } (IntegerLiteral 10)))
)
(Node { start = { row = 1, column = 12 }, end = { row = 1, column = 18 } }
(Operation "^"
Right
(Node { start = { row = 1, column = 12 }, end = { row = 1, column = 16 } }
(Negation
(Node { start = { row = 1, column = 13 }, end = { row = 1, column = 16 } } (IntegerLiteral 100))
Expand All @@ -520,10 +511,8 @@ all =
(Node
{ start = { row = 1, column = 2 }, end = { row = 1, column = 11 } }
(Operation "-"
Left
(Node { start = { row = 1, column = 2 }, end = { row = 1, column = 7 } }
(Operation "+"
Left
(Node { start = { row = 1, column = 2 }, end = { row = 1, column = 3 } } (IntegerLiteral 1))
(Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } (IntegerLiteral 2))
)
Expand All @@ -537,7 +526,6 @@ all =
|> expectAst
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 7 } }
(Operation "|>"
Left
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 2 } } (FunctionOrValue [] "a"))
(Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } (FunctionOrValue [] "b"))
)
Expand All @@ -558,20 +546,16 @@ all =
, expression =
Node { start = { row = 1, column = 19 }, end = { row = 1, column = 53 } }
(Operation "||"
Right
(Node { start = { row = 1, column = 19 }, end = { row = 1, column = 27 } }
(Operation "=="
Non
(Node { start = { row = 1, column = 19 }, end = { row = 1, column = 20 } } (FunctionOrValue [] "c"))
(Node { start = { row = 1, column = 24 }, end = { row = 1, column = 27 } } (CharLiteral ' '))
)
)
(Node { start = { row = 1, column = 31 }, end = { row = 1, column = 53 } }
(Operation "||"
Right
(Node { start = { row = 1, column = 31 }, end = { row = 1, column = 40 } }
(Operation "=="
Non
(Node { start = { row = 1, column = 31 }, end = { row = 1, column = 32 } } (FunctionOrValue [] "c"))
(Node { start = { row = 1, column = 36 }, end = { row = 1, column = 40 } }
(CharLiteral '\n')
Expand All @@ -580,7 +564,6 @@ all =
)
(Node { start = { row = 1, column = 44 }, end = { row = 1, column = 53 } }
(Operation "=="
Non
(Node { start = { row = 1, column = 44 }, end = { row = 1, column = 45 } } (FunctionOrValue [] "c"))
(Node { start = { row = 1, column = 49 }, end = { row = 1, column = 53 } }
(CharLiteral '\u{000D}')
Expand Down Expand Up @@ -653,7 +636,6 @@ all =
|> expectAst
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 16 } }
(Operation "+"
Left
(Node { start = { row = 1, column = 1 }, end = { row = 1, column = 2 } } (IntegerLiteral 1))
(Node { start = { row = 1, column = 5 }, end = { row = 1, column = 16 } }
(Negation
Expand Down
Loading

0 comments on commit eff82e1

Please sign in to comment.