sv_parser_parser/declarations/
module_parameter_declarations.rs

1use crate::*;
2
3// -----------------------------------------------------------------------------
4
5#[tracable_parser]
6#[packrat_parser]
7pub(crate) fn local_parameter_declaration(s: Span) -> IResult<Span, LocalParameterDeclaration> {
8    alt((
9        local_parameter_declaration_param,
10        local_parameter_declaration_type,
11    ))(s)
12}
13
14#[tracable_parser]
15#[packrat_parser]
16pub(crate) fn local_parameter_declaration_param(
17    s: Span,
18) -> IResult<Span, LocalParameterDeclaration> {
19    let (s, a) = keyword("localparam")(s)?;
20    let (s, b) = data_type_or_implicit_local_parameter_declaration_param(s)?;
21    let (s, c) = list_of_param_assignments(s)?;
22    Ok((
23        s,
24        LocalParameterDeclaration::Param(Box::new(LocalParameterDeclarationParam {
25            nodes: (a, b, c),
26        })),
27    ))
28}
29
30#[tracable_parser]
31#[packrat_parser]
32pub(crate) fn data_type_or_implicit_local_parameter_declaration_param(
33    s: Span,
34) -> IResult<Span, DataTypeOrImplicit> {
35    alt((
36        map(terminated(data_type, peek(param_assignment)), |x| {
37            DataTypeOrImplicit::DataType(Box::new(x))
38        }),
39        map(
40            terminated(implicit_data_type, peek(param_assignment)),
41            |x| DataTypeOrImplicit::ImplicitDataType(Box::new(x)),
42        ),
43    ))(s)
44}
45
46#[tracable_parser]
47#[packrat_parser]
48pub(crate) fn local_parameter_declaration_type(
49    s: Span,
50) -> IResult<Span, LocalParameterDeclaration> {
51    let (s, a) = keyword("localparam")(s)?;
52    let (s, b) = keyword("type")(s)?;
53    let (s, c) = list_of_type_assignments(s)?;
54    Ok((
55        s,
56        LocalParameterDeclaration::Type(Box::new(LocalParameterDeclarationType {
57            nodes: (a, b, c),
58        })),
59    ))
60}
61
62#[tracable_parser]
63#[packrat_parser]
64pub(crate) fn parameter_declaration(s: Span) -> IResult<Span, ParameterDeclaration> {
65    alt((parameter_declaration_param, parameter_declaration_type))(s)
66}
67
68#[tracable_parser]
69#[packrat_parser]
70pub(crate) fn parameter_declaration_param(s: Span) -> IResult<Span, ParameterDeclaration> {
71    let (s, a) = keyword("parameter")(s)?;
72    let (s, b) = data_type_or_implicit_parameter_declaration_param(s)?;
73    let (s, c) = list_of_param_assignments(s)?;
74    Ok((
75        s,
76        ParameterDeclaration::Param(Box::new(ParameterDeclarationParam { nodes: (a, b, c) })),
77    ))
78}
79
80#[tracable_parser]
81#[packrat_parser]
82pub(crate) fn data_type_or_implicit_parameter_declaration_param(
83    s: Span,
84) -> IResult<Span, DataTypeOrImplicit> {
85    alt((
86        map(terminated(data_type, peek(param_assignment)), |x| {
87            DataTypeOrImplicit::DataType(Box::new(x))
88        }),
89        map(
90            terminated(implicit_data_type, peek(param_assignment)),
91            |x| DataTypeOrImplicit::ImplicitDataType(Box::new(x)),
92        ),
93    ))(s)
94}
95
96#[tracable_parser]
97#[packrat_parser]
98pub(crate) fn parameter_declaration_type(s: Span) -> IResult<Span, ParameterDeclaration> {
99    let (s, a) = keyword("parameter")(s)?;
100    let (s, b) = keyword("type")(s)?;
101    let (s, c) = list_of_type_assignments(s)?;
102    Ok((
103        s,
104        ParameterDeclaration::Type(Box::new(ParameterDeclarationType { nodes: (a, b, c) })),
105    ))
106}
107
108#[tracable_parser]
109#[packrat_parser]
110pub(crate) fn specparam_declaration(s: Span) -> IResult<Span, SpecparamDeclaration> {
111    let (s, a) = keyword("specparam")(s)?;
112    let (s, b) = opt(packed_dimension)(s)?;
113    let (s, c) = list_of_specparam_assignments(s)?;
114    let (s, d) = symbol(";")(s)?;
115    Ok((
116        s,
117        SpecparamDeclaration {
118            nodes: (a, b, c, d),
119        },
120    ))
121}