evidence-dsl: extract Evidence DSL v2 compiler from @arbiter/core
The Evidence DSL (ADR-000) is a thin declarative layer that compiles to engine rule types. It has zero runtime coupling to the core engine (DSLCompiler takes an arbiter as a duck-typed argument; the only shared code was the ip-utils helpers, now local). Extracting it into its own package keeps the core artifact free of the DSL surface. - @arbiter/evidence-dsl depends on @arbiter/core (config formats are the compilation target) - deep-path exports for the compiler, parser, generator, validation, and built-in functions (the surface the core's DSL tests consume) - tests moved alongside; generate-parser script + peggy devDep local - CI: test on push, publish on v* tags
This commit is contained in:
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Script to generate the DSL parser from Peggy grammar
|
||||
*/
|
||||
|
||||
import peggy from 'peggy';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const grammarPath = path.join(__dirname, '../src/grammar/dsl.peggy');
|
||||
const outputPath = path.join(__dirname, '../src/parser/GeneratedParser.js');
|
||||
|
||||
console.log('Generating DSL parser from Peggy grammar...');
|
||||
console.log('Grammar:', grammarPath);
|
||||
console.log('Output:', outputPath);
|
||||
|
||||
try {
|
||||
// Read the grammar file
|
||||
const grammar = fs.readFileSync(grammarPath, 'utf8');
|
||||
|
||||
// Generate the parser
|
||||
const parserSource = peggy.generate(grammar, {
|
||||
format: 'es',
|
||||
output: 'source',
|
||||
grammarSource: 'dsl.peggy'
|
||||
});
|
||||
|
||||
// Write the generated parser
|
||||
fs.writeFileSync(outputPath, parserSource);
|
||||
|
||||
console.log('✅ Parser generated successfully!');
|
||||
console.log('Generated file:', outputPath);
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Error generating parser:');
|
||||
console.error(error.message);
|
||||
|
||||
if (error.format) {
|
||||
console.error('\nFormatted error:');
|
||||
console.error(error.format([
|
||||
{ source: 'dsl.peggy', text: fs.readFileSync(grammarPath, 'utf8') }
|
||||
]));
|
||||
}
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
Reference in New Issue
Block a user