conglinyizhi/precss/core does not have a README file

    CompileError

    pub(all) suberror CompileError {
    NoEngine(Format)
    EngineFailed(engine~ : String, message~ : String)
    UnsupportedSyntax(String)
    } derive(
    Debug
    )

    统一的编译错误

    把各个后端引擎的错误统一成一种 CompileError,让调用方只需处理它。

    CompileError::output

    fn CompileError::output(self : CompileError, logger : &Logger) -> Unit

    CompileError::to_string

    fn CompileError::to_string(self : CompileError) -> String

    Compiler

    pub struct Compiler {
    engines : Array[Engine]
    }

    编译门面:持有若干可插拔引擎

    门面只负责「识别格式 → 路由到引擎 → 统一错误」,不绑定任何具体预处理引擎。

    Compiler::compile

    fn Compiler::compile(self : Compiler, source : String) -> String raise CompileError

    自动识别格式并编译

    Compiler::compile_file

    fn Compiler::compile_file(self : Compiler, path : String, read : (String) -> String raise CompileError) -> String raise CompileError

    编译文件

    读取函数由调用方注入,核心不耦合具体 IO 后端,跨 target 可用。

    Compiler::compile_input

    fn Compiler::compile_input(self : Compiler, input : Input) -> String raise CompileError

    依据输入形态编译

    Compiler::compile_many

    fn Compiler::compile_many(self : Compiler, inputs : Array[Input], read : (String) -> String raise CompileError) -> String raise CompileError

    编译多个输入(文件/字符串可混用),逐个编译并拼接

    每个输入先归一化成源码(Fileread 读取,Source 直接用), 再交给 SCSS 引擎做 @import 内联编译。

    Compiler::compile_with_format

    fn Compiler::compile_with_format(self : Compiler, source : String, fmt : Format) -> String raise CompileError

    以显式格式编译

    Compiler::new

    fn Compiler::new(engines : Array[Engine]) -> Compiler

    用一组引擎构造门面

    Engine

    pub struct Engine {
    name_fn : () -> String
    supports_fn : (Format) -> Bool
    compile_fn : (String) -> String raise CompileError
    compile_imports_fn : (String, (String) -> String raise CompileError) -> String raise CompileError
    }

    预处理引擎句柄

    每个后端构造一个 Engine,用函数闭包承载其行为。这是「可插拔契约」的载体: 门面 Compiler 只依赖 Enginesupports / compile,不关心是哪个后端。

    Engine::compile

    fn Engine::compile(self : Engine, source : String) -> String raise CompileError

    把源码编译为 CSS

    Engine::compile_imports

    fn Engine::compile_imports(self : Engine, source : String, read : (String) -> String raise CompileError) -> String raise CompileError

    带 @import 内联地编译

    Engine::engine_name

    fn Engine::engine_name(self : Engine) -> String

    引擎名

    Engine::new

    fn Engine::new(name~ : () -> String, supports~ : (Format) -> Bool, compile~ : (String) -> String raise CompileError, compile_imports~ : (String, (String) -> String raise CompileError) -> String raise CompileError) -> Engine

    构造一个引擎

    三个回调分别返回引擎名、是否负责某格式、以及把源码编译为 CSS。

    Engine::supports

    fn Engine::supports(self : Engine, fmt : Format) -> Bool

    是否负责某格式

    Format

    pub(all) enum Format {
    Scss
    Less
    Css
    } derive(Eq,
    Debug
    )

    支持的 CSS 预处理格式

    分发给后端引擎的格式标签。
    impl Show for Format

    Format::detect

    fn Format::detect(source : String) -> Format

    启发式自动识别源码格式

    优先判 SCSS(含 $ 变量或 Sass 控制指令),其次判 LESS @name : 变量定义),否则当作普通 CSS。

    Format::equal

    fn Format::equal(Format, Format) -> Bool

    Format::not_equal

    fn Format::not_equal(x : Format, y : Format) -> Bool

    Format::output

    fn Format::output(self : Format, logger : &Logger) -> Unit

    Format::to_repr

    Format::to_string

    fn Format::to_string(self : Format) -> String

    Input

    pub(all) enum Input {
    Source(String)
    SourceWithFormat(String, Format)
    File(String)
    } derive(Eq,
    Debug
    )

    编译入口的输入形态

    传给 compile_input 的输入,决定格式如何解析。

    Input::equal

    fn Input::equal(Input, Input) -> Bool

    Input::not_equal

    fn Input::not_equal(x : Input, y : Input) -> Bool

    Input::to_repr