@@ -230,13 +230,37 @@ export interface DiagnosticNote {
230
230
location : LocationRange ;
231
231
}
232
232
233
+ /** Possible compilation stage name. */
234
+ type Stage = keyof Stages ;
235
+ /** Severity level of problems that can be registered in compilation session. */
236
+ type Severity = "error" | "warn" | "info" ;
237
+
238
+ type Problem = [
239
+ /** Problem severity. */
240
+ Severity ,
241
+ /** Diagnostic message. */
242
+ string ,
243
+ /** Location where message is generated, if applicable. */
244
+ LocationRange ?,
245
+ /** List of additional messages with their locations, if applicable. */
246
+ DiagnosticNote [ ] ?,
247
+ ] ;
248
+
233
249
/** Thrown if the grammar contains a semantic error. */
234
250
export class GrammarError extends Error {
235
251
/** Location of the error in the source. */
236
252
location ?: LocationRange ;
237
253
/** Additional messages with context information. */
238
254
diagnostics : DiagnosticNote [ ] ;
239
255
256
+ /** Compilation stage during which error was generated. */
257
+ stage : Stage | null ;
258
+ /**
259
+ * List of diagnostics containing all errors, warnings and information
260
+ * messages generated during compilation stage `stage`.
261
+ */
262
+ problems : Problem [ ] ;
263
+
240
264
constructor ( message : string , location ?: LocationRange , diagnostics ?: DiagnosticNote [ ] ) ;
241
265
242
266
/**
@@ -849,6 +873,36 @@ export interface Session {
849
873
info ( message : string , location ?: LocationRange , notes ?: DiagnosticNote [ ] ) : void ;
850
874
}
851
875
876
+ export interface DiagnosticCallback {
877
+ /**
878
+ * Called when compiler reports an error.
879
+ *
880
+ * @param stage Stage in which this diagnostic was originated
881
+ * @param message Main message, which should describe error objectives
882
+ * @param location If defined, this is location described in the `message`
883
+ * @param notes Additional messages with context information
884
+ */
885
+ error ?( stage : Stage , message : string , location ?: LocationRange , notes ?: DiagnosticNote [ ] ) : void ;
886
+ /**
887
+ * Called when compiler reports a warning.
888
+ *
889
+ * @param stage Stage in which this diagnostic was originated
890
+ * @param message Main message, which should describe warning objectives
891
+ * @param location If defined, this is location described in the `message`
892
+ * @param notes Additional messages with context information
893
+ */
894
+ warn ?( stage : Stage , message : string , location ?: LocationRange , notes ?: DiagnosticNote [ ] ) : void ;
895
+ /**
896
+ * Called when compiler reports an informational message.
897
+ *
898
+ * @param stage Stage in which this diagnostic was originated
899
+ * @param message Main message, which gives information about an event
900
+ * @param location If defined, this is location described in the `message`
901
+ * @param notes Additional messages with context information
902
+ */
903
+ info ?( stage : Stage , message : string , location ?: LocationRange , notes ?: DiagnosticNote [ ] ) : void ;
904
+ }
905
+
852
906
export interface BuildOptionsBase {
853
907
/** rules the parser will be allowed to start parsing from (default: the first rule in the grammar) */
854
908
allowedStartRules ?: string [ ] ;
@@ -873,6 +927,13 @@ export interface BuildOptionsBase {
873
927
plugins ?: Plugin [ ] ;
874
928
/** makes the parser trace its progress (default: `false`) */
875
929
trace ?: boolean ;
930
+
931
+ /** Called when a semantic error during build was detected. */
932
+ error ?: DiagnosticCallback ;
933
+ /** Called when a warning during build was registered. */
934
+ warn ?: DiagnosticCallback ;
935
+ /** Called when an informational message during build was registered. */
936
+ info ?: DiagnosticCallback ;
876
937
}
877
938
878
939
export interface ParserBuildOptions extends BuildOptionsBase {
0 commit comments