@@ -266,6 +266,22 @@ export interface DiagnosticNote {
266
266
location : LocationRange ;
267
267
}
268
268
269
+ /** Possible compilation stage name. */
270
+ type Stage = keyof Stages ;
271
+ /** Severity level of problems that can be registered in compilation session. */
272
+ type Severity = "error" | "warn" | "info" ;
273
+
274
+ type Problem = [
275
+ /** Problem severity. */
276
+ Severity ,
277
+ /** Diagnostic message. */
278
+ string ,
279
+ /** Location where message is generated, if applicable. */
280
+ LocationRange ?,
281
+ /** List of additional messages with their locations, if applicable. */
282
+ DiagnosticNote [ ] ?,
283
+ ] ;
284
+
269
285
/** Thrown if the grammar contains a semantic error. */
270
286
export class GrammarError extends Error {
271
287
/** Location of the error in the source. */
@@ -274,6 +290,15 @@ export class GrammarError extends Error {
274
290
/** Additional messages with context information. */
275
291
diagnostics : DiagnosticNote [ ] ;
276
292
293
+ /** Compilation stage during which error was generated. */
294
+ stage : Stage | null ;
295
+
296
+ /**
297
+ * List of diagnostics containing all errors, warnings and information
298
+ * messages generated during compilation stage `stage`.
299
+ */
300
+ problems : Problem [ ] ;
301
+
277
302
constructor (
278
303
message : string ,
279
304
location ?: LocationRange ,
@@ -919,6 +944,51 @@ export interface Session {
919
944
) : void ;
920
945
}
921
946
947
+ export interface DiagnosticCallback {
948
+ /**
949
+ * Called when compiler reports an error.
950
+ *
951
+ * @param stage Stage in which this diagnostic was originated
952
+ * @param message Main message, which should describe error objectives
953
+ * @param location If defined, this is location described in the `message`
954
+ * @param notes Additional messages with context information
955
+ */
956
+ error ?(
957
+ stage : Stage ,
958
+ message : string ,
959
+ location ?: LocationRange ,
960
+ notes ?: DiagnosticNote [ ]
961
+ ) : void ;
962
+ /**
963
+ * Called when compiler reports a warning.
964
+ *
965
+ * @param stage Stage in which this diagnostic was originated
966
+ * @param message Main message, which should describe warning objectives
967
+ * @param location If defined, this is location described in the `message`
968
+ * @param notes Additional messages with context information
969
+ */
970
+ warn ?(
971
+ stage : Stage ,
972
+ message : string ,
973
+ location ?: LocationRange ,
974
+ notes ?: DiagnosticNote [ ]
975
+ ) : void ;
976
+ /**
977
+ * Called when compiler reports an informational message.
978
+ *
979
+ * @param stage Stage in which this diagnostic was originated
980
+ * @param message Main message, which gives information about an event
981
+ * @param location If defined, this is location described in the `message`
982
+ * @param notes Additional messages with context information
983
+ */
984
+ info ?(
985
+ stage : Stage ,
986
+ message : string ,
987
+ location ?: LocationRange ,
988
+ notes ?: DiagnosticNote [ ]
989
+ ) : void ;
990
+ }
991
+
922
992
/**
923
993
* Parser dependencies, is an object which maps variables used to access the
924
994
* dependencies in the parser to module IDs used to load them
@@ -956,6 +1026,13 @@ export interface BuildOptionsBase {
956
1026
957
1027
/** Makes the parser trace its progress (default: `false`) */
958
1028
trace ?: boolean ;
1029
+
1030
+ /** Called when a semantic error during build was detected. */
1031
+ error ?: DiagnosticCallback ;
1032
+ /** Called when a warning during build was registered. */
1033
+ warn ?: DiagnosticCallback ;
1034
+ /** Called when an informational message during build was registered. */
1035
+ info ?: DiagnosticCallback ;
959
1036
}
960
1037
961
1038
export interface ParserBuildOptions extends BuildOptionsBase {
0 commit comments