@@ -271,6 +271,22 @@ export interface DiagnosticNote {
271
271
location : LocationRange ;
272
272
}
273
273
274
+ /** Possible compilation stage name. */
275
+ type Stage = keyof Stages ;
276
+ /** Severity level of problems that can be registered in compilation session. */
277
+ type Severity = "error" | "warn" | "info" ;
278
+
279
+ type Problem = [
280
+ /** Problem severity. */
281
+ Severity ,
282
+ /** Diagnostic message. */
283
+ string ,
284
+ /** Location where message is generated, if applicable. */
285
+ LocationRange ?,
286
+ /** List of additional messages with their locations, if applicable. */
287
+ DiagnosticNote [ ] ?,
288
+ ] ;
289
+
274
290
/** Thrown if the grammar contains a semantic error. */
275
291
export class GrammarError extends Error {
276
292
/** Location of the error in the source. */
@@ -279,6 +295,15 @@ export class GrammarError extends Error {
279
295
/** Additional messages with context information. */
280
296
diagnostics : DiagnosticNote [ ] ;
281
297
298
+ /** Compilation stage during which error was generated. */
299
+ stage : Stage | null ;
300
+
301
+ /**
302
+ * List of diagnostics containing all errors, warnings and information
303
+ * messages generated during compilation stage `stage`.
304
+ */
305
+ problems : Problem [ ] ;
306
+
282
307
constructor (
283
308
message : string ,
284
309
location ?: LocationRange ,
@@ -951,6 +976,51 @@ export interface Session {
951
976
) : void ;
952
977
}
953
978
979
+ export interface DiagnosticCallback {
980
+ /**
981
+ * Called when compiler reports an error.
982
+ *
983
+ * @param stage Stage in which this diagnostic was originated
984
+ * @param message Main message, which should describe error objectives
985
+ * @param location If defined, this is location described in the `message`
986
+ * @param notes Additional messages with context information
987
+ */
988
+ error ?(
989
+ stage : Stage ,
990
+ message : string ,
991
+ location ?: LocationRange ,
992
+ notes ?: DiagnosticNote [ ]
993
+ ) : void ;
994
+ /**
995
+ * Called when compiler reports a warning.
996
+ *
997
+ * @param stage Stage in which this diagnostic was originated
998
+ * @param message Main message, which should describe warning objectives
999
+ * @param location If defined, this is location described in the `message`
1000
+ * @param notes Additional messages with context information
1001
+ */
1002
+ warn ?(
1003
+ stage : Stage ,
1004
+ message : string ,
1005
+ location ?: LocationRange ,
1006
+ notes ?: DiagnosticNote [ ]
1007
+ ) : void ;
1008
+ /**
1009
+ * Called when compiler reports an informational message.
1010
+ *
1011
+ * @param stage Stage in which this diagnostic was originated
1012
+ * @param message Main message, which gives information about an event
1013
+ * @param location If defined, this is location described in the `message`
1014
+ * @param notes Additional messages with context information
1015
+ */
1016
+ info ?(
1017
+ stage : Stage ,
1018
+ message : string ,
1019
+ location ?: LocationRange ,
1020
+ notes ?: DiagnosticNote [ ]
1021
+ ) : void ;
1022
+ }
1023
+
954
1024
/**
955
1025
* Parser dependencies, is an object which maps variables used to access the
956
1026
* dependencies in the parser to module IDs used to load them
@@ -988,6 +1058,13 @@ export interface BuildOptionsBase {
988
1058
989
1059
/** Makes the parser trace its progress (default: `false`) */
990
1060
trace ?: boolean ;
1061
+
1062
+ /** Called when a semantic error during build was detected. */
1063
+ error ?: DiagnosticCallback ;
1064
+ /** Called when a warning during build was registered. */
1065
+ warn ?: DiagnosticCallback ;
1066
+ /** Called when an informational message during build was registered. */
1067
+ info ?: DiagnosticCallback ;
991
1068
}
992
1069
993
1070
export interface ParserBuildOptions extends BuildOptionsBase {
0 commit comments