Add record and variant AST types
This commit is contained in:
parent
be4957ee59
commit
f673ca48a9
3
TODO
3
TODO
@ -1,5 +1,4 @@
|
||||
# AST missing
|
||||
|
||||
- Import
|
||||
- Record
|
||||
- Union
|
||||
- Record and Union initialization
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user