lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Also in my view, all annotations are to be considered optional, they create an "intermingled" meta-language which is to be interpreted by another engine (a compiler, some specific runtime, a debugger) but they should all be safely removed and the code should still be valid and interpretable by a core Lua engine.

The metalanguage however can be written in Lua too just like the engine interpreting it.

But a basic annotation "const" or "toclose" are not meaningful isolately as a plain statement for a metalanguage, they make sense only with the core language statement toi which they are directly associated (i.e. always after the statement starting token but before any declared item and any _expression_). What they annotate can only be used by a compiler (as type hints) but not directly by the runtime engine, a debugger or tracking logger (whose behavior cannot be controled by these annotations, if they use these annotations, it is only to interpret the item in the core language with which they are necessarily associated).



Le sam. 8 juin 2019 à 06:04, Philippe Verdy <verdy_p@wanadoo.fr> a écrit :
I see only a single useful case for annotating an empty statement (i.e. just after any single ";" which is always isolated and has no further tokens in any context), it's for emitting some debugger info (or execution tracking logger, or breakpoint) that applies to a reachable point of execution, i.e. between two separate statements that are otherwise not themselves annotated by it.


Le sam. 8 juin 2019 à 05:55, Philippe Verdy <verdy_p@wanadoo.fr> a écrit :
And given the way Lua parses the ";" (only as an empty statement, which is a no-op), adding an annotation just after it would make no sense.
There's no way to unambiguously allow any annotation in Lua at *start* of any statement: it must necessarily be in the middle of the statement before any _expression_ (it can follow an "," separator too, which probably makes sense only if there's something after it which is not the end of the comma-separated list) or just at end of the statement.



Le sam. 8 juin 2019 à 05:44, Philippe Verdy <verdy_p@wanadoo.fr> a écrit :
Yes but Java requires the ";" terminator, so there's no ambiguity when parsing, even if the annotation precedes all the rest of the statement.

In Lua, without the required ";" there will an ambiguity of parsing if the annotation does not follow immediately a statement initial keyword (local, function, for, return, if, then, else, begin...), or a "(" or "[" or "{".


Le ven. 7 juin 2019 à 18:07, Dibyendu Majumdar <mobile@majumdar.org.uk> a écrit :
> There is a big difference between all those syntaxes
[snip]
> They are all prefixed to the whole item to which they
> apply. Following their syntax, we should write '@toclose local x = 1',
> instead of 'local @toclose x = 1'.
>

In Java the annotation precedes the type in a declaration; it being
classed as a type modifier in the grammar (this is one of the uses).
Lua of course doesn't have type declarations therefore annotations
cannot be placed in the same way.

Regards