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
|
# AST missing
|
||||||
|
|
||||||
- Import
|
- Import
|
||||||
- Record
|
- Record and Union initialization
|
||||||
- Union
|
|
||||||
|
@ -12,6 +12,8 @@ module Language.Elna.AST
|
|||||||
|
|
||||||
import Data.Int (Int32)
|
import Data.Int (Int32)
|
||||||
import Data.List (intercalate)
|
import Data.List (intercalate)
|
||||||
|
import Data.List.NonEmpty (NonEmpty(..))
|
||||||
|
import qualified Data.List.NonEmpty as NonEmpty
|
||||||
import Data.Word (Word8)
|
import Data.Word (Word8)
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import qualified Data.Text as Text
|
import qualified Data.Text as Text
|
||||||
@ -174,13 +176,29 @@ instance Show VariableDeclaration
|
|||||||
<> maybe "" ((" = " <>) . show) initialValue <> ";"
|
<> maybe "" ((" = " <>) . show) initialValue <> ";"
|
||||||
<> showAttributes exports
|
<> 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
|
deriving Eq
|
||||||
|
|
||||||
instance Show Program
|
instance Show Program
|
||||||
where
|
where
|
||||||
show (Program constants globals procedures body)
|
show (Program types constants globals procedures body)
|
||||||
= showConstants constants <> showVariables globals
|
= unlines (show <$> types)
|
||||||
|
<> showConstants constants <> showVariables globals
|
||||||
<> unlines (show <$> procedures) <> show body <> "."
|
<> unlines (show <$> procedures) <> show body <> "."
|
||||||
|
|
||||||
showAttributes :: Bool -> String
|
showAttributes :: Bool -> String
|
||||||
|
Loading…
Reference in New Issue
Block a user