Generating general AST syntax from Elixir app

I need to create an authorization system in Elixir, to do it I will generate a policy containing some permissions but in AST syntax and there will be many client consumers (in different languages JavaScript, Python, Elixir etc…) to verify that permissions (after transforming the ASTs to code).

So my question us, is there some generic AST syntax for all programming languages ? or a syntax per language ?

There is not. Most languages have their own AST representations.

2 Likes

Languages often don’t share even more basic things like supported datatypes. AST of languages is made up of datatypes supported by each individual language. Therefore ASTs usually are not sharable.

E.g. elixir uses atoms extensively, which are a concept only available on the beam. There are some languages, which have similar datatypes to atoms, but there are also many, which don’t have anything comparable.

You’re probably better sharing data (e.g. json is commonly supported) + language specific code parsing/using that data, rather than trying to abstract through some AST.

4 Likes

What I believe you are looking for is a platform agnostic way to represent the business logic, that is Authorisation rules, scopes and policy.

Instead of inventing a language which might not be Turing complete, or would require training. You should have a look at the available options and ways it can be done!!


See how to dynamically write business logic on web; opus, exop, espresso.


There’s also a great talk by Ben Church:


And as @LostKobrakai mentioned, you have to write a decoder in each language to allow the business logic to be reused.