sv_parser_parser/expressions/
concatenations.rs

1use crate::*;
2
3// -----------------------------------------------------------------------------
4
5#[tracable_parser]
6#[packrat_parser]
7pub(crate) fn concatenation(s: Span) -> IResult<Span, Concatenation> {
8    let (s, a) = brace(list(symbol(","), expression))(s)?;
9    Ok((s, Concatenation { nodes: (a,) }))
10}
11
12#[tracable_parser]
13#[packrat_parser]
14pub(crate) fn constant_concatenation(s: Span) -> IResult<Span, ConstantConcatenation> {
15    let (s, a) = brace(list(symbol(","), constant_expression))(s)?;
16    Ok((s, ConstantConcatenation { nodes: (a,) }))
17}
18
19#[tracable_parser]
20#[packrat_parser]
21pub(crate) fn constant_multiple_concatenation(
22    s: Span,
23) -> IResult<Span, ConstantMultipleConcatenation> {
24    let (s, a) = brace(pair(constant_expression, constant_concatenation))(s)?;
25    Ok((s, ConstantMultipleConcatenation { nodes: (a,) }))
26}
27
28#[tracable_parser]
29#[packrat_parser]
30pub(crate) fn module_path_concatenation(s: Span) -> IResult<Span, ModulePathConcatenation> {
31    let (s, a) = brace(list(symbol(","), module_path_expression))(s)?;
32    Ok((s, ModulePathConcatenation { nodes: (a,) }))
33}
34
35#[tracable_parser]
36#[packrat_parser]
37pub(crate) fn module_path_multiple_concatenation(
38    s: Span,
39) -> IResult<Span, ModulePathMultipleConcatenation> {
40    let (s, a) = brace(pair(constant_expression, module_path_concatenation))(s)?;
41    Ok((s, ModulePathMultipleConcatenation { nodes: (a,) }))
42}
43
44#[tracable_parser]
45#[packrat_parser]
46pub(crate) fn multiple_concatenation(s: Span) -> IResult<Span, MultipleConcatenation> {
47    let (s, a) = brace(pair(expression, concatenation))(s)?;
48    Ok((s, MultipleConcatenation { nodes: (a,) }))
49}
50
51#[tracable_parser]
52#[packrat_parser]
53pub(crate) fn streaming_concatenation(s: Span) -> IResult<Span, StreamingConcatenation> {
54    let (s, a) = brace(triple(
55        stream_operator,
56        opt(terminated(slice_size, peek(symbol("{")))),
57        stream_concatenation,
58    ))(s)?;
59    Ok((s, StreamingConcatenation { nodes: (a,) }))
60}
61
62#[tracable_parser]
63#[packrat_parser]
64pub(crate) fn stream_operator(s: Span) -> IResult<Span, StreamOperator> {
65    alt((
66        map(symbol(">>"), |x| StreamOperator { nodes: (x,) }),
67        map(symbol("<<"), |x| StreamOperator { nodes: (x,) }),
68    ))(s)
69}
70
71#[tracable_parser]
72#[packrat_parser]
73pub(crate) fn slice_size(s: Span) -> IResult<Span, SliceSize> {
74    alt((
75        map(simple_type, |x| SliceSize::SimpleType(Box::new(x))),
76        map(constant_expression, |x| {
77            SliceSize::ConstantExpression(Box::new(x))
78        }),
79    ))(s)
80}
81
82#[tracable_parser]
83#[packrat_parser]
84pub(crate) fn stream_concatenation(s: Span) -> IResult<Span, StreamConcatenation> {
85    let (s, a) = brace(list(symbol(","), stream_expression))(s)?;
86    Ok((s, StreamConcatenation { nodes: (a,) }))
87}
88
89#[recursive_parser]
90#[tracable_parser]
91#[packrat_parser]
92pub(crate) fn stream_expression(s: Span) -> IResult<Span, StreamExpression> {
93    let (s, a) = expression(s)?;
94    let (s, b) = opt(pair(keyword("with"), bracket(array_range_expression)))(s)?;
95    Ok((s, StreamExpression { nodes: (a, b) }))
96}
97
98#[tracable_parser]
99#[packrat_parser]
100pub(crate) fn array_range_expression(s: Span) -> IResult<Span, ArrayRangeExpression> {
101    alt((
102        array_range_expression_colon,
103        array_range_expression_plus_colon,
104        array_range_expression_minus_colon,
105        map(expression, |x| {
106            ArrayRangeExpression::Expression(Box::new(x))
107        }),
108    ))(s)
109}
110
111#[recursive_parser]
112#[tracable_parser]
113#[packrat_parser]
114pub(crate) fn array_range_expression_colon(s: Span) -> IResult<Span, ArrayRangeExpression> {
115    let (s, a) = expression(s)?;
116    let (s, b) = symbol(":")(s)?;
117    let (s, c) = expression(s)?;
118    Ok((
119        s,
120        ArrayRangeExpression::Colon(Box::new(ArrayRangeExpressionColon { nodes: (a, b, c) })),
121    ))
122}
123
124#[recursive_parser]
125#[tracable_parser]
126#[packrat_parser]
127pub(crate) fn array_range_expression_plus_colon(s: Span) -> IResult<Span, ArrayRangeExpression> {
128    let (s, a) = expression(s)?;
129    let (s, b) = symbol("+:")(s)?;
130    let (s, c) = expression(s)?;
131    Ok((
132        s,
133        ArrayRangeExpression::PlusColon(Box::new(ArrayRangeExpressionPlusColon {
134            nodes: (a, b, c),
135        })),
136    ))
137}
138
139#[recursive_parser]
140#[tracable_parser]
141#[packrat_parser]
142pub(crate) fn array_range_expression_minus_colon(s: Span) -> IResult<Span, ArrayRangeExpression> {
143    let (s, a) = expression(s)?;
144    let (s, b) = symbol("-:")(s)?;
145    let (s, c) = expression(s)?;
146    Ok((
147        s,
148        ArrayRangeExpression::MinusColon(Box::new(ArrayRangeExpressionMinusColon {
149            nodes: (a, b, c),
150        })),
151    ))
152}
153
154#[tracable_parser]
155#[packrat_parser]
156pub(crate) fn empty_unpacked_array_concatenation(
157    s: Span,
158) -> IResult<Span, EmptyUnpackedArrayConcatenation> {
159    let (s, a) = symbol("{")(s)?;
160    let (s, b) = symbol("}")(s)?;
161    Ok((s, EmptyUnpackedArrayConcatenation { nodes: (a, b) }))
162}