mirror of
https://github.com/fluencelabs/interface-types
synced 2024-12-04 15:20:20 +00:00
improve parsing wit files
This commit is contained in:
parent
6f9baea140
commit
5569b9ab62
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -161,7 +161,7 @@ checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
|
||||
|
||||
[[package]]
|
||||
name = "wasmer-interface-types-fl"
|
||||
version = "0.17.15"
|
||||
version = "0.17.16"
|
||||
dependencies = [
|
||||
"log",
|
||||
"nom",
|
||||
|
@ -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>"]
|
||||
|
@ -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())
|
||||
|
@ -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(),
|
||||
|
Loading…
Reference in New Issue
Block a user