Git Product home page Git Product logo

Comments (7)

benreynwar avatar benreynwar commented on June 14, 2024

I had naively started to implement (1) but I like your solution (3) much better. I'll let you know once I've got something worth looking at.

from rust_hdl.

benreynwar avatar benreynwar commented on June 14, 2024

Thinking about how to deal with comments at the end of the file. There won't be a token that it makes sense to associate them with. I'll just create a FinalComment token. Since this can only occur in one place, the parsing change will be minor.

from rust_hdl.

benreynwar avatar benreynwar commented on June 14, 2024

I've been thinking about this some more (and trying to take the next step to moving the comments from the tokens to the AST) and I'm not happy about how I have implemented it so far. In the current implementation I assigned all comments to a token. Most positions don't make any sense and we need to gather up all those comments to either move them or emit warnings for them. This gathering gets messy.

I would like to remove the comments from the tokens and implement the following methods on the Tokenizer:

// Gets the leading comments for the next token.
pub fn get_leading_comments(&mut self) -> Vec(Comment);
// Gets the trailing comment for the previous token.
pub fn get_trailing_comment(&mut self) -> Option(Comment);
// Returns a vector of all the comments that were parsed since we last
// handled.  Does not include comments that were
// retrieved using get_leading_comments or get_trailing_comment.  This
// is useful if we wish to move all these comments to a new location or to
// generate warning messages from them.
pub fn handle_new_comments(&mut self) -> Vec(Comment);

So if we were parsing a type_definition:

  1. Assert that there aren't any already parsed comments that haven't been handled.
  2. Get the leading comments for the definition.
  3. Parse the definition.
  4. Get the trailing comment.
  5. Get the comments that weren't handled. Either combine them into the other comments, or ignore them. Generate warning messages either way.
  6. Add the combined comment (probably a latin_1_str) into the type_definition object.

The main complexity is dealing with set_state since that should modify the vector of unhandled comments. We could replace set_state with move_backwards which just drops any unhandled comments from the list if their position is ahead of the new state. The other main use of set_state is in move_after(token) which seems to be exclusively used for moving after a peeked token. This could be replaced with move_after_peek() which just moves after the token previously peeked. The state and unhandled comments could be stored in the Tokenizer whenever a peek is performed.

Does this seem like a reasonable approach?

from rust_hdl.

kraigher avatar kraigher commented on June 14, 2024

I agree with the approach.

from rust_hdl.

benreynwar avatar benreynwar commented on June 14, 2024

I've reworked the comment parsing along these lines in #30.
I'm still working on improving the tests and getting the comments into the AST.

from rust_hdl.

m-kru avatar m-kru commented on June 14, 2024

@benreynwar what has happened with the PR, what is the current status?

from rust_hdl.

benreynwar avatar benreynwar commented on June 14, 2024

It's abandoned. I'm trying to focus my 'fun work' time on ghdl now.

from rust_hdl.

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.