mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-08-03 18:38:53 +00:00
deploy: 12e85cb778
This commit is contained in:
parent
f01db459c5
commit
661232845e
9 changed files with 342 additions and 92 deletions
|
@ -169,7 +169,7 @@ This is tedious but not difficult. Here is an example of implementing the trait
|
|||
</span><span class="boring">fn main() {
|
||||
</span>impl DebugWithDb<dyn crate::Db + '_> for Expression {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &dyn crate::Db) -> std::fmt::Result {
|
||||
match self.data(db) {
|
||||
match &self.data {
|
||||
ExpressionData::Op(a, b, c) => f
|
||||
.debug_tuple("ExpressionData::Op")
|
||||
.field(&a.debug(db)) // use `a.debug(db)` for interned things
|
||||
|
@ -219,16 +219,29 @@ impl DebugWithDb<dyn crate::Db + '_> for Diagnostic {
|
|||
pub struct Function {
|
||||
#[id]
|
||||
name: FunctionId,
|
||||
|
||||
name_span: Span,
|
||||
|
||||
#[return_ref]
|
||||
args: Vec<VariableId>,
|
||||
|
||||
#[return_ref]
|
||||
body: Expression,
|
||||
}
|
||||
|
||||
#[salsa::tracked]
|
||||
pub struct Span {
|
||||
pub start: usize,
|
||||
pub end: usize,
|
||||
}
|
||||
|
||||
#[salsa::accumulator]
|
||||
pub struct Diagnostics(Diagnostic);
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(new, Clone, Debug)]
|
||||
pub struct Diagnostic {
|
||||
pub position: usize,
|
||||
pub start: usize,
|
||||
pub end: usize,
|
||||
pub message: String,
|
||||
}
|
||||
<span class="boring">}
|
||||
|
@ -271,21 +284,53 @@ fn parse_print() {
|
|||
let actual = parse_string("print 1 + 2");
|
||||
let expected = expect_test::expect![[r#"
|
||||
(
|
||||
[
|
||||
ExpressionData::Op(
|
||||
Number(
|
||||
OrderedFloat(
|
||||
1.0,
|
||||
Program {
|
||||
statements: [
|
||||
Statement {
|
||||
span: Span(
|
||||
Id {
|
||||
value: 5,
|
||||
},
|
||||
),
|
||||
),
|
||||
Add,
|
||||
Number(
|
||||
OrderedFloat(
|
||||
2.0,
|
||||
data: Print(
|
||||
Expression {
|
||||
span: Span(
|
||||
Id {
|
||||
value: 4,
|
||||
},
|
||||
),
|
||||
data: Op(
|
||||
Expression {
|
||||
span: Span(
|
||||
Id {
|
||||
value: 1,
|
||||
},
|
||||
),
|
||||
data: Number(
|
||||
OrderedFloat(
|
||||
1.0,
|
||||
),
|
||||
),
|
||||
},
|
||||
Add,
|
||||
Expression {
|
||||
span: Span(
|
||||
Id {
|
||||
value: 3,
|
||||
},
|
||||
),
|
||||
data: Number(
|
||||
OrderedFloat(
|
||||
2.0,
|
||||
),
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
[],
|
||||
)"#]];
|
||||
expected.assert_eq(&actual);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue