Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional code context linked with ast node #7

Open
alexeyknyshev opened this issue Apr 23, 2017 · 3 comments
Open

Optional code context linked with ast node #7

alexeyknyshev opened this issue Apr 23, 2017 · 3 comments
Labels

Comments

@alexeyknyshev
Copy link

alexeyknyshev commented Apr 23, 2017

I've faced a problem in reproducing original lua source code from AST. There is a pos field in AST node but is it possible to add optional code context? For example:
I have the following original code:

if a == 3 and b then end

and corresponding AST for it;

{ { { "and", { "eq", { "a",
          pos = 4,
          tag = "Id"
        }, { 3,
          pos = 9,
          tag = "Number"
        },
        pos = 4,
        tag = "Op"
      }, { "b",
        pos = 15,
        tag = "Id"
      },
      pos = 4,
      tag = "Op"
    }, {
      pos = 22,
      tag = "Block"
    },
    pos = 1,
    tag = "If"
  },
  pos = 1,
  tag = "Block"
}

I want to restore orig code for if condition body. On one hand I believe that I can do it via Breadth-first search on the AST, but some info can be missing: some binary comparation operators transformed in non-revertable AST such as >= & <=, etc. Lua comments are dropped and so on.

So as the result there is a bunch of questions:

  1. Is it possible to add some tag and parser for comments to reflect them in AST?
  2. Maybe we should preserve original code format in AST. I mean not combining commutative operators in same tags (comparation operators, constructions like not a == b, etc)
  3. Is it feasible to add original code context to AST node?
  4. Maybe optionally save whilespaces in AST? Can be useful for code structure (indentation based) linting / static analysis.
@alexeyknyshev
Copy link
Author

Hi!
Is there any updates?

@craigbarnes
Copy link

Maybe relevant: fab13n/metalua-parser#8

@andremm
Copy link
Owner

andremm commented Sep 15, 2017

  1. Maybe we should preserve original code format in AST. I mean not combining commutative operators in same tags (comparation operators, constructions like not a == b, etc)

@alexeyknyshev I'm sorry for the delay, but I removed these combinations due to issue #12 and now the AST have all relational operators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants