Skip to content

petter/pts-lang

Repository files navigation

PTS (Package Template Script) / An implementation of Package Templates in TypeScript

Using PTS in a project

Initialize the project

mkdir <name of project>
cd <name of project>
npm init -Y
npm install pts-lang

Add a start and/or build script to package.json:

{
  "scripts": {
    "start": "pts-lang -i src/index.pts --run",
    "build": "pts-lang -i src/index.pts -o build/index"
  }
}

The start script only runs the program, and doesn't emit any files, while the build script transpiles the src/index.pts file to JavaScript. If you'd rather have TypeScript as output you can use -t:

pts-lang -i src/index.pts -o build/index -t ts

TODOs

  • Instantiating closed templates
  • Renaming classes
    • Rename class declarations
    • Rename class heritage
    • Rename class instantiations
    • Rename member_expressions on static class fields (i.e. A.k)
    • Rename other class references, i.e. as a type (Maybe enough to have another pass on type_identifiers)
  • Renaming fields
    • Rename field declaration (public_field_definition)
    • Rename this.x from same class (local member_expressions)
    • Rename this.x from super class (member_expressions)
    • Rename other references to fields, i.e. member_expressions of variables, a.i
  • Merging classes
    • Merge bodies of two classes
    • Checking if it is valid to merge classes (Do they have different heritage?)
    • Merge heritage
  • Addto statements
    • Check if the class to be added to exists
    • Merge bodies of the class and addto-statement
    • Add implementing interfaces and extended classes to the class
    • Override attributes
  • Validating templates