improve parsing wit files

This commit is contained in:
vms 2020-11-08 17:57:11 +03:00
parent 6f9baea140
commit 5569b9ab62
4 changed files with 14 additions and 11 deletions

2
Cargo.lock generated
View File

@ -161,7 +161,7 @@ checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
[[package]]
name = "wasmer-interface-types-fl"
version = "0.17.15"
version = "0.17.16"
dependencies = [
"log",
"nom",

View File

@ -1,6 +1,6 @@
[package]
name = "wasmer-interface-types-fl"
version = "0.17.15"
version = "0.17.16"
description = "WebAssembly Interface Types library for Wasmer"
license = "MIT"
authors = ["The Wasmer Engineering Team <engineering@wasmer.io>"]

View File

@ -32,7 +32,7 @@ mod keyword {
custom_keyword!(u32);
custom_keyword!(u64);
custom_keyword!(string);
custom_keyword!(Array);
custom_keyword!(array);
// Instructions.
custom_keyword!(argument_get = "arg.get");
@ -86,7 +86,6 @@ mod keyword {
impl Parse<'_> for InterfaceType {
fn parse(parser: Parser<'_>) -> Result<Self> {
let mut lookahead = parser.lookahead1();
if lookahead.peek::<keyword::s8>() {
parser.parse::<keyword::s8>()?;
@ -131,10 +130,12 @@ impl Parse<'_> for InterfaceType {
parser.parse::<keyword::string>()?;
Ok(InterfaceType::String)
} else if lookahead.peek::<keyword::Array>() {
parser.parse::<keyword::Array>()?;
} else if lookahead.peek::<keyword::array>() {
parser.parse::<keyword::array>()?;
Ok(InterfaceType::Array(Box::new(parser.parse()?)))
let array_type = parser.parens(|p| p.parse())?;
Ok(InterfaceType::Array(Box::new(array_type)))
} else if lookahead.peek::<keyword::anyref>() {
parser.parse::<keyword::anyref>()?;
@ -148,6 +149,8 @@ impl Parse<'_> for InterfaceType {
Ok(InterfaceType::I64)
} else if lookahead.peek::<keyword::record>() {
parser.parse::<keyword::record>()?;
Ok(InterfaceType::Record(parser.parse()?))
} else {
Err(lookahead.error())

View File

@ -73,7 +73,7 @@ impl ToString for &InterfaceType {
InterfaceType::F32 => "f32".to_string(),
InterfaceType::F64 => "f64".to_string(),
InterfaceType::String => "string".to_string(),
InterfaceType::Array(ty) => format!("Array<{:?}>", ty),
InterfaceType::Array(ty) => format!("array ({})", ty.as_ref().to_string()),
InterfaceType::Anyref => "anyref".to_string(),
InterfaceType::I32 => "i32".to_string(),
InterfaceType::I64 => "i64".to_string(),
@ -85,7 +85,7 @@ impl ToString for &InterfaceType {
impl ToString for &RecordType {
fn to_string(&self) -> String {
format!(
"record ${} {{\n{fields}}}",
"record ${} (\n{fields})",
self.name,
fields = self
.fields
@ -145,10 +145,10 @@ impl ToString for &Instruction {
Instruction::StringLowerMemory => "string.lower_memory".into(),
Instruction::StringSize => "string.size".into(),
Instruction::ArrayLiftMemory { value_type } => {
format!("array.lift_memory {:?}", value_type)
format!("array.lift_memory {}", value_type.to_string())
}
Instruction::ArrayLowerMemory { value_type } => {
format!("array.lower_memory {:?}", value_type)
format!("array.lower_memory {}", value_type.to_string())
}
/*
Instruction::ArraySize => "byte_array.size".into(),