aradi / fypp

Python powered Fortran preprocessor
http://fypp.readthedocs.io
BSD 2-Clause "Simplified" License
188 stars 30 forks source link

Parsing the code -- choice #14

Closed zerothi closed 3 years ago

zerothi commented 3 years ago

Hi Balint,

As for the implementation of fypp I see the parsing is very much done manually (reg-exp etc.).

Did you consider alternatives to this way, i.e. using ast?

I would think that changing the parsing of the "python" part to ast would leverage much complexity since you anyways want to adhere to python linguistics, no?

aradi commented 3 years ago

Hey Nick, yes, Fypp is regexp based so far. However, Python expressions (as on the RHS of assignments or in eval directives) are evaluated by Python directly, without any intervention of Fypp. The only places, where I am really taking Python-like expressions apart by regexps are the assignments (#:set) and the loops (#:for). But, in those cases I need full control over the LHS of the assignments (e.g. to check collisions with reserved variable names), so I would not like to expose the full complexity Python offers (e.g. nested tuples on the LHS). So I am not really sure, whether an AST-based approach would really yield any advantage there.

But do you have an example, where the "unflexibility" of Fypp with respect of Python expressions poses a bottleneck for your application?