boolangery / py-lua-parser

A Lua parser and AST builder written in Python.
MIT License
115 stars 36 forks source link

[Bug] Some Comment Data Ignored #17

Closed TurtleP closed 2 years ago

TurtleP commented 2 years ago

Hi,

It seems that although the parser can detect comments properly, it fails to assign all of it to the node (sometimes?). I know that sounds rather vague, but let me give you an example.

I have in a Lua file, the following comment at the top of the file:

--[[
- @file server.lua
- @brief This is the server file that the client connects to
--]]

When I dump the node data for this file, I can see that the entirety of that file's Chunk contents sees the whole comment:

Chunk: {} 4 keys
  comments: [] 1 item
    0: '--[[\n- @file server.lua\n- @brief This is the server file that the client connects to\n--]]'
...

However, if I use a Visitor class to handle finding the first item I want, @file ... it fails to find it. If I were to print the comment, since it's multiline, I get this:

====================
server.lua
--[[
- @brief Initialize the server protocol.
--]]
...
====================

To be certain, I also tried checking if the parser somehow put it as non-multiline:

====================
server.lua

====================

It should be noted, though, all the other comments are fine and intact, following a similar syntax.

That aside, thank you for creating this useful python package! :)

If you need to see my source code at all, please let me know and I'll gladly provide it. Currently I haven't pushed the python code, but the Lua code is readily available on my GitHub.


P.S. I also would like to know if there's a way to determine where the comments/functions/etc are, but I think that would require a feature request to add line numbers where each Node item starts.

TurtleP commented 2 years ago

Hm.. After moving forward with some of my code, it seems to be working fine? I'm not entirely sure. I'm currently using Windows Terminal to output the data, so if that's causing interference I'll close the issue.

TurtleP commented 2 years ago

Seems like it must have been Windows Terminal at some point. I'm really not sure, but it's resolved now.