question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reflect parentheses that discard extra values in the AST

See original GitHub issue

Currently, the latest released version does not distinguish e.g. f() from (f()) in the AST. These expressions are not equivalent; the former evaluates to all the return values of f(), and the latter evaluates to only the first of them (the rest are discarded). Current git master distinguishes them by the inParens field, but that is just a workaround for #24 and I expect to remove it when that issue is fixed properly.

A more principled approach to distinguishing these expressions is desired. I may keep the inParens field, or I may introduce a new kind of node that expresses the operation of discarding extra values.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
fstirlitzcommented, Jan 16, 2020

There are two kinds of expressions which may evaluate to a value tuple: function calls and the vararg literal, .... There are also five places where discarding extra values matters, all of which are in a context where a multiple-value expression appears as the last one in a comma-delimited list of expressions:

  • table constructors ({ a, b, (...) }; table constructors can also use ; as delimiters, and accept trailing delimiters)
  • simultaneous assignment (a, b, c = d, e, (...))
  • argument lists (f(a, b, (...))
  • for-in loops (for a, b, c in d, e, (...) do --[[ ... ]] end)
  • return statement (return a, b, (...))

In the last of these, parenthesising the only expression also has the effect of preventing tail-call optimisation. This suggests a representation as a new type of node, so that tail calls can be detected simply by checking whether a function-call node appears as a direct child of the return node. This will be a breaking change for users who are not prepared to deal with unknown node types; luamin by @mathiasbynens would be one. In this case it’s arguably a good thing anyway, because as of now luamin will just perform minification incorrectly on code affected by this defect.

Alternatively, I might treat parentheses as a circumfix unary operator, and piggyback on the UnaryExpression node type to reflect it in the AST.

Lua manual links: 5.1 §2.5, 5.2 §3.4, 5.3 §3.4

0reactions
cohlercommented, Dec 20, 2022

This is a MAJOR BUG giving a totally useless and INCORRECT parse. Why hasn’t anyone fixed this yet?

Read more comments on GitHub >

github_iconTop Results From Across the Web

ast — Abstract Syntax Trees — Python 3.11.1 documentation
If the attributes can have zero-or-more values (marked with an asterisk), the values are represented as Python lists. All possible attributes must be...
Read more >
Bracket pair colorization 10000x faster - Visual Studio Code
Querying such an AST to list all brackets and their nesting level in the viewport is relatively simple: do a depth-first traversal, compute...
Read more >
Remove enclosing brackets from a string in C# [closed]
Try this: yourString = yourString.Replace("[", string.Empty).Replace("]", string.Empty);. Updated answer since the question was edited:
Read more >
Custom Excel number format - Ablebits
This tutorial explains the basics of the Excel number format and provides the detailed guidance to create custom formatting.
Read more >
Objects - The Modern JavaScript Tutorial
An object can be created with figure brackets {…} with an optional list of properties. A property is a “key: value” pair, where...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found