mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-23 18:21:13 +08:00
docs: 添加 Rustdoc 注释
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
//! 解析错误类型。
|
||||
//!
|
||||
//! [`OxideError`] 把 oxc 的 `OxcDiagnostic` 归一化为引擎可消费的
|
||||
//! 消息 + 字节区间,供 `parse` 返回错误列表。
|
||||
|
||||
use std::fmt;
|
||||
|
||||
/// 一条解析错误:消息与出错源码区间(`(start, end)` 字节偏移)。
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct OxideError {
|
||||
pub message: String,
|
||||
|
||||
@@ -2,11 +2,20 @@
|
||||
|
||||
mod error;
|
||||
|
||||
/// 解析错误:消息 + 源文件字节区间(起始,结束)。
|
||||
pub use error::OxideError;
|
||||
/// 重导出 `oxc_allocator::Allocator`:AST 节点的 bump 分配器,解析产物生命周期由其决定。
|
||||
pub use oxc_allocator::Allocator;
|
||||
/// 重导出 `oxc_ast::ast` 的全部 AST 节点类型(`Program`、`Statement`、`Expression` 等)。
|
||||
pub use oxc_ast::ast::*;
|
||||
/// 重导出 `oxc_span::Span`:源码中的位置区间。
|
||||
pub use oxc_span::Span;
|
||||
|
||||
/// 把 `source` 解析为 AST 根节点 `Program`,AST 分配在 `allocator` 中。
|
||||
///
|
||||
/// 使用 oxc 默认 `SourceType`(严格模式由语法自身决定)。返回 `Ok(program)`
|
||||
/// 或 `Err`(收集全部解析错误,按源码顺序排列);若 oxc 内部 panic(不可恢复
|
||||
/// 语法错误)则返回单个通用错误。
|
||||
pub fn parse<'a>(allocator: &'a Allocator, source: &'a str) -> Result<Program<'a>, Vec<OxideError>> {
|
||||
use oxc_parser::Parser;
|
||||
use oxc_span::SourceType;
|
||||
|
||||
Reference in New Issue
Block a user