aboutsummaryrefslogtreecommitdiff
path: root/src/parser/Statement.hs
blob: ca16eca62b4e42074820736871e6f3b8138e033c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module Parser.Statement where

import           Control.Applicative

import           Expr
import           Parser.Core
import           Parser.Expr


data Statement
    = Evaluation Expr
    | VariableDeclaration String Expr
    | FunctionDeclaration String String Expr

statementP :: Parser Statement
statementP = functionDeclarationP <|> variableDeclarationP <|> evaluationP
    where
        functionDeclarationP = FunctionDeclaration
                                    <$> alphaStringP
                                    <*> parenthesis alphaStringP
                                    <*> (char '=' *> exprP)

        variableDeclarationP = VariableDeclaration
                                    <$> alphaStringP
                                    <*> (char '=' *> exprP)

        evaluationP          = Evaluation <$> exprP <* char '=' <* char '?'