Skip to content

Commit

Permalink
null in properties of Component
Browse files Browse the repository at this point in the history
  • Loading branch information
metelkin committed Jun 28, 2024
1 parent c2fb8c4 commit 06d7a79
Show file tree
Hide file tree
Showing 29 changed files with 395 additions and 239 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
- write reusable `Build` class
- alternative solution to substitute "pkg": Node.js 21 https://nodejs.org/api/single-executable-applications.html
wait until Node.js 22 will be released
- support `null` for properties: highlight, parse, heta standard
- support `null` for properties: highlight, heta standard

## ideas

Expand Down
34 changes: 34 additions & 0 deletions cases/27-null/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
### Basic .gitattributes for a Heta repo.
# Note that binary is a macro for -text -diff.

* text=auto

# main files
# to have heta files in linux style line endings
*.heta text eol=lf
*.xlsx binary

# auxilary files
*.bash text eol=lf
*.sh text eol=lf
*.xlsm binary
*.xls binary
*.pptx binary
*.ppt binary

# code
*.md text
*.m text
# -diff
*.slv text eol=crlf diff=slv
*.dat text eol=crlf diff=dat
*.cpp text
*.svg text diff=xml
*.xml text diff=xml
*.sbml text diff=xml

# LFS (large files)
large/* filter=lfs diff=lfs merge=lfs -text
literature/* filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.rar filter=lfs diff=lfs merge=lfs -text
11 changes: 11 additions & 0 deletions cases/27-null/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### Heta specific files and dirs
/dist
/draft
/drafts
/meta

### temporal files
*.tmp
~$*.*
*.log
.Rhistory
12 changes: 12 additions & 0 deletions cases/27-null/platform.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"builderVersion": "^0.8.4",
"id": "template",
"notes": "platform notes",
"version": "v0.1.0",
"license": "UNLICENSED",
"options": {},
"importModule": {
"type": "heta",
"source": "src/index.heta"
}
}
19 changes: 19 additions & 0 deletions cases/27-null/src/index.heta
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
template file for creating platform
*/

#defineFunction xxx {
arguments: [x,y,z],
math: null
};

p1 @Record 'This is title' .= 1;
p1 := 2;

p1 {title: null};
p1 .= null;
//p1 := null;
p1 [xxx]= null;

// exports
#export { format: JSON, filepath: output };
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"colors": "^1.4.0",
"commander": "^11.1.0",
"fs-extra": "^11.1.1",
"heta-parser": "^0.3.18",
"heta-parser": "^0.4.0",
"inquirer": "^8.2.6",
"js-yaml": "^4.1.0",
"lodash": "^4.17.21",
Expand Down
3 changes: 2 additions & 1 deletion src/container/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const reservedWords = [
'include', 'block', 'namespace', 'abstract', 'concrete', 'begin', 'end',
'NaN', 'Infinity',
'e', 'E', 'pi', 'PI',
'time', 'SOLVERTIME', 'default' // mrgsolve specific reserved words
'time', 'SOLVERTIME', 'default', // mrgsolve specific reserved words
'null'
];

/**
Expand Down
4 changes: 3 additions & 1 deletion src/core/_size.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class _Size extends Component {
let logger = this.namespace?.container?.logger;
let valid = _Size.isValid(q, logger);
if (valid) {
if (q.units) {
if (q.units !== undefined) {
if (q.units === 1) {
this.unitsParsed = new Unit();
} else if (typeof q.units === 'string') {
Expand All @@ -30,6 +30,8 @@ class _Size extends Component {
let msg = this.index + ': '+ e.message;
logger && logger.error(msg, {type: 'ValidationError', space: this.space});
}
} else if (q.unit === null) {
delete this.unitsParsed;
} else {
this.unitsParsed = Unit.fromQ(q.units);
}
Expand Down
10 changes: 8 additions & 2 deletions src/core/_switcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ class _Switcher extends Component {
let valid = _Switcher.isValid(q, logger);

if (valid) {
if (typeof q.atStart !== 'undefined') {
if (q.atStart === null) {
delete this.atStart;
} else if (typeof q.atStart !== 'undefined') {
this.atStart = !!q.atStart;
}
q.active !== undefined && (this.active = !!q.active);
if (q.active === null) {
delete this.active;
} else if (q.active !== undefined) {
this.active = !!q.active;
}
}

return this;
Expand Down
4 changes: 3 additions & 1 deletion src/core/c-switcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class CSwitcher extends _Switcher {
let valid = CSwitcher.isValid(q, logger);

if (valid) {
if (typeof q.trigger !== 'undefined') {
if (q.trigger === null) {
delete this.trigger;
} else if (typeof q.trigger !== 'undefined') {
try { // this is for the cases of wrong ExprString structure
let expr = Expression.fromString(q.trigger);
if (!expr.hasBooleanResult()) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/compartment.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class Compartment extends Record {
}
merge(q = {}){
super.merge(q);
let logger = this.namespace?.container?.logger;
let valid = Compartment.isValid(q, logger);
//let logger = this.namespace?.container?.logger;
//let valid = Compartment.isValid(q, logger);

return this;
}
Expand Down
24 changes: 20 additions & 4 deletions src/core/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,26 @@ class Component {
let valid = Component.isValid(q, logger);

if (valid) {
if (q.title) this.title = q.title;
if (q.notes) this.notes = q.notes.trim(); // remove trailing symbols
if (q.tags) this.tags = q.tags.map((tag) => tag); // clone
if (q.aux) this.aux = cloneDeep(q.aux);
if (q.title === null) {
delete this.title;
} else if (q.title !== undefined) {
this.title = q.title;
}
if (q.notes === null) {
delete this.notes;
} else if (q.notes !== undefined) {
this.notes = q.notes.trim(); // remove trailing symbols
}
if (q.tags === null) {
this.tags = [];
} else if (q.tags !== undefined) {
this.tags = q.tags.map((tag) => tag); // clone
}
if (q.aux === null) {
this.aux = {};
} else if (q.aux) {
this.aux = cloneDeep(q.aux);
}
}

return this;
Expand Down
30 changes: 25 additions & 5 deletions src/core/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,31 @@ class Const extends _Size { // implicit extend Numeric
let valid = Const.isValid(q, logger);

if (valid) {
if (q.num !== undefined) this.num = q.num;
if (q.free !== undefined) this.free = !!q.free;
if (q.scale !== undefined) this.scale = q.scale;
if (q.lower !== undefined) this.lower = q.lower;
if (q.upper !== undefined) this.upper = q.upper;
if (q.num === null) {
delete this.num;
} else if (q.num !== undefined) {
this.num = q.num
};
if (q.free === null) {
delete this.free;
} else if (q.free !== undefined) {
this.free = !!q.free;
}
if (q.scale === null) {
delete this.scale;
} else if (q.scale !== undefined) {
this.scale = q.scale;
}
if (q.lower === null) {
delete this.lower;
} else if (q.lower !== undefined) {
this.lower = q.lower;
}
if (q.upper === null) {
delete this.upper;
} else if (q.upper !== undefined) {
this.upper = q.upper;
}
}

return this;
Expand Down
4 changes: 3 additions & 1 deletion src/core/d-switcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class DSwitcher extends _Switcher {
let valid = DSwitcher.isValid(q, logger);

if (valid) {
if (typeof q.trigger !== 'undefined') {
if (q.trigger === null) {
delete this.trigger;
} else if (typeof q.trigger !== 'undefined') {
q.trigger += '';
try { // this is for the cases of wrong ExprString structure
let expr = Expression.fromString(q.trigger);
Expand Down
6 changes: 5 additions & 1 deletion src/core/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ class Page extends Component {
let valid = Page.isValid(q, logger);

if (valid) {
if (q.content) this.content = q.content;
if (q.content === null) {
delete this.content;
} else if (q.content !== undefined) {
this.content = q.content;
}
}

return this;
Expand Down
12 changes: 9 additions & 3 deletions src/core/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,24 @@ class Process extends Record {
let valid = Process.isValid(q, logger);

if (valid) {
if (q.actors) {
if(q.actors instanceof Array){
if (q.actors !== undefined) {
if (q.actors instanceof Array) {
this.actors = q.actors
.map((q) => new Actor(q));
} else if (q.actors === null) {
this.actors = [];
} else {
let { targetArray, isReversible } = rct2actors(q.actors);
this.actors = targetArray
.map((q) => new Actor(q));
this.reversible = isReversible;
}
}
if (q.reversible !== undefined) this.reversible = !!q.reversible;
if (q.reversible === null) {
this.reversible = true;
} else if (q.reversible !== undefined) {
this.reversible = !!q.reversible;
}
}

return this;
Expand Down
25 changes: 15 additions & 10 deletions src/core/reaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,23 @@ class Reaction extends Process {
let valid = Reaction.isValid(q, logger);

if (valid) {
if (q.modifiers) {
this.modifiers = q.modifiers
.map((mod) => {
if (typeof mod==='string') {
return new Modifier({target: mod});
} else {
return new Modifier(mod);
}
});
if (q.modifiers === null) {
this.modifiers = [];
} else if (q.modifiers !== undefined) {
this.modifiers = q.modifiers.map((mod) => {
if (typeof mod==='string') {
return new Modifier({target: mod});
} else {
return new Modifier(mod);
}
});
}

if (q.compartment !== undefined) this.compartment = q.compartment;
if (q.compartment === null) {
delete this.compartment;
} else if (q.compartment !== undefined) {
this.compartment = q.compartment;
}
}

return this;
Expand Down
20 changes: 17 additions & 3 deletions src/core/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,29 @@ class Record extends _Size {
let msg = this.index + ': '+ e.message + ` in "${x.toString()}"`;
logger && logger.error(msg, {type: 'ValidationError', space: this.space});
}
} else if (x === null) {
delete this.assignments[key];
} else {
throw new Error('Wrong expression argument.'); // if code is OK never throws
}
});
}

if (q.boundary !== undefined) this.boundary = !!q.boundary;
if (q.ss !== undefined) this.ss = !!q.ss;
if (q.output !== undefined) this.output = !!q.output;
if (q.boundary === null) {
delete this.boundary;
} else if (q.boundary !== undefined) {
this.boundary = !!q.boundary;
}
if (q.ss === null) {
delete this.ss;
} else if (q.ss !== undefined) {
this.ss = !!q.ss;
}
if (q.output === null) {
delete this.output;
} else if (q.output !== undefined) {
this.output = !!q.output;
}
}

return this;
Expand Down
12 changes: 10 additions & 2 deletions src/core/reference-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ class ReferenceDefinition extends Component {
let valid = ReferenceDefinition.isValid(q, logger);

if (valid) {
if(q.prefix) this.prefix = q.prefix;
if(q.suffix) this.suffix = q.suffix;
if (q.prefix === null) {
delete this.prefix;
} else if (q.prefix !== undefined) {
this.prefix = q.prefix;
}
if (q.suffix === null) {
delete this.suffix;
} else if (q.suffix !== undefined) {
this.suffix = q.suffix;
}
}

return this;
Expand Down
Loading

0 comments on commit 06d7a79

Please sign in to comment.