Add host-configurable language service
This commit is contained in:
@@ -140,6 +140,48 @@ It only generates schema construction and typed decoding code.
|
||||
|
||||
Both mechanisms share the same runtime evaluator, thunk model, and materialization rules.
|
||||
|
||||
## Shared host environment
|
||||
|
||||
An embedded application can implement `HostEnvironment` to keep loader creation and global binding setup in one place.
|
||||
Both production evaluation and semantic editor tooling create their engines from this environment, preventing the editor from drifting onto a separate validation path.
|
||||
|
||||
```rust
|
||||
use decodal::{Engine, HostEnvironment};
|
||||
|
||||
struct AppEnvironment;
|
||||
|
||||
impl HostEnvironment for AppEnvironment {
|
||||
type Loader = ContentLoader;
|
||||
|
||||
fn create_loader(&self) -> Self::Loader {
|
||||
ContentLoader::new()
|
||||
}
|
||||
|
||||
fn configure_engine(
|
||||
&self,
|
||||
engine: &mut Engine<Self::Loader>,
|
||||
) -> decodal::Result<()> {
|
||||
engine.bind_global("Site", site_schema())?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
let environment = AppEnvironment;
|
||||
let mut engine = environment.create_engine()?;
|
||||
```
|
||||
|
||||
The semantic service accepts the same environment by value:
|
||||
|
||||
```rust
|
||||
use decodal_language_service::LanguageService;
|
||||
|
||||
let service = LanguageService::new(&environment);
|
||||
let analysis = service.analyze("site.dcdl", "site.dcdl", source);
|
||||
```
|
||||
|
||||
Each analysis uses a fresh engine and runs the normal parse, evaluate, and materialize pipeline.
|
||||
An environment may create loaders backed by shared filesystem, database, or editor-overlay state when repeated analysis needs a current workspace snapshot.
|
||||
|
||||
## Structured imports
|
||||
|
||||
`ImportLoader::load` returns either `LoadedImport::Source` or `LoadedImport::Value`.
|
||||
|
||||
@@ -23,6 +23,9 @@ materialize
|
||||
data / diagnostics
|
||||
```
|
||||
|
||||
Production applications and semantic language services can construct this pipeline through the same host-defined `HostEnvironment`.
|
||||
The environment creates the `ImportLoader` and installs host globals before the root module is registered.
|
||||
|
||||
## lexer / parser
|
||||
|
||||
lexer / parser は source を AST に変換する。
|
||||
|
||||
Reference in New Issue
Block a user