From 00582bd7c39c87cb57804ae477d9db17b1cac2c9 Mon Sep 17 00:00:00 2001 From: vms Date: Mon, 15 Mar 2021 17:05:03 +0300 Subject: [PATCH] improve version parsing --- Cargo.lock | 2 +- wasmer-it/Cargo.toml | 2 +- wasmer-it/src/decoders/wat.rs | 19 ++++++++++++++++--- wasmer-it/src/encoders/wat.rs | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 926ba90..d4d209c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -210,7 +210,7 @@ checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" [[package]] name = "wasmer-interface-types-fl" -version = "0.18.0" +version = "0.18.1" dependencies = [ "fluence-it-types", "it-to-bytes", diff --git a/wasmer-it/Cargo.toml b/wasmer-it/Cargo.toml index eb9e2d7..afd6dd1 100644 --- a/wasmer-it/Cargo.toml +++ b/wasmer-it/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-interface-types-fl" -version = "0.18.0" +version = "0.18.1" description = "WebAssembly Interface Types library for Wasmer" license = "MIT" authors = ["The Wasmer Engineering Team "] diff --git a/wasmer-it/src/decoders/wat.rs b/wasmer-it/src/decoders/wat.rs index e2c145f..e571211 100644 --- a/wasmer-it/src/decoders/wat.rs +++ b/wasmer-it/src/decoders/wat.rs @@ -379,9 +379,22 @@ impl Parse<'_> for FunctionType { } } +#[derive(PartialEq, Debug)] +struct Version(pub String); + +impl Parse<'_> for Version { + fn parse(parser: Parser<'_>) -> Result { + parser.parse::()?; + let version = parser.parse()?; + + Ok(Version(version)) + } +} + + #[derive(PartialEq, Debug)] enum Interface<'a> { - Version(String), + Version(Version), Type(Type), Import(Import<'a>), Adapter(Adapter), @@ -592,7 +605,7 @@ impl<'a> Parse<'a> for Interfaces<'a> { } fn try_handle_version( - version_str: &str, + sdk_version: &Version, version: &mut Option, parser: &Parser<'_>, ) -> Result<()> { @@ -605,7 +618,7 @@ fn try_handle_version( )); } - let parsed_version = semver::Version::from_str(version_str) + let parsed_version = semver::Version::from_str(&sdk_version.0) .map_err(|e| wast::Error::new(parser.cur_span(), format!("version is corrupted: {}", e)))?; *version = Some(parsed_version); diff --git a/wasmer-it/src/encoders/wat.rs b/wasmer-it/src/encoders/wat.rs index b95dbec..de9bab9 100644 --- a/wasmer-it/src/encoders/wat.rs +++ b/wasmer-it/src/encoders/wat.rs @@ -296,7 +296,7 @@ impl<'input> ToString for &Interfaces<'input> { } }; - output.push_str("Version: "); + output.push_str("(@interface version "); output.push_str(&self.version.to_string()); separator(&mut output);