fix: improve parser robustness
This commit is contained in:
@@ -56,13 +56,12 @@ function parseSubsystems(yaml: string): Subsystem[] {
|
||||
|
||||
for (const line of lines) {
|
||||
const trimmed = line.trim();
|
||||
const indent = line.search(/\S/);
|
||||
|
||||
if (trimmed.startsWith('subsystems:')) {
|
||||
if (trimmed.startsWith('modules:')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (trimmed.startsWith('- name:') && indent <= 2) {
|
||||
if (trimmed.startsWith('- name:')) {
|
||||
if (current.name) {
|
||||
subsystems.push({
|
||||
id: current.name,
|
||||
@@ -94,7 +93,7 @@ function parseSubsystems(yaml: string): Subsystem[] {
|
||||
if (trimmed.startsWith('provides:')) {
|
||||
currentField = 'provides';
|
||||
const match = trimmed.match(/\[(.*?)\]/);
|
||||
if (match) {
|
||||
if (match && match[1] !== undefined) {
|
||||
current.provides = match[1].split(',').map(s => s.trim());
|
||||
} else {
|
||||
current.provides = [];
|
||||
@@ -105,7 +104,7 @@ function parseSubsystems(yaml: string): Subsystem[] {
|
||||
if (trimmed.startsWith('depends_on:')) {
|
||||
currentField = 'depends_on';
|
||||
const match = trimmed.match(/\[(.*?)\]/);
|
||||
if (match && match[1].trim()) {
|
||||
if (match && match[1] !== undefined && match[1].trim()) {
|
||||
current.depends_on = match[1].split(',').map(s => s.trim());
|
||||
} else {
|
||||
current.depends_on = [];
|
||||
@@ -130,7 +129,7 @@ function parseSubsystems(yaml: string): Subsystem[] {
|
||||
|
||||
if (currentField === 'boundary' && trimmed.startsWith('inputs:')) {
|
||||
const match = trimmed.match(/\[(.*?)\]/);
|
||||
if (match) {
|
||||
if (match && match[1] !== undefined) {
|
||||
current.boundary!.inputs = match[1].split(',').map(s => s.trim());
|
||||
}
|
||||
continue;
|
||||
@@ -138,7 +137,7 @@ function parseSubsystems(yaml: string): Subsystem[] {
|
||||
|
||||
if (currentField === 'boundary' && trimmed.startsWith('outputs:')) {
|
||||
const match = trimmed.match(/\[(.*?)\]/);
|
||||
if (match) {
|
||||
if (match && match[1] !== undefined) {
|
||||
current.boundary!.outputs = match[1].split(',').map(s => s.trim());
|
||||
}
|
||||
continue;
|
||||
@@ -171,13 +170,12 @@ function parseModules(yaml: string): Module[] {
|
||||
|
||||
for (const line of lines) {
|
||||
const trimmed = line.trim();
|
||||
const indent = line.search(/\S/);
|
||||
|
||||
if (trimmed.startsWith('modules:')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (trimmed.startsWith('- name:') && indent <= 2) {
|
||||
if (trimmed.startsWith('- name:')) {
|
||||
if (current.name && current.parent_subsystem) {
|
||||
modules.push({
|
||||
id: current.name,
|
||||
|
||||
Reference in New Issue
Block a user