sv_parser_parser/general/
identifiers.rs

1use crate::*;
2
3// -----------------------------------------------------------------------------
4
5pub(crate) const AZ_: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
6pub(crate) const AZ09_: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
7pub(crate) const AZ09_DOLLAR: &str =
8    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$";
9
10#[allow(dead_code)]
11#[tracable_parser]
12pub(crate) fn array_identifier(s: Span) -> IResult<Span, ArrayIdentifier> {
13    let (s, a) = identifier(s)?;
14    Ok((s, ArrayIdentifier { nodes: (a,) }))
15}
16
17#[tracable_parser]
18pub(crate) fn block_identifier(s: Span) -> IResult<Span, BlockIdentifier> {
19    let (s, a) = identifier(s)?;
20    Ok((s, BlockIdentifier { nodes: (a,) }))
21}
22
23#[tracable_parser]
24pub(crate) fn bin_identifier(s: Span) -> IResult<Span, BinIdentifier> {
25    let (s, a) = identifier(s)?;
26    Ok((s, BinIdentifier { nodes: (a,) }))
27}
28
29#[tracable_parser]
30#[packrat_parser]
31pub(crate) fn c_identifier(s: Span) -> IResult<Span, CIdentifier> {
32    let (s, a) = ws(c_identifier_impl)(s)?;
33    Ok((s, CIdentifier { nodes: a }))
34}
35
36#[tracable_parser]
37pub(crate) fn c_identifier_impl(s: Span) -> IResult<Span, Locate> {
38    let (s, a) = is_a(AZ_)(s)?;
39    let (s, b) = opt(is_a(AZ09_))(s)?;
40    let a = if let Some(b) = b {
41        concat(a, b).unwrap()
42    } else {
43        a
44    };
45    if is_keyword(&a) {
46        Err(Err::Error(make_error(s, ErrorKind::Fix)))
47    } else {
48        Ok((s, into_locate(a)))
49    }
50}
51
52#[tracable_parser]
53pub(crate) fn cell_identifier(s: Span) -> IResult<Span, CellIdentifier> {
54    let (s, a) = identifier(s)?;
55    Ok((s, CellIdentifier { nodes: (a,) }))
56}
57
58#[tracable_parser]
59pub(crate) fn checker_identifier(s: Span) -> IResult<Span, CheckerIdentifier> {
60    let (s, a) = identifier(s)?;
61    Ok((s, CheckerIdentifier { nodes: (a,) }))
62}
63
64#[tracable_parser]
65pub(crate) fn class_identifier(s: Span) -> IResult<Span, ClassIdentifier> {
66    let (s, a) = identifier(s)?;
67    Ok((s, ClassIdentifier { nodes: (a,) }))
68}
69
70#[tracable_parser]
71pub(crate) fn class_variable_identifier(s: Span) -> IResult<Span, ClassVariableIdentifier> {
72    let (s, a) = variable_identifier(s)?;
73    Ok((s, ClassVariableIdentifier { nodes: (a,) }))
74}
75
76#[tracable_parser]
77pub(crate) fn clocking_identifier(s: Span) -> IResult<Span, ClockingIdentifier> {
78    let (s, a) = identifier(s)?;
79    Ok((s, ClockingIdentifier { nodes: (a,) }))
80}
81
82#[tracable_parser]
83pub(crate) fn config_identifier(s: Span) -> IResult<Span, ConfigIdentifier> {
84    let (s, a) = identifier(s)?;
85    Ok((s, ConfigIdentifier { nodes: (a,) }))
86}
87
88#[tracable_parser]
89pub(crate) fn const_identifier(s: Span) -> IResult<Span, ConstIdentifier> {
90    let (s, a) = identifier(s)?;
91    Ok((s, ConstIdentifier { nodes: (a,) }))
92}
93
94#[tracable_parser]
95pub(crate) fn constraint_identifier(s: Span) -> IResult<Span, ConstraintIdentifier> {
96    let (s, a) = identifier(s)?;
97    Ok((s, ConstraintIdentifier { nodes: (a,) }))
98}
99
100#[tracable_parser]
101pub(crate) fn covergroup_identifier(s: Span) -> IResult<Span, CovergroupIdentifier> {
102    let (s, a) = identifier(s)?;
103    Ok((s, CovergroupIdentifier { nodes: (a,) }))
104}
105
106#[allow(dead_code)]
107#[tracable_parser]
108pub(crate) fn covergroup_variable_identifier(
109    s: Span,
110) -> IResult<Span, CovergroupVariableIdentifier> {
111    let (s, a) = variable_identifier(s)?;
112    Ok((s, CovergroupVariableIdentifier { nodes: (a,) }))
113}
114
115#[tracable_parser]
116pub(crate) fn cover_point_identifier(s: Span) -> IResult<Span, CoverPointIdentifier> {
117    let (s, a) = identifier(s)?;
118    Ok((s, CoverPointIdentifier { nodes: (a,) }))
119}
120
121#[tracable_parser]
122pub(crate) fn cross_identifier(s: Span) -> IResult<Span, CrossIdentifier> {
123    let (s, a) = identifier(s)?;
124    Ok((s, CrossIdentifier { nodes: (a,) }))
125}
126
127#[tracable_parser]
128pub(crate) fn dynamic_array_variable_identifier(
129    s: Span,
130) -> IResult<Span, DynamicArrayVariableIdentifier> {
131    let (s, a) = variable_identifier(s)?;
132    Ok((s, DynamicArrayVariableIdentifier { nodes: (a,) }))
133}
134
135#[tracable_parser]
136pub(crate) fn enum_identifier(s: Span) -> IResult<Span, EnumIdentifier> {
137    let (s, a) = identifier(s)?;
138    Ok((s, EnumIdentifier { nodes: (a,) }))
139}
140
141#[tracable_parser]
142pub(crate) fn escaped_identifier(s: Span) -> IResult<Span, EscapedIdentifier> {
143    let (s, a) = ws(escaped_identifier_impl)(s)?;
144    Ok((s, EscapedIdentifier { nodes: a }))
145}
146
147#[tracable_parser]
148pub(crate) fn escaped_identifier_exact(s: Span) -> IResult<Span, EscapedIdentifier> {
149    let (s, a) = no_ws(escaped_identifier_impl)(s)?;
150    Ok((s, EscapedIdentifier { nodes: a }))
151}
152
153#[tracable_parser]
154pub(crate) fn escaped_identifier_impl(s: Span) -> IResult<Span, Locate> {
155    let (s, a) = tag("\\")(s)?;
156    let (s, b) = is_not(" \t\r\n")(s)?;
157    let a = concat(a, b).unwrap();
158    Ok((s, into_locate(a)))
159}
160
161#[allow(dead_code)]
162#[tracable_parser]
163pub(crate) fn formal_identifier(s: Span) -> IResult<Span, FormalIdentifier> {
164    let (s, a) = identifier(s)?;
165    Ok((s, FormalIdentifier { nodes: (a,) }))
166}
167
168#[tracable_parser]
169pub(crate) fn formal_port_identifier(s: Span) -> IResult<Span, FormalPortIdentifier> {
170    let (s, a) = identifier(s)?;
171    Ok((s, FormalPortIdentifier { nodes: (a,) }))
172}
173
174#[tracable_parser]
175pub(crate) fn function_identifier(s: Span) -> IResult<Span, FunctionIdentifier> {
176    let (s, a) = identifier(s)?;
177    Ok((s, FunctionIdentifier { nodes: (a,) }))
178}
179
180#[tracable_parser]
181pub(crate) fn generate_block_identifier(s: Span) -> IResult<Span, GenerateBlockIdentifier> {
182    let (s, a) = identifier(s)?;
183    Ok((s, GenerateBlockIdentifier { nodes: (a,) }))
184}
185
186#[tracable_parser]
187pub(crate) fn genvar_identifier(s: Span) -> IResult<Span, GenvarIdentifier> {
188    let (s, a) = identifier(s)?;
189    Ok((s, GenvarIdentifier { nodes: (a,) }))
190}
191
192#[tracable_parser]
193pub(crate) fn hierarchical_array_identifier(s: Span) -> IResult<Span, HierarchicalArrayIdentifier> {
194    let (s, a) = hierarchical_identifier(s)?;
195    Ok((s, HierarchicalArrayIdentifier { nodes: (a,) }))
196}
197
198#[tracable_parser]
199pub(crate) fn hierarchical_block_identifier(s: Span) -> IResult<Span, HierarchicalBlockIdentifier> {
200    let (s, a) = hierarchical_identifier(s)?;
201    Ok((s, HierarchicalBlockIdentifier { nodes: (a,) }))
202}
203
204#[tracable_parser]
205pub(crate) fn hierarchical_event_identifier(s: Span) -> IResult<Span, HierarchicalEventIdentifier> {
206    let (s, a) = hierarchical_identifier(s)?;
207    Ok((s, HierarchicalEventIdentifier { nodes: (a,) }))
208}
209
210#[tracable_parser]
211#[packrat_parser]
212pub(crate) fn hierarchical_identifier(s: Span) -> IResult<Span, HierarchicalIdentifier> {
213    let (s, a) = opt(root)(s)?;
214    let (s, b) = many0(terminated(
215        triple(identifier, constant_bit_select, symbol(".")),
216        peek(identifier),
217    ))(s)?;
218    let (s, c) = identifier(s)?;
219    Ok((s, HierarchicalIdentifier { nodes: (a, b, c) }))
220}
221
222#[tracable_parser]
223#[packrat_parser]
224pub(crate) fn root(s: Span) -> IResult<Span, Root> {
225    let (s, a) = keyword("$root")(s)?;
226    let (s, b) = symbol(".")(s)?;
227    Ok((s, Root { nodes: (a, b) }))
228}
229
230#[tracable_parser]
231pub(crate) fn hierarchical_net_identifier(s: Span) -> IResult<Span, HierarchicalNetIdentifier> {
232    let (s, a) = hierarchical_identifier(s)?;
233    Ok((s, HierarchicalNetIdentifier { nodes: (a,) }))
234}
235
236#[tracable_parser]
237pub(crate) fn hierarchical_parameter_identifier(
238    s: Span,
239) -> IResult<Span, HierarchicalParameterIdentifier> {
240    let (s, a) = hierarchical_identifier(s)?;
241    Ok((s, HierarchicalParameterIdentifier { nodes: (a,) }))
242}
243
244#[tracable_parser]
245pub(crate) fn hierarchical_property_identifier(
246    s: Span,
247) -> IResult<Span, HierarchicalPropertyIdentifier> {
248    let (s, a) = hierarchical_identifier(s)?;
249    Ok((s, HierarchicalPropertyIdentifier { nodes: (a,) }))
250}
251
252#[tracable_parser]
253pub(crate) fn hierarchical_sequence_identifier(
254    s: Span,
255) -> IResult<Span, HierarchicalSequenceIdentifier> {
256    let (s, a) = hierarchical_identifier(s)?;
257    Ok((s, HierarchicalSequenceIdentifier { nodes: (a,) }))
258}
259
260#[tracable_parser]
261pub(crate) fn hierarchical_task_identifier(s: Span) -> IResult<Span, HierarchicalTaskIdentifier> {
262    let (s, a) = hierarchical_identifier(s)?;
263    Ok((s, HierarchicalTaskIdentifier { nodes: (a,) }))
264}
265
266#[tracable_parser]
267pub(crate) fn hierarchical_tf_identifier(s: Span) -> IResult<Span, HierarchicalTfIdentifier> {
268    let (s, a) = hierarchical_identifier(s)?;
269    Ok((s, HierarchicalTfIdentifier { nodes: (a,) }))
270}
271
272#[tracable_parser]
273pub(crate) fn hierarchical_variable_identifier(
274    s: Span,
275) -> IResult<Span, HierarchicalVariableIdentifier> {
276    let (s, a) = hierarchical_identifier(s)?;
277    Ok((s, HierarchicalVariableIdentifier { nodes: (a,) }))
278}
279
280#[tracable_parser]
281#[packrat_parser]
282pub(crate) fn identifier(s: Span) -> IResult<Span, Identifier> {
283    alt((
284        map(escaped_identifier, |x| {
285            Identifier::EscapedIdentifier(Box::new(x))
286        }),
287        map(simple_identifier, |x| {
288            Identifier::SimpleIdentifier(Box::new(x))
289        }),
290    ))(s)
291}
292
293#[tracable_parser]
294#[packrat_parser]
295pub(crate) fn identifier_exact(s: Span) -> IResult<Span, Identifier> {
296    alt((
297        map(escaped_identifier_exact, |x| {
298            Identifier::EscapedIdentifier(Box::new(x))
299        }),
300        map(simple_identifier_exact, |x| {
301            Identifier::SimpleIdentifier(Box::new(x))
302        }),
303    ))(s)
304}
305
306#[tracable_parser]
307pub(crate) fn index_variable_identifier(s: Span) -> IResult<Span, IndexVariableIdentifier> {
308    let (s, a) = identifier(s)?;
309    Ok((s, IndexVariableIdentifier { nodes: (a,) }))
310}
311
312#[tracable_parser]
313pub(crate) fn interface_identifier(s: Span) -> IResult<Span, InterfaceIdentifier> {
314    let (s, a) = identifier(s)?;
315    Ok((s, InterfaceIdentifier { nodes: (a,) }))
316}
317
318#[tracable_parser]
319pub(crate) fn interface_instance_identifier(s: Span) -> IResult<Span, InterfaceInstanceIdentifier> {
320    let (s, a) = identifier(s)?;
321    Ok((s, InterfaceInstanceIdentifier { nodes: (a,) }))
322}
323
324#[tracable_parser]
325pub(crate) fn inout_port_identifier(s: Span) -> IResult<Span, InoutPortIdentifier> {
326    let (s, a) = identifier(s)?;
327    Ok((s, InoutPortIdentifier { nodes: (a,) }))
328}
329
330#[tracable_parser]
331pub(crate) fn input_port_identifier(s: Span) -> IResult<Span, InputPortIdentifier> {
332    let (s, a) = identifier(s)?;
333    Ok((s, InputPortIdentifier { nodes: (a,) }))
334}
335
336#[tracable_parser]
337pub(crate) fn instance_identifier(s: Span) -> IResult<Span, InstanceIdentifier> {
338    let (s, a) = identifier(s)?;
339    Ok((s, InstanceIdentifier { nodes: (a,) }))
340}
341
342#[tracable_parser]
343pub(crate) fn library_identifier(s: Span) -> IResult<Span, LibraryIdentifier> {
344    let (s, a) = identifier(s)?;
345    Ok((s, LibraryIdentifier { nodes: (a,) }))
346}
347
348#[tracable_parser]
349pub(crate) fn member_identifier(s: Span) -> IResult<Span, MemberIdentifier> {
350    let (s, a) = identifier(s)?;
351    Ok((s, MemberIdentifier { nodes: (a,) }))
352}
353
354#[tracable_parser]
355pub(crate) fn method_identifier(s: Span) -> IResult<Span, MethodIdentifier> {
356    let (s, a) = identifier(s)?;
357    Ok((s, MethodIdentifier { nodes: (a,) }))
358}
359
360#[tracable_parser]
361pub(crate) fn modport_identifier(s: Span) -> IResult<Span, ModportIdentifier> {
362    let (s, a) = identifier(s)?;
363    Ok((s, ModportIdentifier { nodes: (a,) }))
364}
365
366#[tracable_parser]
367pub(crate) fn module_identifier(s: Span) -> IResult<Span, ModuleIdentifier> {
368    let (s, a) = identifier(s)?;
369    Ok((s, ModuleIdentifier { nodes: (a,) }))
370}
371
372#[tracable_parser]
373pub(crate) fn net_identifier(s: Span) -> IResult<Span, NetIdentifier> {
374    let (s, a) = identifier(s)?;
375    Ok((s, NetIdentifier { nodes: (a,) }))
376}
377
378#[tracable_parser]
379pub(crate) fn net_type_identifier(s: Span) -> IResult<Span, NetTypeIdentifier> {
380    let (s, a) = identifier(s)?;
381    Ok((s, NetTypeIdentifier { nodes: (a,) }))
382}
383
384#[tracable_parser]
385pub(crate) fn output_port_identifier(s: Span) -> IResult<Span, OutputPortIdentifier> {
386    let (s, a) = identifier(s)?;
387    Ok((s, OutputPortIdentifier { nodes: (a,) }))
388}
389
390#[tracable_parser]
391pub(crate) fn package_identifier(s: Span) -> IResult<Span, PackageIdentifier> {
392    let (s, a) = identifier(s)?;
393    Ok((s, PackageIdentifier { nodes: (a,) }))
394}
395
396#[tracable_parser]
397#[packrat_parser]
398pub(crate) fn package_scope(s: Span) -> IResult<Span, PackageScope> {
399    alt((
400        package_scope_package,
401        map(unit, |x| PackageScope::Unit(Box::new(x))),
402    ))(s)
403}
404
405#[tracable_parser]
406#[packrat_parser]
407pub(crate) fn package_scope_package(s: Span) -> IResult<Span, PackageScope> {
408    let (s, a) = package_identifier(s)?;
409    let (s, b) = symbol("::")(s)?;
410    Ok((
411        s,
412        PackageScope::Package(Box::new(PackageScopePackage { nodes: (a, b) })),
413    ))
414}
415
416#[tracable_parser]
417#[packrat_parser]
418pub(crate) fn unit(s: Span) -> IResult<Span, Unit> {
419    let (s, a) = keyword("$unit")(s)?;
420    let (s, b) = symbol("::")(s)?;
421    Ok((s, Unit { nodes: (a, b) }))
422}
423
424#[tracable_parser]
425pub(crate) fn parameter_identifier(s: Span) -> IResult<Span, ParameterIdentifier> {
426    let (s, a) = identifier(s)?;
427    Ok((s, ParameterIdentifier { nodes: (a,) }))
428}
429
430#[tracable_parser]
431pub(crate) fn port_identifier(s: Span) -> IResult<Span, PortIdentifier> {
432    let (s, a) = identifier(s)?;
433    Ok((s, PortIdentifier { nodes: (a,) }))
434}
435
436#[tracable_parser]
437pub(crate) fn production_identifier(s: Span) -> IResult<Span, ProductionIdentifier> {
438    let (s, a) = identifier(s)?;
439    Ok((s, ProductionIdentifier { nodes: (a,) }))
440}
441
442#[tracable_parser]
443pub(crate) fn program_identifier(s: Span) -> IResult<Span, ProgramIdentifier> {
444    let (s, a) = identifier(s)?;
445    Ok((s, ProgramIdentifier { nodes: (a,) }))
446}
447
448#[tracable_parser]
449pub(crate) fn property_identifier(s: Span) -> IResult<Span, PropertyIdentifier> {
450    let (s, a) = identifier(s)?;
451    Ok((s, PropertyIdentifier { nodes: (a,) }))
452}
453
454#[tracable_parser]
455#[packrat_parser]
456pub(crate) fn ps_class_identifier(s: Span) -> IResult<Span, PsClassIdentifier> {
457    let (s, a) = opt(package_scope)(s)?;
458    let (s, b) = class_identifier(s)?;
459    Ok((s, PsClassIdentifier { nodes: (a, b) }))
460}
461
462#[tracable_parser]
463#[packrat_parser]
464pub(crate) fn ps_covergroup_identifier(s: Span) -> IResult<Span, PsCovergroupIdentifier> {
465    let (s, a) = opt(package_scope)(s)?;
466    let (s, b) = covergroup_identifier(s)?;
467    Ok((s, PsCovergroupIdentifier { nodes: (a, b) }))
468}
469
470#[tracable_parser]
471#[packrat_parser]
472pub(crate) fn ps_checker_identifier(s: Span) -> IResult<Span, PsCheckerIdentifier> {
473    let (s, a) = opt(package_scope)(s)?;
474    let (s, b) = checker_identifier(s)?;
475    Ok((s, PsCheckerIdentifier { nodes: (a, b) }))
476}
477
478#[tracable_parser]
479#[packrat_parser]
480pub(crate) fn ps_identifier(s: Span) -> IResult<Span, PsIdentifier> {
481    let (s, a) = opt(package_scope)(s)?;
482    let (s, b) = identifier(s)?;
483    Ok((s, PsIdentifier { nodes: (a, b) }))
484}
485
486#[tracable_parser]
487#[packrat_parser]
488pub(crate) fn ps_or_hierarchical_array_identifier(
489    s: Span,
490) -> IResult<Span, PsOrHierarchicalArrayIdentifier> {
491    let (s, a) = opt(implicit_class_handle_or_class_scope_or_package_scope)(s)?;
492    let (s, b) = hierarchical_array_identifier(s)?;
493    Ok((s, PsOrHierarchicalArrayIdentifier { nodes: (a, b) }))
494}
495
496#[tracable_parser]
497#[packrat_parser]
498pub(crate) fn ps_or_hierarchical_net_identifier(
499    s: Span,
500) -> IResult<Span, PsOrHierarchicalNetIdentifier> {
501    alt((
502        ps_or_hierarchical_net_identifier_package_scope,
503        map(hierarchical_net_identifier, |x| {
504            PsOrHierarchicalNetIdentifier::HierarchicalNetIdentifier(Box::new(x))
505        }),
506    ))(s)
507}
508
509#[tracable_parser]
510#[packrat_parser]
511pub(crate) fn ps_or_hierarchical_net_identifier_package_scope(
512    s: Span,
513) -> IResult<Span, PsOrHierarchicalNetIdentifier> {
514    let (s, a) = opt(package_scope)(s)?;
515    let (s, b) = net_identifier(s)?;
516    Ok((
517        s,
518        PsOrHierarchicalNetIdentifier::PackageScope(Box::new(
519            PsOrHierarchicalNetIdentifierPackageScope { nodes: (a, b) },
520        )),
521    ))
522}
523
524#[tracable_parser]
525#[packrat_parser]
526pub(crate) fn ps_or_hierarchical_property_identifier(
527    s: Span,
528) -> IResult<Span, PsOrHierarchicalPropertyIdentifier> {
529    alt((
530        ps_or_hierarchical_property_identifier_package_scope,
531        map(hierarchical_property_identifier, |x| {
532            PsOrHierarchicalPropertyIdentifier::HierarchicalPropertyIdentifier(Box::new(x))
533        }),
534    ))(s)
535}
536
537#[tracable_parser]
538#[packrat_parser]
539pub(crate) fn ps_or_hierarchical_property_identifier_package_scope(
540    s: Span,
541) -> IResult<Span, PsOrHierarchicalPropertyIdentifier> {
542    let (s, a) = opt(package_scope)(s)?;
543    let (s, b) = property_identifier(s)?;
544    Ok((
545        s,
546        PsOrHierarchicalPropertyIdentifier::PackageScope(Box::new(
547            PsOrHierarchicalPropertyIdentifierPackageScope { nodes: (a, b) },
548        )),
549    ))
550}
551
552#[tracable_parser]
553#[packrat_parser]
554pub(crate) fn ps_or_hierarchical_sequence_identifier(
555    s: Span,
556) -> IResult<Span, PsOrHierarchicalSequenceIdentifier> {
557    alt((
558        ps_or_hierarchical_sequence_identifier_package_scope,
559        map(hierarchical_sequence_identifier, |x| {
560            PsOrHierarchicalSequenceIdentifier::HierarchicalSequenceIdentifier(Box::new(x))
561        }),
562    ))(s)
563}
564
565#[tracable_parser]
566#[packrat_parser]
567pub(crate) fn ps_or_hierarchical_sequence_identifier_package_scope(
568    s: Span,
569) -> IResult<Span, PsOrHierarchicalSequenceIdentifier> {
570    let (s, a) = opt(package_scope)(s)?;
571    let (s, b) = sequence_identifier(s)?;
572    Ok((
573        s,
574        PsOrHierarchicalSequenceIdentifier::PackageScope(Box::new(
575            PsOrHierarchicalSequenceIdentifierPackageScope { nodes: (a, b) },
576        )),
577    ))
578}
579
580#[tracable_parser]
581#[packrat_parser]
582pub(crate) fn ps_or_hierarchical_tf_identifier(
583    s: Span,
584) -> IResult<Span, PsOrHierarchicalTfIdentifier> {
585    alt((
586        ps_or_hierarchical_tf_identifier_package_scope,
587        map(hierarchical_tf_identifier, |x| {
588            PsOrHierarchicalTfIdentifier::HierarchicalTfIdentifier(Box::new(x))
589        }),
590    ))(s)
591}
592
593#[tracable_parser]
594#[packrat_parser]
595pub(crate) fn ps_or_hierarchical_tf_identifier_package_scope(
596    s: Span,
597) -> IResult<Span, PsOrHierarchicalTfIdentifier> {
598    // BNF-WA
599    // reported at https://accellera.mantishub.io/view.php?id=1642
600    //let (s, a) = opt(package_scope)(s)?;
601    let (s, a) = opt(implicit_class_handle_or_class_scope_or_package_scope)(s)?;
602    let (s, b) = tf_identifier(s)?;
603    Ok((
604        s,
605        PsOrHierarchicalTfIdentifier::PackageScope(Box::new(
606            PsOrHierarchicalTfIdentifierPackageScope { nodes: (a, b) },
607        )),
608    ))
609}
610
611#[tracable_parser]
612#[packrat_parser]
613pub(crate) fn ps_parameter_identifier(s: Span) -> IResult<Span, PsParameterIdentifier> {
614    alt((
615        ps_parameter_identifier_scope,
616        ps_parameter_identifier_generate,
617    ))(s)
618}
619
620#[tracable_parser]
621#[packrat_parser]
622pub(crate) fn ps_parameter_identifier_scope(s: Span) -> IResult<Span, PsParameterIdentifier> {
623    let (s, a) = opt(package_scope_or_class_scope)(s)?;
624    let (s, b) = parameter_identifier(s)?;
625    Ok((
626        s,
627        PsParameterIdentifier::Scope(Box::new(PsParameterIdentifierScope { nodes: (a, b) })),
628    ))
629}
630
631#[tracable_parser]
632#[packrat_parser]
633pub(crate) fn ps_parameter_identifier_generate(s: Span) -> IResult<Span, PsParameterIdentifier> {
634    let (s, a) = many0(terminated(
635        triple(
636            generate_block_identifier,
637            opt(bracket(constant_expression)),
638            symbol("."),
639        ),
640        peek(parameter_identifier),
641    ))(s)?;
642    let (s, b) = parameter_identifier(s)?;
643    Ok((
644        s,
645        PsParameterIdentifier::Generate(Box::new(PsParameterIdentifierGenerate { nodes: (a, b) })),
646    ))
647}
648
649#[tracable_parser]
650#[packrat_parser]
651pub(crate) fn ps_type_identifier(s: Span) -> IResult<Span, PsTypeIdentifier> {
652    let (s, a) = opt(local_or_package_scope_or_class_scope)(s)?;
653    let (s, b) = type_identifier(s)?;
654    Ok((s, PsTypeIdentifier { nodes: (a, b) }))
655}
656
657#[tracable_parser]
658pub(crate) fn sequence_identifier(s: Span) -> IResult<Span, SequenceIdentifier> {
659    let (s, a) = identifier(s)?;
660    Ok((s, SequenceIdentifier { nodes: (a,) }))
661}
662
663#[tracable_parser]
664pub(crate) fn signal_identifier(s: Span) -> IResult<Span, SignalIdentifier> {
665    let (s, a) = identifier(s)?;
666    Ok((s, SignalIdentifier { nodes: (a,) }))
667}
668
669#[tracable_parser]
670#[packrat_parser]
671pub(crate) fn simple_identifier(s: Span) -> IResult<Span, SimpleIdentifier> {
672    let (s, a) = ws(simple_identifier_impl)(s)?;
673    Ok((s, SimpleIdentifier { nodes: a }))
674}
675
676#[tracable_parser]
677#[packrat_parser]
678pub(crate) fn simple_identifier_exact(s: Span) -> IResult<Span, SimpleIdentifier> {
679    let (s, a) = no_ws(simple_identifier_impl)(s)?;
680    Ok((s, SimpleIdentifier { nodes: a }))
681}
682
683#[tracable_parser]
684pub(crate) fn simple_identifier_impl(s: Span) -> IResult<Span, Locate> {
685    let (s, a) = is_a(AZ_)(s)?;
686    let (s, b) = opt(is_a(AZ09_DOLLAR))(s)?;
687    let a = if let Some(b) = b {
688        concat(a, b).unwrap()
689    } else {
690        a
691    };
692    if is_keyword(&a) {
693        Err(Err::Error(make_error(s, ErrorKind::Fix)))
694    } else {
695        Ok((s, into_locate(a)))
696    }
697}
698
699#[tracable_parser]
700pub(crate) fn specparam_identifier(s: Span) -> IResult<Span, SpecparamIdentifier> {
701    let (s, a) = identifier(s)?;
702    Ok((s, SpecparamIdentifier { nodes: (a,) }))
703}
704
705#[tracable_parser]
706#[packrat_parser]
707pub(crate) fn system_tf_identifier(s: Span) -> IResult<Span, SystemTfIdentifier> {
708    let (s, a) = ws(system_tf_identifier_impl)(s)?;
709    Ok((s, SystemTfIdentifier { nodes: a }))
710}
711
712#[tracable_parser]
713pub(crate) fn system_tf_identifier_impl(s: Span) -> IResult<Span, Locate> {
714    let (s, a) = tag("$")(s)?;
715    let (s, b) = is_a(AZ09_DOLLAR)(s)?;
716    let a = concat(a, b).unwrap();
717    Ok((s, into_locate(a)))
718}
719
720#[tracable_parser]
721pub(crate) fn task_identifier(s: Span) -> IResult<Span, TaskIdentifier> {
722    let (s, a) = identifier(s)?;
723    Ok((s, TaskIdentifier { nodes: (a,) }))
724}
725
726#[tracable_parser]
727pub(crate) fn tf_identifier(s: Span) -> IResult<Span, TfIdentifier> {
728    let (s, a) = identifier(s)?;
729    Ok((s, TfIdentifier { nodes: (a,) }))
730}
731
732#[tracable_parser]
733pub(crate) fn terminal_identifier(s: Span) -> IResult<Span, TerminalIdentifier> {
734    let (s, a) = identifier(s)?;
735    Ok((s, TerminalIdentifier { nodes: (a,) }))
736}
737
738#[tracable_parser]
739pub(crate) fn topmodule_identifier(s: Span) -> IResult<Span, TopmoduleIdentifier> {
740    let (s, a) = identifier(s)?;
741    Ok((s, TopmoduleIdentifier { nodes: (a,) }))
742}
743
744#[tracable_parser]
745pub(crate) fn type_identifier(s: Span) -> IResult<Span, TypeIdentifier> {
746    let (s, a) = identifier(s)?;
747    Ok((s, TypeIdentifier { nodes: (a,) }))
748}
749
750#[tracable_parser]
751pub(crate) fn udp_identifier(s: Span) -> IResult<Span, UdpIdentifier> {
752    let (s, a) = identifier(s)?;
753    Ok((s, UdpIdentifier { nodes: (a,) }))
754}
755
756#[packrat_parser]
757#[tracable_parser]
758pub(crate) fn variable_identifier(s: Span) -> IResult<Span, VariableIdentifier> {
759    let (s, a) = identifier(s)?;
760    Ok((s, VariableIdentifier { nodes: (a,) }))
761}
762
763#[tracable_parser]
764#[packrat_parser]
765pub(crate) fn implicit_class_handle_or_class_scope_or_package_scope(
766    s: Span,
767) -> IResult<Span, ImplicitClassHandleOrClassScopeOrPackageScope> {
768    alt((
769        map(pair(implicit_class_handle, symbol(".")), |x| {
770            ImplicitClassHandleOrClassScopeOrPackageScope::ImplicitClassHandle(Box::new(x))
771        }),
772        map(class_scope, |x| {
773            ImplicitClassHandleOrClassScopeOrPackageScope::ClassScope(Box::new(x))
774        }),
775        map(package_scope, |x| {
776            ImplicitClassHandleOrClassScopeOrPackageScope::PackageScope(Box::new(x))
777        }),
778    ))(s)
779}
780
781#[tracable_parser]
782#[packrat_parser]
783pub(crate) fn implicit_class_handle_or_package_scope(
784    s: Span,
785) -> IResult<Span, ImplicitClassHandleOrPackageScope> {
786    alt((
787        map(pair(implicit_class_handle, symbol(".")), |x| {
788            ImplicitClassHandleOrPackageScope::ImplicitClassHandle(Box::new(x))
789        }),
790        map(package_scope, |x| {
791            ImplicitClassHandleOrPackageScope::PackageScope(Box::new(x))
792        }),
793    ))(s)
794}
795
796#[tracable_parser]
797#[packrat_parser]
798pub(crate) fn implicit_class_handle_or_class_scope(
799    s: Span,
800) -> IResult<Span, ImplicitClassHandleOrClassScope> {
801    alt((
802        map(pair(implicit_class_handle, symbol(".")), |x| {
803            ImplicitClassHandleOrClassScope::ImplicitClassHandle(Box::new(x))
804        }),
805        map(class_scope, |x| {
806            ImplicitClassHandleOrClassScope::ClassScope(Box::new(x))
807        }),
808    ))(s)
809}
810
811#[tracable_parser]
812#[packrat_parser]
813pub(crate) fn package_scope_or_class_scope(s: Span) -> IResult<Span, PackageScopeOrClassScope> {
814    alt((
815        map(package_scope, |x| {
816            PackageScopeOrClassScope::PackageScope(Box::new(x))
817        }),
818        map(class_scope, |x| {
819            PackageScopeOrClassScope::ClassScope(Box::new(x))
820        }),
821    ))(s)
822}
823
824#[tracable_parser]
825#[packrat_parser]
826pub(crate) fn local_or_package_scope_or_class_scope(
827    s: Span,
828) -> IResult<Span, LocalOrPackageScopeOrClassScope> {
829    alt((
830        map(local, |x| {
831            LocalOrPackageScopeOrClassScope::Local(Box::new(x))
832        }),
833        map(package_scope, |x| {
834            LocalOrPackageScopeOrClassScope::PackageScope(Box::new(x))
835        }),
836        map(class_scope, |x| {
837            LocalOrPackageScopeOrClassScope::ClassScope(Box::new(x))
838        }),
839    ))(s)
840}
841
842#[tracable_parser]
843#[packrat_parser]
844pub(crate) fn local(s: Span) -> IResult<Span, Local> {
845    let (s, a) = keyword("local")(s)?;
846    let (s, b) = symbol("::")(s)?;
847    Ok((s, Local { nodes: (a, b) }))
848}