sv_parser_parser/declarations/
declaration_ranges.rs1use crate::*;
2
3#[tracable_parser]
6#[packrat_parser]
7pub(crate) fn unpacked_dimension(s: Span) -> IResult<Span, UnpackedDimension> {
8 alt((unpacked_dimension_range, unpacked_dimension_expression))(s)
9}
10
11#[tracable_parser]
12#[packrat_parser]
13pub(crate) fn unpacked_dimension_range(s: Span) -> IResult<Span, UnpackedDimension> {
14 let (s, a) = bracket(constant_range)(s)?;
15 Ok((
16 s,
17 UnpackedDimension::Range(Box::new(UnpackedDimensionRange { nodes: (a,) })),
18 ))
19}
20
21#[tracable_parser]
22#[packrat_parser]
23pub(crate) fn unpacked_dimension_expression(s: Span) -> IResult<Span, UnpackedDimension> {
24 let (s, a) = bracket(constant_expression)(s)?;
25 Ok((
26 s,
27 UnpackedDimension::Expression(Box::new(UnpackedDimensionExpression { nodes: (a,) })),
28 ))
29}
30
31#[tracable_parser]
32#[packrat_parser]
33pub(crate) fn packed_dimension(s: Span) -> IResult<Span, PackedDimension> {
34 alt((
35 packed_dimension_range,
36 map(unsized_dimension, |x| {
37 PackedDimension::UnsizedDimension(Box::new(x))
38 }),
39 ))(s)
40}
41
42#[tracable_parser]
43#[packrat_parser]
44pub(crate) fn packed_dimension_range(s: Span) -> IResult<Span, PackedDimension> {
45 let (s, a) = bracket(constant_range)(s)?;
46 Ok((
47 s,
48 PackedDimension::Range(Box::new(PackedDimensionRange { nodes: (a,) })),
49 ))
50}
51
52#[tracable_parser]
53#[packrat_parser]
54pub(crate) fn associative_dimension(s: Span) -> IResult<Span, AssociativeDimension> {
55 alt((
56 associative_dimension_data_type,
57 associative_dimension_asterisk,
58 ))(s)
59}
60
61#[tracable_parser]
62#[packrat_parser]
63pub(crate) fn associative_dimension_data_type(s: Span) -> IResult<Span, AssociativeDimension> {
64 let (s, a) = bracket(data_type)(s)?;
65 Ok((
66 s,
67 AssociativeDimension::DataType(Box::new(AssociativeDimensionDataType { nodes: (a,) })),
68 ))
69}
70
71#[tracable_parser]
72#[packrat_parser]
73pub(crate) fn associative_dimension_asterisk(s: Span) -> IResult<Span, AssociativeDimension> {
74 let (s, a) = bracket(symbol("*"))(s)?;
75 Ok((
76 s,
77 AssociativeDimension::Asterisk(Box::new(AssociativeDimensionAsterisk { nodes: (a,) })),
78 ))
79}
80
81#[tracable_parser]
82#[packrat_parser]
83pub(crate) fn variable_dimension(s: Span) -> IResult<Span, VariableDimension> {
84 alt((
85 map(unsized_dimension, |x| {
86 VariableDimension::UnsizedDimension(Box::new(x))
87 }),
88 map(unpacked_dimension, |x| {
89 VariableDimension::UnpackedDimension(Box::new(x))
90 }),
91 map(associative_dimension, |x| {
92 VariableDimension::AssociativeDimension(Box::new(x))
93 }),
94 map(queue_dimension, |x| {
95 VariableDimension::QueueDimension(Box::new(x))
96 }),
97 ))(s)
98}
99
100#[tracable_parser]
101#[packrat_parser]
102pub(crate) fn queue_dimension(s: Span) -> IResult<Span, QueueDimension> {
103 let (s, a) = bracket(pair(
104 symbol("$"),
105 opt(pair(symbol(":"), constant_expression)),
106 ))(s)?;
107 Ok((s, QueueDimension { nodes: (a,) }))
108}
109
110#[tracable_parser]
111#[packrat_parser]
112pub(crate) fn unsized_dimension(s: Span) -> IResult<Span, UnsizedDimension> {
113 let (s, a) = symbol("[")(s)?;
114 let (s, b) = symbol("]")(s)?;
115 Ok((s, UnsizedDimension { nodes: (a, b) }))
116}