Page MenuHomePhabricator
Diviner libphutil Tech Docs PhutilPythonFragmentLexer

final class PhutilPythonFragmentLexer
libphutil Technical Documentation (Lexers)

Python lexer which can handle fragments of source code, e.g. for syntax highlighting of inline snippets. This is largely based on Pygments:

https://bitbucket.org/birkenfeld/pygments-main/src/default/pygments/lexers/agile.py

This lexer is not suitable for parser construction; it always lexes any input stream, even if the input is not Python.

Tasks

Lexer Implementation

Lexer Rules

  • protected function getRules() — Process, normalize, and validate the raw lexer rules.

Lexer Tokens

  • public function getTokens($input, $initial_state) — Lex an input string into tokens.

Other Methods

  • public function mergeTokens($tokens) — Merge adjacent tokens of the same type. For example, if a comment is tokenized as <"//", "comment">, this method will merge the two tokens into a single combined token.
  • public function getLexerState()

Methods

protected function getRawRules()

PhutilLexer

Return a set of rules for this lexer. See description in PhutilLexer.

PhutilPythonFragmentLexer
This method is not documented.
Return
dictLexer rules.

protected function getRules()
Inherited

PhutilLexer

Process, normalize, and validate the raw lexer rules.

Return
wild

public function getTokens($input, $initial_state)
Inherited

PhutilLexer

Lex an input string into tokens.

Parameters
string$inputInput string.
string$initial_stateInitial lexer state.
Return
listList of lexer tokens.

public function mergeTokens($tokens)
Inherited

PhutilLexer

Merge adjacent tokens of the same type. For example, if a comment is tokenized as <"//", "comment">, this method will merge the two tokens into a single combined token.

Parameters
array$tokens
Return
wild

public function getLexerState()
Inherited

This method is not documented.
Return
wild