Erster Commit

This commit is contained in:
zed
2026-03-13 09:53:40 +01:00
commit 5ebcad02ed
3945 changed files with 974582 additions and 0 deletions

51
reproduce_error.js Normal file
View File

@@ -0,0 +1,51 @@
const fs = require('fs');
try {
const { Reader, NullValidator, Parser } = require('ts-edifact');
const filePath = 'c:\\Users\\matthias.hoesch\\.gemini\\antigravity\\scratch\\vda-to-edifact-converter\\samples\\test_efz.edi';
const content = fs.readFileSync(filePath, 'utf8');
const normalized = content.replace(/\r\n/g, '').replace(/\r/g, '').trim();
console.log('Normalized content length:', normalized.length);
// We cannot easily inject NullValidator into Reader because it's hardcoded in constructor.
// Instead, let's try to use Parser + NullValidator directly if we want pure syntax check.
// However, Reader provides a nice way to get the result array.
const reader = new Reader();
// Re-initialize parser with NullValidator if possible
const validator = new NullValidator();
reader.validator = validator;
// We need to overwrite the parser as well because it's already created with the old validator
reader.parser = new Parser(validator);
// Force UNOC
reader.encoding('UNOC');
// Re-setup callbacks for the new parser
const result = reader.result;
let elements = reader.elements;
let components = reader.components;
reader.parser.onOpenSegment = function (segment) {
elements = [];
result.push({ name: segment, elements: elements });
};
reader.parser.onElement = function () {
components = [];
elements.push(components);
};
reader.parser.onComponent = function (value) {
components.push(value);
};
const segments = reader.parse(normalized);
console.log('Successfully parsed', segments.length, 'segments.');
console.log('First 3 segments:');
console.log(JSON.stringify(segments.slice(0, 3), null, 2));
} catch (e) {
console.error('Error during parsing:');
console.error(e.message);
if (e.stack) console.error(e.stack);
}