@ -3,9 +3,20 @@
"use strict" ;
"use strict" ;
const ast = require ( "../ast" ) ;
const ast = require ( "../ast" ) ;
const GrammarError = require ( "../grammar-error" ) ;
const opcodes = require ( "./opcodes" ) ;
const opcodes = require ( "./opcodes" ) ;
const parser = require ( "../parser" ) ;
const parser = require ( "../parser" ) ;
function fatal ( message , location ) {
if ( typeof location !== "undefined" )
throw new GrammarError ( message , location ) ;
throw new Error ( message ) ;
}
class Session {
class Session {
constructor ( options ) {
constructor ( options ) {
@ -19,6 +30,9 @@ class Session {
this . visitor = options . visitor || ast . visitor ;
this . visitor = options . visitor || ast . visitor ;
if ( typeof options . warn === "function" ) this . warn = options . warn ;
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 ) ;
}
}
}