|
|
@ -13,15 +13,6 @@ use std::path::Path;
|
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
use std::thread;
|
|
|
|
use std::thread;
|
|
|
|
|
|
|
|
|
|
|
|
macro_rules! parse_option {
|
|
|
|
|
|
|
|
($option:expr, $index:expr) => {
|
|
|
|
|
|
|
|
if let Some(_) = $option {
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return Err(ParseError::new($index));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub struct Parser {
|
|
|
|
pub struct Parser {
|
|
|
|
pub(crate) index: usize,
|
|
|
|
pub(crate) index: usize,
|
|
|
|
pub(crate) text: Vec<char>,
|
|
|
|
pub(crate) text: Vec<char>,
|
|
|
@ -58,8 +49,7 @@ impl Parser {
|
|
|
|
paths: Arc<Mutex<Vec<String>>>,
|
|
|
|
paths: Arc<Mutex<Vec<String>>>,
|
|
|
|
is_child: bool,
|
|
|
|
is_child: bool,
|
|
|
|
) -> Self {
|
|
|
|
) -> Self {
|
|
|
|
let mut text: Vec<char> = text.chars().collect();
|
|
|
|
let text: Vec<char> = text.chars().collect();
|
|
|
|
text.append(&mut vec!['\n', ' ']); // it fixes stuff and I don't know why.
|
|
|
|
|
|
|
|
let current_char = text.get(0).unwrap().clone();
|
|
|
|
let current_char = text.get(0).unwrap().clone();
|
|
|
|
if let Some(path) = path.clone() {
|
|
|
|
if let Some(path) = path.clone() {
|
|
|
|
let path_info = Path::new(&path);
|
|
|
|
let path_info = Path::new(&path);
|
|
|
@ -167,6 +157,9 @@ impl Parser {
|
|
|
|
match self.parse_block() {
|
|
|
|
match self.parse_block() {
|
|
|
|
Ok(block) => self.document.add_element(block),
|
|
|
|
Ok(block) => self.document.add_element(block),
|
|
|
|
Err(err) => {
|
|
|
|
Err(err) => {
|
|
|
|
|
|
|
|
if err.eof {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
if let Some(path) = &self.path {
|
|
|
|
if let Some(path) = &self.path {
|
|
|
|
if let Some(position) = err.get_position(&self.get_text()) {
|
|
|
|
if let Some(position) = err.get_position(&self.get_text()) {
|
|
|
|
println!(
|
|
|
|
println!(
|
|
|
@ -439,7 +432,7 @@ impl Parser {
|
|
|
|
return Err(self.revert_with_error(start_index));
|
|
|
|
return Err(self.revert_with_error(start_index));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if self.check_special(&IMPORT_CLOSE) {
|
|
|
|
if self.check_special(&IMPORT_CLOSE) {
|
|
|
|
parse_option!(self.next_char(), self.index);
|
|
|
|
self.skip_char();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// parsing success
|
|
|
|
// parsing success
|
|
|
|
|
|
|
|
|
|
|
@ -613,7 +606,7 @@ impl Parser {
|
|
|
|
let mut element = TextLine::new();
|
|
|
|
let mut element = TextLine::new();
|
|
|
|
while let Ok(inline) = self.parse_inline() {
|
|
|
|
while let Ok(inline) = self.parse_inline() {
|
|
|
|
element.subtext.push(inline);
|
|
|
|
element.subtext.push(inline);
|
|
|
|
if self.check_linebreak() || self.check_special(&PIPE) {
|
|
|
|
if self.check_linebreak() || self.check_special(&PIPE) || self.check_eof() {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -623,7 +616,7 @@ impl Parser {
|
|
|
|
if self.check_special(&PIPE) {
|
|
|
|
if self.check_special(&PIPE) {
|
|
|
|
self.skip_char();
|
|
|
|
self.skip_char();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if self.check_linebreak() {
|
|
|
|
if self.check_linebreak() || self.check_eof() {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.seek_inline_whitespace();
|
|
|
|
self.seek_inline_whitespace();
|
|
|
@ -709,17 +702,19 @@ impl Parser {
|
|
|
|
let mut text = TextLine::new();
|
|
|
|
let mut text = TextLine::new();
|
|
|
|
while let Ok(subtext) = self.parse_inline() {
|
|
|
|
while let Ok(subtext) = self.parse_inline() {
|
|
|
|
text.add_subtext(subtext);
|
|
|
|
text.add_subtext(subtext);
|
|
|
|
let current_index = self.index;
|
|
|
|
if self.check_eof() {
|
|
|
|
if self.next_char() == None {
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.revert_to(current_index)?;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if self.check_linebreak() {
|
|
|
|
if self.check_linebreak() {
|
|
|
|
parse_option!(self.next_char(), self.index);
|
|
|
|
self.skip_char();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if text.subtext.len() > 0 || !self.check_eof() {
|
|
|
|
Ok(text)
|
|
|
|
Ok(text)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Err(ParseError::eof(self.index))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|