You are viewing an older version (9.10.0). Go to latest (9.13.0)
{ } Raw JSON

bundles / IPython 9.10.0 / IPython / core / inputtransformer2 / TokenTransformBase

class

IPython.core.inputtransformer2:TokenTransformBase

source: /IPython/core/inputtransformer2.py :273

Signature

class   TokenTransformBase ( start )

Members

Summary

Base class for transformations which examine tokens.

Extended Summary

Special syntax should not be transformed when it occurs inside strings or comments. This is hard to reliably avoid with regexes. The solution is to tokenise the code as Python, and recognise the special syntax in the tokens.

IPython's special syntax is not valid Python syntax, so tokenising may go wrong after the special syntax starts. These classes therefore find and transform one instance of special syntax at a time into regular Python syntax. After each transformation, tokens are regenerated to find the next piece of special syntax.

Subclasses need to implement one class method (find) and one regular method (transform).

The priority attribute can select which transformation to apply if multiple transformers match in the same place. Lower numbers have higher priority. This allows "%magic?" to be turned into a help call rather than a magic call.

Aliases

  • IPython.core.inputtransformer2.TokenTransformBase