Language matching

Language matcher

class verigen.Matcher(language: str, **kwargs)

This class represents language specific syntax matching.

match(text: str)

Match provided text against rules of this matcher object. As a match result, dict() object is returned with predefined keys:

  • type - match type; one of: script, generated,
    verbatim
  • scope - scope of the successfully matched line; for script
    result it can be either common or local. For generated result it can be either begin or end. verbatim output does not produce any scope.
  • indent - optional hint about indentation of the output text
  • text - content of the script or verbatim text depending on type.
Parameters:text (str Line of text) –
Returns:
Return type:dict Dictionary with match result.
supports_filename(fname: str)

Checks if this matcher can potentially support file name, basing on its extension.

Parameters:fname (str) – File name or path.
Returns:
Return type:True if specified file may be supported by this matcher
supports_language(language: str)

Checks if this matcher supports specified language. Language is case insensitive and can have name aliases like C++ and CPP.

Parameters:language (str) – Language name or it’s alias (case insensitive)
Returns:True if language is supported by this matcher
Return type:bool

Matcher cache

class verigen.MatcherCache

Collection of language matchers initialized with predefined list of matchers.

find(language: str)

Find matcher that supports specified language

Parameters:language (str) – language or alias name, case insensitive
Returns:Instance of matcher object valid for specified language. None if language is not supported
Return type:class:~Matcher
find_by_file(fname: str)

Find matcher by file extension.

Parameters:fname (str) – File name or path
Returns:Instance of matcher object valid for specified extension. None if extension is not supported.
Return type:class:~Matcher