Perth ADUG Meeting (Online)

A summary of our discussion with Josh Gardner, about PasFmt. Video will be available asap.

@jgardn3r Josh Gardner - IntegraDev - Melbourne

HOLD THE PRESS:  
  • I just realised they have an IDE plugin. I would have 100% interested to ask more about that process!
    

Background

  • IntegraDev has a polyglot system, including a lot of Delphi.

  • They use and have contributed a community Delphi plugin to SonarQube - a platform for automated code quality and static/security analysis.

  • The company created DelphiLint as an IDE plugin for sonar-delphi.

  • As a Delphi code base that is 20+ years old, the formatting was highly variable.

  • Josh researched and iterated the idea for the formatter for a long time before starting the project properly.

  • Eventually, the project was greenlit for Josh and a colleague to work on during company time.

Language

  • It is written in Rust, as Josh had an interest in it, was learning it, and had a more familiar coding partner to learn from.

Project

  • The code is open source on GitHub.¹

  • They don’t use any Rust libraries for lexing or parsing and represent the code as “logical lines” rather than in an AST. [ie lines that ‘should’ naturally sit on a line together ]

  • Parsing and optimising approach inspired by Clang Format (C++).

  • Determining the approach to take was a significant deal.

Style Guide

  • Primarily influenced by Google Java Format and their “Rectangle Rule”. ²

  • They canvassed the other developers to some extent.

Delphi Code

  • Delphi’s one- (or low-) pass compilation has certain idiosyncratic features.

  • ‘ifdefs’ (conditional compilation) were a challenge to deal with, but the solution was inspired by Clang Format.

  • It doesn’t touch inline assembly code. [ and comments, I think ]

Parallel

  • It will process all input files in parallel threads

TDD

  • Developed with many tests, in a TDD manner.

Web Demo³

  • WASM functions compiled directly from the same Rust source code.

  • Javascript/Typescript source was created to utilise the WASM functions. [ kinda like using a DLL ]

  • Runs entirely locally. No source code text leaves your browser.

Future Development

  • How will it cope with future changes in syntax (like recent ternary operator)?

    • They have ideas, but are lacking the time to work on it.

¹ Github : GitHub - integrated-application-development/pasfmt: Delphi code formatter
² Rectangle Rule : The Rectangle Rule · google/google-java-format Wiki · GitHub
³ Web Demo : pasfmt demo