Git Product home page Git Product logo

Comments (5)

jyn514 avatar jyn514 commented on July 30, 2024

This is a good idea, but it's going to be really hard. Locations will have to be expanded to keep track of each macro along the way, which means they can no longer be Copy and there will suddenly be a lot of lifetime errors.

Maybe there should be some sort of lookup table for locations so that they don't have to be passed along with each struct? I don't think HashMap<dyn Hash, Location> is a thing, though.

from saltwater.

hdamron17 avatar hdamron17 commented on July 30, 2024

The Locations of #defines are stored in a map somewhere already, I assume? So could we instead add an Option<InternedStr> member to Token::Id which points to where it which macro replaced into it? Then if there's an error, we can do a recursive lookup until None.

from saltwater.

hdamron17 avatar hdamron17 commented on July 30, 2024

Or if the Locations of #defines aren't already stored somewhere, then lex::replace::Definitions could be changed from

pub type Definitions = HashMap<InternedStr, Definition>;

to

pub type Definitions = HashMap<InternedStr, (Definition, Location)>;

Not sure if this will mess with lifetimes.

from saltwater.

jyn514 avatar jyn514 commented on July 30, 2024

@hdamron17 sure, making it a HashMap<InternedStr, Locatable<Definition>> isn't hard. The hard part is tracing back from the replaced version to the original. By the time this error occurs in the parser, all context about macros has been lost, there's only tokens left and you can't tell if they originated from a macro or not.

from saltwater.

jyn514 avatar jyn514 commented on July 30, 2024

I guess a linked list isn't the worst thing since most replacements shouldn't be highly nested. I'm a little concerned about memory usage but we can always worry about performance later.

from saltwater.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.