Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue203 logical expression #204

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,44 @@ const path = require('path')
const ArgumentParser = require('argparse').ArgumentParser
/// ///////////////////////////////////////

var parser = new ArgumentParser({
const parser = new ArgumentParser({
version: '0.0.1',
addHelp: true,
description: 'Modelica parser'
})
parser.addArgument(
[ '-o', '--output' ],
['-o', '--output'],
{
help: 'Specify output format.',
choices: ['raw-json', 'json', 'modelica'],
defaultValue: 'json'
}
)
parser.addArgument(
[ '-l', '--log' ],
['-l', '--log'],
{
help: "Logging level, 'info' is the default.",
choices: ['error', 'warn', 'info', 'verbose', 'debug'],
defaultValue: 'info'
}
)
parser.addArgument(
[ '-m', '--mode' ],
['-m', '--mode'],
{
help: "Parsing mode, CDL model or a package of the Modelica Buildings library, 'cdl' is the default.",
choices: ['cdl', 'modelica'],
defaultValue: 'modelica'
}
)
parser.addArgument(
[ '-f', '--file' ],
['-f', '--file'],
{
help: "Filename or packagename that contains the top-level Modelica class, or a json file when the output format is 'modelica'.",
required: true
}
)
parser.addArgument(
[ '-d', '--directory' ],
['-d', '--directory'],
{
help: 'Specify output directory, with the default being the current.',
defaultValue: 'current'
Expand All @@ -54,14 +54,14 @@ parser.addArgument(

parser.addArgument(

[ '-p', '--prettyPrint' ],
['-p', '--prettyPrint'],
{
help: 'Pretty print JSON output.',
defaultValue: 'false'
}
)

var args = parser.parseArgs()
const args = parser.parseArgs()

const logFile = 'modelica-json.log'
try {
Expand Down Expand Up @@ -92,27 +92,27 @@ if (args.output === 'modelica') {
pa.convertToModelica(args.file, args.directory, false)
} else {
// Get mo files array
var moFiles = ut.getMoFiles(args.file)
const moFiles = ut.getMoFiles(args.file)
// Parse the json representation for moFiles
pa.getJsons(moFiles, args.mode, args.output, args.directory, args.prettyPrint)
}

if (args.output === 'json') {
var schema
let schema
if (args.mode === 'cdl') {
schema = path.join(`${__dirname}`, 'schema-cdl.json')
} else {
schema = path.join(`${__dirname}`, 'schema-modelica.json')
}
var jsonFiles = ut.findFilesInDir(path.join(args.directory, 'json'), '.json')
let jsonFiles = ut.findFilesInDir(path.join(args.directory, 'json'), '.json')
// exclude CDL folder and possibly Modelica folder
var pathSep = path.sep
var cdlPath = path.join(pathSep, 'CDL', pathSep)
var modelicaPath = path.join('Modelica', pathSep)
const pathSep = path.sep
const cdlPath = path.join(pathSep, 'CDL', pathSep)
const modelicaPath = path.join('Modelica', pathSep)
jsonFiles = jsonFiles.filter(obj => !(obj.includes(cdlPath) || obj.includes(modelicaPath)))
// validate json schema
for (var i = 0; i < jsonFiles.length; i++) {
var eachFile = jsonFiles[i]
setTimeout(function () { ut.jsonSchemaValidation(args.mode, eachFile, 'json', schema) }, 100)
for (let i = 0; i < jsonFiles.length; i++) {
const eachFile = jsonFiles[i]
setTimeout(function () { ut.jsonSchemaValidation(args.mode, eachFile, schema) }, 100)
}
}
6 changes: 3 additions & 3 deletions json2mo/algorithmSection.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
function parse (content, rawJson = false) {
const statementParser = require('./statement')

var moOutput = ''
let moOutput = ''
if (content.initial != null) {
if (content.initial) {
moOutput += 'initial '
}
}
moOutput += 'algorithm'
var statements = null
let statements = null
if (rawJson) {
statements = content.statements
} else {
Expand All @@ -24,4 +24,4 @@ function parse (content, rawJson = false) {
return moOutput
}

module.exports = {parse}
module.exports = { parse }
8 changes: 4 additions & 4 deletions json2mo/annotation.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
function parse (content, rawJson = false) {
const classModificationParser = require('./classModification')

var moOutput = ''
let moOutput = ''
moOutput += '\n\tannotation '
if (rawJson) {
if (content.class_modification != null) {
moOutput += classModificationParser.parse(content.class_modification, rawJson)
}
} else {
var classModification = content
const classModification = content
moOutput += classModificationParser.parse(classModification, rawJson)
}
// moOutput+="\n"
// moOutput+="\n"
return moOutput
}

module.exports = {parse}
module.exports = { parse }
4 changes: 2 additions & 2 deletions json2mo/argument.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function parse (content, rawJson = false) {
const elementModificationOrReplaceable = require('./elementModificationOrReplaceable')
const elementRedeclaration = require('./elementRedeclaration')

var moOutput = ''
let moOutput = ''
if (content.element_modification_or_replaceable != null) {
moOutput += elementModificationOrReplaceable.parse(content.element_modification_or_replaceable, rawJson)
} else if (content.element_redeclaration != null) {
Expand All @@ -11,4 +11,4 @@ function parse (content, rawJson = false) {
return moOutput
}

module.exports = {parse}
module.exports = { parse }
6 changes: 3 additions & 3 deletions json2mo/argumentList.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function parse (content, rawJson = false) {
const argumentParser = require('./argument')
var moOutput = ''
let moOutput = ''
if (rawJson) {
var argumentStr = content.arguments
const argumentStr = content.arguments

if (argumentStr != null) {
argumentStr.forEach(argument => {
Expand All @@ -15,4 +15,4 @@ function parse (content, rawJson = false) {
return moOutput
}

module.exports = {parse}
module.exports = { parse }
8 changes: 4 additions & 4 deletions json2mo/arraySubscripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ function parse (content, rawJson = false) {
const expressionParser = require('./expression')
const subscriptParser = require('./subscript')

var moOutput = ''
let moOutput = ''

if (rawJson) {
moOutput += '['
var subscripts = content.subscripts
const subscripts = content.subscripts
if (subscripts != null) {
subscripts.forEach(subscript => {
moOutput += subscriptParser.parse(subscript, rawJson)
Expand All @@ -16,7 +16,7 @@ function parse (content, rawJson = false) {
}
moOutput += '] '
} else {
var arraySubscripts = content
const arraySubscripts = content
moOutput += '['

if (arraySubscripts != null) {
Expand All @@ -37,4 +37,4 @@ function parse (content, rawJson = false) {
return moOutput
}

module.exports = {parse}
module.exports = { parse }
4 changes: 2 additions & 2 deletions json2mo/assignmentEquation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function parse (content, rawJson = false) {
const simpleExpression = require('./simpleExpression')
const expressionParser = require('./expression')

var moOutput = ''
let moOutput = ''
if (content.lhs != null) {
moOutput += simpleExpression.parse(content.lhs, rawJson)
}
Expand All @@ -13,4 +13,4 @@ function parse (content, rawJson = false) {
return moOutput
}

module.exports = {parse}
module.exports = { parse }
4 changes: 2 additions & 2 deletions json2mo/assignmentStatement.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function parse (content, rawJson = false) {
const componentReferenceParser = require('./componentReference')
const expressionParser = require('./expression')

var moOutput = ''
let moOutput = ''
if (content.identifier != null) {
moOutput += componentReferenceParser.parse(content.identifier, rawJson)
}
Expand All @@ -13,4 +13,4 @@ function parse (content, rawJson = false) {
return moOutput
}

module.exports = {parse}
module.exports = { parse }
4 changes: 2 additions & 2 deletions json2mo/assignmentWithFunctionCallStatement.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function parse (content, rawJson = false) {
const outputExpressionListParser = require('./outputExpressionList')
const functionCallArgsParser = require('./functionCallArgs')

var moOutput = ''
let moOutput = ''
moOutput += '('
if (content.output_expression_list != null) {
moOutput += outputExpressionListParser.parse(content.output_expression_list, rawJson)
Expand All @@ -19,4 +19,4 @@ function parse (content, rawJson = false) {
return moOutput
}

module.exports = {parse}
module.exports = { parse }
6 changes: 3 additions & 3 deletions json2mo/basePrefix.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
function parse (content, rawJson = false) {
const util = require('util')
var moOutput = ''
let moOutput = ''
if (rawJson) {
if (content.type_prefix != null) {
moOutput += util.format('%s ', content.type_prefix)
}
} else {
var basePrefix = content
const basePrefix = content
if (basePrefix != null) {
moOutput += util.format('%s ', basePrefix)
}
Expand All @@ -15,4 +15,4 @@ function parse (content, rawJson = false) {
return moOutput
}

module.exports = {parse}
module.exports = { parse }
8 changes: 4 additions & 4 deletions json2mo/classDefinition.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function parse (content, rawJson = false) {
const util = require('util')
const classSpecifier = require('./classSpecifier')
var encapsulated = content.encapsulated
var classPrefixes = content.class_prefixes
var moOutput = ''
const encapsulated = content.encapsulated
const classPrefixes = content.class_prefixes
let moOutput = ''

if (encapsulated != null) {
if (encapsulated) {
Expand All @@ -18,4 +18,4 @@ function parse (content, rawJson = false) {
return moOutput
}

module.exports = {parse}
module.exports = { parse }
6 changes: 3 additions & 3 deletions json2mo/classModification.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ function parse (content, rawJson = false) {
const argumentListParser = require('./argumentList')
const argumentParser = require('./argument')

var moOutput = ''
let moOutput = ''
if (rawJson) {
moOutput += '(\n\t'
if (content.argument_list != null) {
moOutput += argumentListParser.parse(content.argument_list, rawJson)
}
moOutput += ')\n\t'
} else {
var argumentList = content
const argumentList = content
moOutput += '(\n\t'

argumentList.forEach(argument => {
Expand All @@ -24,4 +24,4 @@ function parse (content, rawJson = false) {
return moOutput
}

module.exports = {parse}
module.exports = { parse }
10 changes: 5 additions & 5 deletions json2mo/classSpecifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ function parse (content, rawJson = false) {
const shortClassSpecifierParser = require('./shortClassSpecifier')
const derClassSpecifierParser = require('./derClassSpecifier')

var longClassSpecifier = content.long_class_specifier
var shortClassSpecifier = content.short_class_specifier
var derClassSpecifier = content.der_class_specifier
const longClassSpecifier = content.long_class_specifier
const shortClassSpecifier = content.short_class_specifier
const derClassSpecifier = content.der_class_specifier

var moOutput = ''
let moOutput = ''

if (longClassSpecifier != null) {
moOutput += longClassSpecifierParser.parse(longClassSpecifier, rawJson)
Expand All @@ -24,4 +24,4 @@ function parse (content, rawJson = false) {
return moOutput
}

module.exports = {parse}
module.exports = { parse }
4 changes: 2 additions & 2 deletions json2mo/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function parse (content, rawJson = false) {
const util = require('util')
const annotationParser = require('./annotation')

var moOutput = ''
let moOutput = ''
if (rawJson) {
if (content.string_comment != null) {
moOutput += util.format('\n"\t%s"', content.string_comment)
Expand All @@ -22,4 +22,4 @@ function parse (content, rawJson = false) {
return moOutput
}

module.exports = {parse}
module.exports = { parse }
4 changes: 2 additions & 2 deletions json2mo/componentClause.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function parse (content, rawJson = false) {
const componentListParser = require('./componentList')
const util = require('util')

var moOutput = ''
let moOutput = ''

if (content.type_prefix != null) {
moOutput += util.format('%s ', content.type_prefix)
Expand All @@ -28,4 +28,4 @@ function parse (content, rawJson = false) {
return moOutput
}

module.exports = {parse}
module.exports = { parse }
4 changes: 2 additions & 2 deletions json2mo/componentClause1.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function parse (content, rawJson = false) {
const typeSpecifierParser = require('./typeSpecifier')
const componentDeclaration1Parser = require('./componentDeclaration1')

var moOutput = ''
let moOutput = ''
if (rawJson) {
if (content.type_prefix != null) {
moOutput += util.format('%s ', content.type_prefix)
Expand All @@ -29,4 +29,4 @@ function parse (content, rawJson = false) {
return moOutput
}

module.exports = {parse}
module.exports = { parse }
Loading