improve version parsing

This commit is contained in:
vms 2021-03-15 17:05:03 +03:00
parent ab76621355
commit 00582bd7c3
4 changed files with 19 additions and 6 deletions

2
Cargo.lock generated
View File

@ -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",

View File

@ -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 <engineering@wasmer.io>"]

View File

@ -379,9 +379,22 @@ impl Parse<'_> for FunctionType {
}
}
#[derive(PartialEq, Debug)]
struct Version(pub String);
impl Parse<'_> for Version {
fn parse(parser: Parser<'_>) -> Result<Self> {
parser.parse::<keyword::version>()?;
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<semver::Version>,
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);

View File

@ -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);