Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/ExportEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ interface FileDescriptor {
interface Parameters {
time_limit: string;
memory_limit: string;
max_base: string;
ncpus: string;
mpi_nbcpu: string;
mpi_nbnoeud: string;
testlist: string;
expected_diag: string;
}

interface FormData {
Expand Down Expand Up @@ -299,9 +302,12 @@ export class ExportEditor<TResult> implements vscode.Disposable {
parameters: {
time_limit: '',
memory_limit: '',
max_base: '',
ncpus: '',
mpi_nbcpu: '',
mpi_nbnoeud: '',
testlist: '',
expected_diag: '',
},
inputFiles: [],
outputFiles: [],
Expand All @@ -318,23 +324,24 @@ export class ExportEditor<TResult> implements vscode.Disposable {

const tokens = cleanLine.split(/\s+/);

if (tokens[0] === 'P' && tokens.length === 3) {
const [, key, value] = tokens;
if (tokens[0] === 'P' && tokens.length >= 3) {
const key = tokens[1];
const value = tokens.slice(2).join(' ');
if (key in formData.parameters) {
formData.parameters[key as keyof Parameters] = value;
}
}

if (tokens[0] === 'F' && tokens.length === 5) {
if ((tokens[0] === 'F' || tokens[0] === 'R') && tokens.length === 5) {
const [, type, name, ioFlag, unit] = tokens;
const fileObj: FileDescriptor = {
type: type,
name: name,
unit: unit,
};
if (ioFlag === 'D') {
if (ioFlag === 'D' || ioFlag === 'DC') {
formData.inputFiles.push(fileObj);
} else if (ioFlag === 'R') {
} else if (ioFlag === 'R' || ioFlag === 'RC') {
formData.outputFiles.push(fileObj);
}
}
Expand Down
23 changes: 20 additions & 3 deletions src/ExportFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ interface Entry {
comments: string[];
line: string;
type: string;
head?: 'F' | 'R';
direction?: 'D' | 'R';
}

Expand All @@ -29,6 +30,9 @@ function typeRank(type: string): number {
}

function byType(a: Entry, b: Entry): number {
if (a.head !== b.head) {
return a.head === 'F' ? -1 : 1;
}
const pa = typeRank(a.type);
const pb = typeRank(b.type);
if (pa !== pb) {
Expand All @@ -41,8 +45,11 @@ const SECTION_HEADERS = {
parameters: '# Simulation parameters',
inputs: '# Input files',
outputs: '# Output files',
unknown: '# Unknown lines',
} as const;

const VALID_IO_FLAGS = new Set(['D', 'DC', 'R', 'RC']);

const STATIC_HEADER_LINES = [
'# This file was generated using VS Code Aster - https://github.com/simvia-tech/vs-code-aster',
'# VS Code Aster is an open-source project maintained by Simvia - https://simvia.tech',
Expand Down Expand Up @@ -72,6 +79,7 @@ export function formatExportContent(text: string, filename?: string): string {
const lines = text.split(/\r?\n/);
const pEntries: Entry[] = [];
const fEntries: Entry[] = [];
const unknownEntries: Entry[] = [];
let pendingComments: string[] = [];

for (const line of lines) {
Expand All @@ -87,18 +95,24 @@ export function formatExportContent(text: string, filename?: string): string {
}
const tokens = trimmed.split(/\s+/);
const head = tokens[0];
if (head === 'P') {
const isValidFR =
(head === 'F' || head === 'R') && tokens.length === 5 && VALID_IO_FLAGS.has(tokens[3] ?? '');
if (head === 'P' && tokens.length >= 2) {
pEntries.push({ comments: pendingComments, line: trimmed, type: '' });
pendingComments = [];
} else if (head === 'F') {
const direction: 'D' | 'R' = tokens[3] === 'D' ? 'D' : 'R';
} else if (isValidFR) {
const direction: 'D' | 'R' = tokens[3] === 'D' || tokens[3] === 'DC' ? 'D' : 'R';
fEntries.push({
comments: pendingComments,
line: trimmed,
type: tokens[1] ?? '',
head: head as 'F' | 'R',
direction,
});
pendingComments = [];
} else {
unknownEntries.push({ comments: pendingComments, line: trimmed, type: '' });
pendingComments = [];
}
}

Expand All @@ -123,6 +137,9 @@ export function formatExportContent(text: string, filename?: string): string {
if (rEntries.length > 0) {
sections.push(`${SECTION_HEADERS.outputs}\n${renderSection(rEntries)}`);
}
if (unknownEntries.length > 0) {
sections.push(`${SECTION_HEADERS.unknown}\n${renderSection(unknownEntries)}`);
}
if (pendingComments.length > 0) {
sections.push(pendingComments.join('\n'));
}
Expand Down
9 changes: 7 additions & 2 deletions syntaxes/export.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"patterns": [
{ "include": "#comment" },
{ "include": "#parameter-line" },
{ "include": "#file-line" }
{ "include": "#file-line" },
{ "include": "#unknown-line" }
],
"repository": {
"comment": {
Expand All @@ -30,7 +31,7 @@
]
},
"file-line": {
"begin": "^\\s*(F)\\s+(\\S+)\\s+(\\S+)\\s+(?:(D)|(RC?))\\s+(\\S+)",
"begin": "^\\s*([FR])\\s+(\\S+)\\s+(\\S+)\\s+(?:(DC?)|(RC?))\\s+(\\S+)",
"end": "$",
"beginCaptures": {
"1": { "name": "keyword.control.file.export" },
Expand All @@ -44,6 +45,10 @@
{ "include": "#comment" },
{ "include": "#extra-token" }
]
},
"unknown-line": {
"match": "^\\s*[^#\\s].*$",
"name": "invalid.illegal.unknown-line.export"
}
}
}
Loading
Loading