Define a wasm document.
This commit is contained in:
		
							parent
							
								
									2d5593681f
								
							
						
					
					
						commit
						53320070da
					
				| @ -11,7 +11,7 @@ mod wasm; | ||||
| pub fn parse_org(org_contents: &str) -> wasm_bindgen::JsValue { | ||||
|     let global_settings = GlobalSettings::default(); | ||||
|     let rust_parsed = parse_with_settings(org_contents, &global_settings) | ||||
|         .map(|document| ParseResult::Success(document.into())) | ||||
|         .map(|document| ParseResult::Success((org_contents, document).into())) | ||||
|         .unwrap_or_else(|err| ParseResult::Error(format!("{:?}", err))); | ||||
|     serde_wasm_bindgen::to_value(&rust_parsed).unwrap() | ||||
| } | ||||
|  | ||||
| @ -2,13 +2,17 @@ use organic::types::Document; | ||||
| use serde::Deserialize; | ||||
| use serde::Serialize; | ||||
| 
 | ||||
| use super::macros::to_wasm; | ||||
| 
 | ||||
| #[derive(Serialize, Deserialize)] | ||||
| #[serde(tag = "ast_node")] | ||||
| #[serde(rename = "org-data")] | ||||
| pub(crate) struct WasmDocument {} | ||||
| 
 | ||||
| impl From<Document<'_>> for WasmDocument { | ||||
|     fn from(value: Document) -> Self { | ||||
|         todo!() | ||||
|     } | ||||
| pub(crate) struct WasmDocument { | ||||
|     children: Vec<()>, | ||||
| } | ||||
| 
 | ||||
| to_wasm!(WasmDocument, Document<'s>, original, document, { | ||||
|     WasmDocument { | ||||
|         children: Vec::new(), | ||||
|     } | ||||
| }); | ||||
|  | ||||
							
								
								
									
										15
									
								
								src/wasm/macros.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/wasm/macros.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,15 @@ | ||||
| /// Write the implementation for the intermediate ast node.
 | ||||
| ///
 | ||||
| /// This exists to make changing the type signature easier.
 | ||||
| macro_rules! to_wasm { | ||||
|     ($ostruct:ty, $istruct:ty, $original:ident, $document:ident, $fnbody:tt) => { | ||||
|         impl<'s> From<(&'s str, $istruct)> for $ostruct { | ||||
|             fn from(value: (&'s str, $istruct)) -> $ostruct { | ||||
|                 let ($original, $document) = value; | ||||
|                 $fnbody | ||||
|             } | ||||
|         } | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| pub(crate) use to_wasm; | ||||
| @ -1,4 +1,5 @@ | ||||
| mod document; | ||||
| mod macros; | ||||
| mod parse_result; | ||||
| 
 | ||||
| pub(crate) use parse_result::ParseResult; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander