Closed AntoineGautier closed 1 month ago
@anandkp92 Could you confirm that this is not currently implemented in a feature branch? And tell me if I'm not missing something here. I don't understand why there is often read access to the JSON files on disk instead of relying on in-memory objects. Even for simple use cases such as https://github.com/lbl-srg/modelica-json/blob/master/lib/parser.js#L114-L121
// write the simplified json output to file
const out = (prettyPrint === 'false') ? JSON.stringify(da) : JSON.stringify(da, null, 2)
ut.writeFile(tempJsonPath, out)
let allObjectsJson2
if (outputFormat === 'semantic' || outputFormat === 'cxf') {
const jsonOp = JSON.parse(fs.readFileSync(tempJsonPath, 'utf8'))
allObjectsJson2 = generateAllObjectsJson(jsonOp, moFile, tempDir, prettyPrint)
Why don't we directly use allObjectsJson2 = generateAllObjectsJson(da, ...)
in the code snippet above (since JSON.parse(JSON.stringify(da))
and da
are equal)?
Returning the json object is something that we have discussed and its in the plan of implementation. However, we write files to disk because outputs like semantic, require reading multiple json files at the same time and putting them together.
This FE will be implemented in the branch issue233_returnObject
.
Closed with #234
This ticket is to refactor the following functions from
lib/parser.js
so they return an actual JS object with the parsed data.⚠︎ This object is an array containing the data for all Modelica classes used by the Modelica file passed as argument — even if a class is not actually parsed during the current invocation.
JSON.parse(fs.readFileSync(...))
.getJsons
The function currently declares
const jsonData = []
and returnsjsonData
without never populating the array.This ticket will populate
jsonData
sogetJsons
does not return an empty array.getSimpleJson
The function returns either
null
or the absolute path of the Modelica file that is parsed — not including the absolute path of the classes instantiated in this file, which are only pushed toparsedFile
(to avoid parsing them again).This ticket will make
getSimpleJson
return an array containing the data for all Modelica classes used by the Modelica file:The current
parsedFile
array can then simply be created by fetching allfullMoFilePath
properties fromgetSimpleJson()
output.