I want to create a parser of template engine using Flex & Bison. The thing is that I would like to parse only expressions within {{..}} and ${..}.
The template can be any arbitrary text with embedded tokens with code like this:
</table:table-row>
{{$(/report/row.xml).embed()}}
{{$(//Accreditation/AccreditationDocument/Report).each(fragment(row) """
<table:row>
<table:table-cell office:value-type="string" office:string-value="${row["name"]}" />
</table:row>
""")}}
<table:table-row table:number-rows-repeated="1048574" table:style-name="ro1">
<table:table-cell table:number-columns-repeated="16384"/>
</table:table-row>
</table:table>
I have found the solution myself. Flex has a feature called Start Conditions.
Below is the
lexer.lcode which returns tokens only from {{ }}. Other text is returned as GENERAL_BODY.