Skip to content

A simple super set language of Lua. adds new syntax and features ontop of Lua 5.4

License

Notifications You must be signed in to change notification settings

return5/Project-Dysnomia

Repository files navigation

Project Dysnomia: adding syntax and features on top of Lua 5.4

  • The stated goal of this project is to build on top of Lua 5.4 with new syntax, features, and enhancements.

  • Takes dysnomia files and cross-compiles them into syntactically correct lua 5.4 files.

  • this repo is a huge rewrite of my previous attempt.

  • (currently this is a work in progress.)

  • this project has been rewritten entirley in dysnomia. check it out here (currently out of date)

requirements

  • Lua >= 5.4

installing

the easiest way to install is to grab the single file version of it here. (checkout squish)
you can then place that file anywhere you want, maybe even make an alias or put it on your system path for easy use.

alternatively download the source code of the project and run lua dysnomia.lua

running

simply pass into dysnomia any dysnomia flags and the file which serves at the starting point of your application.
dysnomia will parse through the .dys files and (by default) run the Lua program.
sample command to run dysnomia:
lua dysnomia.lua [flags] [main file]

dysnomia flags

a list of the flags and command line options for dysnomia:

  • -parse only parse through files, do not run the program after parsing.
  • -os [os name] enter the os type you are using, such as linux or windows.
  • -sep [separator] the file separator used by your OS for filepaths.
  • -nl [char(s)] enter the newline character(s) which your OS uses.
  • -skip [file(s)] comma separated list of files to skip over.
  • -perm Do not remove generated files after running.
  • -temp remove all generated files after running.(default)
  • -help print help screen.

features, syntax changed, and enhancements

  • update operators (please see update Ops section)
    • +=
    • -=
    • /=
    • *=
  • by default, all vars are local and const.
  • var keyword. declares a variable.
    • var myVariable
  • global keyword. declares a variable, Record, or function to not be local
    • var myVar <global> = 5
    • global function myFunc() return 5 end
    • global Record myRecord
  • mutable keyword. declares a variable is mutable.
    • var myVar <mutable> = 6
  • class keyword. declares a class. (please see class section)
    • class myClass(var1,var12,var3) endCLass
  • :> used to declare inheritance of class. (please see class section)
    • class childClass() :> parentClass endClass
  • super() calls parent constructor inside of class. (please see class section)
    • super(var1,var2)
  • record immutable collection for holding data. (please see records section)
    • record MyRecord(a,b,c,d) endRec
  • lambdas shorthand syntax for declaring an anonymous function. (please see lambda section)
    • a -> a + 5
  • #skipRequire add this in a comment on the line directly above any require statement to tell dysnomia to ignore that file. dysnomia will not attempt to parse the file included in the require.
      -- #skipRequire
      var myRequire = require('myFile') --dysnomia will not scan this file.
    
  • #skipfile #skipFile #Skipfile #SkipFile add one of these in a comment to tell dysnomia to skip scanning and parsing of this file.

UpdateOps

assigns the value of the right hand expression, the math operator in front of the equals sign, and the variable on the left to the variable.
i += 1

  • equivalent to: i = i + 1

can assign to more than one var at a time: i,j += 1,2

  • equivalent to i = i + 1; j = j + 2

if there are more variables on the left hand side than on the right hand side, then the last variable on the right hand side is repeated: i,j,k += 1

  • is equivalent to: i = i + 1; j = j + 1; k = k + 1

if the repeated value on the right hand side is a function call, then it will be called only once, assigned to a variable, then that variable is used in its place.
i,j,k += returnFive()

  • is equivalent to: local __temp1 <const> = returnFive(); i = i + __temp1; j = j + __temp1; k = k + __temp1

class

offers class declaration inspired by java records.
basic syntax is: class keyword followed by class name.
then include any parameters to pass into constructor and a parent class if it is a child class.
finally, close with endClass:
class MyChildClass(param1,param2) :> MyParentClass endClass

  • if no constructor is provided, then one will be created automatically.
  • constructor declares a class constructor.
    • constructor(param1,param2) end
  • super calls the parent constructor. needs to be included if you include a constructor and class has a parent class.
    • super(param1)
  • you may declare class methods inside the class:
    • method myMethod(a,b) end
  • static declares a method to be static rather than an instance method.
    • static method myMethod()
  • to access class variables you use the self keyword
    • self.myVar = 6
  • self is not needed when accessing class methods
    • myMethod(5,6)
      • translates to: self:myMethod(5,6)
  • :> used in class declaration to declare a parent class.
  • new objects can be instantiated from class by calling the new function on the class.
    • var myObj = MyClass:new(var1,var2)
  • local declares a function to be local.
    • local function myFun(a,b) end
  • global declares that a function is global in scope.
    • global function myFunc(a,b) end
  • metamethod declares a metamethod on the class
    • the metamethods are the standard metamethods for lua objects.
    • metamethod add(c1,c1) return c1.a + c2.a end
  • note: spaces are required between keywords in declaration.
  • note: classes need to be declared inside their own separate file.

records

An immutable object for storing data. declare the number and names of the parameters. call it like a function to generate objects from it.

record MyRecord(a,b) endRec
var rec = MyRecord(5,6)
  • by default records are local.
  • unlike classes, they do not have to be declared inside their own file.
  • like classes, they can have methods,metamethods, and constructors.
    • unlike classes, record constructors take in no parameters. they use the parameters used in the record declaration.
      • constructor() self.a = a end
  • records can be declared global
    • global record MyRec(c,d) endRec

lambda

A shorthand syntax for declaring an anonymous function.

  • a single parameter, single statement can be declared as:

    • a -> a+5
    • this is, a function which takes in one input 'a' and returns 'a' + 5. equivalent to the lua code:
      • function(a) return a + 5 end
    • for single input, no parenthesis are needed.
    • for single statement body, no brackets are used nor is 'return' used.
  • a no parameter lambda can be declared as:

    • () -> 5
    • this, a function which takes no input and returns the number 5.
    • for zero inputs, parenthesis must be used.
  • multiple input lambda can be declared as:

    • (a,b) -> a+b
    • that is, a function which takes two inputs and returns their values added together.
    • for multiple inputs, parenthesis must be used.
  • multiple statement lambdas:

    • (a,b) -> { if a < 5 then return b end return a}
    • a function which takes in two inputs, if the first is less than 5 then return second input, otherwise return the first argument.
    • for multi-statement lambdas, curly brackets and 'return' statement must be used.
  • just as an FYI, lambdas arnt picky about spaces.

    • a->{if a<5 then return 5 end return 5}
    • perfectly valid to have spaces between parameters, '->', curly brackets, etc.

considerations

to keep the parser simpler and easier to write, there are a few things to keep in mind when writing dysnomia syntax.

  • when declaring classes, the keywords in class declarations should have spaces around them. the parameters, if any, should not have spaces.
    • class MyClass(par1,par2,par3) :> MyParentClass endClass
  • classes need to be declared inside their own separate file.
  • for simplicity reasons, the out putted lua code isnt as readable nor optimized as handwritten code.
    it is entirely readable, but may not be formatted well. under normal use cases this isnt a problem as it would only need to be read in a debugging session.

dysnomiaExamples

please see the dysnomiaExamples directory for examples of dysnomia.

About

A simple super set language of Lua. adds new syntax and features ontop of Lua 5.4

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages