blob: aaa5518b8fd33a61b3bdfc40417bdd0248b869e7 [file] [log] [blame]
#!/usr/bin/env python3.8
# Copyright 2020 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from pathlib import Path
import os
import sys
def main():
for path in Path(os.environ["FUCHSIA_DIR"]).rglob("*.fidl"):
if not path.is_file():
with open(path) as file:
except UnicodeDecodeError:
print(f"SKIPPING {path}: not unicode")
def check_file(file):
line_parser = top_level
for index, line in enumerate(file):
if "//" in line:
line = line[:line.index("//")]
line = line.strip()
result = line_parser(line)
if result:
line_parser, output = result
if output:
info = "" if".test.fidl") else "*** "
info += f"{}:{index + 1}"
print(f"{info}: {output}")
def top_level(line):
if line.startswith("union "):
if "{" in line and "};" in line and "?" not in line:
if line.endswith("{"):
return in_union, None
return top_level, "unexpected formatting"
keywords = "struct", "xunion", "enum", "bits", "table", "protocol"
if any(line.startswith(k + " ") for k in keywords):
if "{" in line and "};" in line:
if not line.endswith("{"):
return top_level, "unexpected formatting"
return in_other, None
def in_union(line):
if line.startswith("}"):
assert line == "};"
return top_level, None
if "?" in line:
return in_union, "nullable union field"
def in_other(line):
if line.startswith("}"):
assert line == "};"
return top_level, None
if __name__ == "__main__":