ldoc icon indicating copy to clipboard operation
ldoc copied to clipboard

moon: distinguish static/class members

Open s-ol opened this issue 4 years ago • 1 comments
trafficstars

This PR fixes #229.

It introduces a new flag @classmethod that works together with @static to define the relationship between methods, class functions, class methods, etc. The moonscript parser automatically applies them inside classes as follows:

@static: if the member is a function, and the function is defined using => (not ->), it is considered a static member. @classmethod: if the member name starts with an @, it is considered a 'classmethod' member.

The two tags are used when formatting members as follows:

  • @classmethod decides whether the class name (original casing) or the instance naming (a lowercased version of the class name) is used when printing the member
  • @static decides whether the "method call" token (: or \) or the "index" token (.) is used between class/instance name and member name.
class Example
  inst_method: =>
  inst_fn: -> -- @static
  @class_method: =>  -- @classmethod
  @class_fn: -> -- @classmethod @static

Example\class_method!
Example.class_fn!

inst = Example!
inst\inst_method!
inst.inst_fn!

I think that the meaning of static and classmethod are now essentially reversed. The reason is that before this PR, there was only static. It's probably a bad idea to rename an existing tag (for backwards compatibility), but we could probably come up with something better than the misleading @classmethod.

s-ol avatar Jan 08 '21 10:01 s-ol

@alerque seems like CI is just generally broken?

Maybe @classmember is a better name.

The other question that needs to be cleared up is the lang.method_call setting that I had changed from \ to : in my branch. This needs testing with either setting to remember whether there was / what was the issue with backslashes.

s-ol avatar Jan 08 '21 11:01 s-ol