mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
internal: add prefix entry points
This commit is contained in:
parent
d3ba55bd06
commit
abc658aad0
2 changed files with 36 additions and 0 deletions
|
@ -44,6 +44,18 @@ use crate::{
|
|||
TokenSet, T,
|
||||
};
|
||||
|
||||
pub(crate) mod entry {
|
||||
use super::*;
|
||||
|
||||
pub(crate) mod prefix {
|
||||
use super::*;
|
||||
|
||||
pub(crate) fn vis(p: &mut Parser) {
|
||||
let _ = opt_visibility(p, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) mod entry_points {
|
||||
use super::*;
|
||||
|
||||
|
|
|
@ -41,6 +41,30 @@ pub use crate::{
|
|||
syntax_kind::SyntaxKind,
|
||||
};
|
||||
|
||||
/// Parse a syntactic construct at the *start* of the input.
|
||||
///
|
||||
/// This is used by macro-by-example parser to implement things like `$i:item`.
|
||||
///
|
||||
/// Note that this is generally non-optional -- the result is intentionally not
|
||||
/// `Option<Output>`. The way MBE work, by the time we *try* to parse `$e:expr`
|
||||
/// we already commit to expression. In other words, this API by design can't be
|
||||
/// used to implement "rollback and try another alternative" logic.
|
||||
pub enum PrefixEntryPoint {
|
||||
Vis,
|
||||
}
|
||||
|
||||
impl PrefixEntryPoint {
|
||||
pub fn parse(self, input: &Input) -> Output {
|
||||
let entry_point: fn(&'_ mut parser::Parser) = match self {
|
||||
PrefixEntryPoint::Vis => grammar::entry::prefix::vis,
|
||||
};
|
||||
let mut p = parser::Parser::new(input);
|
||||
entry_point(&mut p);
|
||||
let events = p.finish();
|
||||
event::process(events)
|
||||
}
|
||||
}
|
||||
|
||||
/// rust-analyzer parser allows you to choose one of the possible entry points.
|
||||
///
|
||||
/// The primary consumer of this API are declarative macros, `$x:expr` matchers
|
||||
|
|
Loading…
Reference in a new issue