internal: make name consistent with usage
This commit is contained in:
@@ -173,52 +173,58 @@ impl SourceFile {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: `parse` functions shouldn't hang directly from AST nodes, and they
|
||||
// shouldn't return `Result`.
|
||||
//
|
||||
// We need a dedicated module for parser entry points, and they should always
|
||||
// return `Parse`.
|
||||
|
||||
impl ast::Path {
|
||||
/// Returns `text`, parsed as a path, but only if it has no errors.
|
||||
pub fn parse(text: &str) -> Result<Self, ()> {
|
||||
parsing::parse_text_fragment(text, parser::FragmentKind::Path)
|
||||
parsing::parse_text_as(text, parser::ParserEntryPoint::Path)
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::Pat {
|
||||
/// Returns `text`, parsed as a pattern, but only if it has no errors.
|
||||
pub fn parse(text: &str) -> Result<Self, ()> {
|
||||
parsing::parse_text_fragment(text, parser::FragmentKind::Pattern)
|
||||
parsing::parse_text_as(text, parser::ParserEntryPoint::Pattern)
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::Expr {
|
||||
/// Returns `text`, parsed as an expression, but only if it has no errors.
|
||||
pub fn parse(text: &str) -> Result<Self, ()> {
|
||||
parsing::parse_text_fragment(text, parser::FragmentKind::Expr)
|
||||
parsing::parse_text_as(text, parser::ParserEntryPoint::Expr)
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::Item {
|
||||
/// Returns `text`, parsed as an item, but only if it has no errors.
|
||||
pub fn parse(text: &str) -> Result<Self, ()> {
|
||||
parsing::parse_text_fragment(text, parser::FragmentKind::Item)
|
||||
parsing::parse_text_as(text, parser::ParserEntryPoint::Item)
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::Type {
|
||||
/// Returns `text`, parsed as an type reference, but only if it has no errors.
|
||||
pub fn parse(text: &str) -> Result<Self, ()> {
|
||||
parsing::parse_text_fragment(text, parser::FragmentKind::Type)
|
||||
parsing::parse_text_as(text, parser::ParserEntryPoint::Type)
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::Attr {
|
||||
/// Returns `text`, parsed as an attribute, but only if it has no errors.
|
||||
pub fn parse(text: &str) -> Result<Self, ()> {
|
||||
parsing::parse_text_fragment(text, parser::FragmentKind::Attr)
|
||||
parsing::parse_text_as(text, parser::ParserEntryPoint::Attr)
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::Stmt {
|
||||
/// Returns `text`, parsed as statement, but only if it has no errors.
|
||||
pub fn parse(text: &str) -> Result<Self, ()> {
|
||||
parsing::parse_text_fragment(text, parser::FragmentKind::StatementOptionalSemi)
|
||||
parsing::parse_text_as(text, parser::ParserEntryPoint::StatementOptionalSemi)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) {
|
||||
let mut token_source = TextTokenSource::new(text, &tokens);
|
||||
let mut tree_sink = TextTreeSink::new(text, &tokens);
|
||||
|
||||
parser::parse(&mut token_source, &mut tree_sink);
|
||||
parser::parse_source_file(&mut token_source, &mut tree_sink);
|
||||
|
||||
let (tree, mut parser_errors) = tree_sink.finish();
|
||||
parser_errors.extend(lexer_errors);
|
||||
@@ -29,9 +29,9 @@ pub(crate) fn parse_text(text: &str) -> (GreenNode, Vec<SyntaxError>) {
|
||||
}
|
||||
|
||||
/// Returns `text` parsed as a `T` provided there are no parse errors.
|
||||
pub(crate) fn parse_text_fragment<T: AstNode>(
|
||||
pub(crate) fn parse_text_as<T: AstNode>(
|
||||
text: &str,
|
||||
fragment_kind: parser::FragmentKind,
|
||||
entry_point: parser::ParserEntryPoint,
|
||||
) -> Result<T, ()> {
|
||||
let (tokens, lexer_errors) = tokenize(text);
|
||||
if !lexer_errors.is_empty() {
|
||||
@@ -45,7 +45,7 @@ pub(crate) fn parse_text_fragment<T: AstNode>(
|
||||
// tokens. We arbitrarily give it a SourceFile.
|
||||
use parser::TreeSink;
|
||||
tree_sink.start_node(SyntaxKind::SOURCE_FILE);
|
||||
parser::parse_fragment(&mut token_source, &mut tree_sink, fragment_kind);
|
||||
parser::parse(&mut token_source, &mut tree_sink, entry_point);
|
||||
tree_sink.finish_node();
|
||||
|
||||
let (tree, parser_errors) = tree_sink.finish();
|
||||
|
||||
Reference in New Issue
Block a user