sv_parser_parser/source_text/
library_source_text.rs1use crate::*;
2
3#[tracable_parser]
6#[packrat_parser]
7pub(crate) fn library_text(s: Span) -> IResult<Span, LibraryText> {
8 let (s, a) = many0(white_space)(s)?;
9 let (s, (b, _)) = many_till(library_description, eof)(s)?;
10 Ok((s, LibraryText { nodes: (a, b) }))
11}
12
13#[tracable_parser]
14#[packrat_parser]
15pub(crate) fn library_text_incomplete(s: Span) -> IResult<Span, LibraryText> {
16 let (s, a) = many0(white_space)(s)?;
17 let (s, b) = many0(library_description)(s)?;
18 Ok((s, LibraryText { nodes: (a, b) }))
19}
20
21#[tracable_parser]
22#[packrat_parser]
23pub(crate) fn library_description(s: Span) -> IResult<Span, LibraryDescription> {
24 alt((
25 map(library_declaration, |x| {
26 LibraryDescription::LibraryDeclaration(Box::new(x))
27 }),
28 map(include_statement, |x| {
29 LibraryDescription::IncludeStatement(Box::new(x))
30 }),
31 map(config_declaration, |x| {
32 LibraryDescription::ConfigDeclaration(Box::new(x))
33 }),
34 map(symbol(";"), |x| LibraryDescription::Null(Box::new(x))),
35 ))(s)
36}
37
38#[tracable_parser]
39#[packrat_parser]
40pub(crate) fn library_declaration(s: Span) -> IResult<Span, LibraryDeclaration> {
41 let (s, a) = keyword("library")(s)?;
42 let (s, b) = library_identifier(s)?;
43 let (s, c) = list(symbol(","), file_path_spec)(s)?;
44 let (s, d) = opt(pair(keyword("-incdir"), list(symbol(","), file_path_spec)))(s)?;
45 let (s, e) = symbol(";")(s)?;
46 Ok((
47 s,
48 LibraryDeclaration {
49 nodes: (a, b, c, d, e),
50 },
51 ))
52}
53
54#[tracable_parser]
55#[packrat_parser]
56pub(crate) fn include_statement(s: Span) -> IResult<Span, IncludeStatement> {
57 let (s, a) = keyword("include")(s)?;
58 let (s, b) = file_path_spec(s)?;
59 let (s, c) = symbol(";")(s)?;
60 Ok((s, IncludeStatement { nodes: (a, b, c) }))
61}
62
63#[tracable_parser]
64#[packrat_parser]
65pub(crate) fn file_path_spec(s: Span) -> IResult<Span, FilePathSpec> {
66 alt((
67 map(string_literal, |x| FilePathSpec::Literal(x)),
68 file_path_spec_non_literal,
69 ))(s)
70}
71
72#[tracable_parser]
73#[packrat_parser]
74pub(crate) fn file_path_spec_non_literal(s: Span) -> IResult<Span, FilePathSpec> {
75 let (s, a) = ws(map(is_not(",; "), |x| into_locate(x)))(s)?;
76 Ok((
77 s,
78 FilePathSpec::NonLiteral(FilePathSpecNonLiteral { nodes: a }),
79 ))
80}