Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
VRE Language
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KIT
virtmat-tools
VRE Language
Merge requests
!12
Data structures builtins
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Data structures builtins
data-structures-builtins
into
master
Overview
0
Commits
12
Pipelines
0
Changes
14
Merged
Ivan Kondov
requested to merge
data-structures-builtins
into
master
2 years ago
Overview
0
Commits
12
Pipelines
0
Changes
14
Expand
processing issue
https://git.scc.kit.edu/jk7683/vre-language/-/issues/8
Edited
2 years ago
by
Ivan Kondov
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
3c75280b
12 commits,
2 years ago
14 files
+
1131
−
58
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
14
Search (e.g. *.vue) (Ctrl+P)
constraints/substitute.py
0 → 100644
+
32
−
0
Options
"""
functions related to variable substitutions in expressions
"""
from
copy
import
deepcopy
from
textx
import
get_children_of_type
,
get_children
from
textx
import
get_metamodel
from
textx
import
textx_isinstance
def
subst
(
caller
,
func
,
params
):
"""
substitute dummy identifiers (bound variables) with their parameters
caller: the object of which the new returned expression will become a child
func: object of type FunctionDefinition or Lambda that contain expr
params: an iterable with the parameters in the order of substitution
"""
expr
=
deepcopy
(
func
.
expr
)
new_objs
=
get_children
(
lambda
x
:
True
,
expr
)
for
new_obj
in
new_objs
:
if
new_obj
is
not
expr
:
new_obj
.
parent
=
new_obj
.
parent
.
last_copy
expr
.
parent
=
caller
meta
=
get_metamodel
(
caller
)
vrefs
=
get_children_of_type
(
'
VarReference
'
,
expr
)
for
vref
in
filter
(
lambda
x
:
textx_isinstance
(
x
.
ref
,
meta
[
'
Dummy
'
]),
vrefs
):
if
hasattr
(
vref
.
ref
,
'
name
'
):
for
par
,
arg
in
zip
(
params
,
func
.
args
):
if
vref
.
ref
.
name
==
arg
.
name
:
if
textx_isinstance
(
par
,
meta
[
'
VarReference
'
]):
vref
.
ref
=
par
.
ref
else
:
vref
.
ref
=
par
break
return
expr
Loading