summaryrefslogtreecommitdiff
path: root/src/Language/Elna
diff options
context:
space:
mode:
Diffstat (limited to 'src/Language/Elna')
-rw-r--r--src/Language/Elna/AST.hs24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/Language/Elna/AST.hs b/src/Language/Elna/AST.hs
index 30c6627..45e85a7 100644
--- a/src/Language/Elna/AST.hs
+++ b/src/Language/Elna/AST.hs
@@ -12,6 +12,8 @@ module Language.Elna.AST
import Data.Int (Int32)
import Data.List (intercalate)
+import Data.List.NonEmpty (NonEmpty(..))
+import qualified Data.List.NonEmpty as NonEmpty
import Data.Word (Word8)
import Data.Text (Text)
import qualified Data.Text as Text
@@ -174,13 +176,29 @@ instance Show VariableDeclaration
<> maybe "" ((" = " <>) . show) initialValue <> ";"
<> showAttributes exports
-data Program = Program [ConstantDefinition] [VariableDeclaration] [ProcedureDeclaration] Statement
+data TypeDefinition
+ = RecordDefinition Identifier (NonEmpty Parameter)
+ | VariantDefinition Identifier (NonEmpty Parameter)
+ deriving Eq
+
+instance Show TypeDefinition
+ where
+ show (RecordDefinition identifier fields) = show identifier
+ <> " = record " <> intercalate "; " (NonEmpty.toList $ show <$> fields)
+ <> " end;"
+ show (VariantDefinition identifier fields) = show identifier
+ <> " = variant " <> intercalate "; " (NonEmpty.toList $ show <$> fields)
+ <> " end;"
+
+data Program =
+ Program [TypeDefinition] [ConstantDefinition] [VariableDeclaration] [ProcedureDeclaration] Statement
deriving Eq
instance Show Program
where
- show (Program constants globals procedures body)
- = showConstants constants <> showVariables globals
+ show (Program types constants globals procedures body)
+ = unlines (show <$> types)
+ <> showConstants constants <> showVariables globals
<> unlines (show <$> procedures) <> show body <> "."
showAttributes :: Bool -> String