Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How integrate with codespan or similar? or: How get the original source? #125

Open
mamcx opened this issue Dec 8, 2021 · 1 comment
Open

Comments

@mamcx
Copy link

mamcx commented Dec 8, 2021

I'm looking if move my parsing to rowan, and one thing looks complicated. I wish to also have nice error reporting, like using codespan, but have trouble making the integration. As I see it today, I need to keep 2 copies of the whole source code to make both:

pub type File = SimpleFile<String, String>;  <-- Copy for reports
pub struct FilesDb {
    files: SlotMap<FileId, File>,
}

//Interface to my source code, this is where I need to mix...
impl<'a> Files<'a> for FilesDb {
    type FileId = FileId;
    type Name = String;
    type Source = &'a str;

    fn name(&self, file_id: FileId) -> Result<Self::Name, Error> {
        Ok(self.get(file_id)?.name().to_string())
    }

    fn source(&'a self, file_id: FileId) -> Result<Self::Source, Error> {
        Ok(self.get(file_id)?.source().as_ref())
    }

    fn line_index(&self, file_id: Self::FileId, byte_index: usize) -> Result<usize, Error> {
        self.get(file_id)?.line_index((), byte_index)
    }

    fn line_range(&self, file_id: Self::FileId, line_index: usize) -> Result<Range<usize>, Error> {
        self.get(file_id)?.line_range((), line_index)
    }
}

Now, I see I can allocate the code from the green_nodes:

parser.green_node.to_string()

But then is again a double-copy. How I can get the nodes that are part of the range of an error? Or index into the line/col, etc?

@matklad
Copy link
Member

matklad commented Dec 9, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants