@ibm/ibmi-eventf-parser 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ import { ErrorInformationRecord } from "./record/ErrorInformationRecord";
2
+ /**
3
+ * A call back object implementing this interface is called by the Parser whenever
4
+ * an ErrorInformationRecord is encountered.
5
+ * This should provide all the required information to open an editor on the original file
6
+ * and position or highlight the error.
7
+ */
8
+ export interface IMarkerCreator {
9
+ createMarker(record: ErrorInformationRecord, fileLocation: string, isReadOnly: string): void;
10
+ }
@@ -0,0 +1,108 @@
1
+ import { ErrorInformationRecord } from "./record/ErrorInformationRecord";
2
+ import { ExpansionRecord } from "./record/ExpansionRecord";
3
+ import { FeedbackCodeRecord } from "./record/FeedbackCodeRecord";
4
+ import { FileEndRecord } from "./record/FileEndRecord";
5
+ import { FileIDRecord } from "./record/FileIDRecord";
6
+ import { MapDefineRecord } from "./record/MapDefineRecord";
7
+ import { MapEndRecord } from "./record/MapEndRecord";
8
+ import { MapStartRecord } from "./record/MapStartRecord";
9
+ import { ProcessorRecord } from "./record/ProcessorRecord";
10
+ import { ProgramRecord } from "./record/ProgramRecord";
11
+ import { TimestampRecord } from "./record/TimestampRecord";
12
+ /**
13
+ * This interface defines a backbone for processing Events File Records.
14
+ *
15
+ * As the Events File Format gets more complex and more used, the parsing logic
16
+ * should be seperated from the processing logic. A different processor could
17
+ * potentially be associated with Events Files generated for different purposes.
18
+ *
19
+ * For instance, an SQL compile might need a different processor to make use of the
20
+ * Expansion record.
21
+ */
22
+ export interface IProcessor {
23
+ /**
24
+ * Processes a File ID record object.
25
+ * @param record The File ID record.
26
+ */
27
+ processFileIDRecord(record: FileIDRecord): void;
28
+ /**
29
+ * Processes a File End record object.
30
+ * @param record The File End record.
31
+ */
32
+ processFileEndRecord(record: FileEndRecord): void;
33
+ /**
34
+ * Processes a Processor record object.
35
+ * @param record The Processor record.
36
+ */
37
+ processProcessorRecord(record: ProcessorRecord): void;
38
+ /**
39
+ * Processes a Timestamp record object.
40
+ * @param record The Timestamp record.
41
+ */
42
+ processTimestampRecord(record: TimestampRecord): void;
43
+ /**
44
+ * Processes an Error record object.
45
+ * @param record The Error record.
46
+ */
47
+ processErrorRecord(record: ErrorInformationRecord): void;
48
+ /**
49
+ * Processes a Program record object.
50
+ * @param record The Program record.
51
+ */
52
+ processProgramRecord(record: ProgramRecord): void;
53
+ /**
54
+ * Processes a Feedback Code record object.
55
+ * @param record The Feedback Code record.
56
+ */
57
+ processFeedbackCodeRecord(record: FeedbackCodeRecord): void;
58
+ /**
59
+ * Processes a Map Define record object.
60
+ * @param record The Map Define record.
61
+ */
62
+ processMapDefineRecord(record: MapDefineRecord): void;
63
+ /**
64
+ * Processes a Map Start record object.
65
+ * @param record The Map Start record.
66
+ */
67
+ processMapStartRecord(record: MapStartRecord): void;
68
+ /**
69
+ * Processes a Map End record object.
70
+ * @param record The Map End record.
71
+ */
72
+ processMapEndRecord(record: MapEndRecord): void;
73
+ /**
74
+ * Processes an Expansion record object.
75
+ * @param record The Expansion record.
76
+ */
77
+ processExpansionRecord(record: ExpansionRecord): void;
78
+ /**
79
+ * After parsing all records in the Events File, this method will be called to
80
+ * process the records.
81
+ *
82
+ * @return True if post-processing was succesful or false otherwise.
83
+ */
84
+ doPostProcessing(): boolean;
85
+ /**
86
+ * Before parsing all records in the Events File, this method will be called to
87
+ * allow the processor to perform initialization.
88
+ *
89
+ * @return True if pre-processing was succesful or false otherwise.
90
+ */
91
+ doPreProcessing(): boolean;
92
+ /**
93
+ * After all records in the Events File are processed, this method is called to
94
+ * return all the errors from all the processor blocks (ProcessorBlock) of the
95
+ * Events File. Since each ProcessorBlock contains an array of errors, the result
96
+ * will be returned as a array of those arrays.
97
+ *
98
+ * @return An array of arrays of all parsed errors from all processor blocks of
99
+ * the Events File (one list for each processor block).
100
+ */
101
+ getAllErrors(): ErrorInformationRecord[][];
102
+ /**
103
+ * Return all file ID records.
104
+ *
105
+ * @return An array of all file ID records.
106
+ */
107
+ getAllFileIDRecords(): FileIDRecord[];
108
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Iterates through a sequential file and provides one line at a time.
3
+ */
4
+ export interface ISequentialFileReader {
5
+ /**
6
+ * Get the next line.
7
+ *
8
+ * @return The next line.
9
+ **/
10
+ readNextLine(): string | undefined;
11
+ }
@@ -0,0 +1,78 @@
1
+ import { ErrorInformationRecord } from "./record/ErrorInformationRecord";
2
+ import { ExpansionRecord } from "./record/ExpansionRecord";
3
+ import { FileEndRecord } from "./record/FileEndRecord";
4
+ import { FileIDRecord } from "./record/FileIDRecord";
5
+ export declare class MapTable {
6
+ private map;
7
+ private queueExpansion;
8
+ private files;
9
+ private lookupIndex;
10
+ private fileTable;
11
+ constructor();
12
+ /**
13
+ * Adds file information to the map.
14
+ *
15
+ * @param Tecord The File ID record.
16
+ */
17
+ addFileInformation(record: FileIDRecord): void;
18
+ /**
19
+ * Adds file information only to the file table. This is useful for processing the
20
+ * compiler (000) processor block, since we don't need to keep track of line mappings
21
+ * and FileIDLinesPair pairings.
22
+ *
23
+ * @param record The File ID record
24
+ */
25
+ addFileToFileTable(record: FileIDRecord): void;
26
+ /**
27
+ * Sets the correct bounds for the files in the map that were added using `AddFileInformation()`.
28
+ *
29
+ * @param record The File End record that contains the number of lines in the source.
30
+ */
31
+ closeFile(record: FileEndRecord): void;
32
+ /**
33
+ * Create a `SourceLineRange` with open bounds. The bounds will be set once the FileEnd record is read.
34
+ *
35
+ * @param record The FileID record that contains information about where the `SourceLineRange` should start.
36
+ */
37
+ private createOpenEndedSourceLineRange;
38
+ addExpansionRecord(record: ExpansionRecord): void;
39
+ private getSourceLineRangeForOutputLine;
40
+ private optimizedSourceLineRangeLookup;
41
+ private getSourceLineRangeForInputLine;
42
+ private shiftRangesBy;
43
+ private handleExpansion;
44
+ private splitExpandedSourceLineRange;
45
+ private createSourceLineRange;
46
+ /**
47
+ * Returns the QSYSEventsFileFileIDRecord corresponding to a file ID.
48
+ *
49
+ * @param ID The ID of the file to look for.
50
+ * @return The FileIDRecord corresponding to the file ID if it exists in the table, `undefined` otherwise.
51
+ */
52
+ getFileIDRecordForFileID(ID: string): FileIDRecord | undefined;
53
+ getFileLocationForFileID(ID: string): string | undefined;
54
+ /**
55
+ * Modifies the information contained in the Error record based on the available map.
56
+ *
57
+ * @param record The Error record to be modified.
58
+ */
59
+ modifyErrorInformation(record: ErrorInformationRecord): void;
60
+ /**
61
+ * Calculates the line number based on the initial number and how many lines where
62
+ * shifted in the expansion process.
63
+ *
64
+ * @param range `SourceLineRange` that contains mapping information.
65
+ * @param initial The line number.
66
+ * @return The new line number.
67
+ */
68
+ private getLineFromSourceLineRange;
69
+ finalizeMap(): void;
70
+ /**
71
+ * Prints the map.
72
+ */
73
+ toString(): string;
74
+ /**
75
+ * Get all file locations.
76
+ */
77
+ getAllFileIDRecords(): FileIDRecord[];
78
+ }
@@ -0,0 +1,51 @@
1
+ import { FileIDRecord } from './record/FileIDRecord';
2
+ import { IProcessor } from './IProcessor';
3
+ import { ISequentialFileReader } from './ISequentialFileReader';
4
+ import { IMarkerCreator } from './IMarkerCreator';
5
+ import { ErrorInformationRecord } from './record/ErrorInformationRecord';
6
+ export declare class Parser {
7
+ static LOGGER: any;
8
+ private exception;
9
+ private processor;
10
+ private lastOutputFile;
11
+ private currentOutputFile;
12
+ private sourceTable;
13
+ constructor();
14
+ private getUntilTheEndOfTheLine;
15
+ private log;
16
+ /**
17
+ * To parse an eventf generated by an IBM i compiler.
18
+ * @param fileName local file containing the eventf encoded in UTF-8
19
+ * @param markerCreator optionally passing in an object implementing IMarkerCreator
20
+ * allows the parser to call this object back with each error. The original source
21
+ * file name and error location and error message will be in the information provided
22
+ * on the callback
23
+ */
24
+ parseFile(fileName: string, markerCreator?: IMarkerCreator): void;
25
+ parse(fileReader: ISequentialFileReader, markerCreator?: IMarkerCreator): void;
26
+ private resolveRelativePath;
27
+ getException(): Error | undefined;
28
+ setProcessor(processor: IProcessor): void;
29
+ /**
30
+ * After all records in the Events File are processed, this method is called to
31
+ * return all the errors from all the processor blocks (ProcessorBlock) of the
32
+ * Events File. Since each ProcessorBlock contains an array of errors, the result
33
+ * will be flattened to an array.
34
+ *
35
+ * @return An array of all parsed errors from all processor blocks of the Events File.
36
+ */
37
+ getAllErrors(): ErrorInformationRecord[];
38
+ /**
39
+ * Get all file ID records.
40
+ *
41
+ * @return An array of all file ID records.
42
+ */
43
+ getAllFileIDRecords(): FileIDRecord[];
44
+ }
45
+ export default class FileReader implements ISequentialFileReader {
46
+ file: string;
47
+ linesArray: string[];
48
+ currLineNum: number;
49
+ constructor(fileName: string);
50
+ readNextLine(): string | undefined;
51
+ }
@@ -0,0 +1,93 @@
1
+ import { ErrorInformationRecord } from "./record/ErrorInformationRecord";
2
+ import { FileEndRecord } from "./record/FileEndRecord";
3
+ import { FileIDRecord } from "./record/FileIDRecord";
4
+ import { MapTable } from "./MapTable";
5
+ import { ProcessorRecord } from "./record/ProcessorRecord";
6
+ export declare class ProcessorBlock {
7
+ readonly INPUT_FILE_ID: string;
8
+ private errors;
9
+ private inputFile;
10
+ private outputFile;
11
+ private currentProcessor;
12
+ private mappingTable;
13
+ private previousProcessorBlock;
14
+ private containsExpansionEvents;
15
+ private isFirstInEventsFile;
16
+ private mappingSupported;
17
+ private totalNumberOfLinesInOutputFile;
18
+ private totalNumberOfLinesInInputFiles;
19
+ constructor(record: ProcessorRecord);
20
+ getInputFile(): FileIDRecord | undefined;
21
+ /**
22
+ * Get the input file of the first processor block of the current events file.
23
+ *
24
+ * @return the input file of the first processor block of the current events file.
25
+ */
26
+ getInitialInputFile(): FileIDRecord | undefined;
27
+ setInputFile(file: FileIDRecord): void;
28
+ addFile(file: FileIDRecord): void;
29
+ closeFile(file: FileEndRecord): void;
30
+ getOutputFile(): FileIDRecord | undefined;
31
+ setOutputFile(file: FileIDRecord): void;
32
+ getMappingTable(): MapTable;
33
+ isProcessorIDZero(): boolean;
34
+ addErrorInformation(record: ErrorInformationRecord): void;
35
+ processorEnded(): void;
36
+ setPreviousProcessor(previous: ProcessorBlock): void;
37
+ setContainsExpansionEvents(containsExpansionEvents: boolean): void;
38
+ getContainsExpansionEvents(): boolean;
39
+ increaseTotalNumberOfLinesInInputFiles(numberOfLines: number): void;
40
+ getTotalNumberOfLinesInInputFiles(): number;
41
+ setTotalNumberOfLinesInOutputFile(numberOfLines: number): void;
42
+ getTotalNumberOfLinesInOutputFile(): number;
43
+ getPreviousProcessorBlock(): ProcessorBlock | undefined;
44
+ modifyErrorInformation(error: ErrorInformationRecord): void;
45
+ /**
46
+ * Sets whether the current processor block is the first one in the current "sub" events file
47
+ * (needed for events file that contains multiple events files that have been combined into one).
48
+ *
49
+ * @param isFirstInEventsFile
50
+ */
51
+ setFirstInEventsFile(isFirstInEventsFile: boolean): void;
52
+ /**
53
+ * Returns whether the current processor block is the first one in the current "sub" events file
54
+ * (needed for events file that contains multiple events files that have been combined into one).
55
+ *
56
+ * @return True if the current processor block is the first one in the current "sub" events file, false otherwise.
57
+ */
58
+ getIsFirstInEventsFile(): boolean;
59
+ setMappingSupported(mappingSupported: boolean): void;
60
+ isMappingSupported(): boolean;
61
+ /**
62
+ * Determines whether a file in the current processor block is read-only or not.
63
+ * A file is considered read-only if it is a temporary file created by an SQL pre-compiler.
64
+ *
65
+ * @param fileRecord The FileIDRecord of the file to check.
66
+ * @return True if the file is read-only, false otherwise.
67
+ */
68
+ isFileReadOnly(fileIDRecord: FileIDRecord): boolean;
69
+ /**
70
+ * This method is used by the test for event file processing.
71
+ *
72
+ * This method returns all errors in this and all previous processor blocks.
73
+ * Since each ProcessorBlock contains an array of errors, the result will be
74
+ * returned as an array of those arrays.
75
+ *
76
+ * This method is called by ExpansionProcessor.getAllErrors().
77
+ *
78
+ * @return An array of arrays of all parsed errors from the current and all
79
+ * previous processor blocks (one list for each processor block).
80
+ */
81
+ getAllProcessorErrors(): ErrorInformationRecord[][];
82
+ resolveFileNamesForAllErrors(): void;
83
+ /**
84
+ * Maps the error back to the original input member and resolves the
85
+ * filename of that member. If mappings are not supported, checks and
86
+ * returns whether that member is read-only.
87
+ *
88
+ * @param error The ErrorInformationRecord to resolve.
89
+ * @return True if mappings are not supported and the member that the
90
+ * error points to is read-only, false otherwise.
91
+ */
92
+ resolveFileNameAndDetermineIfReadOnly(error: ErrorInformationRecord): boolean;
93
+ }
@@ -0,0 +1,3 @@
1
+ export { Parser } from "./Parser";
2
+ export { ErrorInformationRecord } from "./record/ErrorInformationRecord";
3
+ export { IMarkerCreator } from "./IMarkerCreator";
@@ -0,0 +1,161 @@
1
+ import { IRecordT } from "./IRecordT";
2
+ import { IRecord } from "./IRecord";
3
+ /**
4
+ * This class represents a Error Information record in an events file.
5
+ */
6
+ export declare class ErrorInformationRecord implements IRecord {
7
+ private version;
8
+ private fileId;
9
+ private annotClass;
10
+ private stmtLine;
11
+ private startErrLine;
12
+ private tokenStart;
13
+ private endErrLine;
14
+ private tokenEnd;
15
+ private msgId;
16
+ private sevChar;
17
+ private sevNum;
18
+ private length;
19
+ private msg;
20
+ private fileName;
21
+ constructor(version: string, fileId: string, annotClass: string, stmtLine: string, startErrLine: string, tokenStart: string, endErrLine: string, tokenEnd: string, msgId: string, sevChar: string, sevNum: string, length: string, msg: string);
22
+ getRecordType(): IRecordT;
23
+ /**
24
+ * Get the version.
25
+ *
26
+ * @return The version.
27
+ */
28
+ getVersion(): string;
29
+ /**
30
+ * Get the file id.
31
+ *
32
+ * @return The file id.
33
+ */
34
+ getFileId(): string;
35
+ /**
36
+ * Set the file id.
37
+ *
38
+ * @param fileId The file id.
39
+ */
40
+ setFileId(fileId: string): void;
41
+ /**
42
+ * Get the file name.
43
+ *
44
+ * @return The file id.
45
+ */
46
+ getFileName(): string;
47
+ /**
48
+ * Set the file name.
49
+ *
50
+ * @param fileName The file id.
51
+ */
52
+ setFileName(fileName: string): void;
53
+ /**
54
+ * Get the annotation class.
55
+ *
56
+ * @return The annotation class.
57
+ */
58
+ getAnnotClass(): string;
59
+ /**
60
+ * Set the annotation class.
61
+ *
62
+ * @param annotClass The annotation class.
63
+ */
64
+ setAnnotClass(annotClass: string): void;
65
+ /**
66
+ * Get the statement line.
67
+ *
68
+ * @return The statement line.
69
+ */
70
+ getStmtLine(): string;
71
+ /**
72
+ * Set the statement line.
73
+ *
74
+ * @param stmtLine The statement line.
75
+ */
76
+ setStmtLine(stmtLine: string): void;
77
+ /**
78
+ * Get the starting error line.
79
+ *
80
+ * @return The starting error line.
81
+ */
82
+ getStartErrLine(): string;
83
+ /**
84
+ * Set the starting error line.
85
+ *
86
+ * @param startErrLine The starting error line.
87
+ */
88
+ setStartErrLine(startErrLine: string): void;
89
+ /**
90
+ * Get the starting error column.
91
+ *
92
+ * @return The starting error column.
93
+ */
94
+ getTokenStart(): string;
95
+ /**
96
+ * Set the starting error column.
97
+ *
98
+ * @param tokenStart The starting error column.
99
+ */
100
+ setTokenStart(tokenStart: string): void;
101
+ /**
102
+ * Get the ending error line.
103
+ *
104
+ * @return The ending error line.
105
+ */
106
+ getEndErrLine(): string;
107
+ /**
108
+ * Set the ending error line.
109
+ *
110
+ * @param endErrLine The ending error line.
111
+ */
112
+ setEndErrLine(endErrLine: string): void;
113
+ /**
114
+ * Get the ending error column.
115
+ *
116
+ * @return The ending error column.
117
+ */
118
+ getTokenEnd(): string;
119
+ /**
120
+ * Set the ending error column.
121
+ *
122
+ * @param tokenEnd The ending error column.
123
+ */
124
+ setTokenEnd(tokenEnd: string): void;
125
+ /**
126
+ * Get the message id.
127
+ *
128
+ * @return The message id.
129
+ */
130
+ getMsgId(): string;
131
+ /**
132
+ * Get the severity code.
133
+ *
134
+ * @return The severity code.
135
+ */
136
+ getSevChar(): string;
137
+ /**
138
+ * Get the severity level number.
139
+ *
140
+ * @return The severity level number.
141
+ */
142
+ getSevNum(): string;
143
+ /**
144
+ * Get the length of the message.
145
+ *
146
+ * @return The length of the message.
147
+ */
148
+ getLength(): string;
149
+ /**
150
+ * Set the length of the message.
151
+ *
152
+ * @param length The length of the message.
153
+ */
154
+ setLength(length: string): void;
155
+ /**
156
+ * Get the message.
157
+ *
158
+ * @return The message.
159
+ */
160
+ getMsg(): string;
161
+ }
@@ -0,0 +1,100 @@
1
+ import { IRecordT } from "./IRecordT";
2
+ import { IRecord } from "./IRecord";
3
+ /**
4
+ * This class represents an Expansion record in an Events File.
5
+ */
6
+ export declare class ExpansionRecord implements IRecord {
7
+ private version;
8
+ private inputFileID;
9
+ private inputLineStart;
10
+ private inputLineEnd;
11
+ private outputFileID;
12
+ private outputLineStart;
13
+ private outputLineEnd;
14
+ constructor(version: string, inputFileID: string, inputLineStart: string, inputLineEnd: string, outputFileID: string, outputLineStart: string, outputLineEnd: string);
15
+ getRecordType(): IRecordT;
16
+ /**
17
+ * Get the version.
18
+ *
19
+ * @return The version.
20
+ */
21
+ getVersion(): string;
22
+ /**
23
+ * Set the version.
24
+ *
25
+ * @param version The version.
26
+ */
27
+ setVersion(version: string): void;
28
+ /**
29
+ * Get the input file ID.
30
+ *
31
+ * @return The input file ID.
32
+ */
33
+ getInputFileID(): string;
34
+ /**
35
+ * Set the input file ID.
36
+ *
37
+ * @param fileID The input file ID.
38
+ */
39
+ setInputFileID(fileID: string): void;
40
+ /**
41
+ * Get the input line start.
42
+ *
43
+ * @return The input line start.
44
+ */
45
+ getInputLineStart(): string;
46
+ /**
47
+ * Set the input line start.
48
+ *
49
+ * @param lineStart The input line start.
50
+ */
51
+ setInputLineStart(lineStart: string): void;
52
+ /**
53
+ * Get the input line end.
54
+ *
55
+ * @return The input line end.
56
+ */
57
+ getInputLineEnd(): string;
58
+ /**
59
+ * Set the input line end.
60
+ *
61
+ * @param lineEnd The input line end.
62
+ */
63
+ setInputLineEnd(lineEnd: string): void;
64
+ /**
65
+ * Get the output file ID.
66
+ *
67
+ * @return The output file ID.
68
+ */
69
+ getOutputFileID(): string;
70
+ /**
71
+ * Set the output file ID.
72
+ *
73
+ * @param fileID The output file ID.
74
+ */
75
+ setOutputFileID(fileID: string): void;
76
+ /**
77
+ * Get the output line start.
78
+ *
79
+ * @return The output line start.
80
+ */
81
+ getOutputLineStart(): string;
82
+ /**
83
+ * Set the output line start.
84
+ *
85
+ * @param lineStart The output line start.
86
+ */
87
+ setOutputLineStart(lineStart: string): void;
88
+ /**
89
+ * Get the output line end.
90
+ *
91
+ * @return The output line end.
92
+ */
93
+ getOutputLineEnd(): string;
94
+ /**
95
+ * Set the output line end.
96
+ *
97
+ * @param lineEnd The output line end.
98
+ */
99
+ setOutputLineEnd(lineEnd: string): void;
100
+ }
@@ -0,0 +1,35 @@
1
+ import { IRecordT } from "./IRecordT";
2
+ import { IRecord } from "./IRecord";
3
+ /**
4
+ * This class represents a Feedback Code record in an events file.
5
+ */
6
+ export declare class FeedbackCodeRecord implements IRecord {
7
+ private returnCode;
8
+ private reasonCode;
9
+ constructor(returnCode: string, reasonCode: string);
10
+ getRecordType(): IRecordT;
11
+ /**
12
+ * Get the return code.
13
+ *
14
+ * @return The return code.
15
+ */
16
+ getReturnCode(): string;
17
+ /**
18
+ * Set the return code.
19
+ *
20
+ * @param returnCode The return code.
21
+ */
22
+ setReturnCode(returnCode: string): void;
23
+ /**
24
+ * Get the reason code.
25
+ *
26
+ * @return The reason code.
27
+ */
28
+ getReasonCode(): string;
29
+ /**
30
+ * Set the reason code.
31
+ *
32
+ * @param reasonCode The reason code.
33
+ */
34
+ setReasonCode(reasonCode: string): void;
35
+ }