Skip to content

Language type

This section contains the reference for the implementation of tokei's LanguageType struct.

LanguageType

LanguageType() -> None

Represents a individual programming language.

Can be used to provide information about the language, such as multi line comments, single line comments, string literal syntax, whether a given language allows nesting comments.

Note

This is defined as a struct in rust. There may be a better way of representing this object in python, but for the moment its a class which has the corresponding LanguageType represented underneath.

Warning

The following methods aren't currently implemented: from_path, from_file_extension, from_mime, from_shebang, parse, parse_from_str, parse_from_slice.

Examples

>>> from pytokei import LanguageType
>>> python = LanguageType("Python")
>>> python
LanguageType(Python)

To see the languages defined, run the following:

>>> LanguageType.list()
['ABNF', 'ABAP', 'ActionScript', 'Ada', ...

References

tokei reference. The implementation of the different methods are here: ref

allows_nested

allows_nested() -> bool

Returns whether the language allows nested multi line comments.

doc_quotes

doc_quotes() -> list[tuple[str]]

Returns the doc quotes of a language.

Examples
>>> LanguageType("Python").doc_quotes()
[(', '), ("'''", "'''")]

important_syntax

important_syntax() -> list[str]

Returns the parts of syntax that determines whether tokei can skip large parts of analysis.

is_literate

is_literate() -> bool

Returns whether the language is "literate", meaning that it considered to primarily be documentation and is counted primarily as comments rather than procedural code.

line_comments

line_comments() -> list[str]

Returns the single line comments of a language.

Examples
>>> from pytokei import LanguageType
>>> python = LanguageType("Python")
>>> python.line_comments()
['#']

multi_line_comments

multi_line_comments() -> list[Optional[tuple[str]]]

Returns the multi line comments of a language (if they have it).

Examples
>>> from pytokei import LanguageType
>>> python = LanguageType("Python")
>>> python.multi_line_comments()
[]

>>> rust = LanguageType("Rust")
>>> rust.multi_line_comments()
[('/*', '*/')]

name

name() -> str

Returns the display name of a language.

nested_comments

nested_comments() -> list[tuple[str]]

Returns what nested comments the language has. (Currently only D has any of this type.)

Examples
>>> d = LanguageType("D")
>>> d.nested_comments()
[('/+', '+/')]

quotes

quotes() -> list[tuple[str]]

Returns the quotes of a language.

Examples
>>> d = LanguageType("C")
>>> d.quotes()
[('"', '"')]

shebangs

shebangs() -> list[str]

Returns the shebang of a language.

Examples
>>> LanguageType("BASH").shebangs()
['#!/bin/bash']

verbatim_quotes

verbatim_quotes() -> list[tuple[str]]

Returns the verbatim quotes of a language.

Examples
>>> LanguageType("C#").verbatim_quotes()
[('@"', '"')]