add two more tutorials
This commit is contained in:
parent
1dfeef767e
commit
069cb439cb
2 changed files with 156 additions and 0 deletions
64
tutorial/02_inheritance.py
Normal file
64
tutorial/02_inheritance.py
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
|
||||
# The following meta-model has an inheritance relation:
|
||||
|
||||
mm_cs = """
|
||||
MyAbstractClass:Class {
|
||||
abstract = True;
|
||||
}
|
||||
|
||||
MyConcreteClass:Class
|
||||
|
||||
:Inheritance (MyConcreteClass -> MyAbstractClass)
|
||||
|
||||
Z:Class
|
||||
|
||||
myZ:Association (MyAbstractClass -> Z) {
|
||||
target_lower_cardinality = 1;
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
# Note that we didn't give our inheritance link a name. A unique name will be auto-generated by the parser.
|
||||
|
||||
|
||||
# A (non-conforming) instance:
|
||||
|
||||
m_nonconform_cs = """
|
||||
cc:MyConcreteClass
|
||||
z:Z
|
||||
"""
|
||||
|
||||
|
||||
# Check conformance:
|
||||
|
||||
from state.devstate import DevState
|
||||
from bootstrap.scd import bootstrap_scd
|
||||
# from concrete_syntax.textual_od import parser
|
||||
# from framework.conformance import Conformance, render_conformance_check_result
|
||||
from util import loader
|
||||
|
||||
state = DevState()
|
||||
mmm = bootstrap_scd(state)
|
||||
|
||||
mm = loader.parse_and_check(state, mm_cs, mmm, "mm")
|
||||
|
||||
print("should be non-conform:")
|
||||
m_nonconform = loader.parse_and_check(state, m_nonconform_cs, mm, "m_nonconform")
|
||||
|
||||
|
||||
# The reason for the non-conformance is that all cardinalities and constraints are inherited. Therefore 'MyConcreteClass' must have at least one outgoing 'myZ' link as well.
|
||||
|
||||
# We fix the non-conformance by adding this link:
|
||||
|
||||
m_conform_cs = m_nonconform_cs + """
|
||||
:myZ (cc -> z)
|
||||
"""
|
||||
|
||||
# Now everything will be fine
|
||||
|
||||
print("should be conform:")
|
||||
m_conform = loader.parse_and_check(state, m_conform_cs, mm, "m_conform")
|
||||
print("OK")
|
||||
|
||||
|
||||
# On to the next tutorial...
|
||||
Loading…
Add table
Add a link
Reference in a new issue