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

treequery/walk.mlua doesn't work if following the walker document #24

Open
wanghc78 opened this issue Jun 17, 2014 · 3 comments
Open

treequery/walk.mlua doesn't work if following the walker document #24

wanghc78 opened this issue Jun 17, 2014 · 3 comments

Comments

@wanghc78
Copy link

If I follow the document http://metalua.luaforge.net/manual004.html#toc9 to write an ast walker, such as

  local cfg      = { expr  = { },
                      stat  = { },
                      block = { } }
  cfg.expr.down = function(x) ... end
  walk.guess(cfg, term)

The walker doesn't work. The function returned by walker_builder() in walk.mlua cannot get the correct cfg up/down functions from the input cfg.

The below changes can fix it.

208c208,209
<       local down, up = cfg.down, cfg.up

---
>       local cfgt = cfg[traverse]
>       local down, up = cfgt and cfgt.down, cfgt and cfgt.up

However, I found the current treequery.mlua will use cfg's first level methods. It seems the issue is still caused by some refactoring inconsistence.

@wanghc78 wanghc78 changed the title treequery/walk.mlua doesn't work treequery/walk.mlua doesn't work if following the walker document Jun 17, 2014
@fab13n
Copy link
Owner

fab13n commented Jun 17, 2014

Thanks, I need to review this more carefully. The generic idea is that walk proved unpracticall to use, so I wish to mostly deprecate it and encourage people to use treequery instead; but that's no reason for it not to work.

@wanghc78
Copy link
Author

Thanks! The treequery is very nice. I'm using it for some analysis. Regarding the bug, my feeling is the original walk requires a two-level cfg with the first level three children "expr", "stat", "block". The current tree query always construct a one level cfg, and the walk code was changed to support the one level structure. If I pass in a two-level cfg into the walk, the code cannot find the right functions.

@wanghc78
Copy link
Author

I think this issue is not a bug in the source code. It is from the inconsistency between the 0.5 document http://metalua.luaforge.net/manual004.html#toc9. and the current walk implementation. This form works in the current code.

local cfg = { down = function(x) ... end}
walk.guess(cfg, ast)

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

No branches or pull requests

2 participants