From d4c6c0d01499e27bace535fc6101714bb8b5aa55 Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Sun, 17 Feb 2019 18:50:56 -0500 Subject: [PATCH] support for multiple module instantiations on one line and for module instantiations with no ports --- Language/SystemVerilog/Parser/Parse.y | 29 ++++++++++++++++----------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/Language/SystemVerilog/Parser/Parse.y b/Language/SystemVerilog/Parser/Parse.y index c9aa43b..97bdb9b 100644 --- a/Language/SystemVerilog/Parser/Parse.y +++ b/Language/SystemVerilog/Parser/Parse.y @@ -225,11 +225,17 @@ ModuleItem :: { [ModuleItem] } | IntegerDeclaration { map MIIntegerV $1 } | "assign" LHS "=" Expr ";" { [Assign $2 $4] } | "always" opt(EventControl) Stmt { [Always $2 $3] } - | Identifier ParameterBindings Identifier Bindings ";" { [Instance $1 $2 $3 $4] } + | Identifier ParameterBindings ModuleInstantiations ";" { map (uncurry $ Instance $1 $2) $3 } | "function" opt(RangeOrType) Identifier FunctionItems Stmt "endfunction" { [Function $2 $3 $4 $5] } | "genvar" Identifiers ";" { map Genvar $2 } | "generate" GenItems "endgenerate" { [Generate $2] } +ModuleInstantiations :: { [(Identifier, [PortBinding])] } + : ModuleInstantiation { [$1] } + | ModuleInstantiations "," ModuleInstantiation { $1 ++ [$3] } +ModuleInstantiation :: { (Identifier, [PortBinding]) } + : Identifier "(" Bindings ")" { ($1, $3) } + FunctionItems :: { [(Bool, BlockItemDeclaration)] } : "(" FunctionPortList ";" BlockItemDeclarations { (map ((,) True) $2) ++ (map ((,) False) $4) } | "(" FunctionPortList ";" { (map ((,) True) $2) } @@ -307,20 +313,19 @@ Sense1 :: { Sense } | "negedge" LHS { SenseNegedge $2 } Bindings :: { [(Identifier, Maybe Expr)] } -: "(" Bindings1 ")" { $2 } - -Bindings1 :: { [(Identifier, Maybe Expr)] } -: Binding { [$1] } -| Bindings1 "," Binding { $1 ++ [$3] } - + : {- empty -} { [] } + | BindingsNonEmpty { $1 } +BindingsNonEmpty :: { [(Identifier, Maybe Expr)] } + : Binding { [$1] } + | Binding "," BindingsNonEmpty { $1 : $3} Binding :: { (Identifier, Maybe Expr) } -: "." Identifier "(" MaybeExpr ")" { ($2, $4) } -| "." Identifier { ($2, Just $ Ident $2) } -| Expr { ("", Just $1) } + : "." Identifier "(" MaybeExpr ")" { ($2, $4) } + | "." Identifier { ($2, Just $ Ident $2) } + | Expr { ("", Just $1) } ParameterBindings :: { [(Identifier, Maybe Expr)] } - : {- empty -} { [] } - | "#" Bindings { $2 } + : {- empty -} { [] } + | "#" "(" BindingsNonEmpty ")" { $3 } Stmts :: { [Stmt] } : {- empty -} { [] }