mirror of https://github.com/mtshiba/pylyzer
trial
This commit is contained in:
parent
94c0d1f86a
commit
69d634115a
|
|
@ -2,6 +2,12 @@
|
|||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "Inflector"
|
||||
version = "0.11.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3"
|
||||
|
||||
[[package]]
|
||||
name = "addr2line"
|
||||
version = "0.19.0"
|
||||
|
|
@ -18,54 +24,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.0.1"
|
||||
name = "anyhow"
|
||||
version = "1.0.71"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67fc08ce920c31afb70f013dcce1bfc3a3195de6a228474e45e1f145b36f8d04"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arrayref"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545"
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
|
||||
|
||||
[[package]]
|
||||
name = "ascii-canvas"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ff8eb72df928aafb99fe5d37b383f2fe25bd2a765e3e5f7c365916b6f2463a29"
|
||||
dependencies = [
|
||||
"term",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0dde43e75fd43e8a1bf86103336bc699aa8d17ad1be60c76c0bdfd4828e19b78"
|
||||
dependencies = [
|
||||
"autocfg 1.1.0",
|
||||
]
|
||||
checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
|
|
@ -99,77 +61,12 @@ dependencies = [
|
|||
"nix",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
|
||||
|
||||
[[package]]
|
||||
name = "bit-set"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1"
|
||||
dependencies = [
|
||||
"bit-vec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bit-vec"
|
||||
version = "0.6.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "blake2b_simd"
|
||||
version = "0.5.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"arrayvec",
|
||||
"constant_time_eq",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b"
|
||||
dependencies = [
|
||||
"block-padding",
|
||||
"byte-tools",
|
||||
"byteorder",
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block-padding"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5"
|
||||
dependencies = [
|
||||
"byte-tools",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "byte-tools"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.79"
|
||||
|
|
@ -183,66 +80,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "cloudabi"
|
||||
version = "0.0.3"
|
||||
name = "crunchy"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "constant_time_eq"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "diff"
|
||||
version = "0.1.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8"
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"redox_users",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "docopt"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f3f119846c823f9eafcf953a8f6ffb6ed69bf6240883261a7f13b634579a51f"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"regex",
|
||||
"serde",
|
||||
"strsim",
|
||||
]
|
||||
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
|
|
@ -263,15 +104,6 @@ dependencies = [
|
|||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ena"
|
||||
version = "0.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8944dc8fa28ce4a38f778bd46bf7d923fe73eed5a439398507246c8e017e6f36"
|
||||
dependencies = [
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "erg_common"
|
||||
version = "0.6.14-nightly.0"
|
||||
|
|
@ -301,21 +133,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "bfd44c03719e8051c7997263298e2b792da6138f818646d0eeae359f92bf0c60"
|
||||
dependencies = [
|
||||
"erg_common",
|
||||
"unicode-xid 0.2.4",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fake-simd"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
|
||||
|
||||
[[package]]
|
||||
name = "fixedbitset"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86d4de0081402f5e88cdac65c8dcdcc73118c1a7a465e2a05f0da05843a8ea33"
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.1.0"
|
||||
|
|
@ -325,32 +145,6 @@ dependencies = [
|
|||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fuchsia-cprng"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.12.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.1.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gimli"
|
||||
version = "0.27.2"
|
||||
|
|
@ -366,6 +160,12 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hexf-parse"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.3.0"
|
||||
|
|
@ -377,10 +177,23 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.8.2"
|
||||
name = "is-macro"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484"
|
||||
checksum = "8a7d079e129b77477a49c5c4f1cfe9ce6c2c909ef52520693e8e811a714c7b20"
|
||||
dependencies = [
|
||||
"Inflector",
|
||||
"pmutil",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.10.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
|
@ -392,41 +205,40 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6"
|
||||
|
||||
[[package]]
|
||||
name = "lalrpop"
|
||||
version = "0.17.2"
|
||||
name = "lalrpop-util"
|
||||
version = "0.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "64dc3698e75d452867d9bd86f4a723f452ce9d01fe1d55990b79f0c790aa67db"
|
||||
checksum = "3f35c735096c0293d313e8f2a641627472b83d01b937177fe76e5e2708d31e0d"
|
||||
|
||||
[[package]]
|
||||
name = "lexical-parse-float"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "683b3a5ebd0130b8fb52ba0bdc718cc56815b6a097e28ae5a6997d0ad17dc05f"
|
||||
dependencies = [
|
||||
"ascii-canvas",
|
||||
"atty",
|
||||
"bit-set",
|
||||
"diff",
|
||||
"docopt",
|
||||
"ena",
|
||||
"itertools",
|
||||
"lalrpop-util",
|
||||
"petgraph",
|
||||
"regex",
|
||||
"regex-syntax 0.6.29",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"sha2",
|
||||
"string_cache",
|
||||
"term",
|
||||
"unicode-xid 0.1.0",
|
||||
"lexical-parse-integer",
|
||||
"lexical-util",
|
||||
"static_assertions",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lalrpop-util"
|
||||
version = "0.17.2"
|
||||
name = "lexical-parse-integer"
|
||||
version = "0.8.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c277d18683b36349ab5cd030158b54856fca6bb2d5dc5263b06288f486958b7c"
|
||||
checksum = "6d0994485ed0c312f6d965766754ea177d07f9c00c9b82a5ee62ed5b47945ee9"
|
||||
dependencies = [
|
||||
"lexical-util",
|
||||
"static_assertions",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
name = "lexical-util"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
checksum = "5255b9ff16ff898710eb9eb63cb39248ea8a5bb036bea8085b1a767ff6c4e3fc"
|
||||
dependencies = [
|
||||
"static_assertions",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
|
|
@ -456,6 +268,12 @@ dependencies = [
|
|||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "matches"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
|
|
@ -468,7 +286,7 @@ version = "0.6.5"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
|
||||
dependencies = [
|
||||
"autocfg 1.1.0",
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -480,12 +298,6 @@ dependencies = [
|
|||
"adler",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "new_debug_unreachable"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.23.2"
|
||||
|
|
@ -501,11 +313,11 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "num-bigint"
|
||||
version = "0.2.6"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304"
|
||||
checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f"
|
||||
dependencies = [
|
||||
"autocfg 1.1.0",
|
||||
"autocfg",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
]
|
||||
|
|
@ -516,7 +328,7 @@ version = "0.1.45"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
|
||||
dependencies = [
|
||||
"autocfg 1.1.0",
|
||||
"autocfg",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
|
|
@ -526,7 +338,7 @@ version = "0.2.15"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
|
||||
dependencies = [
|
||||
"autocfg 1.1.0",
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -539,16 +351,10 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "opaque-debug"
|
||||
version = "0.2.3"
|
||||
name = "once_cell"
|
||||
version = "1.17.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
|
||||
|
||||
[[package]]
|
||||
name = "ordermap"
|
||||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063"
|
||||
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
|
|
@ -557,20 +363,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e"
|
||||
|
||||
[[package]]
|
||||
name = "petgraph"
|
||||
version = "0.4.13"
|
||||
name = "phf"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c3659d1ee90221741f65dd128d9998311b0e40c5d3c23a62445938214abce4f"
|
||||
checksum = "928c6535de93548188ef63bb7c4036bd415cd8f36ad25af44b9789b2ee72a48c"
|
||||
dependencies = [
|
||||
"fixedbitset",
|
||||
"ordermap",
|
||||
"phf_shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_codegen"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a56ac890c5e3ca598bbdeaa99964edb5b0258a583a9eb6ef4e89fc85d9224770"
|
||||
dependencies = [
|
||||
"phf_generator",
|
||||
"phf_shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_generator"
|
||||
version = "0.7.24"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09364cc93c159b8b06b1f4dd8a4398984503483891b0c26b867cf431fb132662"
|
||||
checksum = "b1181c94580fa345f50f19d738aaa39c0ed30a600d95cb2d3e23f94266f14fbf"
|
||||
dependencies = [
|
||||
"phf_shared",
|
||||
"rand",
|
||||
|
|
@ -578,18 +393,23 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "phf_shared"
|
||||
version = "0.7.24"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "234f71a15de2288bcb7e3b6515828d22af7ec8598ee6d24c3b526fa0a80b67a0"
|
||||
checksum = "e1fb5f6f826b772a8d4c0394209441e7d37cbbb967ae9c7e0e8134365c9ee676"
|
||||
dependencies = [
|
||||
"siphasher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "precomputed-hash"
|
||||
version = "0.1.1"
|
||||
name = "pmutil"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
|
||||
checksum = "3894e5d549cccbe44afecf72922f277f603cd4bb0219c8342631ef18fffbe004"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
|
|
@ -606,6 +426,7 @@ version = "0.0.29"
|
|||
dependencies = [
|
||||
"erg_common",
|
||||
"erg_compiler",
|
||||
"rustpython-ast",
|
||||
"rustpython-parser",
|
||||
]
|
||||
|
||||
|
|
@ -631,170 +452,31 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.6.5"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"autocfg 0.1.8",
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core 0.4.2",
|
||||
"rand_hc",
|
||||
"rand_isaac",
|
||||
"rand_jitter",
|
||||
"rand_os",
|
||||
"rand_pcg",
|
||||
"rand_xorshift",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef"
|
||||
dependencies = [
|
||||
"autocfg 0.1.8",
|
||||
"rand_core 0.3.1",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.3.1"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
|
||||
[[package]]
|
||||
name = "ruff_source_location"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"rand_core 0.4.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4"
|
||||
dependencies = [
|
||||
"rand_core 0.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_isaac"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08"
|
||||
dependencies = [
|
||||
"rand_core 0.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_jitter"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_core 0.4.2",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_os"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071"
|
||||
dependencies = [
|
||||
"cloudabi",
|
||||
"fuchsia-cprng",
|
||||
"libc",
|
||||
"rand_core 0.4.2",
|
||||
"rdrand",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_pcg"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44"
|
||||
dependencies = [
|
||||
"autocfg 0.1.8",
|
||||
"rand_core 0.4.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_xorshift"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c"
|
||||
dependencies = [
|
||||
"rand_core 0.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rdrand"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
|
||||
dependencies = [
|
||||
"rand_core 0.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.1.57"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"redox_syscall",
|
||||
"rust-argon2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af83e617f331cc6ae2da5443c602dfa5af81e517212d9d611a5b3ba1777b5370"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax 0.7.1",
|
||||
"once_cell",
|
||||
"ruff_text_size",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a5996294f19bd3aae0453a862ad728f60e6600695733dd5df01da90c54363a3c"
|
||||
|
||||
[[package]]
|
||||
name = "rust-argon2"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"blake2b_simd",
|
||||
"constant_time_eq",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
name = "ruff_text_size"
|
||||
version = "0.0.0"
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
|
|
@ -803,21 +485,64 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
|
||||
|
||||
[[package]]
|
||||
name = "rustpython-parser"
|
||||
version = "0.1.2"
|
||||
name = "rustc-hash"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d85b1038ecd8791bdae455ae784b48f522ebeca1b3323d0af2b251c5c8ff1c68"
|
||||
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
|
||||
|
||||
[[package]]
|
||||
name = "rustpython-ast"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"lalrpop",
|
||||
"is-macro",
|
||||
"num-bigint",
|
||||
"rustpython-literal",
|
||||
"rustpython-parser-core",
|
||||
"static_assertions",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustpython-literal"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"hexf-parse",
|
||||
"is-macro",
|
||||
"lexical-parse-float",
|
||||
"num-traits",
|
||||
"unic-ucd-category",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustpython-parser"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"is-macro",
|
||||
"itertools",
|
||||
"lalrpop-util",
|
||||
"log",
|
||||
"num-bigint",
|
||||
"num-traits",
|
||||
"phf",
|
||||
"phf_codegen",
|
||||
"rustc-hash",
|
||||
"rustpython-ast",
|
||||
"rustpython-parser-core",
|
||||
"tiny-keccak",
|
||||
"unic-emoji-char",
|
||||
"unic-ucd-ident",
|
||||
"unicode_names2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustpython-parser-core"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"is-macro",
|
||||
"ruff_source_location",
|
||||
"ruff_text_size",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.13"
|
||||
|
|
@ -841,7 +566,7 @@ checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.16",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -863,67 +588,32 @@ checksum = "bcec881020c684085e55a25f7fd888954d56609ef363479dc5a1305eb0d40cab"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"digest",
|
||||
"fake-simd",
|
||||
"opaque-debug",
|
||||
"syn 2.0.16",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "0.2.3"
|
||||
version = "0.3.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac"
|
||||
checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
|
||||
|
||||
[[package]]
|
||||
name = "string_cache"
|
||||
version = "0.7.5"
|
||||
name = "static_assertions"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89c058a82f9fd69b1becf8c274f412281038877c553182f1d02eb027045a2d67"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"new_debug_unreachable",
|
||||
"phf_shared",
|
||||
"precomputed-hash",
|
||||
"serde",
|
||||
"string_cache_codegen",
|
||||
"string_cache_shared",
|
||||
]
|
||||
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||
|
||||
[[package]]
|
||||
name = "string_cache_codegen"
|
||||
version = "0.4.4"
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0f45ed1b65bf9a4bf2f7b7dc59212d1926e9eaf00fa998988e420fd124467c6"
|
||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||
dependencies = [
|
||||
"phf_generator",
|
||||
"phf_shared",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"string_cache_shared",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "string_cache_shared"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1884d1bc09741d466d9b14e6d37ac89d6909cbcac41dd9ae982d4d063bbedfc"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.16"
|
||||
|
|
@ -936,14 +626,12 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "term"
|
||||
version = "0.5.2"
|
||||
name = "tiny-keccak"
|
||||
version = "2.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "edd106a334b7657c10b7c540a0106114feadeb4dc314513e97df481d5d966f42"
|
||||
checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"dirs",
|
||||
"winapi",
|
||||
"crunchy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -961,12 +649,6 @@ version = "0.1.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
|
||||
|
||||
[[package]]
|
||||
name = "unic-char-property"
|
||||
version = "0.9.0"
|
||||
|
|
@ -999,6 +681,18 @@ dependencies = [
|
|||
"unic-ucd-version",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unic-ucd-category"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b8d4591f5fcfe1bd4453baaf803c40e1b1e69ff8455c47620440b46efef91c0"
|
||||
dependencies = [
|
||||
"matches",
|
||||
"unic-char-property",
|
||||
"unic-char-range",
|
||||
"unic-ucd-version",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unic-ucd-ident"
|
||||
version = "0.9.0"
|
||||
|
|
@ -1040,12 +734,6 @@ dependencies = [
|
|||
"tinyvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.4"
|
||||
|
|
@ -1054,9 +742,11 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
|
|||
|
||||
[[package]]
|
||||
name = "unicode_names2"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87d6678d7916394abad0d4b19df4d3802e1fd84abd7d701f39b75ee71b9e8cf1"
|
||||
version = "0.6.0"
|
||||
source = "git+https://github.com/youknowone/unicode_names2.git?rev=4ce16aa85cbcdd9cc830410f1a72ef9a235f2fde#4ce16aa85cbcdd9cc830410f1a72ef9a235f2fde"
|
||||
dependencies = [
|
||||
"phf",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "url"
|
||||
|
|
@ -1070,12 +760,6 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.9.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
|
|
|
|||
|
|
@ -25,7 +25,9 @@ repository = "https://github.com/mtshiba/pylyzer"
|
|||
erg_common = { version = "0.6.14-nightly.0", features = ["py_compat", "els"] }
|
||||
erg_compiler = { version = "0.6.14-nightly.0", features = ["py_compat", "els"] }
|
||||
els = { version = "0.1.26-nightly.0", features = ["py_compat"] }
|
||||
rustpython-parser = "0.1.2"
|
||||
# rustpython-parser = { git = "https://github.com/RustPython/Parser.git", rev = "4de0cb18277f45aecd1cfdcc5ac69ab6bd9e2854", features = ["rustpython-literal"] }
|
||||
rustpython-ast = { path = "../RustPython-Parser/ast", features = ["rustpython-literal"] }
|
||||
rustpython-parser = { path = "../RustPython-Parser/parser" }
|
||||
# erg_compiler = { git = "https://github.com/erg-lang/erg", branch = "main", features = ["py_compat", "els"] }
|
||||
# erg_common = { git = "https://github.com/erg-lang/erg", branch = "main", features = ["py_compat", "els"] }
|
||||
# els = { git = "https://github.com/erg-lang/erg", branch = "main", features = ["py_compat"] }
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ debug = ["erg_compiler/debug", "erg_common/debug"]
|
|||
|
||||
[dependencies]
|
||||
rustpython-parser = { workspace = true }
|
||||
rustpython-ast = { workspace = true }
|
||||
erg_common = { workspace = true }
|
||||
erg_compiler = { workspace = true }
|
||||
|
||||
|
|
|
|||
|
|
@ -1,124 +1,12 @@
|
|||
use erg_common::log;
|
||||
use rustpython_parser::ast::{
|
||||
BooleanOperator, Comparison, ExpressionType, Keyword, Number, StringGroup,
|
||||
};
|
||||
use rustpython_parser::ast::{Boolop, Cmpop, Constant, ExpressionType, Keyword, StringGroup};
|
||||
|
||||
pub fn number_to_string(num: &Number) -> String {
|
||||
match num {
|
||||
Number::Integer { value } => value.to_string(),
|
||||
Number::Float { value } => value.to_string(),
|
||||
Number::Complex { real, imag } => format!("{real}+{imag}j"),
|
||||
}
|
||||
pub fn number_to_string(num: &Constant) -> String {
|
||||
num.to_string()
|
||||
}
|
||||
|
||||
pub fn keyword_length(keyword: &Keyword) -> usize {
|
||||
if let Some(name) = &keyword.name {
|
||||
name.len() + 1 + length(&keyword.value.node)
|
||||
} else {
|
||||
length(&keyword.value.node)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn string_length(string: &StringGroup) -> usize {
|
||||
match string {
|
||||
StringGroup::Constant { value } => value.len(),
|
||||
StringGroup::Joined { values } => values.iter().map(string_length).sum(),
|
||||
other => {
|
||||
log!(err "{other:?}");
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn comp_to_string(comp: &Comparison) -> String {
|
||||
match comp {
|
||||
Comparison::In => "in".to_string(),
|
||||
Comparison::NotIn => "not in".to_string(),
|
||||
Comparison::Is => "is".to_string(),
|
||||
Comparison::IsNot => "is not".to_string(),
|
||||
Comparison::Less => "<".to_string(),
|
||||
Comparison::Greater => ">".to_string(),
|
||||
Comparison::Equal => "==".to_string(),
|
||||
Comparison::NotEqual => "!=".to_string(),
|
||||
Comparison::LessOrEqual => "<=".to_string(),
|
||||
Comparison::GreaterOrEqual => ">=".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn length(expr: &ExpressionType) -> usize {
|
||||
match expr {
|
||||
ExpressionType::Identifier { name } => name.len(),
|
||||
ExpressionType::Number { value } => number_to_string(value).len(),
|
||||
ExpressionType::String { value } => string_length(value),
|
||||
ExpressionType::Attribute { value, name } => length(&value.node) + name.len() + 1,
|
||||
ExpressionType::Subscript { a, b } => length(&a.node) + length(&b.node) + 2,
|
||||
ExpressionType::Tuple { elements }
|
||||
| ExpressionType::List { elements }
|
||||
| ExpressionType::Set { elements } => {
|
||||
if let (Some(first), Some(last)) = (elements.first(), elements.last()) {
|
||||
2 + last.location.column() - first.location.column()
|
||||
} else {
|
||||
2
|
||||
}
|
||||
}
|
||||
ExpressionType::Call {
|
||||
function,
|
||||
args,
|
||||
keywords,
|
||||
} => {
|
||||
let args_len = if let (Some(first), Some(last)) = (args.first(), args.last()) {
|
||||
last.location.column() - first.location.column()
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let kw_len = if let (Some(first), Some(last)) = (keywords.first(), keywords.last()) {
|
||||
last.value.location.column() - first.value.location.column()
|
||||
} else {
|
||||
0
|
||||
};
|
||||
length(&function.node) + args_len + kw_len + 2 // ()
|
||||
}
|
||||
ExpressionType::Unop { op: _, a } => 1 + length(&a.node),
|
||||
ExpressionType::Binop { a, op: _, b } => length(&a.node) + 3 + length(&b.node),
|
||||
ExpressionType::BoolOp { op, values } => match op {
|
||||
BooleanOperator::And => values
|
||||
.iter()
|
||||
.map(|elem| length(&elem.node))
|
||||
.fold(0, |acc, x| acc + x + 3),
|
||||
BooleanOperator::Or => values
|
||||
.iter()
|
||||
.map(|elem| length(&elem.node))
|
||||
.fold(0, |acc, x| acc + x + 2),
|
||||
},
|
||||
ExpressionType::Compare { vals, ops } => vals
|
||||
.iter()
|
||||
.zip(ops.iter())
|
||||
.map(|(elem, op)| length(&elem.node) + comp_to_string(op).len())
|
||||
.fold(0, |acc, x| acc + x + 2),
|
||||
ExpressionType::IfExpression { test, body, orelse } => {
|
||||
// x if y else z
|
||||
length(&test.node) + 4 + length(&body.node) + 6 + length(&orelse.node)
|
||||
}
|
||||
ExpressionType::Lambda { args: _, body } => {
|
||||
// lambda x: y
|
||||
// TODO:
|
||||
7 + 1 + length(&body.node)
|
||||
}
|
||||
ExpressionType::Await { value } => 5 + length(&value.node),
|
||||
ExpressionType::Yield { value } => 5 + value.as_ref().map(|x| length(&x.node)).unwrap_or(0),
|
||||
ExpressionType::NamedExpression { left, right } => {
|
||||
// x := y
|
||||
length(&left.node) + 4 + length(&right.node)
|
||||
}
|
||||
ExpressionType::Starred { value } => 1 + length(&value.node),
|
||||
ExpressionType::False => 5,
|
||||
ExpressionType::True | ExpressionType::None => 4,
|
||||
ExpressionType::Ellipsis => 8,
|
||||
other => {
|
||||
log!(err "{other:?}");
|
||||
0
|
||||
}
|
||||
}
|
||||
pub fn comp_to_string(comp: &Cmpop) -> String {
|
||||
cmpop.as_str()
|
||||
}
|
||||
|
||||
pub fn accessor_name(expr: ExpressionType) -> Option<String> {
|
||||
|
|
|
|||
|
|
@ -1,272 +0,0 @@
|
|||
use rustpython_parser::ast::{
|
||||
BooleanOperator, Comparison, Comprehension, ComprehensionKind, ExpressionType, Keyword,
|
||||
Located, Number, Operator, Parameter, Parameters, StringGroup, UnaryOperator, Varargs,
|
||||
};
|
||||
|
||||
fn clone_number(num: &Number) -> Number {
|
||||
match num {
|
||||
Number::Integer { value } => Number::Integer {
|
||||
value: value.clone(),
|
||||
},
|
||||
Number::Float { value } => Number::Float { value: *value },
|
||||
Number::Complex { real, imag } => Number::Complex {
|
||||
real: *real,
|
||||
imag: *imag,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_string_group(group: &StringGroup) -> StringGroup {
|
||||
match group {
|
||||
StringGroup::Constant { value } => StringGroup::Constant {
|
||||
value: value.clone(),
|
||||
},
|
||||
StringGroup::FormattedValue {
|
||||
value,
|
||||
conversion,
|
||||
spec,
|
||||
} => StringGroup::FormattedValue {
|
||||
value: Box::new(clone_loc_expr(value)),
|
||||
conversion: *conversion,
|
||||
spec: spec.as_deref().map(|sp| Box::new(clone_string_group(sp))),
|
||||
},
|
||||
StringGroup::Joined { values } => StringGroup::Joined {
|
||||
values: values.iter().map(clone_string_group).collect::<Vec<_>>(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_unary_op(op: &UnaryOperator) -> UnaryOperator {
|
||||
match op {
|
||||
UnaryOperator::Not => UnaryOperator::Not,
|
||||
UnaryOperator::Inv => UnaryOperator::Inv,
|
||||
UnaryOperator::Pos => UnaryOperator::Pos,
|
||||
UnaryOperator::Neg => UnaryOperator::Neg,
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_bin_op(op: &Operator) -> Operator {
|
||||
match op {
|
||||
Operator::Add => Operator::Add,
|
||||
Operator::Sub => Operator::Sub,
|
||||
Operator::Mult => Operator::Mult,
|
||||
Operator::MatMult => Operator::MatMult,
|
||||
Operator::Div => Operator::Div,
|
||||
Operator::Mod => Operator::Mod,
|
||||
Operator::Pow => Operator::Pow,
|
||||
Operator::LShift => Operator::LShift,
|
||||
Operator::RShift => Operator::RShift,
|
||||
Operator::BitOr => Operator::BitOr,
|
||||
Operator::BitXor => Operator::BitXor,
|
||||
Operator::BitAnd => Operator::BitAnd,
|
||||
Operator::FloorDiv => Operator::FloorDiv,
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_comp_op(op: &Comparison) -> Comparison {
|
||||
match op {
|
||||
Comparison::Equal => Comparison::Equal,
|
||||
Comparison::NotEqual => Comparison::NotEqual,
|
||||
Comparison::Less => Comparison::Less,
|
||||
Comparison::LessOrEqual => Comparison::LessOrEqual,
|
||||
Comparison::Greater => Comparison::Greater,
|
||||
Comparison::GreaterOrEqual => Comparison::GreaterOrEqual,
|
||||
Comparison::Is => Comparison::Is,
|
||||
Comparison::IsNot => Comparison::IsNot,
|
||||
Comparison::In => Comparison::In,
|
||||
Comparison::NotIn => Comparison::NotIn,
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_bool_op(op: &BooleanOperator) -> BooleanOperator {
|
||||
match op {
|
||||
BooleanOperator::And => BooleanOperator::And,
|
||||
BooleanOperator::Or => BooleanOperator::Or,
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_param(param: &Parameter) -> Parameter {
|
||||
Parameter {
|
||||
location: param.location,
|
||||
arg: param.arg.clone(),
|
||||
annotation: param
|
||||
.annotation
|
||||
.as_deref()
|
||||
.map(|a| Box::new(clone_loc_expr(a))),
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_varargs(varargs: &Varargs) -> Varargs {
|
||||
match varargs {
|
||||
Varargs::None => Varargs::None,
|
||||
Varargs::Unnamed => Varargs::Unnamed,
|
||||
Varargs::Named(name) => Varargs::Named(clone_param(name)),
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_params(params: &Parameters) -> Parameters {
|
||||
Parameters {
|
||||
posonlyargs_count: params.posonlyargs_count,
|
||||
args: params.args.iter().map(clone_param).collect::<Vec<_>>(),
|
||||
vararg: clone_varargs(¶ms.vararg),
|
||||
kwonlyargs: params
|
||||
.kwonlyargs
|
||||
.iter()
|
||||
.map(clone_param)
|
||||
.collect::<Vec<_>>(),
|
||||
kw_defaults: params
|
||||
.kw_defaults
|
||||
.iter()
|
||||
.map(|def| def.as_ref().map(clone_loc_expr))
|
||||
.collect::<Vec<_>>(),
|
||||
kwarg: clone_varargs(¶ms.kwarg),
|
||||
defaults: params
|
||||
.defaults
|
||||
.iter()
|
||||
.map(clone_loc_expr)
|
||||
.collect::<Vec<_>>(),
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_kw(keyword: &Keyword) -> Keyword {
|
||||
Keyword {
|
||||
name: keyword.name.clone(),
|
||||
value: clone_loc_expr(&keyword.value),
|
||||
}
|
||||
}
|
||||
|
||||
fn clone_comprehension_kind(kind: &ComprehensionKind) -> ComprehensionKind {
|
||||
match kind {
|
||||
ComprehensionKind::Dict { key, value } => ComprehensionKind::Dict {
|
||||
key: clone_loc_expr(key),
|
||||
value: clone_loc_expr(value),
|
||||
},
|
||||
ComprehensionKind::List { element } => ComprehensionKind::List {
|
||||
element: clone_loc_expr(element),
|
||||
},
|
||||
ComprehensionKind::Set { element } => ComprehensionKind::Set {
|
||||
element: clone_loc_expr(element),
|
||||
},
|
||||
ComprehensionKind::GeneratorExpression { element } => {
|
||||
ComprehensionKind::GeneratorExpression {
|
||||
element: clone_loc_expr(element),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clone_loc_expr(expr: &Located<ExpressionType>) -> Located<ExpressionType> {
|
||||
Located {
|
||||
node: clone_expr(&expr.node),
|
||||
location: expr.location,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clone_expr(expr: &ExpressionType) -> ExpressionType {
|
||||
match expr {
|
||||
ExpressionType::None => ExpressionType::None,
|
||||
ExpressionType::Ellipsis => ExpressionType::Ellipsis,
|
||||
ExpressionType::True => ExpressionType::True,
|
||||
ExpressionType::False => ExpressionType::False,
|
||||
ExpressionType::Identifier { name } => ExpressionType::Identifier { name: name.clone() },
|
||||
ExpressionType::Number { value } => ExpressionType::Number {
|
||||
value: clone_number(value),
|
||||
},
|
||||
ExpressionType::String { value } => ExpressionType::String {
|
||||
value: clone_string_group(value),
|
||||
},
|
||||
ExpressionType::Attribute { value, name } => ExpressionType::Attribute {
|
||||
value: Box::new(clone_loc_expr(value)),
|
||||
name: name.clone(),
|
||||
},
|
||||
ExpressionType::Subscript { a, b } => ExpressionType::Subscript {
|
||||
a: Box::new(clone_loc_expr(a)),
|
||||
b: Box::new(clone_loc_expr(b)),
|
||||
},
|
||||
ExpressionType::Slice { elements } => ExpressionType::Slice {
|
||||
elements: elements.iter().map(clone_loc_expr).collect::<Vec<_>>(),
|
||||
},
|
||||
ExpressionType::Bytes { value } => ExpressionType::Bytes {
|
||||
value: value.clone(),
|
||||
},
|
||||
ExpressionType::Call {
|
||||
function,
|
||||
args,
|
||||
keywords,
|
||||
} => ExpressionType::Call {
|
||||
function: Box::new(clone_loc_expr(function)),
|
||||
args: args.iter().map(clone_loc_expr).collect::<Vec<_>>(),
|
||||
keywords: keywords.iter().map(clone_kw).collect::<Vec<_>>(),
|
||||
},
|
||||
ExpressionType::Unop { op, a } => ExpressionType::Unop {
|
||||
op: clone_unary_op(op),
|
||||
a: Box::new(clone_loc_expr(a)),
|
||||
},
|
||||
ExpressionType::Binop { a, op, b } => ExpressionType::Binop {
|
||||
a: Box::new(clone_loc_expr(a)),
|
||||
op: clone_bin_op(op),
|
||||
b: Box::new(clone_loc_expr(b)),
|
||||
},
|
||||
ExpressionType::Compare { vals, ops } => ExpressionType::Compare {
|
||||
ops: ops.iter().map(clone_comp_op).collect::<Vec<_>>(),
|
||||
vals: vals.iter().map(clone_loc_expr).collect::<Vec<_>>(),
|
||||
},
|
||||
ExpressionType::BoolOp { op, values } => ExpressionType::BoolOp {
|
||||
op: clone_bool_op(op),
|
||||
values: values.iter().map(clone_loc_expr).collect::<Vec<_>>(),
|
||||
},
|
||||
ExpressionType::Lambda { args, body } => ExpressionType::Lambda {
|
||||
args: Box::new(clone_params(args)),
|
||||
body: Box::new(clone_loc_expr(body)),
|
||||
},
|
||||
ExpressionType::IfExpression { test, body, orelse } => ExpressionType::IfExpression {
|
||||
test: Box::new(clone_loc_expr(test)),
|
||||
body: Box::new(clone_loc_expr(body)),
|
||||
orelse: Box::new(clone_loc_expr(orelse)),
|
||||
},
|
||||
ExpressionType::Dict { elements } => ExpressionType::Dict {
|
||||
elements: elements
|
||||
.iter()
|
||||
.map(|(key, value)| (key.as_ref().map(clone_loc_expr), clone_loc_expr(value)))
|
||||
.collect::<Vec<_>>(),
|
||||
},
|
||||
ExpressionType::Set { elements } => ExpressionType::Set {
|
||||
elements: elements.iter().map(clone_loc_expr).collect::<Vec<_>>(),
|
||||
},
|
||||
ExpressionType::List { elements } => ExpressionType::List {
|
||||
elements: elements.iter().map(clone_loc_expr).collect::<Vec<_>>(),
|
||||
},
|
||||
ExpressionType::Tuple { elements } => ExpressionType::Tuple {
|
||||
elements: elements.iter().map(clone_loc_expr).collect::<Vec<_>>(),
|
||||
},
|
||||
ExpressionType::Yield { value } => ExpressionType::Yield {
|
||||
value: value.as_ref().map(|val| Box::new(clone_loc_expr(val))),
|
||||
},
|
||||
ExpressionType::YieldFrom { value } => ExpressionType::YieldFrom {
|
||||
value: Box::new(clone_loc_expr(value)),
|
||||
},
|
||||
ExpressionType::Await { value } => ExpressionType::Await {
|
||||
value: Box::new(clone_loc_expr(value)),
|
||||
},
|
||||
ExpressionType::NamedExpression { left, right } => ExpressionType::NamedExpression {
|
||||
left: Box::new(clone_loc_expr(left)),
|
||||
right: Box::new(clone_loc_expr(right)),
|
||||
},
|
||||
ExpressionType::Starred { value } => ExpressionType::Starred {
|
||||
value: Box::new(clone_loc_expr(value)),
|
||||
},
|
||||
ExpressionType::Comprehension { kind, generators } => ExpressionType::Comprehension {
|
||||
kind: Box::new(clone_comprehension_kind(kind)),
|
||||
generators: generators
|
||||
.iter()
|
||||
.map(|gen| Comprehension {
|
||||
location: gen.location,
|
||||
target: clone_loc_expr(&gen.target),
|
||||
iter: clone_loc_expr(&gen.iter),
|
||||
ifs: gen.ifs.iter().map(clone_loc_expr).collect::<Vec<_>>(),
|
||||
is_async: gen.is_async,
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -22,14 +22,15 @@ use erg_compiler::erg_parser::desugar::Desugarer;
|
|||
use erg_compiler::erg_parser::token::{Token, TokenKind, AS, DOT, EQUAL};
|
||||
use erg_compiler::erg_parser::Parser;
|
||||
use erg_compiler::error::{CompileError, CompileErrors};
|
||||
use rustpython_parser::ast::{
|
||||
BooleanOperator, Comparison, ExpressionType, ImportSymbol, Located, Number, Operator,
|
||||
Parameter, Parameters, Program, StatementType, StringGroup, Suite, UnaryOperator,
|
||||
use rustpython_parser::ast::located::{
|
||||
self as py_ast, Boolop, Cmpop, ImportSymbol, Keyword, Located, ModModule, Number, Operator,
|
||||
Parameter, Parameters, StringGroup, Suite, Suite, Unaryop,
|
||||
};
|
||||
use rustpython_parser::source_code::{
|
||||
SourceLocation as PyLocation, SourceLocator, SourceRange as PySourceRange,
|
||||
};
|
||||
use rustpython_parser::ast::{Keyword, Location as PyLocation};
|
||||
|
||||
use crate::ast_util::{accessor_name, length};
|
||||
use crate::clone::clone_loc_expr;
|
||||
use crate::ast_util::accessor_name;
|
||||
use crate::error::*;
|
||||
|
||||
pub const ARROW: Token = Token::dummy(TokenKind::FuncArrow, "->");
|
||||
|
|
@ -117,12 +118,12 @@ fn op_to_token(op: Operator) -> Token {
|
|||
Token::from_str(kind, cont)
|
||||
}
|
||||
|
||||
pub fn pyloc_to_ergloc(loc: PyLocation, cont_len: usize) -> erg_common::error::Location {
|
||||
pub fn pyloc_to_ergloc(range: PySourceRange) -> erg_common::error::Location {
|
||||
erg_common::error::Location::range(
|
||||
loc.row() as u32,
|
||||
loc.column() as u32,
|
||||
loc.row() as u32,
|
||||
(loc.column() + cont_len) as u32,
|
||||
loc.start.row() as u32,
|
||||
loc.start.column() as u32,
|
||||
loc.end.row() as u32,
|
||||
loc.end.column() as u32,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -369,7 +370,7 @@ impl ASTConverter {
|
|||
.annotation
|
||||
.map(|anot| {
|
||||
(
|
||||
self.convert_type_spec(clone_loc_expr(&anot)),
|
||||
self.convert_type_spec(anot.clone()),
|
||||
self.convert_expr(*anot),
|
||||
)
|
||||
})
|
||||
|
|
@ -380,7 +381,7 @@ impl ASTConverter {
|
|||
fn convert_default_param(
|
||||
&mut self,
|
||||
kw: Parameter,
|
||||
default: Located<ExpressionType>,
|
||||
default: py_ast::Expr,
|
||||
) -> DefaultParamSignature {
|
||||
let sig = self.convert_nd_param(kw);
|
||||
let default = self.convert_expr(default);
|
||||
|
|
@ -422,7 +423,7 @@ impl ASTConverter {
|
|||
/// (i, j) => $1 (i = $1[0]; j = $1[1])
|
||||
fn convert_opt_expr_to_param(
|
||||
&mut self,
|
||||
expr: Option<Located<ExpressionType>>,
|
||||
expr: Option<py_ast::Expr>,
|
||||
) -> (NonDefaultParamSignature, Vec<Expr>) {
|
||||
if let Some(expr) = expr {
|
||||
self.convert_expr_to_param(expr)
|
||||
|
|
@ -437,22 +438,23 @@ impl ASTConverter {
|
|||
|
||||
fn convert_expr_to_param(
|
||||
&mut self,
|
||||
expr: Located<ExpressionType>,
|
||||
expr: py_ast::Expr,
|
||||
) -> (NonDefaultParamSignature, Vec<Expr>) {
|
||||
match expr.node {
|
||||
ExpressionType::Identifier { name } => {
|
||||
(self.convert_for_param(name, expr.location), vec![])
|
||||
}
|
||||
ExpressionType::Tuple { elements } => {
|
||||
match expr {
|
||||
py_ast::Expr::Name(expr) => (
|
||||
self.convert_for_param(expr.name, expr.location().start()),
|
||||
vec![],
|
||||
),
|
||||
py_ast::Expr::Tuple(expr) => {
|
||||
let tmp = fresh_varname();
|
||||
let tmp_name =
|
||||
VarName::from_str_and_line((&tmp).into(), expr.location.row() as u32);
|
||||
VarName::from_str_and_line((&tmp).into(), expr.location().start().row() as u32);
|
||||
let tmp_expr = Expr::Accessor(Accessor::Ident(Identifier::new(
|
||||
VisModifierSpec::Public(DOT),
|
||||
tmp_name.clone(),
|
||||
)));
|
||||
let mut block = vec![];
|
||||
for (i, elem) in elements.into_iter().enumerate() {
|
||||
for (i, elem) in expr.elts.into_iter().enumerate() {
|
||||
let index = Literal::new(Token::new(
|
||||
TokenKind::NatLit,
|
||||
i.to_string(),
|
||||
|
|
@ -464,9 +466,9 @@ impl ASTConverter {
|
|||
Self::param_pattern_to_var(param.pat),
|
||||
param.t_spec,
|
||||
));
|
||||
let method = tmp_expr
|
||||
.clone()
|
||||
.attr_expr(self.convert_ident("__getitem__".to_string(), expr.location));
|
||||
let method = tmp_expr.clone().attr_expr(
|
||||
self.convert_ident("__getitem__".to_string(), expr.location().start()),
|
||||
);
|
||||
let tuple_acc = method.call1(Expr::Literal(index));
|
||||
let body = DefBody::new(EQUAL, Block::new(vec![tuple_acc]), DefId(0));
|
||||
let def = Expr::Def(Def::new(sig, body));
|
||||
|
|
@ -480,8 +482,8 @@ impl ASTConverter {
|
|||
let token = Token::new(
|
||||
TokenKind::UBar,
|
||||
"_",
|
||||
expr.location.row() as u32,
|
||||
expr.location.column() as u32 - 1,
|
||||
expr.location().start().row() as u32,
|
||||
expr.location().start().column() as u32 - 1,
|
||||
);
|
||||
(
|
||||
NonDefaultParamSignature::new(ParamPattern::Discard(token), None),
|
||||
|
|
@ -491,7 +493,7 @@ impl ASTConverter {
|
|||
}
|
||||
}
|
||||
|
||||
fn convert_for_body(&mut self, lhs: Option<Located<ExpressionType>>, body: Suite) -> Lambda {
|
||||
fn convert_for_body(&mut self, lhs: Option<py_ast::Expr>, body: Suite) -> Lambda {
|
||||
let (param, block) = self.convert_opt_expr_to_param(lhs);
|
||||
let params = Params::new(vec![param], None, vec![], None);
|
||||
self.block_id_counter += 1;
|
||||
|
|
@ -521,18 +523,14 @@ impl ASTConverter {
|
|||
}
|
||||
|
||||
// TODO:
|
||||
fn convert_compound_type_spec(
|
||||
&mut self,
|
||||
name: String,
|
||||
args: Located<ExpressionType>,
|
||||
) -> TypeSpec {
|
||||
fn convert_compound_type_spec(&mut self, name: String, args: py_ast::Expr) -> TypeSpec {
|
||||
match &name[..] {
|
||||
"Union" => {
|
||||
let ExpressionType::Tuple { mut elements } = args.node else {
|
||||
let py_ast::Expr::Tuple { mut elements } = args.node else {
|
||||
let err = CompileError::syntax_error(
|
||||
self.cfg.input.clone(),
|
||||
line!() as usize,
|
||||
pyloc_to_ergloc(args.location, length(&args.node)),
|
||||
pyloc_to_ergloc(args.range()),
|
||||
self.cur_namespace(),
|
||||
"`Union` takes at least 2 types".into(),
|
||||
None,
|
||||
|
|
@ -557,7 +555,7 @@ impl ASTConverter {
|
|||
TypeSpec::or(t, none)
|
||||
}
|
||||
"Literal" => {
|
||||
let ExpressionType::Tuple { elements } = args.node else {
|
||||
let py_ast::Expr::Tuple { elements } = args.node else {
|
||||
return Self::gen_dummy_type_spec(args.location);
|
||||
};
|
||||
let mut elems = vec![];
|
||||
|
|
@ -582,13 +580,13 @@ impl ASTConverter {
|
|||
}
|
||||
// TODO: distinguish from collections.abc.Callable
|
||||
"Callable" => {
|
||||
let ExpressionType::Tuple { mut elements } = args.node else {
|
||||
let py_ast::Expr::Tuple { mut elements } = args.node else {
|
||||
return Self::gen_dummy_type_spec(args.location);
|
||||
};
|
||||
let params = elements.remove(0);
|
||||
let mut non_defaults = vec![];
|
||||
match params.node {
|
||||
ExpressionType::List { elements } => {
|
||||
py_ast::Expr::List { elements } => {
|
||||
for param in elements.into_iter() {
|
||||
let t_spec = self.convert_type_spec(param);
|
||||
non_defaults.push(ParamTySpec::anonymous(t_spec));
|
||||
|
|
@ -598,7 +596,7 @@ impl ASTConverter {
|
|||
let err = CompileError::syntax_error(
|
||||
self.cfg.input.clone(),
|
||||
line!() as usize,
|
||||
pyloc_to_ergloc(params.location, length(&other)),
|
||||
pyloc_to_ergloc(params.range()),
|
||||
self.cur_namespace(),
|
||||
"Expected a list of parameters".into(),
|
||||
None,
|
||||
|
|
@ -642,11 +640,11 @@ impl ASTConverter {
|
|||
TypeSpec::poly(acc, ConstArgs::pos_only(vec![elem_t], None))
|
||||
}
|
||||
"Mapping" | "MutableMapping" => {
|
||||
let ExpressionType::Tuple { mut elements } = args.node else {
|
||||
let py_ast::Expr::Tuple { mut elements } = args.node else {
|
||||
let err = CompileError::syntax_error(
|
||||
self.cfg.input.clone(),
|
||||
line!() as usize,
|
||||
pyloc_to_ergloc(args.location, length(&args.node)),
|
||||
pyloc_to_ergloc(args.location.range()),
|
||||
self.cur_namespace(),
|
||||
format!("`{name}` takes 2 types"),
|
||||
None,
|
||||
|
|
@ -718,7 +716,7 @@ impl ASTConverter {
|
|||
TypeSpec::poly(acc, ConstArgs::new(vec![elem_t, len], None, vec![], None))
|
||||
}
|
||||
"dict" => {
|
||||
let ExpressionType::Tuple { mut elements } = args.node else {
|
||||
let py_ast::Expr::Tuple { mut elements } = args.node else {
|
||||
return Self::gen_dummy_type_spec(args.location);
|
||||
};
|
||||
let (l_brace, r_brace) =
|
||||
|
|
@ -763,7 +761,7 @@ impl ASTConverter {
|
|||
TypeSpec::poly(acc, ConstArgs::new(vec![dict], None, vec![], None))
|
||||
}
|
||||
"tuple" => {
|
||||
let ExpressionType::Tuple { elements } = args.node else {
|
||||
let py_ast::Expr::Tuple { elements } = args.node else {
|
||||
return Self::gen_dummy_type_spec(args.location);
|
||||
};
|
||||
let parens =
|
||||
|
|
@ -779,22 +777,24 @@ impl ASTConverter {
|
|||
}
|
||||
}
|
||||
|
||||
fn convert_type_spec(&mut self, expr: Located<ExpressionType>) -> TypeSpec {
|
||||
fn convert_type_spec(&mut self, expr: py_ast::Expr) -> TypeSpec {
|
||||
#[allow(clippy::collapsible_match)]
|
||||
match expr.node {
|
||||
ExpressionType::Identifier { name } => {
|
||||
self.convert_ident_type_spec(name, expr.location)
|
||||
py_ast::Expr::Identifier { name } => {
|
||||
self.convert_ident_type_spec(name, expr.location().start())
|
||||
}
|
||||
ExpressionType::None => self.convert_ident_type_spec("NoneType".into(), expr.location),
|
||||
ExpressionType::Attribute { value, name } => {
|
||||
py_ast::Expr::None => {
|
||||
self.convert_ident_type_spec("NoneType".into(), expr.location().start())
|
||||
}
|
||||
py_ast::Expr::Attribute { value, name } => {
|
||||
let namespace = Box::new(self.convert_expr(*value));
|
||||
let t = self.convert_ident(name, expr.location);
|
||||
let t = self.convert_ident(name, expr.location().start());
|
||||
let predecl = PreDeclTypeSpec::Attr { namespace, t };
|
||||
TypeSpec::PreDeclTy(predecl)
|
||||
}
|
||||
ExpressionType::Subscript { a, b } => match a.node {
|
||||
ExpressionType::Identifier { name } => self.convert_compound_type_spec(name, *b),
|
||||
ExpressionType::Attribute { value, name } => {
|
||||
py_ast::Expr::Subscript { a, b } => match a.node {
|
||||
py_ast::Expr::Identifier { name } => self.convert_compound_type_spec(name, *b),
|
||||
py_ast::Expr::Attribute { value, name } => {
|
||||
match accessor_name(value.node).as_ref().map(|s| &s[..]) {
|
||||
Some("typing" | "collections.abc") => {
|
||||
self.convert_compound_type_spec(name, *b)
|
||||
|
|
@ -810,7 +810,7 @@ impl ASTConverter {
|
|||
Self::gen_dummy_type_spec(a.location)
|
||||
}
|
||||
},
|
||||
ExpressionType::Binop { a, op, b } => {
|
||||
py_ast::Expr::Binop { a, op, b } => {
|
||||
match op {
|
||||
// A | B
|
||||
Operator::BitOr => {
|
||||
|
|
@ -818,12 +818,12 @@ impl ASTConverter {
|
|||
let rhs = self.convert_type_spec(*b);
|
||||
TypeSpec::or(lhs, rhs)
|
||||
}
|
||||
_ => Self::gen_dummy_type_spec(expr.location),
|
||||
_ => Self::gen_dummy_type_spec(expr.location().start()),
|
||||
}
|
||||
}
|
||||
other => {
|
||||
log!(err "unknown: {other:?}");
|
||||
Self::gen_dummy_type_spec(expr.location)
|
||||
Self::gen_dummy_type_spec(expr.location().start())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -834,7 +834,7 @@ impl ASTConverter {
|
|||
expr_loc: PyLocation,
|
||||
) -> (Token, Token)
|
||||
where
|
||||
Elems: Iterator<Item = &'i Located<ExpressionType>> + ExactSizeIterator,
|
||||
Elems: Iterator<Item = &'i py_ast::Expr> + ExactSizeIterator,
|
||||
{
|
||||
let (l_cont, r_cont, r_kind) = match l_kind {
|
||||
TokenKind::LBrace => ("{", "}", TokenKind::RBrace),
|
||||
|
|
@ -868,9 +868,9 @@ impl ASTConverter {
|
|||
Expr::UnaryOp(UnaryOp::new(mut_op, expr))
|
||||
}
|
||||
|
||||
fn convert_expr(&mut self, expr: Located<ExpressionType>) -> Expr {
|
||||
fn convert_expr(&mut self, expr: py_ast::Expr) -> Expr {
|
||||
match expr.node {
|
||||
ExpressionType::Number { value } => {
|
||||
py_ast::Expr::Number { value } => {
|
||||
let (kind, cont) = match value {
|
||||
Number::Integer { value } if value >= 0.into() => {
|
||||
(TokenKind::NatLit, value.to_string())
|
||||
|
|
@ -884,12 +884,12 @@ impl ASTConverter {
|
|||
let token = Token::new(
|
||||
kind,
|
||||
cont,
|
||||
expr.location.row() as u32,
|
||||
expr.location.column() as u32 - 1,
|
||||
expr.location().start().row() as u32,
|
||||
expr.location().start().column() as u32 - 1,
|
||||
);
|
||||
Expr::Literal(Literal::new(token))
|
||||
}
|
||||
ExpressionType::String { value } => {
|
||||
py_ast::Expr::String { value } => {
|
||||
let StringGroup::Constant{ value } = value else {
|
||||
return Expr::Dummy(Dummy::new(None, vec![]));
|
||||
};
|
||||
|
|
@ -898,40 +898,40 @@ impl ASTConverter {
|
|||
let token = Token::new(
|
||||
TokenKind::StrLit,
|
||||
value,
|
||||
expr.location.row() as u32,
|
||||
expr.location.column() as u32 - 2,
|
||||
expr.location().start().row() as u32,
|
||||
expr.location().start().column() as u32 - 2,
|
||||
);
|
||||
Expr::Literal(Literal::new(token))
|
||||
}
|
||||
ExpressionType::False => Expr::Literal(Literal::new(Token::new(
|
||||
py_ast::Expr::False => Expr::Literal(Literal::new(Token::new(
|
||||
TokenKind::BoolLit,
|
||||
"False",
|
||||
expr.location.row() as u32,
|
||||
expr.location.column() as u32 - 1,
|
||||
expr.location().start().row() as u32,
|
||||
expr.location().start().column() as u32 - 1,
|
||||
))),
|
||||
ExpressionType::True => Expr::Literal(Literal::new(Token::new(
|
||||
py_ast::Expr::True => Expr::Literal(Literal::new(Token::new(
|
||||
TokenKind::BoolLit,
|
||||
"True",
|
||||
expr.location.row() as u32,
|
||||
expr.location.column() as u32 - 1,
|
||||
expr.location().start().row() as u32,
|
||||
expr.location().start().column() as u32 - 1,
|
||||
))),
|
||||
ExpressionType::None => Expr::Literal(Literal::new(Token::new(
|
||||
py_ast::Expr::None => Expr::Literal(Literal::new(Token::new(
|
||||
TokenKind::NoneLit,
|
||||
"None",
|
||||
expr.location.row() as u32,
|
||||
expr.location.column() as u32 - 1,
|
||||
expr.location().start().row() as u32,
|
||||
expr.location().start().column() as u32 - 1,
|
||||
))),
|
||||
ExpressionType::Ellipsis => Expr::Literal(Literal::new(Token::new(
|
||||
py_ast::Expr::Ellipsis => Expr::Literal(Literal::new(Token::new(
|
||||
TokenKind::EllipsisLit,
|
||||
"...",
|
||||
expr.location.row() as u32,
|
||||
expr.location.column() as u32 - 1,
|
||||
expr.location().start().row() as u32,
|
||||
expr.location().start().column() as u32 - 1,
|
||||
))),
|
||||
ExpressionType::Identifier { name } => {
|
||||
let ident = self.convert_ident(name, expr.location);
|
||||
py_ast::Expr::Identifier { name } => {
|
||||
let ident = self.convert_ident(name, expr.location().start());
|
||||
Expr::Accessor(Accessor::Ident(ident))
|
||||
}
|
||||
ExpressionType::Attribute { value, name } => {
|
||||
py_ast::Expr::Attribute { value, name } => {
|
||||
let obj = self.convert_expr(*value);
|
||||
let attr_name_loc = PyLocation::new(
|
||||
obj.ln_end().unwrap_or(1) as usize,
|
||||
|
|
@ -940,13 +940,13 @@ impl ASTConverter {
|
|||
let name = self.convert_attr_ident(name, attr_name_loc);
|
||||
obj.attr_expr(name)
|
||||
}
|
||||
ExpressionType::IfExpression { test, body, orelse } => {
|
||||
py_ast::Expr::IfExpression { test, body, orelse } => {
|
||||
let block = self.convert_expr(*body);
|
||||
let params = Params::new(vec![], None, vec![], None);
|
||||
let sig = LambdaSignature::new(params.clone(), None, TypeBoundSpecs::empty());
|
||||
let body = Lambda::new(sig, Token::DUMMY, Block::new(vec![block]), DefId(0));
|
||||
let test = self.convert_expr(*test);
|
||||
let if_ident = self.convert_ident("if".to_string(), expr.location);
|
||||
let if_ident = self.convert_ident("if".to_string(), expr.location().start());
|
||||
let if_acc = Expr::Accessor(Accessor::Ident(if_ident));
|
||||
let else_block = self.convert_expr(*orelse);
|
||||
let sig = LambdaSignature::new(params, None, TypeBoundSpecs::empty());
|
||||
|
|
@ -962,7 +962,7 @@ impl ASTConverter {
|
|||
);
|
||||
if_acc.call_expr(args)
|
||||
}
|
||||
ExpressionType::Call {
|
||||
py_ast::Expr::Call {
|
||||
function,
|
||||
args,
|
||||
keywords,
|
||||
|
|
@ -974,12 +974,9 @@ impl ASTConverter {
|
|||
.collect::<Vec<_>>();
|
||||
let kw_args = keywords
|
||||
.into_iter()
|
||||
.map(|Keyword { name, value }| {
|
||||
let name = name.unwrap_or_default();
|
||||
let name = Token::symbol_with_loc(
|
||||
&name,
|
||||
pyloc_to_ergloc(value.location, name.len()),
|
||||
);
|
||||
.map(|Keyword { arg, value, range }| {
|
||||
let name = arg.unwrap_or_default();
|
||||
let name = Token::symbol_with_loc(name.as_str(), pyloc_to_ergloc(range));
|
||||
let ex = self.convert_expr(value);
|
||||
KwArg::new(name, None, ex)
|
||||
})
|
||||
|
|
@ -992,13 +989,13 @@ impl ASTConverter {
|
|||
let lp = Token::new(
|
||||
TokenKind::LParen,
|
||||
"(",
|
||||
expr.location.row() as u32,
|
||||
expr.location().start().row() as u32,
|
||||
function.col_end().unwrap_or(0) + 1,
|
||||
);
|
||||
let rp = Token::new(
|
||||
TokenKind::RParen,
|
||||
")",
|
||||
expr.location.row() as u32,
|
||||
expr.location().start().row() as u32,
|
||||
last_col + 1,
|
||||
);
|
||||
(lp, rp)
|
||||
|
|
@ -1006,55 +1003,55 @@ impl ASTConverter {
|
|||
let args = Args::new(pos_args, None, kw_args, Some(paren));
|
||||
function.call_expr(args)
|
||||
}
|
||||
ExpressionType::Binop { a, op, b } => {
|
||||
py_ast::Expr::Binop { a, op, b } => {
|
||||
let lhs = self.convert_expr(*a);
|
||||
let rhs = self.convert_expr(*b);
|
||||
let op = op_to_token(op);
|
||||
Expr::BinOp(BinOp::new(op, lhs, rhs))
|
||||
}
|
||||
ExpressionType::Unop { op, a } => {
|
||||
py_ast::Expr::Unop { op, a } => {
|
||||
let rhs = self.convert_expr(*a);
|
||||
let (kind, cont) = match op {
|
||||
UnaryOperator::Pos => (TokenKind::PrePlus, "+"),
|
||||
// UnaryOperator::Not => (TokenKind::PreBitNot, "not"),
|
||||
UnaryOperator::Neg => (TokenKind::PreMinus, "-"),
|
||||
UnaryOperator::Inv => (TokenKind::PreBitNot, "~"),
|
||||
Unaryop::Pos => (TokenKind::PrePlus, "+"),
|
||||
// Unaryop::Not => (TokenKind::PreBitNot, "not"),
|
||||
Unaryop::Neg => (TokenKind::PreMinus, "-"),
|
||||
Unaryop::Inv => (TokenKind::PreBitNot, "~"),
|
||||
_ => return Expr::Dummy(Dummy::new(None, vec![rhs])),
|
||||
};
|
||||
let op = Token::from_str(kind, cont);
|
||||
Expr::UnaryOp(UnaryOp::new(op, rhs))
|
||||
}
|
||||
// TODO
|
||||
ExpressionType::BoolOp { op, mut values } => {
|
||||
py_ast::Expr::BoolOp { op, mut values } => {
|
||||
let lhs = self.convert_expr(values.remove(0));
|
||||
let rhs = self.convert_expr(values.remove(0));
|
||||
let (kind, cont) = match op {
|
||||
BooleanOperator::And => (TokenKind::AndOp, "and"),
|
||||
BooleanOperator::Or => (TokenKind::OrOp, "or"),
|
||||
Boolop::And => (TokenKind::AndOp, "and"),
|
||||
Boolop::Or => (TokenKind::OrOp, "or"),
|
||||
};
|
||||
let op = Token::from_str(kind, cont);
|
||||
Expr::BinOp(BinOp::new(op, lhs, rhs))
|
||||
}
|
||||
// TODO: multiple comparisons
|
||||
ExpressionType::Compare { mut vals, mut ops } => {
|
||||
// TODO: multiple Cmpops
|
||||
py_ast::Expr::Compare { mut vals, mut ops } => {
|
||||
let lhs = self.convert_expr(vals.remove(0));
|
||||
let rhs = self.convert_expr(vals.remove(0));
|
||||
let (kind, cont) = match ops.remove(0) {
|
||||
Comparison::Equal => (TokenKind::DblEq, "=="),
|
||||
Comparison::NotEqual => (TokenKind::NotEq, "!="),
|
||||
Comparison::Less => (TokenKind::Less, "<"),
|
||||
Comparison::LessOrEqual => (TokenKind::LessEq, "<="),
|
||||
Comparison::Greater => (TokenKind::Gre, ">"),
|
||||
Comparison::GreaterOrEqual => (TokenKind::GreEq, ">="),
|
||||
Comparison::Is => (TokenKind::IsOp, "is!"),
|
||||
Comparison::IsNot => (TokenKind::IsNotOp, "isnot!"),
|
||||
Comparison::In => (TokenKind::InOp, "in"),
|
||||
Comparison::NotIn => (TokenKind::NotInOp, "notin"),
|
||||
Cmpop::Eq => (TokenKind::DblEq, "=="),
|
||||
Cmpop::NotEq => (TokenKind::NotEq, "!="),
|
||||
Cmpop::Lt => (TokenKind::Less, "<"),
|
||||
Cmpop::LtE => (TokenKind::LessEq, "<="),
|
||||
Cmpop::Gt => (TokenKind::Gre, ">"),
|
||||
Cmpop::GtE => (TokenKind::GreEq, ">="),
|
||||
Cmpop::Is => (TokenKind::IsOp, "is!"),
|
||||
Cmpop::IsNot => (TokenKind::IsNotOp, "isnot!"),
|
||||
Cmpop::In => (TokenKind::InOp, "in"),
|
||||
Cmpop::NotIn => (TokenKind::NotInOp, "notin"),
|
||||
};
|
||||
let op = Token::from_str(kind, cont);
|
||||
Expr::BinOp(BinOp::new(op, lhs, rhs))
|
||||
}
|
||||
ExpressionType::Lambda { args, body } => {
|
||||
py_ast::Expr::Lambda { args, body } => {
|
||||
self.namespace.push("<lambda>".to_string());
|
||||
let params = self.convert_params(*args);
|
||||
let body = vec![self.convert_expr(*body)];
|
||||
|
|
@ -1063,9 +1060,12 @@ impl ASTConverter {
|
|||
let op = Token::from_str(TokenKind::FuncArrow, "->");
|
||||
Expr::Lambda(Lambda::new(sig, op, Block::new(body), DefId(0)))
|
||||
}
|
||||
ExpressionType::List { elements } => {
|
||||
let (l_sqbr, r_sqbr) =
|
||||
Self::gen_enclosure_tokens(TokenKind::LSqBr, elements.iter(), expr.location);
|
||||
py_ast::Expr::List { elements } => {
|
||||
let (l_sqbr, r_sqbr) = Self::gen_enclosure_tokens(
|
||||
TokenKind::LSqBr,
|
||||
elements.iter(),
|
||||
expr.location().start(),
|
||||
);
|
||||
let elements = elements
|
||||
.into_iter()
|
||||
.map(|ex| PosArg::new(self.convert_expr(ex)))
|
||||
|
|
@ -1074,9 +1074,12 @@ impl ASTConverter {
|
|||
let arr = Expr::Array(Array::Normal(NormalArray::new(l_sqbr, r_sqbr, elems)));
|
||||
Self::mutate_expr(arr)
|
||||
}
|
||||
ExpressionType::Set { elements } => {
|
||||
let (l_brace, r_brace) =
|
||||
Self::gen_enclosure_tokens(TokenKind::LBrace, elements.iter(), expr.location);
|
||||
py_ast::Expr::Set { elements } => {
|
||||
let (l_brace, r_brace) = Self::gen_enclosure_tokens(
|
||||
TokenKind::LBrace,
|
||||
elements.iter(),
|
||||
expr.location().start(),
|
||||
);
|
||||
let elements = elements
|
||||
.into_iter()
|
||||
.map(|ex| PosArg::new(self.convert_expr(ex)))
|
||||
|
|
@ -1085,11 +1088,11 @@ impl ASTConverter {
|
|||
Expr::Set(Set::Normal(NormalSet::new(l_brace, r_brace, elems)))
|
||||
// Self::mutate_expr(set)
|
||||
}
|
||||
ExpressionType::Dict { elements } => {
|
||||
py_ast::Expr::Dict { elements } => {
|
||||
let (l_brace, r_brace) = Self::gen_enclosure_tokens(
|
||||
TokenKind::LBrace,
|
||||
elements.iter().map(|(_, v)| v),
|
||||
expr.location,
|
||||
expr.location().start(),
|
||||
);
|
||||
let kvs = elements
|
||||
.into_iter()
|
||||
|
|
@ -1104,7 +1107,7 @@ impl ASTConverter {
|
|||
let dict = Expr::Dict(Dict::Normal(NormalDict::new(l_brace, r_brace, kvs)));
|
||||
Self::mutate_expr(dict)
|
||||
}
|
||||
ExpressionType::Tuple { elements } => {
|
||||
py_ast::Expr::Tuple { elements } => {
|
||||
let elements = elements
|
||||
.into_iter()
|
||||
.map(|ex| PosArg::new(self.convert_expr(ex)))
|
||||
|
|
@ -1112,10 +1115,11 @@ impl ASTConverter {
|
|||
let elems = Args::pos_only(elements, None);
|
||||
Expr::Tuple(Tuple::Normal(NormalTuple::new(elems)))
|
||||
}
|
||||
ExpressionType::Subscript { a, b } => {
|
||||
py_ast::Expr::Subscript { a, b } => {
|
||||
let obj = self.convert_expr(*a);
|
||||
let method =
|
||||
obj.attr_expr(self.convert_ident("__getitem__".to_string(), expr.location));
|
||||
let method = obj.attr_expr(
|
||||
self.convert_ident("__getitem__".to_string(), expr.location().start()),
|
||||
);
|
||||
method.call1(self.convert_expr(*b))
|
||||
}
|
||||
_other => {
|
||||
|
|
@ -1125,7 +1129,7 @@ impl ASTConverter {
|
|||
}
|
||||
}
|
||||
|
||||
fn convert_block(&mut self, block: Vec<Located<StatementType>>, kind: BlockKind) -> Block {
|
||||
fn convert_block(&mut self, block: Suite, kind: BlockKind) -> Block {
|
||||
let mut new_block = Vec::new();
|
||||
let len = block.len();
|
||||
self.block_id_counter += 1;
|
||||
|
|
@ -1304,7 +1308,7 @@ impl ASTConverter {
|
|||
|
||||
fn extract_method(
|
||||
&mut self,
|
||||
body: Vec<Located<StatementType>>,
|
||||
body: Vec<py_ast::Stmt>,
|
||||
inherit: bool,
|
||||
) -> (Option<Expr>, ClassAttrs) {
|
||||
let mut base_type = None;
|
||||
|
|
@ -1386,7 +1390,7 @@ impl ASTConverter {
|
|||
fn extract_method_list(
|
||||
&mut self,
|
||||
ident: Identifier,
|
||||
body: Vec<Located<StatementType>>,
|
||||
body: Vec<py_ast::Stmt>,
|
||||
inherit: bool,
|
||||
) -> (Option<Expr>, Vec<Methods>) {
|
||||
let class = TypeSpec::mono(ident.clone());
|
||||
|
|
@ -1400,10 +1404,10 @@ impl ASTConverter {
|
|||
&mut self,
|
||||
name: String,
|
||||
params: Parameters,
|
||||
body: Vec<Located<StatementType>>,
|
||||
decorator_list: Vec<Located<ExpressionType>>,
|
||||
returns: Option<Located<ExpressionType>>,
|
||||
loc: PyLocation,
|
||||
body: Vec<py_ast::Stmt>,
|
||||
decorator_list: Vec<py_ast::Expr>,
|
||||
returns: Option<py_ast::Expr>,
|
||||
range: PySourceRange,
|
||||
) -> Expr {
|
||||
// if reassigning of a function referenced by other functions is occurred, it is an error
|
||||
if self
|
||||
|
|
@ -1417,13 +1421,14 @@ impl ASTConverter {
|
|||
{
|
||||
let err = reassign_func_error(
|
||||
self.cfg.input.clone(),
|
||||
pyloc_to_ergloc(loc, name.len()),
|
||||
pyloc_to_ergloc(range),
|
||||
self.namespace.join("."),
|
||||
&name,
|
||||
);
|
||||
self.errs.push(err);
|
||||
Expr::Dummy(Dummy::new(None, vec![]))
|
||||
} else {
|
||||
let loc = range.start;
|
||||
let decos = decorator_list
|
||||
.into_iter()
|
||||
.map(|ex| Decorator(self.convert_expr(ex)))
|
||||
|
|
@ -1466,9 +1471,9 @@ impl ASTConverter {
|
|||
fn convert_classdef(
|
||||
&mut self,
|
||||
name: String,
|
||||
body: Vec<Located<StatementType>>,
|
||||
bases: Vec<Located<ExpressionType>>,
|
||||
decorator_list: Vec<Located<ExpressionType>>,
|
||||
body: Vec<py_ast::Stmt>,
|
||||
bases: Vec<py_ast::Expr>,
|
||||
decorator_list: Vec<py_ast::Expr>,
|
||||
loc: PyLocation,
|
||||
) -> Expr {
|
||||
let _decos = decorator_list
|
||||
|
|
@ -1523,19 +1528,19 @@ impl ASTConverter {
|
|||
Expr::ClassDef(classdef)
|
||||
}
|
||||
|
||||
fn convert_statement(&mut self, stmt: Located<StatementType>, dont_call_return: bool) -> Expr {
|
||||
fn convert_statement(&mut self, stmt: Stmt, dont_call_return: bool) -> Expr {
|
||||
match stmt.node {
|
||||
StatementType::Expression { expression } => self.convert_expr(expression),
|
||||
StatementType::AnnAssign {
|
||||
py_ast::Stmt::Expression(stmt) => self.convert_expr(stmt.expr),
|
||||
py_ast::Stmt::AnnAssign {
|
||||
target,
|
||||
annotation,
|
||||
value,
|
||||
} => {
|
||||
let anot = self.convert_expr(clone_loc_expr(&annotation));
|
||||
let anot = self.convert_expr(annotation.clone());
|
||||
let t_spec = self.convert_type_spec(*annotation);
|
||||
let t_spec = TypeSpecWithOp::new(AS, t_spec, anot);
|
||||
match target.node {
|
||||
ExpressionType::Identifier { name } => {
|
||||
py_ast::Expr::Identifier { name } => {
|
||||
if let Some(value) = value {
|
||||
let block = Block::new(vec![self.convert_expr(value)]);
|
||||
let body = DefBody::new(EQUAL, block, DefId(0));
|
||||
|
|
@ -1556,7 +1561,7 @@ impl ASTConverter {
|
|||
Expr::TypeAscription(tasc)
|
||||
}
|
||||
}
|
||||
ExpressionType::Attribute { value: attr, name } => {
|
||||
py_ast::Expr::Attribute { value: attr, name } => {
|
||||
let attr = self
|
||||
.convert_expr(*attr)
|
||||
.attr(self.convert_attr_ident(name, target.location));
|
||||
|
|
@ -1572,11 +1577,11 @@ impl ASTConverter {
|
|||
_other => Expr::Dummy(Dummy::new(None, vec![])),
|
||||
}
|
||||
}
|
||||
StatementType::Assign { mut targets, value } => {
|
||||
py_ast::Stmt::Assign { mut targets, value } => {
|
||||
if targets.len() == 1 {
|
||||
let lhs = targets.remove(0);
|
||||
match lhs.node {
|
||||
ExpressionType::Identifier { name } => {
|
||||
py_ast::Expr::Identifier { name } => {
|
||||
let block = Block::new(vec![self.convert_expr(value)]);
|
||||
let body = DefBody::new(EQUAL, block, DefId(0));
|
||||
self.register_name_info(&name, NameKind::Variable);
|
||||
|
|
@ -1586,11 +1591,12 @@ impl ASTConverter {
|
|||
let def = Def::new(sig, body);
|
||||
Expr::Def(def)
|
||||
}
|
||||
ExpressionType::Attribute { value: attr, name } => {
|
||||
let attr_name_loc = PyLocation::new(
|
||||
attr.location.row(),
|
||||
attr.location.column() + length(&attr.node) + 1,
|
||||
);
|
||||
py_ast::Expr::Attribute(py_ast::ExprAttribute {
|
||||
value: attr,
|
||||
name,
|
||||
range,
|
||||
}) => {
|
||||
let attr_name_loc = attr.end_location();
|
||||
let attr = self
|
||||
.convert_expr(*attr)
|
||||
.attr(self.convert_attr_ident(name, attr_name_loc));
|
||||
|
|
@ -1598,7 +1604,7 @@ impl ASTConverter {
|
|||
let adef = ReDef::new(attr, expr);
|
||||
Expr::ReDef(adef)
|
||||
}
|
||||
ExpressionType::Tuple { elements } => {
|
||||
py_ast::Expr::Tuple { elements } => {
|
||||
let tmp = fresh_varname();
|
||||
let tmp_name = VarName::from_str_and_line(
|
||||
(&tmp).into(),
|
||||
|
|
@ -1644,7 +1650,7 @@ impl ASTConverter {
|
|||
}
|
||||
// a[b] = x
|
||||
// => a.__setitem__(b, x)
|
||||
ExpressionType::Subscript { a, b } => {
|
||||
py_ast::Expr::Subscript { a, b } => {
|
||||
let a = self.convert_expr(*a);
|
||||
let b = self.convert_expr(*b);
|
||||
let x = self.convert_expr(value);
|
||||
|
|
@ -1663,7 +1669,7 @@ impl ASTConverter {
|
|||
let mut defs = vec![];
|
||||
for target in targets {
|
||||
match target.node {
|
||||
ExpressionType::Identifier { name } => {
|
||||
py_ast::Expr::Identifier { name } => {
|
||||
let body =
|
||||
DefBody::new(EQUAL, Block::new(vec![value.clone()]), DefId(0));
|
||||
self.register_name_info(&name, NameKind::Variable);
|
||||
|
|
@ -1683,10 +1689,10 @@ impl ASTConverter {
|
|||
Expr::Dummy(Dummy::new(None, defs))
|
||||
}
|
||||
}
|
||||
StatementType::AugAssign { target, op, value } => {
|
||||
py_ast::Stmt::AugAssign { target, op, value } => {
|
||||
let op = op_to_token(op);
|
||||
match target.node {
|
||||
ExpressionType::Identifier { name } => {
|
||||
py_ast::Expr::Identifier { name } => {
|
||||
let val = self.convert_expr(*value);
|
||||
let prev_ident = self.convert_ident(name.clone(), stmt.location);
|
||||
if self
|
||||
|
|
@ -1712,7 +1718,7 @@ impl ASTConverter {
|
|||
Expr::ReDef(redef)
|
||||
}
|
||||
}
|
||||
ExpressionType::Attribute { value: attr, name } => {
|
||||
py_ast::Expr::Attribute { value: attr, name } => {
|
||||
let val = self.convert_expr(*value);
|
||||
let attr = self
|
||||
.convert_expr(*attr)
|
||||
|
|
@ -1727,22 +1733,24 @@ impl ASTConverter {
|
|||
}
|
||||
}
|
||||
}
|
||||
StatementType::FunctionDef {
|
||||
py_ast::Stmt::FunctionDef {
|
||||
is_async: _,
|
||||
name,
|
||||
args,
|
||||
body,
|
||||
decorator_list,
|
||||
returns,
|
||||
} => self.convert_funcdef(name, *args, body, decorator_list, returns, stmt.location),
|
||||
StatementType::ClassDef {
|
||||
range,
|
||||
} => self.convert_funcdef(name, *args, body, decorator_list, returns, range),
|
||||
py_ast::Stmt::ClassDef {
|
||||
name,
|
||||
body,
|
||||
bases,
|
||||
keywords: _,
|
||||
decorator_list,
|
||||
} => self.convert_classdef(name, body, bases, decorator_list, stmt.location),
|
||||
StatementType::For {
|
||||
range,
|
||||
} => self.convert_classdef(name, body, bases, decorator_list, range),
|
||||
py_ast::Stmt::For {
|
||||
is_async: _,
|
||||
target,
|
||||
iter,
|
||||
|
|
@ -1755,7 +1763,7 @@ impl ASTConverter {
|
|||
let for_acc = Expr::Accessor(Accessor::Ident(for_ident));
|
||||
for_acc.call2(iter, Expr::Lambda(block))
|
||||
}
|
||||
StatementType::While {
|
||||
py_ast::Stmt::While {
|
||||
test,
|
||||
body,
|
||||
orelse: _,
|
||||
|
|
@ -1769,7 +1777,7 @@ impl ASTConverter {
|
|||
let while_acc = Expr::Accessor(Accessor::Ident(while_ident));
|
||||
while_acc.call2(test, Expr::Lambda(body))
|
||||
}
|
||||
StatementType::If { test, body, orelse } => {
|
||||
py_ast::Stmt::If { test, body, orelse } => {
|
||||
let block = self.convert_block(body, BlockKind::If);
|
||||
let params = Params::new(vec![], None, vec![], None);
|
||||
let sig = LambdaSignature::new(params.clone(), None, TypeBoundSpecs::empty());
|
||||
|
|
@ -1794,7 +1802,7 @@ impl ASTConverter {
|
|||
if_acc.call2(test, Expr::Lambda(body))
|
||||
}
|
||||
}
|
||||
StatementType::Return { value } => {
|
||||
py_ast::Stmt::Return { value } => {
|
||||
let value = value
|
||||
.map(|val| self.convert_expr(val))
|
||||
.unwrap_or_else(|| Expr::Tuple(Tuple::Normal(NormalTuple::new(Args::empty()))));
|
||||
|
|
@ -1809,7 +1817,7 @@ impl ASTConverter {
|
|||
return_acc.call1(value)
|
||||
}
|
||||
}
|
||||
StatementType::Assert { test, msg } => {
|
||||
py_ast::Stmt::Assert { test, msg } => {
|
||||
let test = self.convert_expr(test);
|
||||
let args = if let Some(msg) = msg {
|
||||
let msg = self.convert_expr(msg);
|
||||
|
|
@ -1822,7 +1830,7 @@ impl ASTConverter {
|
|||
));
|
||||
assert_acc.call_expr(args)
|
||||
}
|
||||
StatementType::Import { names } => {
|
||||
py_ast::Stmt::Import { names } => {
|
||||
let mut imports = vec![];
|
||||
for name in names {
|
||||
let import_acc = Expr::Accessor(Accessor::Ident(
|
||||
|
|
@ -1862,12 +1870,12 @@ impl ASTConverter {
|
|||
Expr::Dummy(Dummy::new(None, imports))
|
||||
}
|
||||
// from module import foo, bar
|
||||
StatementType::ImportFrom {
|
||||
py_ast::Stmt::ImportFrom {
|
||||
level: _,
|
||||
module,
|
||||
names,
|
||||
} => self.convert_from_import(module, names, stmt.location),
|
||||
StatementType::Try {
|
||||
py_ast::Stmt::Try {
|
||||
body,
|
||||
handlers: _,
|
||||
orelse,
|
||||
|
|
@ -1889,7 +1897,7 @@ impl ASTConverter {
|
|||
};
|
||||
Expr::Dummy(Dummy::new(None, dummy))
|
||||
}
|
||||
StatementType::With {
|
||||
py_ast::Stmt::With {
|
||||
is_async: _,
|
||||
mut items,
|
||||
body,
|
||||
|
|
@ -2017,9 +2025,9 @@ impl ASTConverter {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn convert_program(mut self, program: Program) -> IncompleteArtifact<Module> {
|
||||
pub fn convert_program(mut self, program: ModModule) -> IncompleteArtifact<Module> {
|
||||
let program = program
|
||||
.statements
|
||||
.body
|
||||
.into_iter()
|
||||
.map(|stmt| self.convert_statement(stmt, true))
|
||||
.collect();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
pub mod ast_util;
|
||||
mod clone;
|
||||
mod convert;
|
||||
mod error;
|
||||
mod gen_decl;
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@ use erg_common::Str;
|
|||
use erg_compiler::artifact::{BuildRunnable, Buildable, CompleteArtifact, IncompleteArtifact};
|
||||
use erg_compiler::context::register::CheckStatus;
|
||||
use erg_compiler::context::ModuleContext;
|
||||
use erg_compiler::erg_parser::ast::{AST, Module};
|
||||
use erg_compiler::erg_parser::ast::{Module, AST};
|
||||
use erg_compiler::erg_parser::error::ParseErrors;
|
||||
use erg_compiler::erg_parser::parse::Parsable;
|
||||
use erg_compiler::error::{CompileError, CompileErrors};
|
||||
use erg_compiler::lower::ASTLowerer;
|
||||
use erg_compiler::module::SharedCompilerResource;
|
||||
use py2erg::{dump_decl_er, reserve_decl_er, ShadowingMode};
|
||||
use rustpython_parser::parser;
|
||||
use rustpython_parser::{Parse, ast as py_ast};
|
||||
|
||||
use crate::handle_err;
|
||||
|
||||
|
|
@ -22,9 +22,8 @@ pub struct SimplePythonParser {}
|
|||
|
||||
impl Parsable for SimplePythonParser {
|
||||
fn parse(code: String) -> Result<Module, ParseErrors> {
|
||||
let py_program = parser::parse_program(&code).map_err(|_err| {
|
||||
ParseErrors::empty()
|
||||
})?;
|
||||
let py_program = py_ast::Suite::parse(&code).map_err(|_err| ParseErrors::empty())?;
|
||||
// TODO: SourceLocator
|
||||
let shadowing = if cfg!(feature = "debug") {
|
||||
ShadowingMode::Visible
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue