mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
move abstract traits to top
This commit is contained in:
parent
d2bce118ae
commit
2b5e336ce7
4 changed files with 59 additions and 65 deletions
|
@ -4,47 +4,17 @@ pub(crate) mod input;
|
|||
use std::cell::Cell;
|
||||
|
||||
use crate::{
|
||||
SmolStr,
|
||||
syntax_error::{ParseError, SyntaxError},
|
||||
syntax_error::ParseError,
|
||||
parsing::{
|
||||
TreeSink, TokenSource, TokenPos,
|
||||
lexer::Token,
|
||||
parser_api::Parser,
|
||||
parser_impl::{
|
||||
event::{Event, EventProcessor},
|
||||
input::InputPosition,
|
||||
},
|
||||
parser_impl::event::{Event, EventProcessor},
|
||||
},
|
||||
};
|
||||
|
||||
use crate::SyntaxKind::{self, EOF, TOMBSTONE};
|
||||
|
||||
pub(super) trait TreeSink {
|
||||
type Tree;
|
||||
|
||||
/// Adds new leaf to the current branch.
|
||||
fn leaf(&mut self, kind: SyntaxKind, text: SmolStr);
|
||||
|
||||
/// Start new branch and make it current.
|
||||
fn start_branch(&mut self, kind: SyntaxKind);
|
||||
|
||||
/// Finish current branch and restore previous
|
||||
/// branch as current.
|
||||
fn finish_branch(&mut self);
|
||||
|
||||
fn error(&mut self, error: SyntaxError);
|
||||
|
||||
/// Complete tree building. Make sure that
|
||||
/// `start_branch` and `finish_branch` calls
|
||||
/// are paired!
|
||||
fn finish(self) -> Self::Tree;
|
||||
}
|
||||
|
||||
pub(super) trait TokenSource {
|
||||
fn token_kind(&self, pos: InputPosition) -> SyntaxKind;
|
||||
fn is_token_joint_to_next(&self, pos: InputPosition) -> bool;
|
||||
fn is_keyword(&self, pos: InputPosition, kw: &str) -> bool;
|
||||
}
|
||||
|
||||
/// Parse a sequence of tokens into the representative node tree
|
||||
pub(super) fn parse_with<S: TreeSink>(
|
||||
sink: S,
|
||||
|
@ -67,7 +37,7 @@ pub(super) fn parse_with<S: TreeSink>(
|
|||
/// the public API of the `Parser`.
|
||||
pub(super) struct ParserImpl<'a> {
|
||||
token_source: &'a dyn TokenSource,
|
||||
pos: InputPosition,
|
||||
pos: TokenPos,
|
||||
events: Vec<Event>,
|
||||
steps: Cell<u32>,
|
||||
}
|
||||
|
@ -76,7 +46,7 @@ impl<'a> ParserImpl<'a> {
|
|||
fn new(token_source: &'a dyn TokenSource) -> ParserImpl<'a> {
|
||||
ParserImpl {
|
||||
token_source,
|
||||
pos: InputPosition::new(),
|
||||
pos: TokenPos::default(),
|
||||
events: Vec::new(),
|
||||
steps: Cell::new(0),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue