diff options
author | Daniel Mensinger <daniel@mensinger-ka.de> | 2020-08-28 21:40:51 +0200 |
---|---|---|
committer | Daniel Mensinger <daniel@mensinger-ka.de> | 2020-09-08 20:15:56 +0200 |
commit | 0d57e307b2fea541a9ee368873431fe224e5c982 (patch) | |
tree | 2ead0d7c0824a2564cc81643a4a89a1c1f6e62b5 /tools/cmake2meson.py | |
parent | 449dd8e72a3ccc4c6f7ec70169515784cd687a2c (diff) | |
download | meson-0d57e307b2fea541a9ee368873431fe224e5c982.zip meson-0d57e307b2fea541a9ee368873431fe224e5c982.tar.gz meson-0d57e307b2fea541a9ee368873431fe224e5c982.tar.bz2 |
typing: fully annotate tools
Diffstat (limited to 'tools/cmake2meson.py')
-rwxr-xr-x | tools/cmake2meson.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/tools/cmake2meson.py b/tools/cmake2meson.py index 05acd8f..e19ef68 100755 --- a/tools/cmake2meson.py +++ b/tools/cmake2meson.py @@ -34,7 +34,7 @@ class Statement: self.args = args class Lexer: - def __init__(self): + def __init__(self) -> None: self.token_specification = [ # Need to be sorted longest to shortest. ('ignore', re.compile(r'[ \t]')), @@ -87,11 +87,11 @@ class Lexer: raise ValueError('Lexer got confused line %d column %d' % (lineno, col)) class Parser: - def __init__(self, code: str): + def __init__(self, code: str) -> None: self.stream = Lexer().lex(code) self.getsym() - def getsym(self): + def getsym(self) -> None: try: self.current = next(self.stream) except StopIteration: @@ -118,8 +118,8 @@ class Parser: self.expect('rparen') return Statement(cur.value, args) - def arguments(self) -> list: - args = [] + def arguments(self) -> T.List[T.Union[Token, T.Any]]: + args = [] # type: T.List[T.Union[Token, T.Any]] if self.accept('lparen'): args.append(self.arguments()) self.expect('rparen') @@ -139,7 +139,7 @@ class Parser: while not self.accept('eof'): yield(self.statement()) -def token_or_group(arg): +def token_or_group(arg: T.Union[Token, T.List[Token]]) -> str: if isinstance(arg, Token): return ' ' + arg.value elif isinstance(arg, list): @@ -148,6 +148,7 @@ def token_or_group(arg): line += ' ' + token_or_group(a) line += ' )' return line + raise RuntimeError('Conversion error in token_or_group') class Converter: ignored_funcs = {'cmake_minimum_required': True, @@ -183,7 +184,7 @@ class Converter: return res[0] return '' - def write_entry(self, outfile: T.TextIO, t: Statement): + def write_entry(self, outfile: T.TextIO, t: Statement) -> None: if t.name in Converter.ignored_funcs: return preincrement = 0 @@ -274,7 +275,7 @@ class Converter: outfile.write('\n') self.indent_level += postincrement - def convert(self, subdir: Path = None): + def convert(self, subdir: Path = None) -> None: if not subdir: subdir = self.cmake_root cfile = Path(subdir).expanduser() / 'CMakeLists.txt' @@ -297,7 +298,7 @@ class Converter: if subdir == self.cmake_root and len(self.options) > 0: self.write_options() - def write_options(self): + def write_options(self) -> None: filename = self.cmake_root / 'meson_options.txt' with filename.open('w') as optfile: for o in self.options: |