Better error reporting for missing semicolon in code clock

cc #33 #53
This commit is contained in:
Kogia-sima 2021-04-06 21:49:05 +09:00
parent f0ef8e409a
commit 9bf4090468
1 changed files with 8 additions and 0 deletions

View File

@ -116,6 +116,14 @@ impl SourceBuilder {
fn write_text<'a>(&mut self, token: &Token<'a>) -> Result<(), Error> {
use std::fmt::Write;
// if error has occured at the first byte of `render_text!` macro, it
// will be mapped to the first byte of text
self.source_map.entries.push(SourceMapEntry {
original: token.offset(),
new: self.source.len(),
length: 1,
});
self.source.push_str("__sf_rt::render_text!(__sf_buf, ");
// write text token with Debug::fmt
write!(self.source, "{:?}", token.as_str()).unwrap();