1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
mod utils;
use wasm_bindgen::prelude::*;
use parser::{parse_ast_json_string};
use wasm_bindgen::throw_str;
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
#[wasm_bindgen]
extern {
fn alert(s: &str);
}
#[wasm_bindgen]
pub fn parse(input: &str) -> String {
match parse_ast_json_string(input) {
Ok(node) => {
node.to_string()
},
Err(e) => throw_str(format!("parse error: {}", e[0]).as_str())
}
}