|
|
|
|
| """
|
| Definición de 52 Zonas de Brodmann para código.
|
|
|
| Inspirado en la neurociencia: cada zona procesa un tipo específico
|
| de información, permitiendo especialización y eficiencia.
|
|
|
| Territorios (4):
|
| - SINTAXIS: Estructura del lenguaje (keywords, delimitadores)
|
| - SEMANTICA: Significado (identificadores, literales)
|
| - LOGICO: Razonamiento (operadores, control de flujo)
|
| - ESTRUCTURAL: Patrones (bloques, formato)
|
| """
|
|
|
| from enum import IntEnum, auto
|
| from typing import Dict, Set, Tuple
|
|
|
|
|
| class Territorio(IntEnum):
|
| """Los 4 macro-territorios (lóbulos cerebrales)."""
|
|
|
| SINTAXIS = 0
|
| SEMANTICA = 1
|
| LOGICO = 2
|
| ESTRUCTURAL = 3
|
|
|
|
|
| class Zona(IntEnum):
|
| """
|
| 52 zonas especializadas para procesamiento de código.
|
|
|
| Nomenclatura: B{num}_{funcion}
|
| - B01-B15: SINTAXIS
|
| - B16-B30: SEMANTICA
|
| - B31-B42: LOGICO
|
| - B43-B52: ESTRUCTURAL
|
| """
|
|
|
|
|
|
|
|
|
| B01_KW_DEF = auto()
|
| B02_KW_CLASS = auto()
|
| B03_KW_IMPORT = auto()
|
| B04_KW_RETURN = auto()
|
| B05_KW_CONTROL = auto()
|
| B06_KW_LOOP = auto()
|
| B07_KW_EXCEPT = auto()
|
| B08_KW_ASYNC = auto()
|
| B09_KW_MOD = auto()
|
| B10_KW_VAR = auto()
|
| B11_DELIM_PAREN = auto()
|
| B12_DELIM_BRACK = auto()
|
| B13_DELIM_BRACE = auto()
|
| B14_PUNCT = auto()
|
| B15_COMMENT = auto()
|
|
|
|
|
|
|
|
|
| B16_ID_VAR = auto()
|
| B17_ID_FUNC = auto()
|
| B18_ID_CLASS = auto()
|
| B19_ID_PARAM = auto()
|
| B20_ID_ATTR = auto()
|
| B21_LIT_INT = auto()
|
| B22_LIT_FLOAT = auto()
|
| B23_LIT_STR = auto()
|
| B24_LIT_BOOL = auto()
|
| B25_LIT_NONE = auto()
|
| B26_TYPE_PRIM = auto()
|
| B27_TYPE_COLL = auto()
|
| B28_TYPE_GEN = auto()
|
| B29_BUILTIN = auto()
|
| B30_MAGIC = auto()
|
|
|
|
|
|
|
|
|
| B31_OP_ARITH = auto()
|
| B32_OP_COMP = auto()
|
| B33_OP_LOGIC = auto()
|
| B34_OP_BIT = auto()
|
| B35_OP_ASSIGN = auto()
|
| B36_OP_MEMBER = auto()
|
| B37_OP_TERNARY = auto()
|
| B38_FLOW_BRANCH = auto()
|
| B39_FLOW_LOOP = auto()
|
| B40_FLOW_JUMP = auto()
|
| B41_FLOW_CALL = auto()
|
| B42_FLOW_EXCEPT = auto()
|
|
|
|
|
|
|
|
|
| B43_BLOCK_FUNC = auto()
|
| B44_BLOCK_CLASS = auto()
|
| B45_BLOCK_LOOP = auto()
|
| B46_BLOCK_COND = auto()
|
| B47_INDENT = auto()
|
| B48_NEWLINE = auto()
|
| B49_SPACE = auto()
|
| B50_PATTERN_LIST = auto()
|
| B51_PATTERN_DICT = auto()
|
| B52_PATTERN_CALL = auto()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| def _zona_a_territorio(zona: Zona) -> Territorio:
|
| """Determina el territorio de una zona."""
|
| z = zona.value
|
| if z <= 15:
|
| return Territorio.SINTAXIS
|
| elif z <= 30:
|
| return Territorio.SEMANTICA
|
| elif z <= 42:
|
| return Territorio.LOGICO
|
| else:
|
| return Territorio.ESTRUCTURAL
|
|
|
|
|
|
|
| ZONA_TERRITORIO: Dict[Zona, Territorio] = {z: _zona_a_territorio(z) for z in Zona}
|
|
|
|
|
|
|
|
|
|
|
| ZONA_TERRITORIO[Zona.B35_OP_ASSIGN] = Territorio.SINTAXIS
|
|
|
|
|
|
|
|
|
|
|
|
|
| ZONA_TERRITORIO[Zona.B07_KW_EXCEPT] = Territorio.SEMANTICA
|
|
|
|
|
| ZONAS_POR_TERRITORIO: Dict[Territorio, Tuple[Zona, ...]] = {
|
| t: tuple(z for z in Zona if ZONA_TERRITORIO[z] == t) for t in Territorio
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| ZONAS: Dict[Zona, Set[str]] = {
|
|
|
|
|
|
|
|
|
|
|
| Zona.B01_KW_DEF: {
|
| "def",
|
| "lambda",
|
| "function",
|
| "fn",
|
| },
|
| Zona.B02_KW_CLASS: {
|
| "class",
|
| "struct",
|
| "enum",
|
| "interface",
|
| "trait",
|
| "impl",
|
| "extends",
|
| "implements",
|
| },
|
| Zona.B03_KW_IMPORT: {
|
| "import",
|
| "require",
|
| "export",
|
| "use",
|
| "mod",
|
| "crate",
|
| "include",
|
| "package",
|
| "source",
|
| },
|
| Zona.B04_KW_RETURN: {"return", "yield"},
|
| Zona.B05_KW_CONTROL: {
|
| "if",
|
| "else",
|
| "elif",
|
| "match",
|
| "case",
|
| "switch",
|
| "default",
|
| "then",
|
| "fi",
|
| "esac",
|
| "when",
|
| "end",
|
| },
|
| Zona.B06_KW_LOOP: {
|
| "for",
|
| "while",
|
| "do",
|
| "loop",
|
| "done",
|
| "foreach",
|
| },
|
| Zona.B07_KW_EXCEPT: {
|
| "try",
|
| "except",
|
| "finally",
|
| "raise",
|
| "catch",
|
| "throw",
|
| },
|
| Zona.B08_KW_ASYNC: {"async", "await"},
|
| Zona.B09_KW_MOD: {
|
|
|
| "global",
|
| "nonlocal",
|
| "del",
|
| "with",
|
| "as",
|
| "staticmethod",
|
| "classmethod",
|
| "property",
|
|
|
| "public",
|
| "private",
|
| "protected",
|
| "static",
|
| "abstract",
|
| "final",
|
| "override",
|
| "readonly",
|
| "new",
|
|
|
| "mut",
|
| "pub",
|
| "unsafe",
|
| "extern",
|
|
|
| "select",
|
| "insert",
|
| "update",
|
| "delete",
|
| "create",
|
| "drop",
|
| "alter",
|
| "truncate",
|
| "order",
|
| "group",
|
| "limit",
|
| "offset",
|
| "distinct",
|
| "primary",
|
| "foreign",
|
| "key",
|
| "references",
|
| "constraint",
|
| "unique",
|
|
|
| "alias",
|
| },
|
| Zona.B10_KW_VAR: {
|
| "assert",
|
| "pass",
|
| "break",
|
| "continue",
|
| "let",
|
| "const",
|
| "var",
|
| "exit",
|
| },
|
|
|
| Zona.B11_DELIM_PAREN: {"(", ")", "('", '("', "')", '")'},
|
| Zona.B12_DELIM_BRACK: {"[", "]"},
|
| Zona.B13_DELIM_BRACE: {"{", "}"},
|
| Zona.B14_PUNCT: {",", ";", ":", "..."},
|
| Zona.B15_COMMENT: {
|
| "#",
|
| "//",
|
| "/*",
|
| "*/",
|
| "--",
|
| },
|
|
|
|
|
|
|
| Zona.B16_ID_VAR: {
|
| "self",
|
| "cls",
|
| "_",
|
| "this",
|
| },
|
| Zona.B17_ID_FUNC: {},
|
| Zona.B18_ID_CLASS: {},
|
| Zona.B19_ID_PARAM: {"args", "kwargs"},
|
| Zona.B20_ID_ATTR: {},
|
| Zona.B21_LIT_INT: {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"},
|
| Zona.B22_LIT_FLOAT: {
|
| "0.0",
|
| "1.0",
|
| "0.5",
|
| "0.1",
|
| "3.14",
|
| "1e-5",
|
| "NaN",
|
| "Infinity",
|
| },
|
| Zona.B23_LIT_STR: {
|
| "'",
|
| '"',
|
| "f'",
|
| 'f"',
|
| "r'",
|
| 'r"',
|
| "b'",
|
| 'b"',
|
| "`",
|
| },
|
| Zona.B24_LIT_BOOL: {
|
| "True",
|
| "False",
|
| "true",
|
| "false",
|
| },
|
| Zona.B25_LIT_NONE: {
|
| "None",
|
| "null",
|
| "undefined",
|
| "nil",
|
| },
|
| Zona.B26_TYPE_PRIM: {
|
|
|
| "int",
|
| "str",
|
| "float",
|
| "bool",
|
| "bytes",
|
| "complex",
|
|
|
| "number",
|
| "string",
|
| "boolean",
|
| "bigint",
|
| "symbol",
|
| "void",
|
|
|
| "i8",
|
| "i16",
|
| "i32",
|
| "i64",
|
| "i128",
|
| "isize",
|
| "u8",
|
| "u16",
|
| "u32",
|
| "u64",
|
| "u128",
|
| "usize",
|
| "f32",
|
| "f64",
|
| "char",
|
|
|
| "integer",
|
| "varchar",
|
| "text",
|
| "decimal",
|
| "numeric",
|
| "timestamp",
|
| "serial",
|
| "bigint",
|
| "smallint",
|
| },
|
| Zona.B27_TYPE_COLL: {
|
|
|
| "list",
|
| "dict",
|
| "set",
|
| "tuple",
|
| "frozenset",
|
| "deque",
|
|
|
| "Array",
|
| "Object",
|
| "Map",
|
| "Set",
|
| "WeakMap",
|
| "WeakSet",
|
|
|
| "Vec",
|
| "HashMap",
|
| "HashSet",
|
| "BTreeMap",
|
| "BTreeSet",
|
| "VecDeque",
|
| "String",
|
|
|
| "table",
|
| "view",
|
| "index",
|
| "schema",
|
| "database",
|
| "column",
|
| },
|
| Zona.B28_TYPE_GEN: {
|
|
|
| "Optional",
|
| "List",
|
| "Dict",
|
| "Tuple",
|
| "Set",
|
| "Union",
|
| "Any",
|
| "Callable",
|
| "Iterator",
|
| "Generator",
|
| "Iterable",
|
| "Sequence",
|
| "Mapping",
|
|
|
| "Option",
|
| "Result",
|
| "Box",
|
| "Arc",
|
| "Rc",
|
| "Ref",
|
| "RefCell",
|
| "Mutex",
|
| "Some",
|
| "Ok",
|
| "Err",
|
|
|
| "Partial",
|
| "Readonly",
|
| "Record",
|
| "Pick",
|
| "Omit",
|
| "Exclude",
|
| "Extract",
|
| "ReturnType",
|
| "Promise",
|
| },
|
| Zona.B29_BUILTIN: {
|
|
|
| "print",
|
| "len",
|
| "range",
|
| "open",
|
| "input",
|
| "type",
|
| "isinstance",
|
| "issubclass",
|
| "hasattr",
|
| "getattr",
|
| "setattr",
|
| "delattr",
|
| "abs",
|
| "min",
|
| "max",
|
| "sum",
|
| "sorted",
|
| "reversed",
|
| "enumerate",
|
| "zip",
|
| "map",
|
| "filter",
|
| "any",
|
| "all",
|
| "round",
|
| "pow",
|
| "repr",
|
| "hash",
|
| "id",
|
| "iter",
|
| "next",
|
| "callable",
|
| "super",
|
| "object",
|
| "format",
|
| "chr",
|
| "ord",
|
| "hex",
|
| "bin",
|
| "oct",
|
| "ValueError",
|
| "TypeError",
|
| "KeyError",
|
| "IndexError",
|
| "AttributeError",
|
| "RuntimeError",
|
| "StopIteration",
|
| "FileNotFoundError",
|
| "IOError",
|
| "Exception",
|
| "BaseException",
|
| "NotImplementedError",
|
| "ZeroDivisionError",
|
|
|
| "console",
|
| "JSON",
|
| "Math",
|
| "Date",
|
| "RegExp",
|
| "Symbol",
|
| "parseInt",
|
| "parseFloat",
|
| "isNaN",
|
| "isFinite",
|
| "setTimeout",
|
| "setInterval",
|
| "clearTimeout",
|
| "clearInterval",
|
| "fetch",
|
| "Error",
|
| "Promise",
|
|
|
| "println",
|
| "eprintln",
|
| "dbg",
|
| "vec",
|
| "panic",
|
| "assert_eq",
|
| "assert_ne",
|
| "todo",
|
| "unimplemented",
|
|
|
| "count",
|
| "avg",
|
| "coalesce",
|
| "cast",
|
| "convert",
|
| "exists",
|
| "between",
|
| "like",
|
| "ilike",
|
|
|
| "echo",
|
| "read",
|
| "cd",
|
| "ls",
|
| "grep",
|
| "sed",
|
| "awk",
|
| "cat",
|
| "mv",
|
| "cp",
|
| "rm",
|
| "mkdir",
|
| "chmod",
|
| "chown",
|
| "find",
|
| "xargs",
|
| "curl",
|
| "wget",
|
| "tar",
|
| "ssh",
|
| "git",
|
| "docker",
|
| },
|
| Zona.B30_MAGIC: {
|
| "__init__",
|
| "__str__",
|
| "__repr__",
|
| "__len__",
|
| "__call__",
|
| "__enter__",
|
| "__exit__",
|
| "__iter__",
|
| "__next__",
|
| "__getitem__",
|
| "__setitem__",
|
| "__delitem__",
|
| "__contains__",
|
| "__eq__",
|
| "__lt__",
|
| "__gt__",
|
| "__le__",
|
| "__ge__",
|
| "__ne__",
|
| "__hash__",
|
| "__add__",
|
| "__sub__",
|
| "__mul__",
|
| "__truediv__",
|
| "__floordiv__",
|
| "__mod__",
|
| "__pow__",
|
| "__and__",
|
| "__or__",
|
| "__xor__",
|
| "__bool__",
|
| "__int__",
|
| "__float__",
|
| "__index__",
|
| "__new__",
|
| "__del__",
|
| "__slots__",
|
| "__dict__",
|
| "__class__",
|
| "__name__",
|
| "__doc__",
|
| "__module__",
|
| "__file__",
|
| "__all__",
|
| },
|
|
|
|
|
|
|
|
|
|
|
| Zona.B31_OP_ARITH: {"+", "-", "*", "/", "%", "**", "//"},
|
| Zona.B32_OP_COMP: {
|
| "==",
|
| "!=",
|
| "<",
|
| ">",
|
| "<=",
|
| ">=",
|
| "is",
|
| "in",
|
| "not",
|
| "===",
|
| "!==",
|
| "typeof",
|
| "instanceof",
|
| },
|
| Zona.B33_OP_LOGIC: {
|
| "and",
|
| "or",
|
| "&&",
|
| "||",
|
| "union",
|
| "intersect",
|
| },
|
| Zona.B34_OP_BIT: {"&", "|", "^", "~", "<<", ">>", ">>>"},
|
| Zona.B35_OP_ASSIGN: {
|
| "=",
|
| "+=",
|
| "-=",
|
| "*=",
|
| "/=",
|
| ":=",
|
| "//=",
|
| "**=",
|
| "%=",
|
| "&=",
|
| "|=",
|
| "^=",
|
| "<<=",
|
| ">>=",
|
| "??=",
|
| },
|
| Zona.B36_OP_MEMBER: {
|
| ".",
|
| "::",
|
| "?.",
|
| },
|
| Zona.B37_OP_TERNARY: {
|
| "??",
|
| },
|
| Zona.B38_FLOW_BRANCH: {},
|
| Zona.B39_FLOW_LOOP: {},
|
| Zona.B40_FLOW_JUMP: {},
|
| Zona.B41_FLOW_CALL: {},
|
| Zona.B42_FLOW_EXCEPT: {},
|
|
|
|
|
|
|
|
|
| Zona.B43_BLOCK_FUNC: {
|
| "->",
|
| "=>",
|
| },
|
| Zona.B44_BLOCK_CLASS: {},
|
| Zona.B45_BLOCK_LOOP: {},
|
| Zona.B46_BLOCK_COND: {},
|
| Zona.B47_INDENT: {"\t", " "},
|
| Zona.B48_NEWLINE: {"\n", "\r\n"},
|
| Zona.B49_SPACE: {" ", " "},
|
| Zona.B50_PATTERN_LIST: {},
|
| Zona.B51_PATTERN_DICT: {},
|
| Zona.B52_PATTERN_CALL: {"from"},
|
| }
|
|
|