GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — codeql/misc/codegen/lib/rust.py at codeql-cli/v2.24.1 · github/codeql Expand file tree/ Copy pathrust.pyMore file actions 155 lines (130 loc) · 3.03 KB / Copy pathrust.pyFile metadata and controls155 lines (130 loc) · 3.03 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 import dataclasses import re import typing import inflection # taken from https://doc.rust-lang.org/reference/keywords.html keywords = { "as", "break", "const", "continue", "crate", "else", "enum", "extern", "false", "fn", "for", "if", "impl", "in", "let", "loop", "match", "mod", "move", "mut", "pub", "ref", "return", "self", "Self", "static", "struct", "super", "trait", "true", "type", "unsafe", "use", "where", "while", "async", "await", "dyn", "abstract", "become", "box", "do", "final", "macro", "override", "priv", "typeof", "unsized", "virtual", "yield", "try", } def avoid_keywords(s: str) -> str: return s + "_" if s in keywords else s _field_overrides = [ (re.compile(r"(.*)_"), lambda m: {"field_name": m[1]}), ] def get_field_override(field: str): for r, o in _field_overrides: m = r.fullmatch(field) if m: return o(m) if callable(o) else o return {} @dataclasses.dataclass class Field: field_name: str base_type: str table_name: str is_optional: bool = False is_repeated: bool = False is_unordered: bool = False is_predicate: bool = False first: bool = False def __post_init__(self): self.field_name = avoid_keywords(self.field_name) @property def type(self) -> str: type = self.base_type if self.is_optional: type = f"Option<{type}>" if self.is_repeated: type = f"Vec<{type}>" return type @property def is_single(self): return not (self.is_optional or self.is_repeated or self.is_predicate) @property def is_label(self): return self.base_type == "trap::Label" @property def singular_field_name(self) -> str: return inflection.singularize(self.field_name.rstrip("_")) @dataclasses.dataclass class Class: name: str entry_table: str | None = None fields: list[Field] = dataclasses.field(default_factory=list) detached_fields: list[Field] = dataclasses.field(default_factory=list) ancestors: list[str] = dataclasses.field(default_factory=list) @property def is_entry(self) -> bool: return bool(self.entry_table) @property def single_field_entries(self) -> dict[str, list[dict]]: ret = {} if self.is_entry: ret[self.entry_table] = [] for f in self.fields: if f.is_single: ret.setdefault(f.table_name, []).append(f) return [{"table_name": k, "fields": v} for k, v in ret.items()] @property def has_detached_fields(self) -> bool: return bool(self.detached_fields) @dataclasses.dataclass class ClassList: template: typing.ClassVar[str] = "rust_classes" classes: list[Class] source: str @dataclasses.dataclass class ModuleList: template: typing.ClassVar[str] = "rust_module" modules: list[str] source: str |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |