gix_revision/spec/parse/
mod.rs

1use bstr::BString;
2
3use crate::spec;
4
5/// The error returned by [`spec::parse()`][crate::spec::parse()].
6#[derive(Debug, thiserror::Error)]
7#[allow(missing_docs)]
8pub enum Error {
9    #[error("'~' needs to follow an anchor, like '@~'.")]
10    MissingTildeAnchor,
11    #[error("':' needs to be followed by either '/' and regex or the path to lookup in the HEAD tree.")]
12    MissingColonSuffix,
13    #[error("':/' must be followed by a regular expression.")]
14    EmptyTopLevelRegex,
15    #[error("Need one character after '/!', typically '-', but got {:?}", .regex)]
16    UnspecifiedRegexModifier { regex: BString },
17    #[error("Cannot peel to {:?} - unknown target.", .input)]
18    InvalidObject { input: BString },
19    #[error("Could not parse time {:?} for revlog lookup.", .input)]
20    Time {
21        input: BString,
22        source: Option<gix_date::parse::Error>,
23    },
24    #[error("Sibling branches like 'upstream' or 'push' require a branch name with remote configuration, got {:?}", .name)]
25    SiblingBranchNeedsBranchName { name: BString },
26    #[error("Reflog entries require a ref name, got {:?}", .name)]
27    ReflogLookupNeedsRefName { name: BString },
28    #[error("A reference name must be followed by positive numbers in '@{{n}}', got {:?}", .nav)]
29    RefnameNeedsPositiveReflogEntries { nav: BString },
30    #[error("Negative or explicitly positive numbers are invalid here: {:?}", .input)]
31    SignedNumber { input: BString },
32    #[error("Could not parse number from {input:?}")]
33    InvalidNumber { input: BString },
34    #[error("Negative zeroes are invalid: {:?} - remove the '-'", .input)]
35    NegativeZero { input: BString },
36    #[error("The opening brace in {:?} was not matched", .input)]
37    UnclosedBracePair { input: BString },
38    #[error("Cannot set spec kind more than once. Previous value was {:?}, now it is {:?}", .prev_kind, .kind)]
39    KindSetTwice { prev_kind: spec::Kind, kind: spec::Kind },
40    #[error("The @ character is either standing alone or followed by `{{<content>}}`, got {:?}", .input)]
41    AtNeedsCurlyBrackets { input: BString },
42    #[error("A portion of the input could not be parsed: {:?}", .input)]
43    UnconsumedInput { input: BString },
44    #[error("The delegate didn't indicate success - check delegate for more information")]
45    Delegate,
46}
47
48///
49pub mod delegate;
50
51/// A delegate to be informed about parse events, with methods split into categories.
52///
53/// - **Anchors** - which revision to use as starting point for…
54/// - **Navigation** - where to go once from the initial revision
55/// - **Range** - to learn if the specification is for a single or multiple references, and how to combine them.
56pub trait Delegate: delegate::Revision + delegate::Navigate + delegate::Kind {
57    /// Called at the end of a successful parsing operation.
58    /// It can be used as a marker to finalize internal data structures.
59    ///
60    /// Note that it will not be called if there is unconsumed input.
61    fn done(&mut self);
62}
63
64pub(crate) mod function;