-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from EdenComp/pablo/parse-conditions-operators
Add parse conditions operators
- Loading branch information
Showing
5 changed files
with
109 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Dreamberd.Parsing.Elements.Operator (parseExpression) where | ||
|
||
import Dreamberd.Parsing.Values (parseAnyValue) | ||
import Dreamberd.Types (AstNode (Operator)) | ||
|
||
parseExpression :: String -> Either String AstNode | ||
parseExpression str = | ||
case words str of | ||
[lhs, op, rhs] -> | ||
case parseAnyValue lhs of | ||
Left err -> Left err | ||
Right lhsNode -> | ||
case parseOperator op of | ||
Left err -> Left err | ||
Right opNode -> | ||
case parseAnyValue rhs of | ||
Left err -> Left err | ||
Right rhsNode -> Right (Operator opNode lhsNode rhsNode) | ||
_ -> Left "Invalid expression" | ||
|
||
parseOperator :: String -> Either String String | ||
parseOperator str = | ||
let operators = ["=", "+=", "-=", "*=", "/=", "%="] | ||
in if str `elem` operators | ||
then Right str | ||
else Left "Invalid operator" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters