Commit c6dbdd09 by Zachary Snow

preliminary language support for basic classes

parent c0cac486
......@@ -93,6 +93,8 @@ traverseDescriptionM (PackageItem item) = do
idents -> Decl $ CommentDecl $ "removed " ++ show idents
traverseDescriptionM (Package _ 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
(_, items') <- processItems name "" items
return $ Part attrs extern kw liftetime name ports items'
......
......@@ -151,11 +151,22 @@ traverseModuleItemsM mapper (PackageItem packageItem) = do
return $ case item' of
MIPackageItem packageItem' -> PackageItem packageItem'
other -> error $ "encountered bad package module item: " ++ show other
traverseModuleItemsM mapper (Package lifetime name packageItems) = do
let items = map MIPackageItem packageItems
items' <- mapM (traverseNestedModuleItemsM mapper) items
let items'' = concatMap breakGenerate items'
return $ Package lifetime name $ map (\(MIPackageItem item) -> item) items''
traverseModuleItemsM mapper (Package lifetime name items) = do
let itemsWrapped = map MIPackageItem items
itemsWrapped' <- mapM (traverseNestedModuleItemsM mapper) itemsWrapped
let items' = map (\(MIPackageItem item) -> item) $
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 = unmonad traverseModuleItemsM
......
......@@ -26,6 +26,7 @@ data Description
= Part [Attr] Bool PartKW Lifetime Identifier [Identifier] [ModuleItem]
| PackageItem PackageItem
| Package Lifetime Identifier [PackageItem]
| Class Lifetime Identifier [Decl] [PackageItem]
deriving Eq
instance Show Description where
......@@ -49,6 +50,12 @@ instance Show Description where
(showPad lifetime) name bodyStr
where
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
data PackageItem
......
......@@ -555,6 +555,7 @@ InterfaceKW :: { PartKW }
PackageDeclaration :: { Description }
: "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 }
: ":" Identifier { $2 }
......@@ -571,9 +572,11 @@ PackageImportDeclaration :: { [ModuleItem] }
: "import" PackageImportItems ";" { map (MIPackageItem . uncurry Import) $2 }
Params :: { [ModuleItem] }
: PIParams { map (MIPackageItem . Decl) $1 }
PIParams :: { [Decl] }
: {- empty -} { [] }
| "#" "(" ")" { [] }
| "#" "(" ParamsFollow { map (MIPackageItem . Decl) $3 }
| "#" "(" ParamsFollow { $3 }
ParamsFollow :: { [Decl] }
: ParamAsgn ")" { [$1] }
| ParamAsgn "," ParamsFollow { $1 : $3 }
......@@ -1380,6 +1383,7 @@ position :: { Position }
: {- empty -} {% gets fst }
end : "end" {} | error {% missingToken "end" }
endclass : "endclass" {} | error {% missingToken "endclass" }
endfunction : "endfunction" {} | error {% missingToken "endfunction" }
endgenerate : "endgenerate" {} | error {% missingToken "endgenerate" }
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