Advanced Compiler-Compiler Platform
Minotaur provides superior context management compared to traditional AST-based approaches:
Context Modifiers:
// Function-level context
<function-declaration (function-scope)> ::= "function" <identifier> "(" <parameters> ")" "{" <statements> "}"
// Class-level context
<method-declaration (class-scope)> ::= <access-modifier> <identifier> "(" <parameters> ")" "{" <statements> "}"
// Block-level context
<block-statement (block-scope)> ::= "{" <statements> "}"
Dynamic Context Switching:
// Enable/disable contexts during parsing
Context(function-scope, on) // Enter function context
Context(class-scope, off) // Exit class context
Unlike refakts’ single-path approach, Minotaur maintains multiple parsing contexts simultaneously:
Minotaur supports nested contexts that refakts cannot easily handle:
// Nested context example
<class-declaration> ::= "class" <identifier> "{" <class-members> "}" => {
enterContext("class", $2)
processMembers($4)
exitContext("class")
}
<method-declaration> ::= <access> <identifier> "(" <params> ")" "{" <body> "}" => {
enterContext("method", $2, getCurrentContext())
processMethodBody($7)
exitContext("method")
}
Minotaur enables more precise refactoring than refakts through grammar awareness:
Variable Extraction with Grammar Context:
<extract-candidate> ::= <complex-expression> => {
if (isExtractionWorthy($1) && inValidContext()) {
suggestExtraction($1, getCurrentScope())
}
}
// Context-aware extraction rules
<assignment-expression (function-scope)> ::= <identifier> "=" <expression> => {
if (shouldExtract($3)) {
extractToLocalVariable($3, getCurrentFunction())
}
}
<assignment-expression (class-scope)> ::= <identifier> "=" <expression> => {
if (shouldExtract($3)) {
extractToClassField($3, getCurrentClass())
}
}
Scope-Aware Renaming:
<identifier-reference> ::= <identifier> => {
recordReference($1, getCurrentScope(), getCurrentPosition())
}
// Rename operation with scope awareness
function renameInScope(identifier: string, newName: string, scope: string) {
// Only rename references within the specified scope
// Grammar context ensures we don't rename across scope boundaries
}
Minotaur can define refactoring rules specific to language constructs:
// TypeScript-specific refactoring
<interface-declaration> ::= "interface" <identifier> "{" <interface-members> "}" => {
enableRefactoring("extract-interface", $2, $4)
enableRefactoring("implement-interface", $2)
}
// SQL-specific refactoring
<select-statement> ::= "SELECT" <columns> "FROM" <table> <where-clause>? => {
enableRefactoring("extract-subquery", $2, $4, $5)
enableRefactoring("optimize-query", $0)
}
// Domain-specific language refactoring
<business-rule> ::= "WHEN" <condition> "THEN" <action> => {
enableRefactoring("extract-rule", $2, $4)
enableRefactoring("combine-rules", $0)
}
Minotaur’s grammar switching enables refactoring across language boundaries:
// HTML with embedded CSS and JavaScript
<style-block> ::= "<style>" <css-rules> "</style>" => {
switchGrammar("CSS")
enableRefactoring("extract-css-class", $2)
enableRefactoring("optimize-css", $2)
switchGrammar("HTML")
}
<script-block> ::= "<script>" <javascript-code> "</script>" => {
switchGrammar("JavaScript")
enableRefactoring("extract-function", $2)
enableRefactoring("minify-code", $2)
switchGrammar("HTML")
}
| Capability | RefakTS | Minotaur | |————|———|————–| | Language Support | TypeScript only | Any language with grammar | | Multi-language Files | Limited | Native support | | Custom Languages | Not supported | Full support | | Language Extensions | Not supported | Dynamic extensions |
| Context Level | RefakTS | Minotaur | |—————|———|————–| | Function Scope | ✓ | ✓ | | Class Scope | ✓ | ✓ | | Block Scope | ✓ | ✓ | | Custom Scopes | Limited | Full support | | Nested Contexts | Basic | Advanced | | Context History | No | Yes |
| Operation Type | RefakTS | Minotaur | |—————-|———|————–| | Variable Operations | ✓ | ✓ | | Function Operations | ✓ | ✓ | | Language-Specific | Limited | Full support | | Cross-Language | No | Yes | | Custom Operations | No | Yes | | Grammar-Guided | No | Yes |
interface ContextStack {
push(context: string, identifier?: string): void;
pop(): string | undefined;
current(): string | undefined;
contains(context: string): boolean;
depth(): number;
}
// Grammar rules with context stack operations
<function-start> ::= "function" <identifier> "(" <parameters> ")" "{" => {
contextStack.push("function", $2)
}
<function-end> ::= "}" => {
if (contextStack.current() === "function") {
contextStack.pop()
}
}
interface ScopeAwareSymbolTable {
declare(symbol: string, type: string, scope: string): void;
lookup(symbol: string, scope: string): SymbolInfo | undefined;
getAllInScope(scope: string): SymbolInfo[];
findReferences(symbol: string): Reference[];
}
// Grammar integration
<variable-declaration> ::= <type> <identifier> "=" <expression> => {
symbolTable.declare($2, $1, contextStack.current())
}
<identifier-usage> ::= <identifier> => {
symbolTable.addReference($1, contextStack.current(), getCurrentPosition())
}
interface RefactoringOperation {
name: string;
applicableContexts: string[];
preconditions: (context: ParseContext) => boolean;
execute: (target: ASTNode, context: ParseContext) => RefactoringResult;
}
// Grammar-triggered refactoring
<refactoring-trigger> ::= <pattern> => {
const operations = getApplicableRefactorings(getCurrentContext())
operations.forEach(op => {
if (op.preconditions(getCurrentContext())) {
suggestRefactoring(op, $1)
}
})
}
Minotaur provides superior context-aware refactoring capabilities compared to refakts by:
The grammar-based approach enables AI systems to perform surgical refactoring operations with better precision and broader language support than traditional AST manipulation tools.