Commit c6dbdd09 by Zachary Snow

preliminary language support for basic classes

parent c0cac486
...@@ -93,6 +93,8 @@ traverseDescriptionM (PackageItem item) = do ...@@ -93,6 +93,8 @@ traverseDescriptionM (PackageItem item) = do
idents -> Decl $ CommentDecl $ "removed " ++ show idents idents -> Decl $ CommentDecl $ "removed " ++ show idents
traverseDescriptionM (Package _ name _) = traverseDescriptionM (Package _ name _) =
return $ PackageItem $ Decl $ CommentDecl $ "removed package " ++ show name return $ PackageItem $ Decl $ CommentDecl $ "removed package " ++ show name
traverseDescriptionM (Class _ name _ _) =
return $ PackageItem $ Decl $ CommentDecl $ "removed class " ++ show name
traverseDescriptionM (Part attrs extern kw liftetime name ports items) = do traverseDescriptionM (Part attrs extern kw liftetime name ports items) = do
(_, items') <- processItems name "" items (_, items') <- processItems name "" items
return $ Part attrs extern kw liftetime name ports items' return $ Part attrs extern kw liftetime name ports items'
......
...@@ -151,11 +151,22 @@ traverseModuleItemsM mapper (PackageItem packageItem) = do ...@@ -151,11 +151,22 @@ traverseModuleItemsM mapper (PackageItem packageItem) = do
return $ case item' of return $ case item' of
MIPackageItem packageItem' -> PackageItem packageItem' MIPackageItem packageItem' -> PackageItem packageItem'
other -> error $ "encountered bad package module item: " ++ show other other -> error $ "encountered bad package module item: " ++ show other
traverseModuleItemsM mapper (Package lifetime name packageItems) = do traverseModuleItemsM mapper (Package lifetime name items) = do
let items = map MIPackageItem packageItems let itemsWrapped = map MIPackageItem items
items' <- mapM (traverseNestedModuleItemsM mapper) items itemsWrapped' <- mapM (traverseNestedModuleItemsM mapper) itemsWrapped
let items'' = concatMap breakGenerate items' let items' = map (\(MIPackageItem item) -> item) $
return $ Package lifetime name $ map (\(MIPackageItem item) -> item) items'' concatMap breakGenerate itemsWrapped'
return $ Package lifetime name items'
traverseModuleItemsM mapper (Class lifetime name decls items) = do
let declsWrapped = map (MIPackageItem . Decl) decls
declsWrapped' <- mapM (traverseNestedModuleItemsM mapper) declsWrapped
let decls' = map (\(MIPackageItem (Decl decl)) -> decl) $
concatMap breakGenerate declsWrapped'
let itemsWrapped = map MIPackageItem items
itemsWrapped' <- mapM (traverseNestedModuleItemsM mapper) itemsWrapped
let items' = map (\(MIPackageItem item) -> item) $
concatMap breakGenerate itemsWrapped'
return $ Class lifetime name decls' items'
traverseModuleItems :: Mapper ModuleItem -> Mapper Description traverseModuleItems :: Mapper ModuleItem -> Mapper Description
traverseModuleItems = unmonad traverseModuleItemsM traverseModuleItems = unmonad traverseModuleItemsM
......
...@@ -26,6 +26,7 @@ data Description ...@@ -26,6 +26,7 @@ data Description
= Part [Attr] Bool PartKW Lifetime Identifier [Identifier] [ModuleItem] = Part [Attr] Bool PartKW Lifetime Identifier [Identifier] [ModuleItem]
| PackageItem PackageItem | PackageItem PackageItem
| Package Lifetime Identifier [PackageItem] | Package Lifetime Identifier [PackageItem]
| Class Lifetime Identifier [Decl] [PackageItem]
deriving Eq deriving Eq
instance Show Description where instance Show Description where
...@@ -49,6 +50,12 @@ instance Show Description where ...@@ -49,6 +50,12 @@ instance Show Description where
(showPad lifetime) name bodyStr (showPad lifetime) name bodyStr
where where
bodyStr = indent $ unlines' $ map show items bodyStr = indent $ unlines' $ map show items
show (Class lifetime name decls items) =
printf "class %s%s;\n%s\nendclass"
(showPad lifetime) name bodyStr
where
bodyStr = indent $ unlines' $ map show items'
items' = (map Decl decls) ++ items
show (PackageItem i) = show i show (PackageItem i) = show i
data PackageItem data PackageItem
......
...@@ -555,6 +555,7 @@ InterfaceKW :: { PartKW } ...@@ -555,6 +555,7 @@ InterfaceKW :: { PartKW }
PackageDeclaration :: { Description } PackageDeclaration :: { Description }
: "package" Lifetime Identifier ";" PackageItems endpackage opt(Tag) { Package $2 $3 $5 } : "package" Lifetime Identifier ";" PackageItems endpackage opt(Tag) { Package $2 $3 $5 }
| "class" Lifetime Identifier PIParams ";" PackageItems endclass opt(Tag) { Class $2 $3 $4 $6 }
Tag :: { Identifier } Tag :: { Identifier }
: ":" Identifier { $2 } : ":" Identifier { $2 }
...@@ -571,9 +572,11 @@ PackageImportDeclaration :: { [ModuleItem] } ...@@ -571,9 +572,11 @@ PackageImportDeclaration :: { [ModuleItem] }
: "import" PackageImportItems ";" { map (MIPackageItem . uncurry Import) $2 } : "import" PackageImportItems ";" { map (MIPackageItem . uncurry Import) $2 }
Params :: { [ModuleItem] } Params :: { [ModuleItem] }
: PIParams { map (MIPackageItem . Decl) $1 }
PIParams :: { [Decl] }
: {- empty -} { [] } : {- empty -} { [] }
| "#" "(" ")" { [] } | "#" "(" ")" { [] }
| "#" "(" ParamsFollow { map (MIPackageItem . Decl) $3 } | "#" "(" ParamsFollow { $3 }
ParamsFollow :: { [Decl] } ParamsFollow :: { [Decl] }
: ParamAsgn ")" { [$1] } : ParamAsgn ")" { [$1] }
| ParamAsgn "," ParamsFollow { $1 : $3 } | ParamAsgn "," ParamsFollow { $1 : $3 }
...@@ -1380,6 +1383,7 @@ position :: { Position } ...@@ -1380,6 +1383,7 @@ position :: { Position }
: {- empty -} {% gets fst } : {- empty -} {% gets fst }
end : "end" {} | error {% missingToken "end" } end : "end" {} | error {% missingToken "end" }
endclass : "endclass" {} | error {% missingToken "endclass" }
endfunction : "endfunction" {} | error {% missingToken "endfunction" } endfunction : "endfunction" {} | error {% missingToken "endfunction" }
endgenerate : "endgenerate" {} | error {% missingToken "endgenerate" } endgenerate : "endgenerate" {} | error {% missingToken "endgenerate" }
endinterface : "endinterface" {} | error {% missingToken "endinterface" } endinterface : "endinterface" {} | error {% missingToken "endinterface" }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment