erlang - Is leex a good choice for writing a template engine lexer? -


i in initial design phase of implementing jinja2-like template language elixir. had been inclined writer lexer hand, have come across leex module erlang. looks promising, after initial research unsure if proper tool purposes.

one of hesitations template language being, essentially, string embedded language, not clear how use tokenize case using leex. trivial example, imagine tokenizing template:

<p>here text inclusion in template.</p> {% x in some_variable %}   value variable: {{ x }}. {% endfor %} 

in example, need ensure kewords 'for' , 'in' tokenized differently depending on:

  • if inside tag: {% %}
  • if inside tag: {{ }}
  • if in template, not inside tags.

to me looks need either 2 passes in tokenizing phase, or roll own lexer in order in 1 pass.

i wondering if has experience lexical analysis, , particularly leex, or writing template engines can provide insight best way forward?

let me apologize in advance if isn't helpful, think of lexical analysis having power of regular expression and, such, suspect trying not in sweet-spot of re's or leex. first pass go source-code lexical elements (tokens) devoid of context , appropriate use of leex.

i think handling of different, context-sensitive semantics of , in tokens handled via parsing , erlang's yecc. may able handle comments in lexical analysis phase, think in general might use combination of leex , yecc.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -