mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
First draft of the macro lexer
This commit is contained in:
39
public/scripts/macros/MacroEngine.js
Normal file
39
public/scripts/macros/MacroEngine.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import { MacroLexer } from './MacroLexer.js';
|
||||
import { MacroParser } from './MacroParser.js';
|
||||
|
||||
class MacroEngine {
|
||||
static instance = new MacroEngine();
|
||||
|
||||
constructor() {
|
||||
this.parser = MacroParser.instance;
|
||||
}
|
||||
|
||||
parseDocument(input) {
|
||||
const lexingResult = MacroLexer.tokenize(input);
|
||||
this.parser.input = lexingResult.tokens;
|
||||
// const cst = this.parser.document();
|
||||
// return cst;
|
||||
}
|
||||
|
||||
evaluate(input) {
|
||||
const lexingResult = MacroLexer.tokenize(input);
|
||||
this.parser.input = lexingResult.tokens;
|
||||
// const cst = this.parser.macro();
|
||||
|
||||
// if (this.parser.errors.length > 0) {
|
||||
// throw new Error('Parsing errors detected');
|
||||
// }
|
||||
|
||||
// return this.execute(cst);
|
||||
}
|
||||
|
||||
execute(cstNode) {
|
||||
// Implement execution logic here, traversing the CST and replacing macros with their values
|
||||
// For now, we'll just return a placeholder result
|
||||
return 'Executed Macro';
|
||||
}
|
||||
}
|
||||
|
||||
const macroEngineInstance = MacroEngine.instance;
|
||||
|
||||
export { MacroEngine, macroEngineInstance };
|
Reference in New Issue
Block a user