1use crate::*;
2
3#[tracable_parser]
6#[packrat_parser]
7pub(crate) fn compiler_directive(s: Span) -> IResult<Span, CompilerDirective> {
8 begin_directive();
9 let ret = alt((
10 map(resetall_compiler_directive, |x| {
11 CompilerDirective::ResetallCompilerDirective(Box::new(x))
12 }),
13 map(include_compiler_directive, |x| {
14 CompilerDirective::IncludeCompilerDirective(Box::new(x))
15 }),
16 map(text_macro_definition, |x| {
17 CompilerDirective::TextMacroDefinition(Box::new(x))
18 }),
19 map(undefine_compiler_directive, |x| {
20 CompilerDirective::UndefineCompilerDirective(Box::new(x))
21 }),
22 map(undefineall_compiler_directive, |x| {
23 CompilerDirective::UndefineallCompilerDirective(Box::new(x))
24 }),
25 map(conditional_compiler_directive, |x| {
26 CompilerDirective::ConditionalCompilerDirective(Box::new(x))
27 }),
28 map(timescale_compiler_directive, |x| {
29 CompilerDirective::TimescaleCompilerDirective(Box::new(x))
30 }),
31 map(default_nettype_compiler_directive, |x| {
32 CompilerDirective::DefaultNettypeCompilerDirective(Box::new(x))
33 }),
34 map(unconnected_drive_compiler_directive, |x| {
35 CompilerDirective::UnconnectedDriveCompilerDirective(Box::new(x))
36 }),
37 map(nounconnected_drive_compiler_directive, |x| {
38 CompilerDirective::NounconnectedDriveCompilerDirective(Box::new(x))
39 }),
40 map(celldefine_compiler_directive, |x| {
41 CompilerDirective::CelldefineDriveCompilerDirective(Box::new(x))
42 }),
43 map(endcelldefine_compiler_directive, |x| {
44 CompilerDirective::EndcelldefineDriveCompilerDirective(Box::new(x))
45 }),
46 map(pragma, |x| CompilerDirective::Pragma(Box::new(x))),
47 map(line_compiler_directive, |x| {
48 CompilerDirective::LineCompilerDirective(Box::new(x))
49 }),
50 map(position_compiler_directive, |x| {
51 CompilerDirective::PositionCompilerDirective(Box::new(x))
52 }),
53 map(keywords_directive, |x| {
54 CompilerDirective::KeywordsDirective(Box::new(x))
55 }),
56 map(endkeywords_directive, |x| {
57 CompilerDirective::EndkeywordsDirective(Box::new(x))
58 }),
59 map(text_macro_usage, |x| {
60 CompilerDirective::TextMacroUsage(Box::new(x))
61 }),
62 ))(s);
63 end_directive();
64 ret
65}
66
67#[tracable_parser]
68#[packrat_parser]
69pub(crate) fn compiler_directive_without_resetall(s: Span) -> IResult<Span, CompilerDirective> {
70 begin_directive();
71 let ret = alt((
72 map(include_compiler_directive, |x| {
73 CompilerDirective::IncludeCompilerDirective(Box::new(x))
74 }),
75 map(text_macro_definition, |x| {
76 CompilerDirective::TextMacroDefinition(Box::new(x))
77 }),
78 map(undefine_compiler_directive, |x| {
79 CompilerDirective::UndefineCompilerDirective(Box::new(x))
80 }),
81 map(undefineall_compiler_directive, |x| {
82 CompilerDirective::UndefineallCompilerDirective(Box::new(x))
83 }),
84 map(conditional_compiler_directive, |x| {
85 CompilerDirective::ConditionalCompilerDirective(Box::new(x))
86 }),
87 map(timescale_compiler_directive, |x| {
88 CompilerDirective::TimescaleCompilerDirective(Box::new(x))
89 }),
90 map(default_nettype_compiler_directive, |x| {
91 CompilerDirective::DefaultNettypeCompilerDirective(Box::new(x))
92 }),
93 map(unconnected_drive_compiler_directive, |x| {
94 CompilerDirective::UnconnectedDriveCompilerDirective(Box::new(x))
95 }),
96 map(nounconnected_drive_compiler_directive, |x| {
97 CompilerDirective::NounconnectedDriveCompilerDirective(Box::new(x))
98 }),
99 map(celldefine_compiler_directive, |x| {
100 CompilerDirective::CelldefineDriveCompilerDirective(Box::new(x))
101 }),
102 map(endcelldefine_compiler_directive, |x| {
103 CompilerDirective::EndcelldefineDriveCompilerDirective(Box::new(x))
104 }),
105 map(pragma, |x| CompilerDirective::Pragma(Box::new(x))),
106 map(line_compiler_directive, |x| {
107 CompilerDirective::LineCompilerDirective(Box::new(x))
108 }),
109 map(position_compiler_directive, |x| {
110 CompilerDirective::PositionCompilerDirective(Box::new(x))
111 }),
112 map(keywords_directive, |x| {
113 CompilerDirective::KeywordsDirective(Box::new(x))
114 }),
115 map(endkeywords_directive, |x| {
116 CompilerDirective::EndkeywordsDirective(Box::new(x))
117 }),
118 map(text_macro_usage, |x| {
119 CompilerDirective::TextMacroUsage(Box::new(x))
120 }),
121 ))(s);
122 end_directive();
123 ret
124}
125
126#[tracable_parser]
127#[packrat_parser]
128pub(crate) fn resetall_compiler_directive(s: Span) -> IResult<Span, ResetallCompilerDirective> {
129 let (s, a) = symbol("`")(s)?;
130 let (s, b) = keyword("resetall")(s)?;
131 Ok((s, ResetallCompilerDirective { nodes: (a, b) }))
132}
133
134#[tracable_parser]
135#[packrat_parser]
136pub(crate) fn include_compiler_directive(s: Span) -> IResult<Span, IncludeCompilerDirective> {
137 alt((
138 include_compiler_directive_double_quote,
139 include_compiler_directive_angle_bracket,
140 include_compiler_directive_text_macro_usage,
141 ))(s)
142}
143
144#[tracable_parser]
145#[packrat_parser]
146pub(crate) fn include_compiler_directive_double_quote(
147 s: Span,
148) -> IResult<Span, IncludeCompilerDirective> {
149 let (s, a) = symbol("`")(s)?;
150 let (s, b) = keyword("include")(s)?;
151 let (s, c) = string_literal(s)?;
152 Ok((
153 s,
154 IncludeCompilerDirective::DoubleQuote(Box::new(IncludeCompilerDirectiveDoubleQuote {
155 nodes: (a, b, c),
156 })),
157 ))
158}
159
160#[tracable_parser]
161#[packrat_parser]
162pub(crate) fn include_compiler_directive_angle_bracket(
163 s: Span,
164) -> IResult<Span, IncludeCompilerDirective> {
165 let (s, a) = symbol("`")(s)?;
166 let (s, b) = keyword("include")(s)?;
167 let (s, c) = angle_bracket_literal(s)?;
168 Ok((
169 s,
170 IncludeCompilerDirective::AngleBracket(Box::new(IncludeCompilerDirectiveAngleBracket {
171 nodes: (a, b, c),
172 })),
173 ))
174}
175
176#[tracable_parser]
177#[packrat_parser]
178pub(crate) fn include_compiler_directive_text_macro_usage(
179 s: Span,
180) -> IResult<Span, IncludeCompilerDirective> {
181 let (s, a) = symbol("`")(s)?;
182 let (s, b) = keyword("include")(s)?;
183 let (s, c) = text_macro_usage(s)?;
184 Ok((
185 s,
186 IncludeCompilerDirective::TextMacroUsage(Box::new(
187 IncludeCompilerDirectiveTextMacroUsage { nodes: (a, b, c) },
188 )),
189 ))
190}
191
192#[tracable_parser]
193#[packrat_parser]
194pub(crate) fn angle_bracket_literal(s: Span) -> IResult<Span, AngleBracketLiteral> {
195 let (s, a) = ws(angle_bracket_literal_impl)(s)?;
196 Ok((s, AngleBracketLiteral { nodes: a }))
197}
198
199#[tracable_parser]
200pub(crate) fn angle_bracket_literal_impl(s: Span) -> IResult<Span, Locate> {
201 let (s, a) = tag("<")(s)?;
202 let (s, b) = is_not(">")(s)?;
203 let (s, c) = tag(">")(s)?;
204
205 let a = concat(a, b).unwrap();
206 let a = concat(a, c).unwrap();
207
208 Ok((s, into_locate(a)))
209}
210
211#[tracable_parser]
212#[packrat_parser]
213pub(crate) fn text_macro_definition(s: Span) -> IResult<Span, TextMacroDefinition> {
214 let (s, a) = symbol("`")(s)?;
215 let (s, b) = keyword("define")(s)?;
216 begin_keywords("directive");
217 let (s, c) = text_macro_name(s)?;
218 end_keywords();
219 let (s, d) = opt(macro_text)(s)?;
220 Ok((
221 s,
222 TextMacroDefinition {
223 nodes: (a, b, c, d),
224 },
225 ))
226}
227
228#[tracable_parser]
229#[packrat_parser]
230pub(crate) fn text_macro_name(s: Span) -> IResult<Span, TextMacroName> {
231 let (s, a) = text_macro_identifier_exact(s)?;
232 let (s, b) = opt(paren_exact(list_of_formal_arguments))(s)?;
233 Ok((s, TextMacroName { nodes: (a, b) }))
234}
235
236#[tracable_parser]
237#[packrat_parser]
238pub(crate) fn list_of_formal_arguments(s: Span) -> IResult<Span, ListOfFormalArguments> {
239 let (s, a) = list(symbol(","), formal_argument)(s)?;
240 Ok((s, ListOfFormalArguments { nodes: (a,) }))
241}
242
243#[tracable_parser]
244#[packrat_parser]
245pub(crate) fn formal_argument(s: Span) -> IResult<Span, FormalArgument> {
246 let (s, a) = simple_identifier(s)?;
247 let (s, b) = opt(pair(symbol("="), default_text))(s)?;
248 Ok((s, FormalArgument { nodes: (a, b) }))
249}
250
251#[tracable_parser]
252#[packrat_parser]
253pub(crate) fn text_macro_identifier(s: Span) -> IResult<Span, TextMacroIdentifier> {
254 let (s, a) = identifier(s)?;
255 Ok((s, TextMacroIdentifier { nodes: (a,) }))
256}
257
258#[tracable_parser]
259#[packrat_parser]
260pub(crate) fn text_macro_identifier_exact(s: Span) -> IResult<Span, TextMacroIdentifier> {
261 let (s, a) = identifier_exact(s)?;
262 Ok((s, TextMacroIdentifier { nodes: (a,) }))
263}
264
265#[tracable_parser]
266#[packrat_parser]
267pub(crate) fn macro_text(s: Span) -> IResult<Span, MacroText> {
268 let (s, a) = many1(alt((
269 tag("\\\n"),
270 tag("\\\r\n"),
271 tag("\\\r"),
272 tag("\\"),
273 is_not("\\\r\n"),
274 )))(s)?;
275
276 let mut ret = None;
277 for x in a {
278 ret = if let Some(ret) = ret {
279 Some(concat(ret, x).unwrap())
280 } else {
281 Some(x)
282 }
283 }
284 let a = ret.unwrap();
285 Ok((
286 s,
287 MacroText {
288 nodes: (into_locate(a),),
289 },
290 ))
291}
292
293#[tracable_parser]
294#[packrat_parser]
295pub(crate) fn default_text(s: Span) -> IResult<Span, DefaultText> {
296 let (s, a) = define_argument(s)?;
297 Ok((
298 s,
299 DefaultText {
300 nodes: (into_locate(a),),
301 },
302 ))
303}
304
305#[tracable_parser]
306#[packrat_parser]
307pub(crate) fn text_macro_usage(s: Span) -> IResult<Span, TextMacroUsage> {
308 let (s, a) = symbol("`")(s)?;
309 begin_keywords("directive");
310 let (s, b) = text_macro_identifier(s)?;
311 end_keywords();
312 let (s, c) = opt(paren(list_of_actual_arguments))(s)?;
313 Ok((s, TextMacroUsage { nodes: (a, b, c) }))
314}
315
316#[tracable_parser]
317#[packrat_parser]
318pub(crate) fn list_of_actual_arguments(s: Span) -> IResult<Span, ListOfActualArguments> {
319 let (s, a) = list(symbol(","), opt(actual_argument))(s)?;
320 Ok((s, ListOfActualArguments { nodes: (a,) }))
321}
322
323#[tracable_parser]
324#[packrat_parser]
325pub(crate) fn actual_argument(s: Span) -> IResult<Span, ActualArgument> {
326 let (s, a) = define_argument(s)?;
327 Ok((
328 s,
329 ActualArgument {
330 nodes: (into_locate(a),),
331 },
332 ))
333}
334
335#[tracable_parser]
336pub(crate) fn define_argument(s: Span) -> IResult<Span, Span> {
337 let (s, a) = many1(alt((
338 is_not(",([{}])\""),
339 define_argument_str,
340 define_argument_paren,
341 define_argument_bracket,
342 define_argument_brace,
343 )))(s)?;
344 let mut ret = None;
345 for x in a {
346 ret = if let Some(ret) = ret {
347 Some(concat(ret, x).unwrap())
348 } else {
349 Some(x)
350 }
351 }
352 let a = ret.unwrap();
353 Ok((s, a))
354}
355
356#[tracable_parser]
357pub(crate) fn define_argument_inner(s: Span) -> IResult<Span, Span> {
358 let (s, a) = many1(alt((
359 is_not("([{}])\""),
360 define_argument_str,
361 define_argument_paren,
362 define_argument_bracket,
363 define_argument_brace,
364 )))(s)?;
365 let mut ret = None;
366 for x in a {
367 ret = if let Some(ret) = ret {
368 Some(concat(ret, x).unwrap())
369 } else {
370 Some(x)
371 }
372 }
373 let a = ret.unwrap();
374 Ok((s, a))
375}
376
377#[tracable_parser]
378pub(crate) fn define_argument_str(s: Span) -> IResult<Span, Span> {
379 let (s, (a, b, c)) = triple(tag("\""), opt(is_not("\"")), tag("\""))(s)?;
380 let a = if let Some(b) = b {
381 concat(concat(a, b).unwrap(), c).unwrap()
382 } else {
383 concat(a, c).unwrap()
384 };
385 Ok((s, a))
386}
387
388#[recursive_parser]
389#[tracable_parser]
390pub(crate) fn define_argument_paren(s: Span) -> IResult<Span, Span> {
391 let (s, (a, b, c)) = triple(tag("("), opt(define_argument_inner), tag(")"))(s)?;
392 let a = if let Some(b) = b {
393 concat(concat(a, b).unwrap(), c).unwrap()
394 } else {
395 concat(a, c).unwrap()
396 };
397 Ok((s, a))
398}
399
400#[recursive_parser]
401#[tracable_parser]
402pub(crate) fn define_argument_bracket(s: Span) -> IResult<Span, Span> {
403 let (s, (a, b, c)) = triple(tag("["), opt(define_argument_inner), tag("]"))(s)?;
404 let a = if let Some(b) = b {
405 concat(concat(a, b).unwrap(), c).unwrap()
406 } else {
407 concat(a, c).unwrap()
408 };
409 Ok((s, a))
410}
411
412#[recursive_parser]
413#[tracable_parser]
414pub(crate) fn define_argument_brace(s: Span) -> IResult<Span, Span> {
415 let (s, (a, b, c)) = triple(tag("{"), opt(define_argument_inner), tag("}"))(s)?;
416 let a = if let Some(b) = b {
417 concat(concat(a, b).unwrap(), c).unwrap()
418 } else {
419 concat(a, c).unwrap()
420 };
421 Ok((s, a))
422}
423
424#[tracable_parser]
425#[packrat_parser]
426pub(crate) fn undefine_compiler_directive(s: Span) -> IResult<Span, UndefineCompilerDirective> {
427 let (s, a) = symbol("`")(s)?;
428 let (s, b) = keyword("undef")(s)?;
429 let (s, c) = text_macro_identifier(s)?;
430 Ok((s, UndefineCompilerDirective { nodes: (a, b, c) }))
431}
432
433#[tracable_parser]
434#[packrat_parser]
435pub(crate) fn undefineall_compiler_directive(
436 s: Span,
437) -> IResult<Span, UndefineallCompilerDirective> {
438 let (s, a) = symbol("`")(s)?;
439 let (s, b) = keyword("undefineall")(s)?;
440 Ok((s, UndefineallCompilerDirective { nodes: (a, b) }))
441}
442
443#[tracable_parser]
444#[packrat_parser]
445pub(crate) fn conditional_compiler_directive(
446 s: Span,
447) -> IResult<Span, ConditionalCompilerDirective> {
448 alt((
449 map(ifdef_directive, |x| {
450 ConditionalCompilerDirective::IfdefDirective(Box::new(x))
451 }),
452 map(ifndef_directive, |x| {
453 ConditionalCompilerDirective::IfndefDirective(Box::new(x))
454 }),
455 ))(s)
456}
457
458#[tracable_parser]
459#[packrat_parser]
460pub(crate) fn ifdef_directive(s: Span) -> IResult<Span, IfdefDirective> {
461 let (s, a) = symbol("`")(s)?;
462 let (s, b) = keyword("ifdef")(s)?;
463 let (s, c) = text_macro_identifier(s)?;
464 let (s, d) = ifdef_group_of_lines(s)?;
465 let (s, e) = many0(tuple((
466 symbol("`"),
467 keyword("elsif"),
468 text_macro_identifier,
469 elsif_group_of_lines,
470 )))(s)?;
471 let (s, f) = opt(tuple((symbol("`"), keyword("else"), else_group_of_lines)))(s)?;
472 let (s, g) = symbol("`")(s)?;
473 let (s, h) = keyword("endif")(s)?;
474 Ok((
475 s,
476 IfdefDirective {
477 nodes: (a, b, c, d, e, f, g, h),
478 },
479 ))
480}
481
482#[tracable_parser]
483#[packrat_parser]
484pub(crate) fn ifndef_directive(s: Span) -> IResult<Span, IfndefDirective> {
485 let (s, a) = symbol("`")(s)?;
486 let (s, b) = keyword("ifndef")(s)?;
487 let (s, c) = text_macro_identifier(s)?;
488 let (s, d) = ifndef_group_of_lines(s)?;
489 let (s, e) = many0(tuple((
490 symbol("`"),
491 keyword("elsif"),
492 text_macro_identifier,
493 elsif_group_of_lines,
494 )))(s)?;
495 let (s, f) = opt(tuple((symbol("`"), keyword("else"), else_group_of_lines)))(s)?;
496 let (s, g) = symbol("`")(s)?;
497 let (s, h) = keyword("endif")(s)?;
498 Ok((
499 s,
500 IfndefDirective {
501 nodes: (a, b, c, d, e, f, g, h),
502 },
503 ))
504}
505
506#[tracable_parser]
507#[packrat_parser]
508pub(crate) fn ifdef_group_of_lines(s: Span) -> IResult<Span, IfdefGroupOfLines> {
509 let (s, a) = many0(preceded(
510 peek(not(alt((tag("`elsif"), tag("`else"), tag("`endif"))))),
511 source_description,
512 ))(s)?;
513 Ok((s, IfdefGroupOfLines { nodes: (a,) }))
514}
515
516#[tracable_parser]
517#[packrat_parser]
518pub(crate) fn ifndef_group_of_lines(s: Span) -> IResult<Span, IfndefGroupOfLines> {
519 let (s, a) = many0(preceded(
520 peek(not(alt((tag("`elsif"), tag("`else"), tag("`endif"))))),
521 source_description,
522 ))(s)?;
523 Ok((s, IfndefGroupOfLines { nodes: (a,) }))
524}
525
526#[tracable_parser]
527#[packrat_parser]
528pub(crate) fn elsif_group_of_lines(s: Span) -> IResult<Span, ElsifGroupOfLines> {
529 let (s, a) = many0(preceded(
530 peek(not(alt((tag("`elsif"), tag("`else"), tag("`endif"))))),
531 source_description,
532 ))(s)?;
533 Ok((s, ElsifGroupOfLines { nodes: (a,) }))
534}
535
536#[tracable_parser]
537#[packrat_parser]
538pub(crate) fn else_group_of_lines(s: Span) -> IResult<Span, ElseGroupOfLines> {
539 let (s, a) = many0(preceded(peek(not(tag("`endif"))), source_description))(s)?;
540 Ok((s, ElseGroupOfLines { nodes: (a,) }))
541}
542
543#[tracable_parser]
544#[packrat_parser]
545pub(crate) fn source_description(s: Span) -> IResult<Span, SourceDescription> {
546 alt((
547 map(comment, |x| SourceDescription::Comment(Box::new(x))),
548 map(string_literal, |x| {
549 SourceDescription::StringLiteral(Box::new(x))
550 }),
551 map(escaped_identifier, |x| {
552 SourceDescription::EscapedIdentifier(Box::new(x))
553 }),
554 source_description_not_directive,
555 map(compiler_directive, |x| {
556 SourceDescription::CompilerDirective(Box::new(x))
557 }),
558 ))(s)
559}
560
561#[tracable_parser]
562#[packrat_parser]
563pub(crate) fn source_description_not_directive(s: Span) -> IResult<Span, SourceDescription> {
564 let (s, a) = many1(alt((
565 is_not("`/\"\\"),
566 terminated(tag("/"), peek(not(alt((tag("/"), tag("*")))))),
567 )))(s)?;
568
569 let mut ret = None;
570 for x in a {
571 ret = if let Some(ret) = ret {
572 Some(concat(ret, x).unwrap())
573 } else {
574 Some(x)
575 }
576 }
577 let a = ret.unwrap();
578 Ok((
579 s,
580 SourceDescription::NotDirective(Box::new(SourceDescriptionNotDirective {
581 nodes: (into_locate(a),),
582 })),
583 ))
584}
585
586#[tracable_parser]
587#[packrat_parser]
588pub(crate) fn timescale_compiler_directive(s: Span) -> IResult<Span, TimescaleCompilerDirective> {
589 let (s, a) = symbol("`")(s)?;
590 let (s, b) = keyword("timescale")(s)?;
591 let (s, c) = unsigned_number(s)?;
592 let (s, d) = time_unit(s)?;
593 let (s, e) = symbol("/")(s)?;
594 let (s, f) = unsigned_number(s)?;
595 let (s, g) = time_unit(s)?;
596 Ok((
597 s,
598 TimescaleCompilerDirective {
599 nodes: (a, b, c, d, e, f, g),
600 },
601 ))
602}
603
604#[tracable_parser]
605#[packrat_parser]
606pub(crate) fn default_nettype_compiler_directive(
607 s: Span,
608) -> IResult<Span, DefaultNettypeCompilerDirective> {
609 let (s, a) = symbol("`")(s)?;
610 let (s, b) = keyword("default_nettype")(s)?;
611 let (s, c) = default_nettype_value(s)?;
612 Ok((s, DefaultNettypeCompilerDirective { nodes: (a, b, c) }))
613}
614
615#[tracable_parser]
616#[packrat_parser]
617pub(crate) fn default_nettype_value(s: Span) -> IResult<Span, DefaultNettypeValue> {
618 let (s, a) = alt((
619 keyword("none"),
620 keyword("tri0"),
621 keyword("tri1"),
622 keyword("trior"),
623 keyword("trireg"),
624 keyword("triand"),
625 keyword("tri"),
626 keyword("uwire"),
627 keyword("wand"),
628 keyword("wire"),
629 keyword("wor"),
630 ))(s)?;
631 Ok((s, DefaultNettypeValue { nodes: (a,) }))
632}
633
634#[tracable_parser]
635#[packrat_parser]
636pub(crate) fn unconnected_drive_compiler_directive(
637 s: Span,
638) -> IResult<Span, UnconnectedDriveCompilerDirective> {
639 let (s, a) = symbol("`")(s)?;
640 let (s, b) = keyword("unconnected_drive")(s)?;
641 let (s, c) = alt((keyword("pull0"), keyword("pull1")))(s)?;
642 Ok((s, UnconnectedDriveCompilerDirective { nodes: (a, b, c) }))
643}
644
645#[tracable_parser]
646#[packrat_parser]
647pub(crate) fn nounconnected_drive_compiler_directive(
648 s: Span,
649) -> IResult<Span, NounconnectedDriveCompilerDirective> {
650 let (s, a) = symbol("`")(s)?;
651 let (s, b) = keyword("nounconnected_drive")(s)?;
652 Ok((s, NounconnectedDriveCompilerDirective { nodes: (a, b) }))
653}
654
655#[tracable_parser]
656#[packrat_parser]
657pub(crate) fn celldefine_compiler_directive(
658 s: Span,
659) -> IResult<Span, CelldefineDriveCompilerDirective> {
660 let (s, a) = symbol("`")(s)?;
661 let (s, b) = keyword("celldefine")(s)?;
662 Ok((s, CelldefineDriveCompilerDirective { nodes: (a, b) }))
663}
664
665#[tracable_parser]
666#[packrat_parser]
667pub(crate) fn endcelldefine_compiler_directive(
668 s: Span,
669) -> IResult<Span, EndcelldefineDriveCompilerDirective> {
670 let (s, a) = symbol("`")(s)?;
671 let (s, b) = keyword("endcelldefine")(s)?;
672 Ok((s, EndcelldefineDriveCompilerDirective { nodes: (a, b) }))
673}
674
675#[tracable_parser]
676#[packrat_parser]
677pub(crate) fn pragma(s: Span) -> IResult<Span, Pragma> {
678 let (s, a) = symbol("`")(s)?;
679 let (s, b) = keyword("pragma")(s)?;
680 let (s, c) = pragma_name(s)?;
681 let (s, d) = opt(list(symbol(","), pragma_expression))(s)?;
682 Ok((
683 s,
684 Pragma {
685 nodes: (a, b, c, d),
686 },
687 ))
688}
689
690#[tracable_parser]
691#[packrat_parser]
692pub(crate) fn pragma_name(s: Span) -> IResult<Span, PragmaName> {
693 let (s, a) = simple_identifier(s)?;
694 Ok((s, PragmaName { nodes: (a,) }))
695}
696
697#[tracable_parser]
698#[packrat_parser]
699pub(crate) fn pragma_expression(s: Span) -> IResult<Span, PragmaExpression> {
700 alt((
701 pragma_expression_assignment,
702 map(pragma_keyword, |x| {
703 PragmaExpression::PragmaKeyword(Box::new(x))
704 }),
705 map(pragma_value, |x| PragmaExpression::PragmaValue(Box::new(x))),
706 ))(s)
707}
708
709#[tracable_parser]
710#[packrat_parser]
711pub(crate) fn pragma_expression_assignment(s: Span) -> IResult<Span, PragmaExpression> {
712 let (s, a) = pragma_keyword(s)?;
713 let (s, b) = symbol("=")(s)?;
714 let (s, c) = pragma_value(s)?;
715 Ok((
716 s,
717 PragmaExpression::Assignment(Box::new(PragmaExpressionAssignment { nodes: (a, b, c) })),
718 ))
719}
720
721#[tracable_parser]
722#[packrat_parser]
723pub(crate) fn pragma_value(s: Span) -> IResult<Span, PragmaValue> {
724 alt((
725 pragma_value_paren,
726 map(number, |x| PragmaValue::Number(Box::new(x))),
727 map(string_literal, |x| PragmaValue::StringLiteral(Box::new(x))),
728 map(identifier_pragma, |x| PragmaValue::Identifier(Box::new(x))),
729 ))(s)
730}
731
732#[tracable_parser]
733#[packrat_parser]
734pub(crate) fn pragma_value_paren(s: Span) -> IResult<Span, PragmaValue> {
735 let (s, a) = paren(list(symbol(","), pragma_expression))(s)?;
736 Ok((
737 s,
738 PragmaValue::Paren(Box::new(PragmaValueParen { nodes: (a,) })),
739 ))
740}
741
742#[tracable_parser]
743#[packrat_parser]
744pub(crate) fn pragma_keyword(s: Span) -> IResult<Span, PragmaKeyword> {
745 let (s, a) = simple_identifier_pragma(s)?;
746 Ok((s, PragmaKeyword { nodes: (a,) }))
747}
748
749#[tracable_parser]
750#[packrat_parser]
751pub(crate) fn identifier_pragma(s: Span) -> IResult<Span, Identifier> {
752 alt((
753 map(escaped_identifier, |x| {
754 Identifier::EscapedIdentifier(Box::new(x))
755 }),
756 map(simple_identifier_pragma, |x| {
757 Identifier::SimpleIdentifier(Box::new(x))
758 }),
759 ))(s)
760}
761
762#[tracable_parser]
763#[packrat_parser]
764pub(crate) fn simple_identifier_pragma(s: Span) -> IResult<Span, SimpleIdentifier> {
765 let (s, a) = ws(simple_identifier_pragma_impl)(s)?;
766 Ok((s, SimpleIdentifier { nodes: a }))
767}
768
769#[tracable_parser]
770pub(crate) fn simple_identifier_pragma_impl(s: Span) -> IResult<Span, Locate> {
771 let (s, a) = is_a(AZ_)(s)?;
772 let (s, b) = opt(is_a(AZ09_DOLLAR))(s)?;
773 let a = if let Some(b) = b {
774 concat(a, b).unwrap()
775 } else {
776 a
777 };
778 Ok((s, into_locate(a)))
779}
780
781#[tracable_parser]
782#[packrat_parser]
783pub(crate) fn line_compiler_directive(s: Span) -> IResult<Span, LineCompilerDirective> {
784 let (s, a) = symbol("`")(s)?;
785 let (s, b) = keyword("line")(s)?;
786 let (s, c) = number(s)?;
787 let (s, d) = string_literal(s)?;
788 let (s, e) = level(s)?;
789 Ok((
790 s,
791 LineCompilerDirective {
792 nodes: (a, b, c, d, e),
793 },
794 ))
795}
796
797#[tracable_parser]
798#[packrat_parser]
799pub(crate) fn position_compiler_directive(s: Span) -> IResult<Span, PositionCompilerDirective> {
800 let (s, a) = symbol("`")(s)?;
801 let (s, b) = alt((keyword("__FILE__"), keyword("__LINE__")))(s)?;
802 Ok((s, PositionCompilerDirective { nodes: (a, b) }))
803}
804
805#[tracable_parser]
806#[packrat_parser]
807pub(crate) fn level(s: Span) -> IResult<Span, Level> {
808 let (s, a) = alt((symbol("0"), symbol("1"), symbol("2")))(s)?;
809 Ok((s, Level { nodes: (a,) }))
810}
811
812#[tracable_parser]
813#[packrat_parser]
814pub(crate) fn keywords_directive(s: Span) -> IResult<Span, KeywordsDirective> {
815 let (s, a) = symbol("`")(s)?;
816 let (s, b) = keyword("begin_keywords")(s)?;
817 let (s, c) = symbol("\"")(s)?;
818 let (s, d) = version_specifier(s)?;
819 let (s, e) = symbol("\"")(s)?;
820 Ok((
821 s,
822 KeywordsDirective {
823 nodes: (a, b, c, d, e),
824 },
825 ))
826}
827
828#[tracable_parser]
829#[packrat_parser]
830pub(crate) fn version_specifier(s: Span) -> IResult<Span, VersionSpecifier> {
831 let (s, a) = alt((
832 map(keyword("1800-2017"), |x| {
833 begin_keywords("1800-2017");
834 x
835 }),
836 map(keyword("1800-2012"), |x| {
837 begin_keywords("1800-2012");
838 x
839 }),
840 map(keyword("1800-2009"), |x| {
841 begin_keywords("1800-2009");
842 x
843 }),
844 map(keyword("1800-2005"), |x| {
845 begin_keywords("1800-2005");
846 x
847 }),
848 map(keyword("1364-2005"), |x| {
849 begin_keywords("1364-2005");
850 x
851 }),
852 map(keyword("1364-2001-noconfig"), |x| {
853 begin_keywords("1364-2001-noconfig");
854 x
855 }),
856 map(keyword("1364-2001"), |x| {
857 begin_keywords("1364-2001");
858 x
859 }),
860 map(keyword("1364-1995"), |x| {
861 begin_keywords("1364-1995");
862 x
863 }),
864 ))(s)?;
865 Ok((s, VersionSpecifier { nodes: (a,) }))
866}
867
868#[tracable_parser]
869#[packrat_parser]
870pub(crate) fn endkeywords_directive(s: Span) -> IResult<Span, EndkeywordsDirective> {
871 let (s, a) = symbol("`")(s)?;
872 let (s, b) = keyword("end_keywords")(s)?;
873 end_keywords();
874 Ok((s, EndkeywordsDirective { nodes: (a, b) }))
875}