Skip to content

Pattern matching for expressions #2

@albop

Description

@albop

For the preliminary implementation, a pattern is an expression, with some wildcards.
Wildcards are valid identifiers starting by one underscore.

For instance, _a + _b*_a is supposed to match p + b*p but not p + b*c.

We can use that to define the elements of syntax that we want, for instance to define _x[_inds](_t) as the generic form of a timed and index variable (like v_{i,t+1})

There is a crude python implementation in https://github.com/EconForge/dolang/blob/master/dolang/pattern.py.

Some questions:

  • are there available libraries which do it efficiently ?
  • we probably want to "type" the wildcard so that, in the above example, _t could stand for a signed integer and _inds would be expected to be a list of indices
  • would we be better of by defining the expression parser ourselve instead of operating on the syntax tree ?

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