4 ms·
Mito looks interesting! Regarding the sin, I don't think it entirely applies here, unless I'm misunderstanding you - I'm not super familiar with transpilers. I
by lucasluitjes 5y ago
Mito looks interesting! Regarding the sin, I don't think it entirely applies here, unless I'm misunderstanding you - I'm not super familiar with transpilers.
In this case the template is also ruby code, but with placeholders for the values. So both the template and the input get parsed into ASTs, then both of them are recursively walked and compared on the fly. During that walk it builds up the data structure with initial values.
In the code generation direction it walks one AST and does lookups and rewrites with values from the values.
Does that make sense?
- narush 5y agoGotcha. Pretty much the template language is close enough to the destination language that you don’t need an AST for the template language at all. That makes sense! Seems like a legit simplification to take advantage of. Do you have any plans to make the template language more advanced/complex?
- lucasluitjes 5y agoWell, looking at the rails monocles (for matching controllers, views, etc) a common pattern is custom matchers/replacers for things like "ast.children.first.to_s.singularize.camelize", so a shorthand for defining those in both directions could be handy. Other than that, not right now. But if there are common situations where you end up writing the same matchers/replacers, those would be prime candidates for built-in placeholders.