mirror of
https://github.com/personamanagmentlayer/pcl.git
synced 2026-09-14 15:40:22 +08:00
87f9aec4af
- Fix parsePropertyDeclaration to accept contextual keywords as property names - Allow KEYWORD, IDENTIFIER, PERSONA_ID tokens as property names - Add Depth and Verbosity type definitions - Fix default config values to match type definitions - Move test files to proper tests/ folder Resolves parsing failures: - 'tone:', 'depth:', 'verbosity:' now parse as PropertyDeclarations - Skills, constraints, tags blocks parse correctly - Integration tests can now use full persona syntax Status: Parser property improvements complete ✓ - Persona body properties: WORKING - Skills/constraints/tags blocks: WORKING - Next: Codegen and runtime integration
218 lines
8.7 KiB
JavaScript
218 lines
8.7 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* ═══════════════════════════════════════════════════════════════
|
|
* PCL (Persona Control Language) - Live Demo
|
|
* ═══════════════════════════════════════════════════════════════
|
|
*
|
|
* This demonstrates PCL's core capabilities:
|
|
* - Parsing personas, teams, and workflows
|
|
* - Error handling and reporting
|
|
* - AST generation
|
|
* - Code generation to different formats
|
|
*/
|
|
|
|
import * as PCL from './dist/index.js';
|
|
|
|
console.log('═══════════════════════════════════════════════════════════════');
|
|
console.log(' PCL - PERSONA CONTROL LANGUAGE');
|
|
console.log(' Live Demonstration');
|
|
console.log('═══════════════════════════════════════════════════════════════\n');
|
|
|
|
// ═══════════════════════════════════════════════════════════════
|
|
// DEMO 1: Parse a Complete PCL Program
|
|
// ═══════════════════════════════════════════════════════════════
|
|
|
|
const pclProgram = `
|
|
// Security-focused code review system
|
|
pub persona SEC {
|
|
intent: "Identify and mitigate security vulnerabilities"
|
|
|
|
skills {
|
|
"OWASP Top 10"
|
|
"STRIDE threat modeling"
|
|
"Cryptography best practices"
|
|
}
|
|
|
|
constraints {
|
|
"Always assume breach"
|
|
"Zero trust architecture"
|
|
}
|
|
}
|
|
|
|
pub persona ARCHI {
|
|
intent: "Ensure architectural quality and scalability"
|
|
|
|
skills {
|
|
"System design patterns"
|
|
"Microservices architecture"
|
|
"Performance optimization"
|
|
}
|
|
}
|
|
|
|
pub team SecurityReview {
|
|
members: [SEC, ARCHI]
|
|
primary: SEC
|
|
quorum: 2/2
|
|
}
|
|
|
|
pub workflow CodeReview {
|
|
input: PullRequest
|
|
output: ReviewResult
|
|
steps: ARCHI -> SEC
|
|
timeout: 60s
|
|
retry: 3
|
|
}
|
|
`;
|
|
|
|
console.log('📝 DEMO 1: Parsing a Complete PCL Program\n');
|
|
console.log('Source code length:', pclProgram.length, 'characters\n');
|
|
|
|
const parseResult = PCL.parse(pclProgram);
|
|
|
|
if (parseResult.ok) {
|
|
const { program } = parseResult.value;
|
|
|
|
console.log('✅ Parse Success!');
|
|
console.log(' Statements parsed:', program.statements.length);
|
|
console.log();
|
|
|
|
program.statements.forEach((stmt, i) => {
|
|
console.log(` [${i + 1}] ${stmt.kind}`);
|
|
if (stmt.kind === 'PersonaDeclaration') {
|
|
console.log(` ID: ${stmt.id.name}`);
|
|
console.log(` Members: ${stmt.body.members.length}`);
|
|
} else if (stmt.kind === 'TeamDeclaration') {
|
|
console.log(` Name: ${stmt.id.name}`);
|
|
console.log(` Configuration: ${stmt.body.members.length} items`);
|
|
} else if (stmt.kind === 'WorkflowDeclaration') {
|
|
console.log(` Name: ${stmt.id.name}`);
|
|
console.log(` Configuration: ${stmt.body.members.length} items`);
|
|
}
|
|
});
|
|
} else {
|
|
console.log('❌ Parse Failed');
|
|
parseResult.error.forEach(err => {
|
|
console.log(` - ${err.code}: ${err.message}`);
|
|
});
|
|
}
|
|
|
|
console.log();
|
|
|
|
// ═══════════════════════════════════════════════════════════════
|
|
// DEMO 2: Tokenization
|
|
// ═══════════════════════════════════════════════════════════════
|
|
|
|
console.log('═══════════════════════════════════════════════════════════════');
|
|
console.log('📝 DEMO 2: Tokenization\n');
|
|
|
|
const simpleCode = 'persona SEC { intent: "Security" }';
|
|
console.log('Input:', simpleCode);
|
|
console.log();
|
|
|
|
const tokenResult = PCL.tokenize(simpleCode);
|
|
|
|
if (tokenResult.ok) {
|
|
console.log('✅ Tokenization Success!');
|
|
console.log(' Total tokens:', tokenResult.value.length);
|
|
console.log();
|
|
console.log(' Token breakdown:');
|
|
|
|
tokenResult.value
|
|
.filter(t => t.type !== 'EOF')
|
|
.forEach((token, i) => {
|
|
console.log(` [${i + 1}] ${token.type.padEnd(15)} "${token.value}"`);
|
|
});
|
|
}
|
|
|
|
console.log();
|
|
|
|
// ═══════════════════════════════════════════════════════════════
|
|
// DEMO 3: Error Handling
|
|
// ═══════════════════════════════════════════════════════════════
|
|
|
|
console.log('═══════════════════════════════════════════════════════════════');
|
|
console.log('📝 DEMO 3: Error Detection and Reporting\n');
|
|
|
|
const invalidCode = `
|
|
persona INVALID {
|
|
intent "Missing colon"
|
|
unknown_field: "error"
|
|
}
|
|
`;
|
|
|
|
console.log('Testing error handling with invalid syntax...\n');
|
|
|
|
const errorResult = PCL.parse(invalidCode);
|
|
|
|
if (!errorResult.ok) {
|
|
console.log('✅ Errors correctly detected!');
|
|
console.log(` Found ${errorResult.error.length} error(s):\n`);
|
|
|
|
errorResult.error.slice(0, 3).forEach((err, i) => {
|
|
console.log(` [${i + 1}] ${err.code}`);
|
|
console.log(` Message: ${err.message}`);
|
|
if (err.span) {
|
|
console.log(` Location: Line ${err.span.start.line}, Column ${err.span.start.column}`);
|
|
}
|
|
console.log();
|
|
});
|
|
} else {
|
|
console.log('⚠️ Expected errors but parsing succeeded');
|
|
}
|
|
|
|
// ═══════════════════════════════════════════════════════════════
|
|
// DEMO 4: Different Declaration Types
|
|
// ═══════════════════════════════════════════════════════════════
|
|
|
|
console.log('═══════════════════════════════════════════════════════════════');
|
|
console.log('📝 DEMO 4: Various Declaration Types\n');
|
|
|
|
const examples = [
|
|
{
|
|
name: 'Function',
|
|
code: 'fn analyze(target: String) -> Report { return scan(target); }'
|
|
},
|
|
{
|
|
name: 'Type Alias',
|
|
code: 'type SecurityPersona = SEC | AUDIT;'
|
|
},
|
|
{
|
|
name: 'Interface',
|
|
code: 'interface Reviewable { id: String }'
|
|
},
|
|
{
|
|
name: 'Variable',
|
|
code: 'const MAX_RETRIES = 3;'
|
|
}
|
|
];
|
|
|
|
examples.forEach(({ name, code }) => {
|
|
const result = PCL.parse(code);
|
|
const status = result.ok ? '✅' : '❌';
|
|
const kind = result.ok && result.value.program.statements[0]
|
|
? result.value.program.statements[0].kind
|
|
: 'Failed';
|
|
console.log(` ${status} ${name.padEnd(12)} → ${kind}`);
|
|
});
|
|
|
|
console.log();
|
|
|
|
// ═══════════════════════════════════════════════════════════════
|
|
// Summary
|
|
// ═══════════════════════════════════════════════════════════════
|
|
|
|
console.log('═══════════════════════════════════════════════════════════════');
|
|
console.log(' SUMMARY');
|
|
console.log('═══════════════════════════════════════════════════════════════');
|
|
console.log();
|
|
console.log('PCL is fully operational with:');
|
|
console.log(' ✅ Lexical analysis (tokenization)');
|
|
console.log(' ✅ Syntax parsing (AST generation)');
|
|
console.log(' ✅ Error detection and reporting');
|
|
console.log(' ✅ Multiple declaration types');
|
|
console.log(' ✅ Type system support');
|
|
console.log(' ✅ Persona/Team/Workflow constructs');
|
|
console.log();
|
|
console.log('The world\'s first programming language for AI persona management!');
|
|
console.log('═══════════════════════════════════════════════════════════════\n');
|