Giter Site home page Giter Site logo

Accessing comments through AST about gopher-lua HOT 9 CLOSED

yuin avatar yuin commented on August 25, 2024
Accessing comments through AST

from gopher-lua.

Comments (9)

yuin avatar yuin commented on August 25, 2024

As comments are read and thrown away, you can not access comments through ASTs.
Instead, you can implement a library like lua-annotate.

from gopher-lua.

otm avatar otm commented on August 25, 2024

There is no way to change the implementation of the tokenizer so the comments are not thrown away and can be analyzed in the AST?

The reason is that it makes the desired syntax to complex.

from gopher-lua.

yuin avatar yuin commented on August 25, 2024

ASTs in the GopherLua are currently just an intermediate-representing format for translating source codes to byte codes.
GopherLua's ASTs do not have interfaces like visitors, therefore, it is probably hard to analyze ASTs even if comments were not thrown away by the GopherLua parser.
I’m now busy with my work and I can't get much time to make these major alteration.

It might be good idea for you to fork the GopherLua and make it what you want.

from gopher-lua.

otm avatar otm commented on August 25, 2024

I will take a look at it. I might write a tiny purpose built tokenizer for this, as I'm only interested in functions and comments associated with them.

However, if you have any pointers on how to implement this is gopher-lua I'm interested. Also, would you be interested in a pull request regarding this?

from gopher-lua.

yuin avatar yuin commented on August 25, 2024

However, if you have any pointers on how to implement this is gopher-lua I'm interested.

If I were you, I would not use ASTs.

1. LFunction objects have a FunctionProto object. This allows you to know where the function was defined.

lineDefined := fn.Proto.LineDefined

2. Read the .lua source file and check whether a line:lineDefined - 1 starts with -- .
3. If line:lineDefined -1 starts with --, parse this line as a directive.

Also, would you be interested in a pull request regarding this?

If you implement AST analyze functions and it is not causes significant performance degradation, I would like to consider merging.

from gopher-lua.

otm avatar otm commented on August 25, 2024

Thanks for the help! That is actally a really neat idea. I think that will work well.

Again, thanks for a really nice project.

from gopher-lua.

otm avatar otm commented on August 25, 2024

Your idea worked perfectly. I wrote a small tokenizer for Lua comments which emitted comments and line number and then used fn.Proto.LineDefined to check if there was a comment associated with the function.

from gopher-lua.

yuin avatar yuin commented on August 25, 2024

Good to hear πŸ‘

from gopher-lua.

flzyup avatar flzyup commented on August 25, 2024

I have a question, how do i get the the LFunction instance to read line number when i exe lua file or lua string. As we register global function as the following:

L.SetGlobal("double", L.NewFunction(Double)) /* Original lua_setglobal uses stack... */

from gopher-lua.

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.