mirror of
https://github.com/sagiegurari/duckscript
synced 2024-10-14 11:53:05 +00:00
Add parser::parse_text_with_source_file
This commit is contained in:
parent
0d2e32e53c
commit
23042418ce
|
@ -20,13 +20,9 @@ static LABEL_PREFIX: char = ':';
|
|||
|
||||
/// parses the file and returns a vector of instructions
|
||||
pub fn parse_file(file: &str) -> Result<Vec<Instruction>, ScriptError> {
|
||||
let mut meta_info = InstructionMetaInfo::new();
|
||||
meta_info.source = Some(file.to_string());
|
||||
|
||||
match read_text_file(file) {
|
||||
Ok(text) => parse_lines(&text, meta_info),
|
||||
Err(error) => Err(ScriptError::ErrorReadingFile(file.to_string(), Some(error))),
|
||||
}
|
||||
let text = read_text_file(file)
|
||||
.map_err(|error| ScriptError::ErrorReadingFile(file.to_string(), Some(error)))?;
|
||||
parse_text_with_source_file(&text, file)
|
||||
}
|
||||
|
||||
/// parses the provided script text and returns a vector of instructions
|
||||
|
@ -34,6 +30,17 @@ pub fn parse_text(text: &str) -> Result<Vec<Instruction>, ScriptError> {
|
|||
parse_lines(&text, InstructionMetaInfo::new())
|
||||
}
|
||||
|
||||
/// parses the provided script text with the file provided as its source path and returns a vector of instructions
|
||||
pub fn parse_text_with_source_file(
|
||||
text: &str,
|
||||
source_file: &str,
|
||||
) -> Result<Vec<Instruction>, ScriptError> {
|
||||
let mut meta_info = InstructionMetaInfo::new();
|
||||
meta_info.source = Some(source_file.to_string());
|
||||
|
||||
parse_lines(&text, meta_info)
|
||||
}
|
||||
|
||||
fn parse_lines(
|
||||
lines: &str,
|
||||
meta_info: InstructionMetaInfo,
|
||||
|
|
Loading…
Reference in a new issue