Left associative operators with high precedence

Since you are working on strings, you don’t need a macro, you need a parser.

You can make your from scratch or use tools like

https://lcsb-biocore.github.io/PikaParser.jl/stable/

https://gkappler.github.io/CombinedParsers.jl/dev/man/user/

I don’t think you can use Julia’s parser for this because it can’t distinguish between

julia> Meta.parse("(a⊗b*c)⊗d")
:(((a ⊗ b) * c) ⊗ d)

julia> Meta.parse("a⊗b*c⊗d")
:(((a ⊗ b) * c) ⊗ d)

Though maybe you can modify the output of the JuliaSyntax parser using the fancy parenthesis-tracking stuff — probably not worthwhile.

1 Like