Skip to content

Commit

Permalink
extract parsing of commands and stems
Browse files Browse the repository at this point in the history
  • Loading branch information
joswig committed Feb 11, 2025
1 parent 0803e6d commit c4fa414
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/utilities/codemirror/cdlDictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,32 @@ export function parseCdlDictionary(contents: string, id?: string, path?: string)
version,
};

const enums: Enum[] = [];
const { enums, fswCommands } = parseArgumentsAndStems(lineIterator);

const globalArguments: FswCommandArgumentMap = {};
const fswCommands: FswCommand[] = [];
return {
enumMap: Object.fromEntries(enums.map(e => [e.name, e])),
enums,
fswCommandMap: Object.fromEntries(fswCommands.map(cmd => [cmd.stem, cmd])),
fswCommands,
header,
hwCommandMap: {},
hwCommands: [],
id: id ?? '',
path: path ?? '',
};
}

function parseArgumentsAndStems(lineIterator: ArrayIterator<string>): {
enums: Enum[];
fswCommands: FswCommand[];
} {
// parse globals and stems
// assumes all global arguments are defined prior to stems

const enums: Enum[] = [];
const globalArguments: FswCommandArgumentMap = {};
const fswCommands: FswCommand[] = [];

for (const line of lineIterator) {
if (line.match(START_LOOKUP_ARG)) {
const lookupLines: string[] = [line];
Expand Down Expand Up @@ -109,17 +129,9 @@ export function parseCdlDictionary(contents: string, id?: string, path?: string)
}
}
}

return {
enumMap: Object.fromEntries(enums.map(e => [e.name, e])),
enums,
fswCommandMap: Object.fromEntries(fswCommands.map(cmd => [cmd.stem, cmd])),
fswCommands,
header,
hwCommandMap: {},
hwCommands: [],
id: id ?? '',
path: path ?? '',
};
}

Expand Down

0 comments on commit c4fa414

Please sign in to comment.