Parsable!

trunk
Alona EM 2022-01-16 01:25:47 +00:00
parent 6fcfea664f
commit e4e044e733
11 changed files with 9318 additions and 122 deletions

433
hidl/Cargo.lock generated
View File

@ -2,12 +2,80 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "aho-corasick"
version = "0.7.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
dependencies = [
"memchr",
]
[[package]]
name = "anyhow"
version = "1.0.52"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84450d0b4a8bd1ba4144ce8ce718fbc5d071358b1e5384bace6536b3d1f2d5b3"
[[package]]
name = "ascii-canvas"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8824ecca2e851cec16968d54a01dd372ef8f95b244fb84b84e70128be347c3c6"
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 = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "bit-set"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de"
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 = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "crunchy"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
[[package]]
name = "debug2"
version = "0.1.0"
@ -27,18 +95,97 @@ dependencies = [
"synstructure",
]
[[package]]
name = "diff"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499"
[[package]]
name = "dirs-next"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"
dependencies = [
"cfg-if",
"dirs-sys-next",
]
[[package]]
name = "dirs-sys-next"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
dependencies = [
"libc",
"redox_users",
"winapi",
]
[[package]]
name = "either"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]]
name = "ena"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7402b94a93c24e742487327a7cd839dc9d36fec9de9fb25b09f2dae459f36c3"
dependencies = [
"log",
]
[[package]]
name = "fixedbitset"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d"
[[package]]
name = "fs-err"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ebd3504ad6116843b8375ad70df74e7bfe83cac77a1f3fe73200c844d43bfe0"
[[package]]
name = "getrandom"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "hashbrown"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]]
name = "hidl"
version = "0.1.0"
dependencies = [
"anyhow",
"debug2",
"fs-err",
"lalrpop",
"lalrpop-util",
"serde",
"serde_json",
"serde_yaml",
]
@ -52,12 +199,166 @@ dependencies = [
"hashbrown",
]
[[package]]
name = "instant"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
"cfg-if",
]
[[package]]
name = "itertools"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3"
dependencies = [
"either",
]
[[package]]
name = "itoa"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
[[package]]
name = "lalrpop"
version = "0.19.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15174f1c529af5bf1283c3bc0058266b483a67156f79589fab2a25e23cf8988"
dependencies = [
"ascii-canvas",
"atty",
"bit-set",
"diff",
"ena",
"itertools",
"lalrpop-util",
"petgraph",
"pico-args",
"regex",
"regex-syntax",
"string_cache",
"term",
"tiny-keccak",
"unicode-xid",
]
[[package]]
name = "lalrpop-util"
version = "0.19.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3e58cce361efcc90ba8a0a5f982c741ff86b603495bb15a998412e957dcd278"
dependencies = [
"regex",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.112"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125"
[[package]]
name = "linked-hash-map"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
[[package]]
name = "lock_api"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109"
dependencies = [
"scopeguard",
]
[[package]]
name = "log"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
dependencies = [
"cfg-if",
]
[[package]]
name = "memchr"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
[[package]]
name = "new_debug_unreachable"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
[[package]]
name = "parking_lot"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
dependencies = [
"instant",
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216"
dependencies = [
"cfg-if",
"instant",
"libc",
"redox_syscall",
"smallvec",
"winapi",
]
[[package]]
name = "petgraph"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7"
dependencies = [
"fixedbitset",
"indexmap",
]
[[package]]
name = "phf_shared"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c00cf8b9eafe68dde5e9eaa2cef8ee84a9336a47d566ec55ca16589633b65af7"
dependencies = [
"siphasher",
]
[[package]]
name = "pico-args"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468"
[[package]]
name = "precomputed-hash"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
[[package]]
name = "proc-macro2"
version = "1.0.36"
@ -76,12 +377,60 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "redox_syscall"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff"
dependencies = [
"bitflags",
]
[[package]]
name = "redox_users"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64"
dependencies = [
"getrandom",
"redox_syscall",
]
[[package]]
name = "regex"
version = "1.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.6.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
[[package]]
name = "rustversion"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2cc38e8fa666e2de3c4aba7edeb5ffc5246c1c2ed0e3d17e560aeeba736b23f"
[[package]]
name = "ryu"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "serde"
version = "1.0.133"
@ -102,6 +451,17 @@ dependencies = [
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.75"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c059c05b48c5c0067d4b4b2b4f0732dd65feb52daf7e0ea09cd87e7dadc1af79"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "serde_yaml"
version = "0.8.23"
@ -114,6 +474,31 @@ dependencies = [
"yaml-rust",
]
[[package]]
name = "siphasher"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "533494a8f9b724d33625ab53c6c4800f7cc445895924a8ef649222dcb76e938b"
[[package]]
name = "smallvec"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
[[package]]
name = "string_cache"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "923f0f39b6267d37d23ce71ae7235602134b250ace715dd2c90421998ddac0c6"
dependencies = [
"lazy_static",
"new_debug_unreachable",
"parking_lot",
"phf_shared",
"precomputed-hash",
]
[[package]]
name = "syn"
version = "1.0.85"
@ -137,12 +522,60 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "term"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f"
dependencies = [
"dirs-next",
"rustversion",
"winapi",
]
[[package]]
name = "tiny-keccak"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237"
dependencies = [
"crunchy",
]
[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "yaml-rust"
version = "0.4.5"

View File

@ -6,8 +6,15 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1.0.52"
debug2 = { git = "https://github.com/aDotInTheVoid/debug2/" }
fs-err = "2.6.0"
lalrpop-util = { version = "0.19.6", features = ["lexer"] }
serde = { version = "1.0.133", features = ["derive"] }
serde_json = "1.0.75"
serde_yaml = "0.8.23"
[features]
[build-dependencies]
lalrpop = "0.19.6"

6
hidl/build.rs Normal file
View File

@ -0,0 +1,6 @@
fn main() {
lalrpop::Configuration::new()
.generate_in_source_tree()
.process()
.unwrap();
}

View File

@ -36,13 +36,11 @@ extension asset_delivery {
getId(name: string) -> uuid
}
}
types {
struct Asset {
id: uuid
name: string
data: []u8
}
struct Asset {
id: uuid
name: string
data: []u8
}
}
@ -63,18 +61,17 @@ extension world {
}
}
types {
struct EntityInfo {
assetId: uuid
entity: Entity
transformation: matrix4x4
flags: EntityFlags
}
enum EntityFlags(vu128) {
None = 0
Interactable = 1
Collidable = 2
}
struct EntityInfo {
assetId: uuid
entity: Entity
transformation: matrix4x4
flags: EntityFlags
}
enum EntityFlags(vu128) {
None = 0
Interactable = 1
Collidable = 2
}
}

364
hidl/hypercosm.json Normal file
View File

@ -0,0 +1,364 @@
{
"name": "hypercosm",
"interfaces": [
{
"name": "Object",
"version": [
0,
0,
0
],
"methods": [
{
"name": "list_interfaces",
"args": [],
"ret": {
"Array": {
"Primitive": "String"
}
}
},
{
"name": "release",
"args": [],
"ret": null
}
],
"events": []
},
{
"name": "Root",
"version": [
0,
0,
0
],
"methods": [
{
"name": "list_extenstions",
"args": [],
"ret": {
"Array": {
"Primitive": "String"
}
}
},
{
"name": "ping",
"args": [],
"ret": null
},
{
"name": "get_object_by_id",
"args": [
{
"name": "id",
"ty": {
"Primitive": "Uuid"
}
}
],
"ret": {
"Primitive": "Object"
}
},
{
"name": "get_object_by_name",
"args": [
{
"name": "name",
"ty": {
"Primitive": "String"
}
}
],
"ret": {
"Primitive": "Object"
}
}
],
"events": []
}
],
"types": [],
"extensions": [
{
"name": "asset_delivery",
"version": [
0,
0,
0
],
"interface": {
"methods": [
{
"name": "fetchById",
"args": [
{
"name": "id",
"ty": {
"Primitive": "Uuid"
}
}
],
"ret": {
"Custom": "Asset"
}
},
{
"name": "fetchByName",
"args": [
{
"name": "name",
"ty": {
"Primitive": "String"
}
}
],
"ret": {
"Custom": "Asset"
}
},
{
"name": "fetchByIds",
"args": [
{
"name": "ids",
"ty": {
"Array": {
"Primitive": "Uuid"
}
}
}
],
"ret": {
"Array": {
"Custom": "Asset"
}
}
},
{
"name": "fetchByNames",
"args": [
{
"name": "names",
"ty": {
"Array": {
"Primitive": "String"
}
}
}
],
"ret": {
"Array": {
"Custom": "Asset"
}
}
},
{
"name": "getId",
"args": [
{
"name": "name",
"ty": {
"Primitive": "String"
}
}
],
"ret": {
"Primitive": "Uuid"
}
}
],
"events": [
{
"name": "load_assets",
"args": [
{
"name": "assets",
"ty": {
"Array": {
"Custom": "Asset"
}
}
}
],
"ret": null
},
{
"name": "unload_assets",
"args": [
{
"name": "assets",
"ty": {
"Array": {
"Primitive": "Uuid"
}
}
}
],
"ret": null
}
]
},
"interfaces": [],
"types": [
{
"name": "Asset",
"kind": {
"Struct": {
"fields": [
{
"name": "id",
"ty": {
"Primitive": "Uuid"
}
},
{
"name": "name",
"ty": {
"Primitive": "String"
}
},
{
"name": "data",
"ty": {
"Array": {
"IntType": "U8"
}
}
}
]
}
}
}
]
},
{
"name": "world",
"version": [
0,
0,
0
],
"interface": {
"methods": [],
"events": [
{
"name": "add_entitys",
"args": [
{
"name": "entities",
"ty": {
"Array": {
"Custom": "EntityInfo"
}
}
}
],
"ret": null
},
{
"name": "update_entitys",
"args": [
{
"name": "entities",
"ty": {
"Array": {
"Custom": "EntityInfo"
}
}
}
],
"ret": null
},
{
"name": "remove_entitys",
"args": [
{
"name": "entities",
"ty": {
"Array": {
"Primitive": "Uuid"
}
}
}
],
"ret": null
}
]
},
"interfaces": [
{
"name": "Entity",
"version": null,
"methods": [
{
"name": "interact",
"args": [],
"ret": null
}
],
"events": []
}
],
"types": [
{
"name": "EntityInfo",
"kind": {
"Struct": {
"fields": [
{
"name": "assetId",
"ty": {
"Primitive": "Uuid"
}
},
{
"name": "entity",
"ty": {
"Custom": "Entity"
}
},
{
"name": "transformation",
"ty": {
"Primitive": "Matrix4x4"
}
},
{
"name": "flags",
"ty": {
"Custom": "EntityFlags"
}
}
]
}
}
},
{
"name": "EntityFlags",
"kind": {
"Enum": {
"backing": "VU128",
"fields": [
{
"name": "None",
"value": 0
},
{
"name": "Interactable",
"value": 1
},
{
"name": "Collidable",
"value": 2
}
]
}
}
}
]
}
]
}

142
hidl/src/ast.rs Normal file
View File

@ -0,0 +1,142 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, debug2::Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Namespace {
pub name: String,
pub interfaces: Vec<Interface>,
pub types: Vec<TypeDef>,
pub extensions: Vec<Extension>,
}
#[derive(Debug, debug2::Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Extension {
pub name: String,
pub version: Version,
pub interface: ImplicitInterface,
pub interfaces: Vec<ExtensionInterface>,
pub types: Vec<TypeDef>,
}
#[derive(Debug, debug2::Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Interface {
pub name: String,
pub version: Version,
pub methods: Vec<Func>,
pub events: Vec<Func>,
}
#[derive(Debug, debug2::Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ImplicitInterface {
// Gets version and name from extension
pub methods: Vec<Func>,
pub events: Vec<Func>,
}
#[derive(Debug, debug2::Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ExtensionInterface {
pub name: String,
// May get version from extension
pub version: Option<Version>,
pub methods: Vec<Func>,
pub events: Vec<Func>,
}
pub type Version = (u8, u8, u8);
#[derive(Debug, debug2::Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Func {
pub name: String,
pub args: Vec<Arg>,
pub ret: Option<Type>,
}
#[derive(Debug, debug2::Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum Type {
Primitive(PrimType),
Custom(String),
Array(Box<Type>),
IntType(IntType),
}
#[derive(Debug, debug2::Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum PrimType {
String,
Object,
Uuid,
Bytes,
Bool,
Matrix4x4,
F32,
F64,
}
#[derive(Debug, debug2::Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum IntType {
U8,
U16,
U32,
U64,
U128,
VU8,
VU16,
VU32,
VU64,
VU128,
I8,
I16,
I32,
I64,
I128,
VI8,
VI16,
VI32,
VI64,
VI128,
}
#[derive(Debug, debug2::Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Arg {
pub name: String,
pub ty: Type,
}
#[derive(Debug, debug2::Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TypeDef {
pub name: String,
pub kind: TypeKind,
}
#[derive(Debug, debug2::Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum TypeKind {
Struct(Struct),
Enum(Enum),
}
#[derive(Debug, debug2::Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Enum {
pub backing: IntType,
pub fields: Vec<EnumField>,
}
#[derive(Debug, debug2::Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct EnumField {
pub name: String,
pub value: Option<i64>,
}
#[derive(Debug, debug2::Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Struct {
pub fields: Vec<StructField>,
}
#[derive(Debug, debug2::Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct StructField {
pub name: String,
pub ty: Type,
}

View File

@ -1,9 +1,15 @@
use std::fs;
use anyhow::Result;
use fs_err as fs;
fn main() {
let root = hidl::spec::spec();
debug2::dbg!(&root);
let yaml_str = serde_yaml::to_string(&root).unwrap();
eprintln!("{}", yaml_str);
fs::write("spec-demo.yaml", &yaml_str).unwrap();
fn main() -> Result<()> {
let tree = fs::read_to_string("hypercosm.hidl")?;
let tree = hidl::grammar::NamespaceParser::new().parse(&tree).unwrap();
debug2::dbg!(&tree);
let json = serde_json::to_string_pretty(&tree)?;
fs::write("hypercosm.json", &json)?;
Ok(())
}

171
hidl/src/grammar.lalrpop Normal file
View File

@ -0,0 +1,171 @@
use crate::ast::*;
grammar();
// Skip over comments
match {
r"\s*" => { },
r"//[^\n\r]*[\n\r]*" => { },
_
}
pub Namespace: Namespace = {
"namespace" <name:Ident>
<interfaces:List<Interface>>
<types:List<TypeDef>>
<extensions:List<Extension>>
=> Namespace{<>}
}
Extension: Extension = {
"extension" <name:Ident> "{"
<version:Version?>
<interface:ImplicitInterface>
<interfaces:List<ExtensionInterface>>
<types:List<TypeDef>>
"}"
=> Extension{name, version: version.unwrap_or_default(), interface, interfaces, types}
}
Interface: Interface = {
"interface" <name:Ident> "{"
<v:Version?>
<e:Events?>
<m:Methods?>
"}" => Interface { name, version: v.unwrap_or_default(), events: e.unwrap_or_default(), methods: m.unwrap_or_default() }
}
ExtensionInterface: ExtensionInterface = {
"interface" <name:Ident> "{"
<version:Version?>
<e:Events?>
<m:Methods?>
"}" => ExtensionInterface { name, version, events: e.unwrap_or_default(), methods: m.unwrap_or_default() }
}
ImplicitInterface: ImplicitInterface = {
"interface" "{"
<e:Events?>
<m:Methods?>
"}" => ImplicitInterface { events: e.unwrap_or_default(), methods: m.unwrap_or_default() }
}
Version: Version = {
"version" <Num> <Num> <Num> => (<>)
}
Events: Vec<Func> = { "events" "{" <List<Func>> "}" => <> }
Methods: Vec<Func> = { "methods" "{" <List<Func>> "}" => <> }
Func: Func = {
<name:Ident> "(" <args: Comma<Arg>> ")" <ret:("->" <Type>)?> => Func{<>}
}
Arg: Arg = {
<name:Ident> ":" <ty:Type> => Arg{<>}
}
// Argument types
Type: Type = {
PrimType => Type::Primitive(<>),
Ident => Type::Custom(<>),
IntType => Type::IntType(<>),
"[]" <Type> => Type::Array(Box::new(<>)),
}
PrimType: PrimType = {
"string" => PrimType::String,
"object" => PrimType::Object,
"uuid" => PrimType::Uuid,
"bytes" => PrimType::Bytes,
"bool" => PrimType::Bool,
"matrix4x4" => PrimType::Matrix4x4,
"f32" => PrimType::F32,
"f64" => PrimType::F64,
}
// These are seperate as only they can back an enum
IntType: IntType = {
"u8" => IntType::U8,
"u16" => IntType::U16,
"u32" => IntType::U32,
"u64" => IntType::U64,
"u128" => IntType::U128,
"vu8" => IntType::VU8,
"vu16" => IntType::VU16,
"vu32" => IntType::VU32,
"vu64" => IntType::VU64,
"vu128" => IntType::VU128,
"i8" => IntType::I8,
"i16" => IntType::I16,
"i32" => IntType::I32,
"i64" => IntType::I64,
"i128" => IntType::I128,
"vi8" => IntType::VI8,
"vi16" => IntType::VI16,
"vi32" => IntType::VI32,
"vi64" => IntType::VI64,
"vi128" => IntType::VI128,
}
// Typedefs
TypeDef: TypeDef = {
"struct" <name:Ident> <s:Struct> => TypeDef{name, kind: TypeKind::Struct(s)},
"enum" <name:Ident> "(" <backing:IntType> ")" <fields:Enum>
=> TypeDef{name, kind: TypeKind::Enum(Enum{fields, backing})},
// Enum => TypeDef::Enum(<>),
}
Struct: Struct = { "{" <fields:List<StructField>> "}" => Struct{<>} }
StructField: StructField = {
<name:Ident> ":" <ty:Type> => StructField{<>}
}
Enum: Vec<EnumField> = { "{" <List<EnumField>> "}" => <> }
EnumField: EnumField = {
<name:Ident> <value:("=" <Int>)?> => EnumField{<>}
}
// Terminals
// Num: u8 = {
// r"[0-9]+" => <>.parse().unwrap()
// }
Num: u8 = {
// TODO: This is a bit hacky, but it works for now
Int => <>.try_into().unwrap(),
}
Int: i64 = {
r"(-)?[0-9]+" => <>.parse().unwrap()
}
Ident: String = { r"[a-zA-Z][a-zA-Z0-9_]*" => <>.to_owned() }
// Combinators
List<T>: Vec<T> = {
<v:(<T>)*> => v
};
Comma<T>: Vec<T> = {
<v:(<T> ",")*> <e:T?> => match e {
None=> v,
Some(e) => {
let mut v = v;
v.push(e);
v
}
}
};

8156
hidl/src/grammar.rs Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,16 @@
use debug2::Debug as Debug2;
use serde::{Deserialize, Serialize};
pub mod spec;
pub mod ast;
#[allow(clippy::all)]
pub mod grammar;
#[derive(Debug, Debug2, Default, Clone, Serialize, Deserialize, PartialEq)]
pub struct Module {
#[serde(default, skip_serializing_if = "is_default")]
interfaces: Vec<Interface>,
#[serde(default, skip_serializing_if = "is_default")]
types: Vec<CustomType>,
}
@ -17,7 +19,7 @@ pub struct Module {
pub struct IDL {
name: String,
root: Module,
#[serde(default, skip_serializing_if = "is_default")]
extenstions: Vec<Extension>,
}
@ -35,18 +37,17 @@ pub struct Interface {
name: String,
version: Version,
#[serde(default, skip_serializing_if = "is_default")]
methods: Vec<Method>,
#[serde(default, skip_serializing_if = "is_default")]
events: Vec<Method>,
}
#[derive(Debug, Debug2, Default, Clone, Serialize, Deserialize, PartialEq)]
pub struct Method {
name: String,
#[serde(default, skip_serializing_if = "is_default")]
ret: Type,
#[serde(default, skip_serializing_if = "is_default")]
args: Vec<(String, Type)>,
}

View File

@ -1,87 +0,0 @@
use crate::*;
// TODO: Use autodefault when https://github.com/Lucretiel/autodefault/issues/4
// is fixed
pub fn spec() -> IDL {
IDL {
name: "hypercosm".to_owned(),
root: Module {
interfaces: vec![
Interface {
name: "object".to_owned(),
version: (1, 0, 0), // TODO: Change
methods: vec![
Method {
name: "listInterfaces".to_owned(),
args: vec![],
ret: ty::array(ty::string()),
},
Method {
name: "release".to_owned(),
..default()
},
],
..default()
},
Interface {
name: "root".to_owned(),
version: (0, 1, 0),
methods: vec![
Method {
name: "listExtensions".to_owned(),
ret: ty::array(ty::string()),
..default()
},
Method {
name: "ping".to_owned(),
..default()
},
Method {
name: "getObjectById".to_owned(),
ret: ty::object(),
args: vec![("id".to_owned(), ty::uuid())],
},
Method {
name: "getObjectByName".to_owned(),
ret: ty::object(),
args: vec![("name".to_owned(), ty::string())],
},
],
..default()
},
],
..default()
},
extenstions: vec![Extension {
name: "assetdelivery".to_owned(),
version: (0, 1, 0),
module: Module {
interfaces: vec![Interface {
name: "assetdelivery".to_owned(),
version: (0, 1, 0),
events: vec![Method {
name: "loadAssets".to_owned(),
args: vec![("name".to_owned(), ty::string())],
..default()
}],
..default()
}],
types: vec![CustomType {
name: "asset".to_owned(),
kind: CustomTypeKind::Struct(CustomStruct {
fields: vec![
("id".to_owned(), ty::uuid()),
("name".to_owned(), ty::string()),
("data".to_owned(), ty::array(ty::u8())),
],
}),
}],
},
}],
}
}
fn default<D: Default>() -> D {
Default::default()
}