MsilParser

Struct MsilParser 

Source
pub struct MsilParser<'config> { /* private fields */ }
Expand description

MSIL 解析器

负责将 MSIL 源代码解析为抽象语法树。 解析器维护对配置的引用,并使用词法分析器将源代码转换为 token 流。

§生命周期参数

  • 'config: 解析器配置的生命周期

§示例

use clr_msil::{MsilParser, ReadConfig};

let config = ReadConfig::default();
let parser = MsilParser::new(&config);

Implementations§

Source§

impl<'config> MsilParser<'config>

Source

pub fn new(config: &'config MsilReadConfig) -> Self

创建新的 MSIL 解析器

§参数
  • config: 解析器配置
§返回值

返回一个新的 MsilParser 实例

§示例
use clr_msil::{MsilParser, ReadConfig};

let config = ReadConfig::default();
let parser = MsilParser::new(&config);
Source

pub fn parse_text(&self, text: &str) -> GaiaDiagnostics<MsilRoot>

解析 MSIL 源代码文本

这个方法将 MSIL 源代码字符串解析为抽象语法树。 它首先使用词法分析器将源代码转换为 token 流,然后进行语法分析。

§参数
  • text: MSIL 源代码字符串
§返回值

返回包含解析结果的 GaiaDiagnostics<MsilRoot>

§示例
use clr_msil::{MsilParser, ReadConfig};

let config = ReadConfig::default();
let parser = MsilParser::new(&config);

let result = parser.parse_text(".assembly MyAssembly");
if let Ok(ast) = result.result {
    println!("解析成功");
}
Source

pub fn parse( &self, tokens: TokenStream<'_, MsilTokenType>, ) -> GaiaDiagnostics<MsilRoot>

解析 MSIL token 流

这个方法将已经词法分析过的 token 流解析为抽象语法树。 它处理各种 MSIL 语句,包括程序集声明、模块声明、类声明等。

§参数
  • tokens: 词法分析器生成的 token 流
§返回值

返回包含解析结果的 GaiaDiagnostics<MsilRoot>

§解析过程
  1. 跳过空白字符和注释
  2. 识别以 . 开头的指令
  3. 根据指令类型调用相应的解析函数
  4. 构建抽象语法树
§支持的语法构造
  • .assembly extern <name> - 外部程序集引用
  • .assembly <name> - 程序集声明
  • .module <name> - 模块声明
  • .class <modifiers> <name> extends <base> - 类声明
  • .method <modifiers> <return_type> <name>(<parameters>) - 方法声明
§示例
use clr_msil::{MsilParser, ReadConfig};
use gaia_types::reader::TokenStream;

let config = ReadConfig::default();
let parser = MsilParser::new(&config);

// 通常通过 parse_text 方法使用,这个方法主要用于内部处理

Trait Implementations§

Source§

impl<'config> Clone for MsilParser<'config>

Source§

fn clone(&self) -> MsilParser<'config>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'config> Debug for MsilParser<'config>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'config> Freeze for MsilParser<'config>

§

impl<'config> RefUnwindSafe for MsilParser<'config>

§

impl<'config> Send for MsilParser<'config>

§

impl<'config> Sync for MsilParser<'config>

§

impl<'config> Unpin for MsilParser<'config>

§

impl<'config> UnwindSafe for MsilParser<'config>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,