summaryrefslogtreecommitdiff
path: root/src/Language/Elna/Parser.hs
blob: bf5b4e5c7f025465e81e60a054de9682f3a80202 (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
28
29
30
31
32
33
34
35
36
37
module Language.Elna.Parser
    ( Parser
    , programP
    ) where

import Control.Monad (void)
import Data.Text (Text)
import Data.Void (Void)
import Language.Elna.AST
    ( Statement(..)
    , Program(..)
    )
import Text.Megaparsec (Parsec)
import Text.Megaparsec.Char (space1)
import qualified Text.Megaparsec.Char.Lexer as Lexer

type Parser = Parsec Void Text

space :: Parser ()
space = Lexer.space space1 (Lexer.skipLineComment "//")
    $ Lexer.skipBlockComment "{" "}"

lexeme :: forall a. Parser a -> Parser a
lexeme = Lexer.lexeme space

symbol :: Text -> Parser Text
symbol = Lexer.symbol space

beginP :: Parser ()
beginP = void $ symbol "begin"

endP :: Parser ()
endP = void $ symbol  "end"

programP :: Parser Program
programP = beginP >> endP >> symbol "."
    >> pure (Program mempty mempty mempty $ CompoundStatement mempty)