Comments (9)
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.
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.
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.
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.
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.
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.
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.
Good to hear π
from gopher-lua.
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)
- Function names do not support UTF-8/Unicode
- Virtual machine interfaces need to be advertised
- bug: pcall affecting function upvalues HOT 4
- xpcall with error in error handler returns (nil, nil)
- The parameter passed by xpcall is nil
- different behavior in read function HOT 1
- Expand fopen modes
- different behavior in io.popen function
- Incorrect behavior for string.gmatch
- stuck when xpcall HOT 3
- LNumber.String() use strconv instead of fmt.Sprint HOT 1
- Can't require lua-cjson
- tonumber doesn't handle E notation correctly HOT 1
- γBUGγpanic: runtime error: index out of range [1048577] with length 1048577 HOT 2
- os.execute not behaving correctly on windows
- Result of L.DoString with coercion is not correct
- Extra PC increment in JMP instruction
- Error from parsing from LString to LNumber
- Incorrect code generation for `LOADNIL`
- Memory usage is too high
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gopher-lua.