Improve flattening (#69)

This commit is contained in:
vms
2021-02-18 17:30:14 +03:00
committed by GitHub
parent d43b5454fa
commit 13f93a0f88
24 changed files with 1137 additions and 540 deletions

View File

@ -147,5 +147,34 @@ fn lexical_error_to_label(file_id: usize, error: LexerError) -> Label<usize> {
LeadingDot(start, end) => {
Label::primary(file_id, start..end).with_message(error.to_string())
}
CallArgsNotFlattened(start, end) => {
Label::primary(file_id, start..end).with_message(error.to_string())
}
}
}
pub(super) fn into_variable_and_path(str: &str, pos: usize, should_flatten: bool) -> (&str, &str) {
let json_path = if should_flatten {
&str[pos + 1..str.len() - 1]
} else {
&str[pos + 1..]
};
(&str[0..pos], json_path)
}
pub(super) fn make_flattened_error(
start_pos: usize,
token: Token<'_>,
end_pos: usize,
) -> ErrorRecovery<usize, Token<'_>, LexerError> {
let error = LexerError::CallArgsNotFlattened(start_pos, end_pos);
let error = ParseError::User { error };
let dropped_tokens = vec![(start_pos, token, end_pos)];
ErrorRecovery {
error,
dropped_tokens,
}
}