Skip to content

Instantly share code, notes, and snippets.

@Sigmanificient
Last active August 28, 2023 13:30
Show Gist options
  • Save Sigmanificient/d87a462b934161965271f890bae5c230 to your computer and use it in GitHub Desktop.
Save Sigmanificient/d87a462b934161965271f890bae5c230 to your computer and use it in GitHub Desktop.
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
import vera_wrapper as vera
# Replace vera with the wrapper only for the typechecker
# at runtime, the vera_wrapper doesn't exists
else:
import vera
from collections.abc import MutableSequence, Sequence
from typing import Literal, TypeVar, Union
TokenName = Literal[
"and",
"andand",
"assign",
"andassign",
"or",
"orassign",
"xor",
"xorassign",
"comma",
"colon",
"divide",
"divideassign",
"dot",
"dotstar",
"ellipsis",
"equal",
"greater",
"greaterequal",
"leftbrace",
"less",
"lessequal",
"leftparen",
"leftbracket",
"minus",
"minusassign",
"minusminus",
"percent",
"percentassign",
"not",
"notequal",
"oror",
"plus",
"plusassign",
"plusplus",
"arrow",
"arrowstar",
"question_mark",
"rightbrace",
"rightparen",
"rightbracket",
"colon_colon",
"semicolon",
"shiftleft",
"shiftleftassign",
"shiftright",
"shiftrightassign",
"star",
"compl",
"starassign",
"asm",
"auto",
"bool",
"false",
"true",
"break",
"case",
"catch",
"char",
"class",
"const",
"constcast",
"continue",
"default",
"delete",
"do",
"double",
"dynamiccast",
"else",
"enum",
"explicit",
"export",
"extern",
"float",
"for",
"friend",
"goto",
"if",
"inline",
"int",
"long",
"mutable",
"namespace",
"new",
"operator",
"private",
"protected",
"public",
"register",
"reinterpretcast",
"return",
"short",
"signed",
"sizeof",
"static",
"staticcast",
"struct",
"switch",
"template",
"this",
"throw",
"try",
"typedef",
"typeid",
"typename",
"union",
"unsigned",
"using",
"virtual",
"void",
"volatile",
"wchart",
"while",
"pp_define",
"pp_if",
"pp_ifdef",
"pp_ifndef",
"pp_else",
"pp_elif",
"pp_endif",
"pp_error",
"pp_line",
"pp_pragma",
"pp_undef",
"pp_warning",
"identifier",
"octalint",
"decimalint",
"hexaint",
"intlit",
"longintlit",
"floatlit",
"ccomment",
"cppcomment",
"charlit",
"stringlit",
"contline",
"space",
"space2",
"newline",
"pound_pound",
"pound",
"any",
"pp_include",
"pp_qheader",
"pp_hheader",
"eof",
"eoi",
"pp_number",
"msext_int8",
"msext_int16",
"msext_int32",
"msext_int64",
"msext_based",
"msext_declspec",
"msext_cdecl",
"msext_fastcall",
"msext_stdcall",
"msext_try",
"msext_except",
"msext_finally",
"msext_leave",
"msext_inline",
"msext_asm",
"msext_region",
"msext_endregion",
"import",
]
class Token:
column: int
file: str
line: int
name: str
raw: str
type: str
value: str
T = TypeVar("T")
# C++ Vector can be mapped to a MultableSequence[T]
_Vector = MutableSequence[T]
def getAllLines(filepath: str) -> _Vector[str]: ...
def getLine(filepath: str, line: int) -> str: ...
def getLineCount(filepath: str) -> int: ...
def getParameter(filepath: str, default_value: str) -> str: ...
def getSourceFileNames() -> _Vector[str]: ...
def getTokens(
filename: str,
from_line: int,
from_column: int,
to_line: int,
to_column: int,
token_filter: Sequence[TokenName],
) -> _Vector[Token]: ...
def isBinary(filepath: str) -> bool: ...
def report(filepath: str, line: int, rule: str) -> None: ...
__all__ = (
"getAllLines",
"getLine",
"getLineCount",
"getParameter",
"getSourceFileNames",
"getTokens",
"isBinary",
"report",
)
from collections.abc import MutableSequence, Sequence
from typing import Literal, cast
import vera
TokenName = Literal[
"and",
"andand",
"assign",
"andassign",
"or",
"orassign",
"xor",
"xorassign",
"comma",
"colon",
"divide",
"divideassign",
"dot",
"dotstar",
"ellipsis",
"equal",
"greater",
"greaterequal",
"leftbrace",
"less",
"lessequal",
"leftparen",
"leftbracket",
"minus",
"minusassign",
"minusminus",
"percent",
"percentassign",
"not",
"notequal",
"oror",
"plus",
"plusassign",
"plusplus",
"arrow",
"arrowstar",
"question_mark",
"rightbrace",
"rightparen",
"rightbracket",
"colon_colon",
"semicolon",
"shiftleft",
"shiftleftassign",
"shiftright",
"shiftrightassign",
"star",
"compl",
"starassign",
"asm",
"auto",
"bool",
"false",
"true",
"break",
"case",
"catch",
"char",
"class",
"const",
"constcast",
"continue",
"default",
"delete",
"do",
"double",
"dynamiccast",
"else",
"enum",
"explicit",
"export",
"extern",
"float",
"for",
"friend",
"goto",
"if",
"inline",
"int",
"long",
"mutable",
"namespace",
"new",
"operator",
"private",
"protected",
"public",
"register",
"reinterpretcast",
"return",
"short",
"signed",
"sizeof",
"static",
"staticcast",
"struct",
"switch",
"template",
"this",
"throw",
"try",
"typedef",
"typeid",
"typename",
"union",
"unsigned",
"using",
"virtual",
"void",
"volatile",
"wchart",
"while",
"pp_define",
"pp_if",
"pp_ifdef",
"pp_ifndef",
"pp_else",
"pp_elif",
"pp_endif",
"pp_error",
"pp_line",
"pp_pragma",
"pp_undef",
"pp_warning",
"identifier",
"octalint",
"decimalint",
"hexaint",
"intlit",
"longintlit",
"floatlit",
"ccomment",
"cppcomment",
"charlit",
"stringlit",
"contline",
"space",
"space2",
"newline",
"pound_pound",
"pound",
"any",
"pp_include",
"pp_qheader",
"pp_hheader",
"eof",
"eoi",
"pp_number",
"msext_int8",
"msext_int16",
"msext_int32",
"msext_int64",
"msext_based",
"msext_declspec",
"msext_cdecl",
"msext_fastcall",
"msext_stdcall",
"msext_try",
"msext_except",
"msext_finally",
"msext_leave",
"msext_inline",
"msext_asm",
"msext_region",
"msext_endregion",
"import",
]
class Token:
column: int
file: str
line: int
name: str
raw: str
type: str
value: str
def getAllLines(filepath: str) -> MutableSequence[str]:
return vera.getAllLines(filepath)
def getLine(filepath: str, line: int) -> str:
return vera.getLine(filepath, line)
def getLineCount(filepath: str) -> int:
return vera.getLineCount(filepath)
def getParameter(filepath: str, default_value: str) -> str:
return vera.getParameter(filepath, default_value)
def getSourceFileNames() -> MutableSequence[str]:
return vera.getSourceFileNames()
def getTokens(
filename: str,
from_line: int,
from_column: int,
to_line: int,
to_column: int,
token_filter: Sequence[TokenName],
) -> MutableSequence[Token]:
return cast(
MutableSequence[Token],
vera.getTokens(
filename,
from_line,
from_column,
to_line,
to_column,
token_filter
),
)
def isBinary(filepath: str) -> bool:
return vera.isBinary(filepath)
def report(filepath: str, line: int, rule: str) -> None:
return vera.report(filepath, line, rule)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment