introduce salsa and integrate into djls-project crate (#139)
Some checks failed
lint / pre-commit (push) Waiting to run
zizmor 🌈 / zizmor latest via PyPI (push) Waiting to run
release / build (push) Failing after 15s
release / test (push) Has been skipped
release / release (push) Has been cancelled

This commit is contained in:
Josh Thomas 2025-05-09 23:16:39 -05:00 committed by GitHub
parent 0c041e20d7
commit ccf33290b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 896 additions and 670 deletions

View file

@ -164,6 +164,7 @@ impl Lexer {
self.peek_at(-1)
}
#[allow(dead_code)]
fn peek_until(&self, end: &str) -> Result<bool, LexerError> {
let mut index = self.current;
let end_chars: Vec<char> = end.chars().collect();
@ -224,6 +225,7 @@ impl Lexer {
Ok(self.source[start..self.current].trim().to_string())
}
#[allow(dead_code)]
fn consume_chars(&mut self, s: &str) -> Result<char, LexerError> {
for c in s.chars() {
if c != self.peek()? {

View file

@ -150,6 +150,7 @@ impl Parser {
self.peek_at(0)
}
#[allow(dead_code)]
fn peek_next(&self) -> Result<Token, ParserError> {
self.peek_at(1)
}
@ -192,6 +193,7 @@ impl Parser {
self.peek_previous()
}
#[allow(dead_code)]
fn backtrack(&mut self, steps: usize) -> Result<Token, ParserError> {
if self.current < steps {
return Err(ParserError::stream_error(StreamError::AtBeginning));

View file

@ -13,20 +13,24 @@ pub enum TagSpecError {
#[error("Failed to parse TOML: {0}")]
Toml(#[from] toml::de::Error),
#[error("Failed to extract specs: {0}")]
#[allow(dead_code)]
Extract(String),
#[error(transparent)]
Other(#[from] anyhow::Error),
}
#[derive(Clone, Debug, Default)]
#[allow(dead_code)]
pub struct TagSpecs(HashMap<String, TagSpec>);
impl TagSpecs {
#[allow(dead_code)]
pub fn get(&self, key: &str) -> Option<&TagSpec> {
self.0.get(key)
}
/// Load specs from a TOML file, looking under the specified table path
#[allow(dead_code)]
fn load_from_toml(path: &Path, table_path: &[&str]) -> Result<Self, TagSpecError> {
let content = fs::read_to_string(path)?;
let value: Value = toml::from_str(&content)?;
@ -51,6 +55,7 @@ impl TagSpecs {
}
/// Load specs from a user's project directory
#[allow(dead_code)]
pub fn load_user_specs(project_root: &Path) -> Result<Self, anyhow::Error> {
let config_files = ["djls.toml", ".djls.toml", "pyproject.toml"];
@ -68,6 +73,7 @@ impl TagSpecs {
}
/// Load builtin specs from the crate's tagspecs directory
#[allow(dead_code)]
pub fn load_builtin_specs() -> Result<Self, anyhow::Error> {
let specs_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("tagspecs");
let mut specs = HashMap::new();
@ -85,12 +91,14 @@ impl TagSpecs {
}
/// Merge another TagSpecs into this one, with the other taking precedence
#[allow(dead_code)]
pub fn merge(&mut self, other: TagSpecs) -> &mut Self {
self.0.extend(other.0);
self
}
/// Load both builtin and user specs, with user specs taking precedence
#[allow(dead_code)]
pub fn load_all(project_root: &Path) -> Result<Self, anyhow::Error> {
let mut specs = Self::load_builtin_specs()?;
let user_specs = Self::load_user_specs(project_root)?;
@ -107,6 +115,7 @@ pub struct TagSpec {
impl TagSpec {
/// Recursive extraction: Check if node is spec, otherwise recurse if table.
#[allow(dead_code)]
fn extract_specs(
value: &Value,
prefix: Option<&str>, // Path *to* this value node