@@ -37,12 +37,13 @@ function getPackageLocation(packageName: string, theFullListInJson: string): str
3737
3838/*
3939Parse the registered package (the type 1 of import macro: *import PACKAGE_NAME: LIB_NAME_LIST)
40- Input: the second part of current line splitted by "*import". For example, current line is "*import std:magic, cholesky",
40+ Input: secondPart: the second part of current line splitted by "*import". For example, current line is "*import std:magic, cholesky",
4141 then the input will be "std:magic, cholesky"; if current line is "let myMagic = *import std:magic", then the input should
4242 be "std:magic, cholesky"
43+ strCurrentCallStack: current call stack
4344Output: A list of string, each string represents the corresponding hhs source file
4445*/
45- async function parseRegisterdPackage ( secondPart : string ) : Promise < Array < string > > {
46+ async function parseRegisterdPackage ( secondPart : string , strCurrentCallStack : string ) : Promise < Array < string > > {
4647 let returnListOfFunctions : string [ ] = [ ] ;
4748 let theFullListInJson = await fetch ( "https://raw.githubusercontent.com/Hedgehog-Computing/Hedgehog-Package-Manager/main/hedgehog-packages.json" , { method : 'get' } ) . then ( body => body . text ( ) ) ;
4849 let splittedResult = secondPart . split ( ':' ) ;
@@ -72,11 +73,15 @@ async function parseRegisterdPackage(secondPart: string): Promise<Array<string>>
7273 if ( setHHSCompleteList . has ( eachItemWithoutSpace ) ) {
7374 let currentHHSLocation = packageLocation + eachItemWithoutSpace + ".hhs" ;
7475 let currentItemSourceCode = await fetch ( currentHHSLocation , { method : 'get' } ) . then ( body => body . text ( ) ) ;
75- returnListOfFunctions . push ( currentItemSourceCode ) ;
76+
77+ // After get the whole hhs source file, preprocess the string via DFS preprocessor
78+ // to handle the dependencies of current source file string
79+ let preprocessedCurrentItemSourceCode = await preprocessDFS ( currentItemSourceCode , strCurrentCallStack + " -> " + strCurrentCallStack + ":" + eachItemWithoutSpace ) ;
80+ returnListOfFunctions . push ( preprocessedCurrentItemSourceCode ) ;
7681 }
7782 }
7883 }
79- else { throw "Cannot find \"includes\" key in the hedgehog-package.json configuration file! Please add a key with name \"includes\" with a complete list of exported libraries. Exception at " + secondPart }
84+ else { throw "Cannot find \"includes\" key in the hedgehog-package.json configuration file! Please add a key with name \"includes\" with a complete list of exported libraries. Exception at " + secondPart + ".\nCall Stack at: " + strCurrentCallStack }
8085 return returnListOfFunctions ;
8186}
8287
@@ -136,7 +141,7 @@ async function preprocessDFS(code: string, strCurrentCallStack: string): Promise
136141
137142 else {
138143 // otherwise, try to split with colon and comma and fetch the registered packages
139- let result = await parseRegisterdPackage ( splittedResult [ 1 ] ) ;
144+ let result = await parseRegisterdPackage ( splittedResult [ 1 ] , strCurrentCallStack ) ;
140145 let combined_result = "" ;
141146 result . forEach ( element => {
142147 combined_result += element + "\n"
0 commit comments