|
|
|
@ -84,7 +84,6 @@ pub struct IndentQuery {
|
|
|
|
|
pub outdent: HashSet<String>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(not(feature = "embed_runtime"))]
|
|
|
|
|
fn load_runtime_file(language: &str, filename: &str) -> Result<String, std::io::Error> {
|
|
|
|
|
let path = crate::RUNTIME_DIR
|
|
|
|
|
.join("queries")
|
|
|
|
@ -93,34 +92,6 @@ fn load_runtime_file(language: &str, filename: &str) -> Result<String, std::io::
|
|
|
|
|
std::fs::read_to_string(&path)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "embed_runtime")]
|
|
|
|
|
fn load_runtime_file(language: &str, filename: &str) -> Result<String, Box<dyn std::error::Error>> {
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
|
|
#[derive(rust_embed::RustEmbed)]
|
|
|
|
|
#[folder = "../runtime/"]
|
|
|
|
|
struct Runtime;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
struct EmbeddedFileNotFoundError {
|
|
|
|
|
path: PathBuf,
|
|
|
|
|
}
|
|
|
|
|
impl std::error::Error for EmbeddedFileNotFoundError {}
|
|
|
|
|
impl fmt::Display for EmbeddedFileNotFoundError {
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
|
write!(f, "failed to load embedded file {}", self.path.display())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let path = PathBuf::from("queries").join(language).join(filename);
|
|
|
|
|
|
|
|
|
|
if let Some(query_bytes) = Runtime::get(&path.display().to_string()) {
|
|
|
|
|
String::from_utf8(query_bytes.to_vec()).map_err(|err| err.into())
|
|
|
|
|
} else {
|
|
|
|
|
Err(Box::new(EmbeddedFileNotFoundError { path }))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn read_query(language: &str, filename: &str) -> String {
|
|
|
|
|
static INHERITS_REGEX: Lazy<Regex> =
|
|
|
|
|
Lazy::new(|| Regex::new(r";+\s*inherits\s*:?\s*([a-z_,()]+)\s*").unwrap());
|
|
|
|
|