Updated mapping data structure
This commit is contained in:
@@ -3,11 +3,11 @@ pub mod expr;
|
||||
pub mod statement;
|
||||
pub mod top_level;
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use mist_parser::{
|
||||
ast::*,
|
||||
rev_mapper::{MistMap, RustMap},
|
||||
rev_mapper::{Mapping, MistMap, RustMap},
|
||||
};
|
||||
|
||||
pub struct Context {
|
||||
@@ -27,20 +27,19 @@ pub trait GetRust {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct RustCodegen {
|
||||
output: String,
|
||||
indent: usize,
|
||||
pub mapping: HashSet<(RustMap, MistMap)>,
|
||||
pub mapping: Mapping,
|
||||
position: RustMap,
|
||||
}
|
||||
|
||||
impl RustCodegen {
|
||||
pub fn new() -> Self {
|
||||
pub fn new(mist_path: PathBuf) -> Self {
|
||||
Self {
|
||||
output: String::new(),
|
||||
indent: 0,
|
||||
mapping: HashSet::new(),
|
||||
mapping: Mapping::new(mist_path),
|
||||
position: RustMap(1, 0),
|
||||
}
|
||||
}
|
||||
@@ -51,16 +50,16 @@ impl RustCodegen {
|
||||
|
||||
fn add(&mut self, s: &str) {
|
||||
let newline_count = bytecount::count(s.as_bytes(), b'\n');
|
||||
|
||||
|
||||
if newline_count == 0 {
|
||||
self.position.1 += s.len();
|
||||
} else {
|
||||
self.position.0 += newline_count;
|
||||
|
||||
|
||||
let last_newline = s.rfind('\n').unwrap();
|
||||
self.position.1 = s.len() - last_newline - 1;
|
||||
}
|
||||
|
||||
|
||||
self.output.push_str(s);
|
||||
}
|
||||
|
||||
@@ -152,6 +151,7 @@ impl<T: GetRust> GenRust for T {
|
||||
impl<T: GenRust> GenRust for Spanned<T> {
|
||||
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
|
||||
cg.mapping
|
||||
.map
|
||||
.insert((cg.position, MistMap(self.line, self.column)));
|
||||
|
||||
self.item.gen_rust(ctx, cg);
|
||||
|
||||
Reference in New Issue
Block a user