Towards an OPL language server

By Colin Hoad | Jan 02, 2025
RSS

The Open Psion Language (OPL) is a procedural programming language used for writing applications on Psion portable devices. As many Acorn fans will know, the Psion Series 3a was also rebadged as an Acorn Pocketbook II and, while bearing the Acorn logo, was materially the same as a Psion Series 3a, and supported OPL.

I've been fascinated with OPL ever since I first learnt about it at a retro computing event back in November 2023. I think this is in part because it feels quite BASIC-like, and even shares some of the same keywords with BASIC. I also love “coding on the go”, and so being able to carry around my Psion 3a and tap away a few lines of code when the mood strikes is immensely appealing; and the 3a is certainly considerably more pocket-friendly than my Beeb (or even my Z88).

However, for significant coding projects, the 3a does have its limitations as a programming device. The screen is - naturally - quite small, and being monochrome (OK, technically it supports black, white and grey…) it doesn't lend itself to syntax highlighting, still less features such as auto-completion, dynamic error checking or definition lookups. Using a comprehensive IDE like VS Code would - at least for me - be preferable, especially if the coding project needs to be split across multiple source files. But, OPL being a fairly old (I like to think ‘venerable’) language, there is scant support for it in any modern IDE, including VS Code. After some illuminating chats about this on the Psion Discord server, Alex Brown seeded the idea in my head of writing a language server for OPL, using the now widely adopted Language Server Protocol (LSP). This felt like a meaty project I could really get my teeth into, and which would also serve as an opportunity to expand my own programming abilities.

My first “MVP” was to create a simple syntax highlighting extension for VS Code, which I wrote in TypeScript. This proved to be a fairly straightforward exercise once I'd grasped the nuances of TypeScript and how VS Code manages Oniguruma regex pattern matching. While I was broadly happy with the result (particularly after getting some very helpful feedback from the Psion community) I very quickly came to see the limitations of a syntax highlighting extension in isolation. Even something as basic as auto-completing each PROC keyword with an ENDP keyword, while keeping the cursor indented one line below the PROC keyword, was just not possible to do. A proper language server, therefore, was clearly needed.

The next question I faced was “what language should I code it in?" The stock response from VS Code folks is “TypeScript”, and there are many positive reasons for why. First of all, it will “just run” in VS Code and there are already lots of good libraries providing support, as well as some excellent YouTube videos from a chap called Jeff that I've watched and enjoyed. However, I must confess… I've never particularly liked JavaScript and so - by extension (pardon the pun) - I don't really like TypeScript much, either. This is just a personal preference, I don't deny they are powerful languages when wielded by people far smarter than I, but I couldn't see myself enjoying working on what will likely be a very time-consuming project using a language that didn't spark joy.

The good news is, the LSP itself is totally language agnostic. All you need to ensure is that any language server you create is capable of communicating via JSON-RPC. This means you could, in theory, write said server in anything. (Indeed, Jeff has done so in bash, just to prove a point - he doesn't recommend doing so!) In theory this means I could write a language server for OPL… in OPL! But, I'm not that clever, and much as I love dear OPL, its pattern matching capabilities probably won't suffice. I'd also need to leverage a compiled version of OPL - which, again, I could do, there are projects out there providing such support - but this would necessitate further learning that, if I'm honest, I'd prefer to expend on something that I could potentially use for other, future applications.

This has led me to Pascal. It might sound like an unorthodox choice ("isn't that another dead language, Colin, what is your problem?") but truth be told, there are lots of live Pascal projects out there using Free Pascal, and having read up a bit about it, I like what I see. I missed the boat with Pascal back in the day, and it's always been one of those “what if” languages that I could have learnt but didn't. Pascal even runs on a Beeb! What is more, there are other Psion projects afoot - such as Alex's own CTRAN - that are being written in Pascal, so it feels like a nice fit. I'd come away from this project with not only the stated outcome - a nice LSP-compliant language server for OPL - but also, hopefully, a solid foundation in Pascal, too.

It's only the 2nd day of 2025 and I'm not generally one for making New Year's resolutions, but this feels like a nice way to start the year, all the same. I'll continue to blog my progress as I make it.