lua-users home
lua-l archive

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


It was thus said that the Great Dibyendu Majumdar once stated:
> On Thu, 25 Apr 2019 at 06:54, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> >
> > Op Do. 25 Apr. 2019 om 03:33 het Philippe Verdy <verdy_p@wanadoo.fr> geskryf:
> > > I also agree that the "*xxx" or "*(xxx, params...)" syntax is very fuzzy and will not work with the future evolution of annotations
> > >
> > > Le jeu. 25 avr. 2019 à 00:22, Dibyendu Majumdar <mobile@majumdar.org.uk> a écrit :
> > >> I am writing about this again in the hope that it is not too late to
> > >> change the syntax of the *toclose attribute. I think there is an
> > >> opportunity to allow a general way of introducing annotations in Lua,
> > >> which can be exploited by extensions. It would be sad if that
> > >> opportunity is lost.
> >
> > Therefore I would suggest that an annotation starts with ! and
> > continues until but not including the first termination character.
> > Sensible termination characters might be comma, semicolon and end-of
> > line, allowing annotations for every item in a parameter/return list,
> > table constructor etc, but not encumbering the parser with a difficult
> > decision whether the annotation is done. In the contex of "local", an
> > empty annotation could default to 'toclose', so that "local a!, b, c!`
> > is all that one needs to supply "toclose" directives.
> >
> 
> I would suggest that the syntax should be:
> 
> <special character><optional name><optional table with only literal
> keys and values>

  So I'm looking at Java because they now have annotations.  From a cursory
look, it appears the syntax to be:

	'@' ID

  So things like

	@Override
	@Deprecated
	@SuppressWarnings

  Annotations can be used at development time, compile time or runtime [1]. 
They can also be targetted towards a particular usage [2].  In Java, custom
annotations are handled with creating an interface.

  Assuming we use something similar to Java, the "to-close" annotation of
Lua 5.4 could probably look somthign like:

	@target(local)
	function @to_close(var)
	  -- whatever this does
	end

	do
	  local @to_close file = io.open(...)
	  lcoal @to_close obj  = custom:blah(...)
	  -- code code code
	end
  
> So assuming your choice of !, we could have:
> 
> local a!
> local b !go_to_space { when=true }
> local c !array { 20 }

  Well ...

	local @my_annotation a
	local @go_to_space { when = true } b
	local @array(20) c

where '@array' is a special function called with certain parameters
depending on what it's targetting and any parameters given to it.  Too
magical?  Not magical enough?  Too much like Java? I don't know, it's
beginning to look a bit heavy to me.

  -spc

[1]	https://stackoverflow.com/questions/1372876/how-and-where-are-annotations-used-in-java

[2]	https://beginnersbook.com/2014/09/java-annotations/