diff --git a/lib/compiler/session.js b/lib/compiler/session.js index 7a1a0da..222b355 100644 --- a/lib/compiler/session.js +++ b/lib/compiler/session.js @@ -3,9 +3,20 @@ "use strict"; const ast = require( "../ast" ); +const GrammarError = require( "../grammar-error" ); const opcodes = require( "./opcodes" ); const parser = require( "../parser" ); +function fatal( message, location ) { + + if ( typeof location !== "undefined" ) + + throw new GrammarError( message, location ); + + throw new Error( message ); + +} + class Session { constructor( options ) { @@ -19,6 +30,9 @@ class Session { this.visitor = options.visitor || ast.visitor; if ( typeof options.warn === "function" ) this.warn = options.warn; + if ( typeof options.error === "function" ) this.error = options.error; + + Object.defineProperty( this, "fatal", { value: fatal } ); } @@ -34,7 +48,13 @@ class Session { } - warn( message, details ) {} + warn( message, location ) {} + + error( message, location ) { + + fatal( message, location ); + + } }