I'm writing a web app that requires a component that let's the user input a piece of text thats automatically formatted based on something the client calls "macros". These macros have a very specific syntax. Examples:
- "{{ greetings_alternatives}}, my name is {{ names_alternatives|cap }}" -In this example, {{ greetings_alternatives}} will be substituted (randomly) by "Hello", "Hi" or "Greetings" and {{ names_alternatives|cap }} will be subsituted by "John Doe" or "Jane Doe" and then capitalized (because of |cap). We can also have multitple modififers, example: {{ greetings_alternatives|caps|reverse }} this will pick a random name, capitalize it and then reverse the character order of the name.
I've been thinking about using a lexer to split the initial into tokens and then feed these tokens to a parser to generate a parse tree. So basically it will be a "one-pass compiler", but i'm not sure if this is the best way to go. Any suggestions?
Note: There are way more symbols and rules than what i exemplified, hence the thought of using stuff i learned from compiler theory for this.