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