Skip to content

Add support for variable scoping #21

@benkrikler

Description

@benkrikler

I've started looking into using this package for a project I'm working on. We'll want to be able to specify branches which might be nested within our trees, eg. branch.sub_branch. I've tested this briefly with version 0.0.7 of formulate though and I see that such variables cannot be identified:

$ python -m formulate --from-numexpr 'branch.sub_branch < 4' --variables
ERROR:formulate:TODO TRACEBACK: ('branch.sub_branch < 4', 6, 'Expected end of text')
ERROR:formulate:Error parsing: branch.sub_branch < 4
ERROR:formulate:                     ▲
ERROR:formulate:                     ┃
ERROR:formulate:                     ┗━━━━━━ Error here or shortly after

Would it be possible to add support for this? PyParsing has a specific helper method which might be useful here, delimitedList. I think the easiest for the user is to return a single variable in this case branch.sub_branch in the example above. That might mean just including the . in the definition of the Word for Variables?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions