@@ -29,13 +29,15 @@ class InstructionLine {
2929
3030export class Parser {
3131 private _currentToken : Token | null = null ;
32+ private _moduleName = '' ;
3233
3334 /**
3435 * Parses tokens and return Ast - Abstract Syntax Tree for jsPython code
3536 * @param tokens tokens
3637 * @param options parsing options. By default it will exclude comments and include LOC (Line of code)
3738 */
3839 parse ( tokens : Token [ ] , name = 'main.jspy' , type : string = 'module' ) : AstBlock {
40+ this . _moduleName = name ;
3941 const ast = { name, type, funcs : [ ] , body : [ ] } as AstBlock ;
4042
4143 if ( ! tokens || ! tokens . length ) { return ast ; }
@@ -50,7 +52,7 @@ export class Parser {
5052
5153 } catch ( err ) {
5254 const token = this . _currentToken ?? { } as Token
53- throw new JspyParserError ( ast . name , getStartLine ( token ) , getStartColumn ( token ) , err . message )
55+ throw new JspyParserError ( ast . name , getStartLine ( token ) , getStartColumn ( token ) , err . message || err )
5456 }
5557 return ast ;
5658 }
@@ -59,7 +61,7 @@ export class Parser {
5961
6062 const getBody = ( tokens : Token [ ] , startTokenIndex : number ) : AstNode [ ] => {
6163 const instructionLines = this . tokensToInstructionLines ( tokens , getStartLine ( tokens [ startTokenIndex ] ) ) ;
62- const bodyAst = { body : [ ] as AstNode [ ] , funcs : [ ] as AstNode [ ] } as AstBlock ;
64+ const bodyAst = { name : ast . name , body : [ ] as AstNode [ ] , funcs : [ ] as AstNode [ ] } as AstBlock ;
6365 this . instructionsToNodes ( instructionLines , bodyAst ) ;
6466 return bodyAst . body ;
6567 }
@@ -225,7 +227,7 @@ export class Parser {
225227 const sColumn = getStartColumn ( token ) ;
226228 const value = getTokenValue ( token ) ;
227229 this . _currentToken = token ;
228-
230+
229231 if ( sLine >= startLine ) {
230232
231233 if ( currentLine !== sLine ) {
@@ -293,6 +295,7 @@ export class Parser {
293295
294296 const instructionLines = this . tokensToInstructionLines ( arrowFuncParts [ 1 ] , 0 ) ;
295297 const funcAst = {
298+ name : this . _moduleName ,
296299 body : [ ] as AstNode [ ] ,
297300 funcs : [ ] as AstNode [ ]
298301 } as AstBlock ;
0 commit comments