in playground/tree-sitter/concrete-syntax.js [257:304]
function executeConcreteSyntaxPattern(pattern) {
const statusText = document.getElementById('concrete-syntax-status');
statusText.textContent = 'Searching...';
if (!window.ConcreteSyntax) {
statusText.textContent = 'WASM not ready';
return;
}
try {
// Always get fresh source code
let sourceCode = getFreshSourceCode();
if (!sourceCode || !sourceCode.trim()) {
statusText.textContent = 'No code';
clearHighlights();
return;
}
// Always parse fresh tree
const languageSelect = document.getElementById('language-select');
const currentLanguage = languageSelect ? languageSelect.value : 'python';
parseFreshTree(sourceCode, currentLanguage).then(tree => {
if (!tree || !tree.rootNode) {
statusText.textContent = 'Parse failed';
return;
}
// Execute concrete syntax matching
const matches = executeConcreteSyntaxQuery(pattern, tree.rootNode, sourceCode);
// Highlight matches in editor
highlightMatchesInEditor(matches);
statusText.textContent = matches.length > 0 ? `${matches.length} match${matches.length !== 1 ? 'es' : ''}` : 'No matches';
}).catch(err => {
console.error('Parse error:', err);
statusText.textContent = 'Parse error';
});
} catch (error) {
console.error('Error executing concrete syntax pattern:', error);
statusText.textContent = 'Error';
}
}