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

#135: Initial work to Group Schedule Table Inputs #144

Merged
merged 23 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c46e691
WIP: update 'dat' structure
darenkeck-dev Jul 6, 2022
10359d7
Fix syntax error in dat subcomponents
darenkeck-dev Jul 8, 2022
75a082d
Fix typos in test template
darenkeck-dev Jul 11, 2022
b94fecc
WIP: add debug for redeclaration modifiers
darenkeck-dev Jul 12, 2022
9009a15
WIP: add TODO for expanding 'Modification' class for redeclares
darenkeck-dev Jul 12, 2022
0ec2572
Expand 'Modification' class to support redeclare modifiers
darenkeck-dev Jul 13, 2022
ea910dc
Add additional typing for redeclaration structures
darenkeck-dev Jul 13, 2022
4dcf4d3
WIP: add 'dat' specific test group
darenkeck-dev Jul 18, 2022
35bfa86
Correct replaceable param in Testpackage
darenkeck-dev Jul 19, 2022
53c747e
WIP: Update how child options are populated
darenkeck-dev Jul 19, 2022
fef44bb
Fix bug in how child options are fetched for replaceable inputs
darenkeck-dev Jul 21, 2022
a9e5639
Add optionTree helper function
darenkeck-dev Jul 21, 2022
1b7d8d9
WIP: refactor modification factory method, add additional types
darenkeck-dev Jul 22, 2022
9ffc4c8
WIP: add mod unpacking helper method
darenkeck-dev Jul 22, 2022
5766550
Add 'Import' parser element
darenkeck-dev Jul 22, 2022
d5ce807
Handle package redeclarations
darenkeck-dev Jul 22, 2022
673f324
Remove option count test
darenkeck-dev Jul 22, 2022
b8c728f
WIP: split out schedule options from config options
darenkeck-dev Jul 23, 2022
4a48c42
Fix order-of-operations error in condition
darenkeck-dev Jul 27, 2022
cdf2be7
Punch out on duplicate type references when splitting schedule options
darenkeck-dev Jul 28, 2022
9fa6e36
Prevent recursive extraction of schedule options
darenkeck-dev Jul 29, 2022
19f0cc1
Update system option tests
darenkeck-dev Jul 29, 2022
78439b3
Remove debugging logs
darenkeck-dev Jul 29, 2022
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
5 changes: 4 additions & 1 deletion server/scripts/parse-template-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import {

loadPackage("Buildings");

const { options, scheduleOptions } = getOptions();

const data = {
templates: getTemplates(),
systemTypes: getSystemTypes(),
options: getOptions(),
options: options,
scheduleOptions: scheduleOptions,
};

const dest = path.resolve(
Expand Down
5 changes: 4 additions & 1 deletion server/scripts/parse-test-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ loadPackage(`${fullTempDirPath}/TestPackage`);
// const buildDir = `${process.cwd()}/build/modelica-json/json`;
// loadPackage(`${buildDir}/Buildings/Templates`);

const { options, scheduleOptions } = getOptions();

const data = {
templates: getTemplates(),
systemTypes: getSystemTypes(),
options: getOptions(),
options: options,
scheduleOptions: scheduleOptions,
};

const dest = path.resolve(
Expand Down
5 changes: 4 additions & 1 deletion server/src/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export function getSystemTypes(): templates.SystemTypeN[] {
return templates.getSystemTypes();
}

export function getOptions(): parser.OptionN[] {
export function getOptions(): {
options: parser.OptionN[];
scheduleOptions: templates.ScheduleOption[];
} {
return templates.getOptions();
}
156 changes: 107 additions & 49 deletions server/src/parser/modification.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ShortClassSpecifier } from "./parser";

/**
* Modifications are places where there is an assignment, e.g.
* 'my_param=5'. Modifications can also contain groups of modifications, e.g.
Expand All @@ -23,22 +25,38 @@

const modStore: Map<string, Modification> = new Map();

type RedeclarationMod = {
type ComponentDeclaration1 = {
declaration: DeclarationBlock;
description?: DescriptionBlock;
};

type ComponentClause1 = {
type_specifier: string; // Modelica Path
component_declaration1: ComponentDeclaration1;
};

type ShortClassDefinition = {
class_prefixes: string; // //(PARTIAL)? (CLASS | MODEL | (OPERATOR)? RECORD | BLOCK | (EXPANDABLE)? CONNECTOR | TYPE | PACKAGE | ((PURE | IMPURE))? (OPERATOR)? FUNCTION | OPERATOR),
short_class_specifier: ShortClassSpecifier; // from 'parser.ts'
};

type ElementReplaceable = {
component_clause1: ComponentClause1;
short_class_definition: ShortClassDefinition;
};

type RedeclareMod = {
element_redeclaration: {
element_replaceable: {
component_clause1: {
type_specifier: string; // Modelica Path
component_declaration1: {
declaration: DeclarationBlock;
description: DescriptionBlock;
};
};
}
each: boolean;
final: boolean;
short_class_definition?: ShortClassDefinition;
element_replaceable?: ElementReplaceable;
component_clause1?: ComponentClause1;
};
};

type ClassMod = {
class_modification: (WrappedMod | RedeclarationMod)[];
class_modification: (WrappedMod | RedeclareMod)[];
};

type Assignment = {
Expand All @@ -57,12 +75,12 @@ export type WrappedMod = {

export type Mod = {
name: string;
modification: ClassMod | WrappedMod | Assignment | RedeclarationMod;
modification: ClassMod | WrappedMod | Assignment | RedeclareMod;
};

export type DeclarationBlock = {
identifier: string;
modification?: ClassMod | WrappedMod | Assignment | RedeclarationMod;
modification?: ClassMod | WrappedMod | Assignment | RedeclareMod;
};

export type DescriptionBlock = {
Expand All @@ -79,25 +97,28 @@ export function getModificationList(
classMod: ClassMod,
modelicaPath: string,
name = "",
): Modification[] {
return classMod.class_modification.map((m) =>
createModification({
definition: m as WrappedMod,
basePath: modelicaPath,
name: name,
}),
);
) {
return classMod.class_modification
.map((m) =>
createModification({
definition: m as WrappedMod,
basePath: modelicaPath,
name: name,
}),
)
.filter((m) => m !== undefined) as Modification[];
}

interface ModificationBasics {
basePath?: string;
name?: string;
value?: any;
definition?: any;
type?: string;
}

interface ModificationWithDefinition extends ModificationBasics {
definition: WrappedMod | Mod | DeclarationBlock;
definition: WrappedMod | Mod | DeclarationBlock | RedeclareMod;
value?: never;
}

Expand All @@ -109,6 +130,64 @@ interface ModificationWithValue extends ModificationBasics {

type ModificationProps = ModificationWithDefinition | ModificationWithValue;

function unpackRedeclaration(props: ModificationProps) {
let { definition } = props;
const redeclaration = (definition as RedeclareMod).element_redeclaration;
if ("component_clause1" in redeclaration) {
const componentClause1 =
redeclaration.component_clause1 as ComponentClause1;
const type = componentClause1.type_specifier;
const redeclareDefinition =
componentClause1.component_declaration1.declaration;
const modProps = { ...props, type, definition: redeclareDefinition };
const redeclareMod = createModification(modProps);
return redeclareMod;
} else if ("short_class_definition" in redeclaration) {
} else if ("element_replaceable" in redeclaration) {
}
}

function unpackModblock(props: ModificationProps) {
let mods: Modification[] = [];
let value: string = "";
let { definition, basePath = "", name } = props as ModificationWithDefinition;

let modBlock = definition;

modBlock =
"element_modification_or_replaceable" in definition
? definition.element_modification_or_replaceable.element_modification
: definition;

if ("name" in modBlock) {
name = modBlock.name;
} else if ("identifier" in modBlock) {
name = modBlock.identifier;
}

let modelicaPath = basePath ? `${basePath}.${name}` : "";
const mod = (modBlock as Mod).modification;
if (mod) {
// test if an assignment
if ("equal" in mod) {
// simple_expression can potentially be an expression
// TODO be ready to feed that into Expression generator
value = (mod as Assignment).expression.simple_expression;
} else if (name == "choice") {
const choiceMod = (mod as ClassMod).class_modification[0] as RedeclareMod;
if (choiceMod.element_redeclaration) {
const replaceable = choiceMod.element_redeclaration
.element_replaceable as ElementReplaceable;
value = replaceable.component_clause1.type_specifier;
}
} else if ("class_modification" in mod) {
mods = getModificationList(mod as ClassMod, modelicaPath);
}
}

return new Modification(basePath, name, value, mods);
}

/**
* Factory method that can create a Modification from two approaches:
*
Expand All @@ -118,40 +197,19 @@ type ModificationProps = ModificationWithDefinition | ModificationWithValue;
* @param props: ModificationProps
* @returns Modification
*/
export function createModification(props: ModificationProps): Modification {
export function createModification(
props: ModificationProps,
): Modification | undefined {
let mods: Modification[] = [];
let { definition, value, basePath = "", name } = props;
let modelicaPath = basePath ? `${basePath}.${name}` : "";

if (definition) {
const modBlock =
"element_modification_or_replaceable" in definition
? definition.element_modification_or_replaceable.element_modification
: definition;

if ("name" in modBlock) {
name = modBlock.name;
} else if ("identifier" in modBlock) {
name = modBlock.identifier;
if ("element_redeclaration" in definition) {
return unpackRedeclaration(props);
}

const mod = modBlock.modification;
if (mod) {
// test if an assignment
if ("equal" in mod) {
// simple_expression can potentially be an expression
// TODO be ready to feed that into Expression generator
value = (mod as Assignment).expression.simple_expression;
} else if (name == "choice") {
const choiceMod = (mod as ClassMod)
.class_modification[0] as RedeclarationMod;
value =
choiceMod.element_redeclaration.element_replaceable.component_clause1.type_specifier;
} else if ("class_modification" in mod) {
// const type = "";
mods = getModificationList(mod as ClassMod, modelicaPath);
}
}
return unpackModblock(props);
}

return new Modification(basePath, name, value, mods);
Expand Down
Loading