Skip to content

Instantly share code, notes, and snippets.

@lucaswerkmeister
Last active November 18, 2017 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucaswerkmeister/a4da0fa5d9d5b14cc3e9 to your computer and use it in GitHub Desktop.
Save lucaswerkmeister/a4da0fa5d9d5b14cc3e9 to your computer and use it in GitHub Desktop.
Ideas for ceylon-ast source gen

Input: Type Supertype (ParamType paramName)*

Generates:

  • The class with
    • header:
      "TODO document"
      shared class $Type($paramName, ...)
              extends $SuperType(TODO args) {
          
          shared actual Result transform<out Result>(Transformer<Result> transformer)
                  => transformer.transform$Type(this);
    • equals – gets finicky for optional types, we might want to let eclipse generate this? On second thought, no. I’m currently not letting eclipse do that because I’m hesitant which attributes it will use. It shouldn’t be too hard to get this right.
    • hash – watch out for optional params!
    • copy
  • Additional line in Transformer, WideningTransformer (use $SuperType), Editor (=> copy(transform$ParamType($paramName), ...) – don’t care that it’s not always correct), Visitor (+ visit)
    • keep alphabetical sorting
  • Additional method in CeylonExpressionTransformer – generate => "$Type(``transformWithIndent(that.$paramName)``, ...)";, don’t care that it’s not always correct
  • Additional import J$Type=$Type and method to RedHatTransformer
  • New file $Type.ceylon in backend, with imports, $TypeToCeylon(J$Type) and compile$Type (probably empty)
  • New file $Type.ceylon in test-backend, with imports and conversion and compilation test (no samples)

We could also read documentation on stdin (until Ctrl+D). Can be detected because process.readLine() returns String?.

@lucaswerkmeister
Copy link
Author

Everything that adds a new file (class, backend conversion, backend tests) is done. Modifying existing files is trickier.

@lucaswerkmeister
Copy link
Author

Modifying the lines could be easy-ish in Transformer, WideningTransformer and Visitor because there the existing functions are all exactly one line, and I have to add one line, so I can easily work on the lines level. In Editor and RedHatTransformer, on the other hand, functions can span multiple lines, and finding out where one ends might become very tricky. I think I might pass on these. Luckily, these are the classes where I’ll get compiler errors if I forgot to implement the methods, so that should be okay.

@lucaswerkmeister
Copy link
Author

Okay, Transformer, WideningTransformer and Visitor are done now as well. That’s enough for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment