Reflect parentheses that discard extra values in the AST
See original GitHub issueCurrently, 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:
- Created 4 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:{ a, b, (...) }
; table constructors can also use;
as delimiters, and accept trailing delimiters)a, b, c = d, e, (...)
)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
This is a MAJOR BUG giving a totally useless and INCORRECT parse. Why hasn’t anyone fixed this yet?