digital-scurf wikiAranha > Language Modifications

Modifications to the Lua language/interpreter

Most of Aranha will be implementable inside the framework provided for by the Lua 5.0 interpreter. However there will be a few modifications made to the language which are detailed below.

Diverted printing

Aranha includes a concept called the diverter (Documented here: Aranha/OutputDiverter). One of the ways of writing text to the diverter includes the use of >> and << as delimiters in a long-string type fashion. This requires slight changes in the long-string lexer and support in the parser for a dprint_string to show up as a statement.

Touches:

  1. am tempted to drop this patch in favour of a soft-implementation of a preprocessor. This patch will be much harder to implement if we're after the <? ?> <?aranha ?> and similar delimiters also. The soft implementation may end up using a derivative of LuaParse? or similar.

Method Calls

The foo:bar() syntax involves the OP_SELF op code where foo.bar() involves OP_GETTABLE. Since OP_SELF is used only for the colon-method-call syntax, we're safe to alter it to using a new metamethod. We propose the introduction of the __methcall metamethod whose purpose would be identical to __index (indeed the OP_SELF code will fall back to __index if __methcall is not present) but would only be used for method-call expression evaluation.

Touches:

The patch from [here] supplies the requisite changes.

C Style comments

The // and /* */ comment style is known to lots of people and preferred by many to Lua's -- and --[[ ]] style of comments. The following patch (when added into llex.c around line 386 or so) supports those styles of comments. As it is a very small patch and no licence was supplied with it, it is assumed to be under the same licence as the rest of Lua.

      //Dan East: support for // and /* */ style comments
      case '/':
        next(LS);
        if (LS->current == '/') {
          while (LS->current != '\n' && LS->current != EOZ)
            next(LS);
          continue;
        } else if (LS->current == '*') {
          next(LS);
          while (LS->current != EOZ) {
            if (LS->current == '*') {
              next(LS);
              if (LS->current == '/') {
                next(LS);
                break;
              }
            }
            next(LS);
          }
          continue;
        } else
          return '/';

Table constructors

It would be very convenient if instead of:

foo = {
  bar = function() ... end,
  baz = function() ... end,

  age = 12
}

we could do something like:

foo = {
  function bar() ... end
  function baz() ... end

  age = 12
}

The table constructor syntax currently requires commas separating items. Also the ability to declare functions in the same way would be bliss, especially for the Aranha/ClassesAndObjects system described for Aranha. Adding this is a slightly less simple patch than the C style comments. [This] is the patch needed. Note that this patch also implements the following syntax elements:

foo = { function :bar() ...something involving self... end }

baz = function : () ...something involving self... end }

The critical things there being the support of the colon to indicate that the functions need the implicit 'self' parameter for method calls.

Touches:


Stuff which requires 5.1

Documentation strings

In an attempt to make it easier to introspect documentation in the language, documentation strings would be very very useful. The only things in the language which make sense to have documentation attached to are tables and functions. (An entire file classes as a function declared as: function (...).....end in new-style vararg syntax)

This allows for syntax of the form:

function frobbleThingy(thingy)
   -=-
   Frobbling involes taking a thingy and murfling it and then tickling it

   @param (Thingy)thingy The thingy to frobble
   @return (FrobbledThingy) The thingy once frobbled.
   -=-

   thingy.murfle()
   return thingy.tickle()
end

And similar syntax for tables and for files.

The patch for this is very invasive and not yet finalised.