Skip to content

Custom Match Implementation

Tip

You may check how built-in Matches are implemented here.

You may create your own custom Match implementation by following steps.

  1. Run AutoSetSyntax: Create New Match from the command palette1.
  2. It will create a template like

    Example

    from __future__ import annotations
    
    from AutoSetSyntax.plugin import AbstractMatch, MatchableRule, ViewSnapshot
    
    
    class MyOwnMatch(AbstractMatch):
        """Your custom `Match` must inherit `AbstractMatch` and implement the `test` method."""
    
        def is_droppable(self, rules: tuple[MatchableRule, ...]) -> bool:
            # Optionally, you can implement `is_droppable` to indicate that this object
            # can be dropped under certain circumstances by the optimizer.
            return False
    
        def test(self, view_snapshot: ViewSnapshot, rules: tuple[MatchableRule, ...]) -> bool:
            # Your job is to implement this function, at least.
            # This function tests `rules` (mix of `ConstraintRule`s and `MatchRule`s).
            return False
    
  3. Decide the match name of your Match.

    Say, if your class name is MyOwnMatch, the match name is decided by

    1. Remove Match suffix from the class name. (MyOwnMatch » MyOwn)
    2. Convert it into snake case. (MyOwn » my_own)

    That is, you can use it via "match": "my_own" in a match rule.

  4. At least, implement the test method.

  5. Save your implementation in Packages/AutoSetSyntax-Custom/matches/. Conventionally, the file name used is the match name, my_own.py.

  6. Restart ST and check whether your implementation is loaded via Debug Information.


  1. Command palette: Ctrl+P for Windows/Linux. Cmd+P for macOS.