Translator¶
-
class
verigen.
Translator
(output, language=None, **kwargs)¶ This class represents top level translation engine that generates single output from multiple sources.
Parameters: - output (str) – output filename or standard output placeholder (
-
) - language (str, optional) – preferred language (enforced on all source input)
- matcher_cache (MatcherCache, keyword, optional) – custom cache of language matchers
Raises: TranslationError
– when translator is unable to find valid matcher for given language-
find_matcher
(language: str)¶ Find syntax matcher for given language name or it’s alias.
Parameters: language (str) – language name Raises: TranslationError
– when language is not supportedReturns: valid matcher that can be passed to translation units. Return type: class:~Matcher
-
select_stream
(file, *args, **kwargs)¶ Selects proper stream depending on
file
type or name and additional hints. To be used withwith
clause.If
file
represents file path, all positional and keyword parameters exceptdir
are passed to standardopen()
function.Parameters: - file (str, IOBase) – filename or existing stream
- dir (str, keyword) – stream direction hint with valid values:
'input'
(default) or'output'
Yields: tuple – This function yields tuple of two values: 1. Stream object 2. Stream source name string for diagnostic purposes
-
translate_all
(src_list)¶ Translates all sources from the specified list.
Parameters: src_list (list) – List of filenames, or standard input placeholders ( -
)Raises: TranslationError
– On any severe translation error. Note that embedded script errors are not considered as ‘severe’ error.
-
translate_stream
(in_s, out_s)¶ Translate one open input stream to the open output stream
Parameters: - in_s (tuple (IOBase, str)) – input stream and corresponding name for diagnostic purposes
- out_s (tuple (IOBase, str)) – output stream and corresponding name for diagnostic purposes
Raises: TranslationError
– On any severe translation error. Note that embedded script errors are not considered as ‘severe’ error.
- output (str) – output filename or standard output placeholder (