Using rowan for programming languages?

I recently started working on my own programming language (my first) that transpiles into Lua. Since it is my first time, I don't really know all of the best practices when it comes to writing a language. So here is one of my questions:

Does it make sense to use rowan for a programming language parser and representation?

The big advantage I see is that I can use the same parser/representation to write tooling for the language like linting, syntax highlighting, etc. The part I am not so sure about is how rowan can give you an incomplete AST. Does that even make sense in the context of a compiler (in my case a transpiler)? Would it make syntactic analysis harder? Even if it does make sense, is it just over complicating my internals?

Any insight would be appreciated!

It depends on what you want to do and how far down the rabbit hole you want to go. I'd use something like Rowan if I was writing a "serious" compiler frontend and wanted to give good error messages in the face of incomplete/garbage source code.

I would personally start with something simple and hand-made, then as you expand or want to improve UX (at the expense of ease-of-development) you might reach a point where Rowan makes sense for your use case.

You might want to have a look at this section of the rust-analyzer internal docs.

The magic that lets you work with incomplete ASTs is the fact that an error is just another type of node (e.g. you could imagine representing something like enum SyntaxNode { Error, Keyword, Identifier, ... }). To go from this loosely typed concrete syntax tree to a more reliable abstract syntax tree you have getters which do the actual parsing and return something like Option<FunctionSignature<'_>> and you'll use ? when accessing them to return early if you don't have a well-formed AST.

1 Like

I realize now that this sentence is a little misleading. I am aware how errors are represented with rowan. What I meant is that I wasn't sure if you should you an incomplete AST for a compiler.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.