aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-06-12 16:31:51 +0100
committerAkshay <[email protected]>2021-06-12 16:31:51 +0100
commit73177af78f61975a0eaef9a88758d59db4ccc473 (patch)
treea0b2fb434e4bebb500635b257b331487549be8cb /src
parent987ce60b9fc60ccdb91e0d271fcba10a0a6cf51a (diff)
syntax tree <-> dom tree
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/lib.rs b/src/lib.rs
index f9a6a26..a1e085f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -53,7 +53,16 @@ impl SynNode {
53 } 53 }
54 54
55 pub fn to_string(&self) -> String { 55 pub fn to_string(&self) -> String {
56 format!("{:?}@{:?}", self.node.kind(), self.node.text_range(),) 56 format!("{:?} {:?}", self.node.kind(), self.node.text_range(),)
57 }
58
59 pub fn range(&self) -> TextRange {
60 let r = self.node.text_range();
61 (r.start().into(), r.end().into()).into()
62 }
63
64 pub fn text(&self) -> String {
65 format!("{:?}", self.node.kind())
57 } 66 }
58 67
59 pub fn from_str(s: &str) -> Result<JsValue, JsValue> { 68 pub fn from_str(s: &str) -> Result<JsValue, JsValue> {
@@ -95,7 +104,18 @@ impl SynErr {
95} 104}
96 105
97#[wasm_bindgen] 106#[wasm_bindgen]
98struct TextRange { 107impl SynErr {
108 pub fn range(&self) -> TextRange {
109 let r = self.err.range();
110 (r.start().into(), r.end().into()).into()
111 }
112 pub fn to_string(&self) -> String {
113 self.err.to_string()
114 }
115}
116
117#[wasm_bindgen]
118pub struct TextRange {
99 start: u32, 119 start: u32,
100 end: u32, 120 end: u32,
101} 121}
@@ -107,12 +127,14 @@ impl From<(u32, u32)> for TextRange {
107} 127}
108 128
109#[wasm_bindgen] 129#[wasm_bindgen]
110impl SynErr { 130impl TextRange {
111 pub fn range(&self) -> TextRange { 131 pub fn start(&self) -> u32 {
112 let r = self.err.range(); 132 self.start
113 (r.start().into(), r.end().into()).into() 133 }
134 pub fn end(&self) -> u32 {
135 self.end
114 } 136 }
115 pub fn to_string(&self) -> String { 137 pub fn to_string(&self) -> String {
116 self.err.to_string() 138 format!("{}..{}", self.start, self.end)
117 } 139 }
118} 140}