Skip to content

Commit e68e1c6

Browse files
committed
Merge #146: Add getters for Span and improve error handling
f00714d added getters for span in parse and ast structs (Volodymyr Herashchenko) 23e637c added getter for span in parse.rs and ast.rs (Volodymyr Herashchenko) b2ab9f4 added getters to span and error in RichError (Volodymyr Herashchenko) Pull request description: ## Description This pull request introduces getter methods for Span in Parse and AST nodes, and adds getters for RichError fields. These changes make span and error information more accessible, simplifying the development of tools for SimplicityHL. ## Impact - Supports easier integration with developer tooling (e.g., LSP, analyzers). - No breaking changes introduced. ACKs for top commit: apoelstra: ACK f00714d; successfully ran local tests Tree-SHA512: 25e66a907858973241544a897273f3242fc234f4ce8057b5db65d952738eec113dcbfdcdebcb3a825a3fd603cc47ef93577f5a4f6de5fa8064df4dfb46929254
2 parents 7ec4063 + f00714d commit e68e1c6

3 files changed

Lines changed: 88 additions & 0 deletions

File tree

src/ast.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ impl Assignment {
126126
pub fn expression(&self) -> &Expression {
127127
&self.expression
128128
}
129+
130+
/// Access the span of the assignment.
131+
pub fn span(&self) -> &Span {
132+
&self.span
133+
}
129134
}
130135

131136
impl_eq_hash!(Assignment; pattern, expression);
@@ -150,6 +155,11 @@ impl Expression {
150155
pub fn ty(&self) -> &ResolvedType {
151156
&self.ty
152157
}
158+
159+
/// Access the span of the expression.
160+
pub fn span(&self) -> &Span {
161+
&self.span
162+
}
153163
}
154164

155165
/// Variant of an expression.
@@ -193,6 +203,11 @@ impl SingleExpression {
193203
pub fn ty(&self) -> &ResolvedType {
194204
&self.ty
195205
}
206+
207+
/// Access the span of the expression.
208+
pub fn span(&self) -> &Span {
209+
&self.span
210+
}
196211
}
197212

198213
impl_eq_hash!(SingleExpression; inner, ty);
@@ -244,6 +259,11 @@ impl Call {
244259
pub fn args(&self) -> &Arc<[Expression]> {
245260
&self.args
246261
}
262+
263+
/// Access the span of the call.
264+
pub fn span(&self) -> &Span {
265+
&self.span
266+
}
247267
}
248268

249269
impl_eq_hash!(Call; name, args);
@@ -355,6 +375,11 @@ impl Match {
355375
pub fn right(&self) -> &MatchArm {
356376
&self.right
357377
}
378+
379+
/// Access the span of the match statement.
380+
pub fn span(&self) -> &Span {
381+
&self.span
382+
}
358383
}
359384

360385
impl_eq_hash!(Match; scrutinee, left, right);
@@ -397,6 +422,11 @@ impl Module {
397422
pub fn assignments(&self) -> &[ModuleAssignment] {
398423
&self.assignments
399424
}
425+
426+
/// Access the span of the module.
427+
pub fn span(&self) -> &Span {
428+
&self.span
429+
}
400430
}
401431

402432
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
@@ -416,6 +446,11 @@ impl ModuleAssignment {
416446
pub fn value(&self) -> &Value {
417447
&self.value
418448
}
449+
450+
/// Access the span of the module.
451+
pub fn span(&self) -> &Span {
452+
&self.span
453+
}
419454
}
420455

421456
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]

src/error.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ impl RichError {
221221
file: Some(file),
222222
}
223223
}
224+
225+
pub fn error(&self) -> &Error {
226+
&self.error
227+
}
228+
229+
pub fn span(&self) -> &Span {
230+
&self.span
231+
}
224232
}
225233

226234
impl fmt::Display for RichError {

src/parse.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ impl Function {
8686
pub fn body(&self) -> &Expression {
8787
&self.body
8888
}
89+
90+
/// Access the span of the function.
91+
pub fn span(&self) -> &Span {
92+
&self.span
93+
}
8994
}
9095

9196
impl_eq_hash!(Function; name, params, ret, body);
@@ -143,6 +148,11 @@ impl Assignment {
143148
pub fn expression(&self) -> &Expression {
144149
&self.expression
145150
}
151+
152+
/// Access the span of the expression.
153+
pub fn span(&self) -> &Span {
154+
&self.span
155+
}
146156
}
147157

148158
impl_eq_hash!(Assignment; pattern, ty, expression);
@@ -165,6 +175,11 @@ impl Call {
165175
pub fn args(&self) -> &[Expression] {
166176
self.args.as_ref()
167177
}
178+
179+
/// Access the span of the call.
180+
pub fn span(&self) -> &Span {
181+
&self.span
182+
}
168183
}
169184

170185
impl_eq_hash!(Call; name, args);
@@ -223,6 +238,11 @@ impl TypeAlias {
223238
pub fn ty(&self) -> &AliasedType {
224239
&self.ty
225240
}
241+
242+
/// Access the span of the alias.
243+
pub fn span(&self) -> &Span {
244+
&self.span
245+
}
226246
}
227247

228248
impl_eq_hash!(TypeAlias; name, ty);
@@ -240,6 +260,11 @@ impl Expression {
240260
&self.inner
241261
}
242262

263+
/// Access the span of the expression.
264+
pub fn span(&self) -> &Span {
265+
&self.span
266+
}
267+
243268
/// Convert the expression into a block expression.
244269
#[cfg(feature = "arbitrary")]
245270
fn into_block(self) -> Self {
@@ -278,6 +303,11 @@ impl SingleExpression {
278303
pub fn inner(&self) -> &SingleExpressionInner {
279304
&self.inner
280305
}
306+
307+
/// Access the span of the expression.
308+
pub fn span(&self) -> &Span {
309+
&self.span
310+
}
281311
}
282312

283313
impl_eq_hash!(SingleExpression; inner);
@@ -344,6 +374,11 @@ impl Match {
344374
&self.right
345375
}
346376

377+
/// Access the span of the match statement.
378+
pub fn span(&self) -> &Span {
379+
&self.span
380+
}
381+
347382
/// Get the type of the expression that is matched.
348383
pub fn scrutinee_type(&self) -> AliasedType {
349384
match (&self.left.pattern, &self.right.pattern) {
@@ -430,6 +465,11 @@ impl ModuleProgram {
430465
pub fn items(&self) -> &[ModuleItem] {
431466
&self.items
432467
}
468+
469+
/// Access the span of the program.
470+
pub fn span(&self) -> &Span {
471+
&self.span
472+
}
433473
}
434474

435475
impl_eq_hash!(ModuleProgram; items);
@@ -458,6 +498,11 @@ impl Module {
458498
pub fn assignments(&self) -> &[ModuleAssignment] {
459499
&self.assignments
460500
}
501+
502+
/// Access the span of the module.
503+
pub fn span(&self) -> &Span {
504+
&self.span
505+
}
461506
}
462507

463508
#[derive(Clone, Debug, Eq, PartialEq, Hash)]

0 commit comments

Comments
 (0)