JuliaCon 2023

ExprParsers.jl: Object Orientation for Macros
2023-07-28 , 26-100

You want to build a complex macro? ExprParsers.jl gives you many prebuilt expression parsers - for functions, calls, args, wheres, macros, ... - so that you don't need to care about the different ways these high-level Expr-types can be represented in Julia syntax. Everything is well typed, so that you can use familiar julia multiple dispatch to extract the needed information from your input Expr.


The need of abstracting upon Expr-types like functions is already recognized by the widespread MacroTools.jl. There you have support for functions (and arguments) by a set of helpers like splitdef and combinedef which go from Expr to Dict and back.

ExprParsers.jl is different from MacroTools.jl in that it 100% focuses on this kind of object-orientation, extended to many more Expr-types like where syntax, type annotations, keyword arg, etc. In addition, ExprParsers are well typed, composable and extendable in that you can easily write your own parser object.

When working with ExprParsers, you first construct your (possibly nested) parser, describing in detail what you expect as the input. Then you safely parse given expressions and dispatch on the precise ExprParser types. Finally, you can mutate the parsed results and return the manipulated version, or simply extract information from it.

Stephan Sahm is founder of the Julia consultancy Jolin.io, and organizer of the Julia User Group Munich Meetup. In his academic days, he certified as Master of Applied Stochastics, Master and Bachelor of Cognitive Science, and Bachelor of Mathematics/Informatics. Since more than 5 years Stephan Sahm works as senior consultant for Data Science and Engineering, now bringing Julia to industry.

Stephan Sahm's top interest are in green computing, functional programming, probabilistic programming, real time analysis, big data, applied machine learning and in general industry applications of Julia.

Aside Julia and sustainable computing, he likes chatting about Philosophy of Mind, Ethics, Consciousness, Artificial Intelligence and other Cognitive Science topics.

This speaker also appears in: