summaryrefslogtreecommitdiff
path: root/src/Language/Fiddle/Parser.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Language/Fiddle/Parser.hs')
-rw-r--r--src/Language/Fiddle/Parser.hs51
1 files changed, 41 insertions, 10 deletions
diff --git a/src/Language/Fiddle/Parser.hs b/src/Language/Fiddle/Parser.hs
index 37ef34e..7eed0f2 100644
--- a/src/Language/Fiddle/Parser.hs
+++ b/src/Language/Fiddle/Parser.hs
@@ -7,8 +7,8 @@ module Language.Fiddle.Parser
)
where
-import Data.Kind (Type)
import Data.Functor.Identity
+import Data.Kind (Type)
import Data.Text (Text)
import qualified Data.Text
import Debug.Trace
@@ -28,6 +28,7 @@ type P = ParsecT S () Identity
type A = Commented SourceSpan
type Pa (a :: Stage -> (Type -> Type) -> Type -> Type) = P (a 'Stage1 F (Commented SourceSpan))
+
type PaS (a :: (Type -> Type) -> Type -> Type) = P (a F (Commented SourceSpan))
comment :: P Comment
@@ -68,9 +69,15 @@ fiddleDecl = do
<*> defer body packageBody
KWLocation -> LocationDecl <$> ident <*> (tok TokEq >> expression)
KWBits -> BitsDecl <$> ident <*> (tok TokColon >> bitType)
- KWObjtype ->
- ObjTypeDecl <$> ident <*> (tok TokColon >> defer body objTypeBody)
- KWObject ->
+ KWType ->
+ ObjTypeDecl
+ <$> ident
+ <*> ( do
+ tok TokColon
+ bt <- bodyType
+ defer body (objTypeBody bt)
+ )
+ KWInstance ->
ObjectDecl
<$> ident
<*> (tok KWAt *> expression)
@@ -114,15 +121,18 @@ objType = do
baseObj :: P (A -> ObjType Stage1 F A)
baseObj =
(ReferencedObjType <$> ident)
- <|> (AnonymousObjType <$> defer body objTypeBody)
+ <|> ( do
+ t <- bodyType
+ AnonymousObjType <$> defer body (objTypeBody t)
+ )
exprInParen :: Pa Expression
exprInParen = tok TokLParen *> expression <* tok TokRParen
-objTypeBody :: Pa ObjTypeBody
-objTypeBody =
+objTypeBody :: BodyType F (Commented SourceSpan) -> Pa ObjTypeBody
+objTypeBody bt =
withMeta $
- ObjTypeBody <$> many (objTypeDecl <* tok TokSemi)
+ ObjTypeBody bt <$> many (objTypeDecl <* tok TokSemi)
objTypeDecl :: Pa ObjTypeDecl
objTypeDecl =
@@ -132,6 +142,14 @@ objTypeDecl =
AssertPosStatement <$> exprInParen
)
<|> ( do
+ tok KWReserved
+ ReservedDecl <$> exprInParen
+ )
+ <|> ( do
+ bt <- bodyType
+ TypeSubStructure <$> defer body (objTypeBody bt) <*> optionMaybe ident
+ )
+ <|> ( do
mod <- optionMaybe modifier
tok KWReg
RegisterDecl mod
@@ -150,8 +168,19 @@ modifier =
tok KWWo >> return Wo
]
+bitBodyType :: PaS BodyType
+bitBodyType =
+ withMeta $
+ (tok KWStruct >> return Struct)
+ <|> (tok KWUnion >> return Union)
+
+bodyType :: PaS BodyType
+bodyType =
+ withMeta $
+ (tok KWStruct >> return Struct) <|> (tok KWUnion >> return Union)
+
registerBody :: Pa RegisterBody
-registerBody = withMeta $ RegisterBody <$> defer body deferredRegisterBody
+registerBody = withMeta $ RegisterBody <$> bitBodyType <*> defer body deferredRegisterBody
deferredRegisterBody :: Pa DeferredRegisterBody
deferredRegisterBody =
@@ -164,7 +193,9 @@ registerBitsDecl =
( do
tok KWReserved >> ReservedBits <$> exprInParen
)
- <|> ( DefinedBits <$> optionMaybe modifier
+ <|> (BitsSubStructure <$> registerBody <*> optionMaybe ident)
+ <|> ( DefinedBits
+ <$> optionMaybe modifier
<*> ident
<*> (tok TokColon >> registerBitsTypeRef)
)