sv_parser_parser/declarations/
let_declarations.rs1use crate::*;
2
3#[tracable_parser]
6#[packrat_parser]
7pub(crate) fn let_declaration(s: Span) -> IResult<Span, LetDeclaration> {
8 let (s, a) = keyword("let")(s)?;
9 let (s, b) = let_identifier(s)?;
10 let (s, c) = opt(paren(opt(let_port_list)))(s)?;
11 let (s, d) = symbol("=")(s)?;
12 let (s, e) = expression(s)?;
13 let (s, f) = symbol(";")(s)?;
14 Ok((
15 s,
16 LetDeclaration {
17 nodes: (a, b, c, d, e, f),
18 },
19 ))
20}
21
22#[tracable_parser]
23#[packrat_parser]
24pub(crate) fn let_identifier(s: Span) -> IResult<Span, LetIdentifier> {
25 let (s, a) = identifier(s)?;
26 Ok((s, LetIdentifier { nodes: (a,) }))
27}
28
29#[tracable_parser]
30#[packrat_parser]
31pub(crate) fn let_port_list(s: Span) -> IResult<Span, LetPortList> {
32 let (s, a) = list(symbol(","), let_port_item)(s)?;
33 Ok((s, LetPortList { nodes: (a,) }))
34}
35
36#[tracable_parser]
37#[packrat_parser]
38pub(crate) fn let_port_item(s: Span) -> IResult<Span, LetPortItem> {
39 let (s, a) = many0(attribute_instance)(s)?;
40 let (s, b) = let_formal_type(s)?;
41 let (s, c) = formal_port_identifier(s)?;
42 let (s, d) = many0(variable_dimension)(s)?;
43 let (s, e) = opt(pair(symbol("="), expression))(s)?;
44 Ok((
45 s,
46 LetPortItem {
47 nodes: (a, b, c, d, e),
48 },
49 ))
50}
51
52#[tracable_parser]
53#[packrat_parser]
54pub(crate) fn let_formal_type(s: Span) -> IResult<Span, LetFormalType> {
55 alt((
56 map(data_type_or_implicit_let_formal_type, |x| {
57 LetFormalType::DataTypeOrImplicit(Box::new(x))
58 }),
59 map(keyword("untyped"), |x| LetFormalType::Untyped(Box::new(x))),
60 ))(s)
61}
62
63#[tracable_parser]
64#[packrat_parser]
65pub(crate) fn data_type_or_implicit_let_formal_type(s: Span) -> IResult<Span, DataTypeOrImplicit> {
66 alt((
67 map(terminated(data_type, peek(formal_port_identifier)), |x| {
68 DataTypeOrImplicit::DataType(Box::new(x))
69 }),
70 map(
71 terminated(implicit_data_type, peek(formal_port_identifier)),
72 |x| DataTypeOrImplicit::ImplicitDataType(Box::new(x)),
73 ),
74 ))(s)
75}
76
77#[tracable_parser]
78#[packrat_parser]
79pub(crate) fn let_expression(s: Span) -> IResult<Span, LetExpression> {
80 let (s, a) = opt(package_scope)(s)?;
81 let (s, b) = let_identifier(s)?;
82 let (s, c) = opt(paren(opt(let_list_of_arguments)))(s)?;
83 Ok((s, LetExpression { nodes: (a, b, c) }))
84}
85
86#[tracable_parser]
87#[packrat_parser]
88pub(crate) fn let_list_of_arguments(s: Span) -> IResult<Span, LetListOfArguments> {
89 alt((let_list_of_arguments_named, let_list_of_arguments_ordered))(s)
90}
91
92#[recursive_parser]
93#[tracable_parser]
94#[packrat_parser]
95pub(crate) fn let_list_of_arguments_ordered(s: Span) -> IResult<Span, LetListOfArguments> {
96 let (s, a) = list(symbol(","), opt(let_actual_arg))(s)?;
97 let (s, b) = many0(tuple((
98 symbol(","),
99 symbol("."),
100 identifier,
101 paren(opt(let_actual_arg)),
102 )))(s)?;
103 Ok((
104 s,
105 LetListOfArguments::Ordered(Box::new(LetListOfArgumentsOrdered { nodes: (a, b) })),
106 ))
107}
108
109#[tracable_parser]
110#[packrat_parser]
111pub(crate) fn let_list_of_arguments_named(s: Span) -> IResult<Span, LetListOfArguments> {
112 let (s, a) = list(
113 symbol(","),
114 triple(symbol("."), identifier, paren(opt(let_actual_arg))),
115 )(s)?;
116 Ok((
117 s,
118 LetListOfArguments::Named(Box::new(LetListOfArgumentsNamed { nodes: (a,) })),
119 ))
120}
121
122#[tracable_parser]
123#[packrat_parser]
124pub(crate) fn let_actual_arg(s: Span) -> IResult<Span, LetActualArg> {
125 let (s, a) = expression(s)?;
126 Ok((s, LetActualArg { nodes: (a,) }))
127}