Skip to content

Commit

Permalink
Merge pull request #993 from candy-lang/660-format-cst-rcst-in-candy-…
Browse files Browse the repository at this point in the history
…debug

Implement ToRichIr for Cst
  • Loading branch information
jwbot authored Mar 21, 2024
2 parents 25cd24b + f0d7741 commit 888674e
Show file tree
Hide file tree
Showing 7 changed files with 525 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ callgrind.out.*
# ANTLR
.antlr/

# direnv
.direnv/

# Rust
target

Expand Down
23 changes: 19 additions & 4 deletions compiler/frontend/src/cst/id.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
use crate::impl_countable_id;
use std::fmt::{self, Display, Formatter};
use crate::{
impl_countable_id,
rich_ir::{RichIrBuilder, ToRichIr, TokenType},
};
use enumset::EnumSet;
use std::fmt::{self, Debug, Display, Formatter};

#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Id(pub usize);

impl_countable_id!(Id);

impl Debug for Id {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "${}", self.0)
}
}
impl Display for Id {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "CstId({})", self.0)
write!(f, "${}", self.0)
}
}
impl ToRichIr for Id {
fn build_rich_ir(&self, builder: &mut RichIrBuilder) {
let range = builder.push(self.to_string(), TokenType::Variable, EnumSet::empty());
builder.push_reference(*self, range);
}
}
Loading

0 comments on commit 888674e

Please sign in to comment.