Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 #![allow(clippy::tabs_in_doc_comments)] // Makefile uses tabs
2 #![deny(missing_docs)]
3
4 //! A lossless parser for Makefiles
5 //!
6 //! Example:
7 //!
8 //! ```rust
9 //! use std::io::Read;
10 //! let contents = r#"PYTHON = python3
11 //!
12 //! .PHONY: all
13 //!
14 //! all: build
15 //!
16 //! build:
17 //! $(PYTHON) setup.py build
18 //! "#;
19 //! let makefile: makefile_lossless::Makefile = contents.parse().unwrap();
20 //!
21 //! assert_eq!(makefile.rules().count(), 3);
22 //! ```
23
24 mod astrust-analyzer cargo makefile-lossless 0.3.40 ast/;
25 mod incrementalrust-analyzer cargo makefile-lossless 0.3.40 incremental/;
26 mod lexrust-analyzer cargo makefile-lossless 0.3.40 lex/;
27 mod losslessrust-analyzer cargo makefile-lossless 0.3.40 lossless/;
28 mod parserust-analyzer cargo makefile-lossless 0.3.40 parse/;
29 mod patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/;
30 mod textrust-analyzer cargo makefile-lossless 0.3.40 text/;
31
32 pub use astrust-analyzer cargo makefile-lossless 0.3.40 ast/::makefilerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/::MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#;
33 pub use astrust-analyzer cargo makefile-lossless 0.3.40 ast/::rulerust-analyzer cargo makefile-lossless 0.3.40 ast/rule/::RuleItemrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#;
34 pub use incrementalrust-analyzer cargo makefile-lossless 0.3.40 incremental/::{apply_edit_to_textrust-analyzer cargo makefile-lossless 0.3.40 incremental/apply_edit_to_text()., TextEditrust-analyzer cargo makefile-lossless 0.3.40 incremental/TextEdit#};
35 pub use losslessrust-analyzer cargo makefile-lossless 0.3.40 lossless/::{
36 ArchiveMemberrust-analyzer cargo makefile-lossless 0.3.40 lossless/ArchiveMember#, ArchiveMembersrust-analyzer cargo makefile-lossless 0.3.40 lossless/ArchiveMembers#, Conditionalrust-analyzer cargo makefile-lossless 0.3.40 lossless/Conditional#, Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#, ErrorInforust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#, Identifierrust-analyzer cargo makefile-lossless 0.3.40 lossless/Identifier#, Includerust-analyzer cargo makefile-lossless 0.3.40 lossless/Include#, Langrust-analyzer cargo makefile-lossless 0.3.40 lossless/Lang#,
37 Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#, ParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#, PositionedParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/PositionedParseError#, Reciperust-analyzer cargo makefile-lossless 0.3.40 lossless/Recipe#, RecipeVariableReferencerust-analyzer cargo makefile-lossless 0.3.40 lossless/RecipeVariableReference#, Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#,
38 VariableDefinitionrust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableDefinition#, VariableReferencerust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference#, Vpathrust-analyzer cargo makefile-lossless 0.3.40 lossless/Vpath#,
39 };
40 pub use parserust-analyzer cargo makefile-lossless 0.3.40 parse/::Parserust-analyzer cargo makefile-lossless 0.3.40 parse/Parse#;
41 pub use rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#;
42 pub use textrust-analyzer cargo makefile-lossless 0.3.40 text/::{is_in_prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 text/is_in_prerequisites()., variable_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 text/variable_at_offset()., word_at_offsetrust-analyzer cargo makefile-lossless 0.3.40 text/word_at_offset().};
43
44 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)]
45 /// The variant of makefile being parsed
46 pub enum MakefileVariantrust-analyzer cargo makefile-lossless 0.3.40 MakefileVariant# {
47 /// GNU Make (most common, supports ifeq/ifneq/ifdef/ifndef conditionals, pattern rules, etc.)
48 GNUMakerust-analyzer cargo makefile-lossless 0.3.40 MakefileVariant#GNUMake#,
49 /// BSD Make (FreeBSD, NetBSD, OpenBSD - uses .if/.ifdef/.ifndef directives)
50 BSDMakerust-analyzer cargo makefile-lossless 0.3.40 MakefileVariant#BSDMake#,
51 /// Microsoft nmake (Windows - uses !IF/!IFDEF/!IFNDEF directives)
52 NMakerust-analyzer cargo makefile-lossless 0.3.40 MakefileVariant#NMake#,
53 /// POSIX-compliant make (basic portable subset, no extensions)
54 POSIXMakerust-analyzer cargo makefile-lossless 0.3.40 MakefileVariant#POSIXMake#,
55 }
56
57 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)]
58 #[allow(non_camel_case_types)]
59 #[repr(u16)]
60 #[allow(missing_docs)]
61 pub enum SyntaxKindrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind# {
62 IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER# = 0,
63 INDENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INDENT#,
64 TEXTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#TEXT#,
65 WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE#,
66 NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#,
67 DOLLARrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#DOLLAR#,
68 LPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LPAREN#,
69 RPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RPAREN#,
70 LBRACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LBRACE#,
71 RBRACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RBRACE#,
72 QUOTErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#QUOTE#,
73 BACKSLASHrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#BACKSLASH#,
74 COMMArust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMA#,
75 OPERATORrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#OPERATOR#,
76
77 COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT#,
78 ERRORrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#ERROR#,
79
80 // composite nodes
81 ROOTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#ROOT#, // The entire file
82 RULErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RULE#, // A single rule
83 RECIPErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RECIPE#, // A command/recipe line
84 VARIABLErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#VARIABLE#, // A variable definition
85 EXPRrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#EXPR#, // An expression (e.g., targets before colon, or old-style prerequisites)
86 TARGETSrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#TARGETS#, // Container for targets before the colon
87 PREREQUISITESrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#PREREQUISITES#, // Container for prerequisites after the colon
88 PREREQUISITErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#PREREQUISITE#, // A single prerequisite item
89
90 // Directives
91 CONDITIONALrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL#, // The entire conditional block (ifdef...endif)
92 CONDITIONAL_IFrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL_IF#, // The initial conditional (ifdef/ifndef/ifeq/ifneq)
93 CONDITIONAL_ELSErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL_ELSE#, // An else or else-conditional clause
94 CONDITIONAL_ENDIFrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL_ENDIF#, // The endif keyword
95 INCLUDErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INCLUDE#,
96 VPATHrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#VPATH#, // A `vpath PATTERN DIRS` / `vpath PATTERN` / `vpath` directive
97
98 // Archive members
99 ARCHIVE_MEMBERSrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#ARCHIVE_MEMBERS#, // Container for just the members inside parentheses
100 ARCHIVE_MEMBERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#ARCHIVE_MEMBER#, // Individual member like "bar.o" or "baz.o"
101
102 // Blank lines
103 BLANK_LINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#BLANK_LINE#, // A blank line between top-level items
104 }
105
106 /// Convert our `SyntaxKind` into the rowan `SyntaxKind`.
107 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<SyntaxKindrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#> for rowanrust-analyzer cargo rowan 0.16.1 crate/::SyntaxKindrust-analyzer cargo rowan 0.16.1 green/SyntaxKind# {
108 fn fromrust-analyzer cargo makefile-lossless 0.3.40 impl#[`rowan::SyntaxKind`][`From<SyntaxKind>`]from().(kind: SyntaxKindrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#) -> Selfrust-analyzer cargo makefile-lossless 0.3.40 impl#[`rowan::SyntaxKind`][`From<SyntaxKind>`] {
109 Selfrust-analyzer cargo makefile-lossless 0.3.40 impl#[`rowan::SyntaxKind`][`From<SyntaxKind>`](kind as u16)
110 }
111 }