loader can also load without checking conformance

This commit is contained in:
Joeri Exelmans 2024-11-22 16:25:27 +01:00
parent 4fe7e19714
commit a91c7d2bdd

View file

@ -4,7 +4,7 @@ from concrete_syntax.textual_od import parser
from transformation.rule import Rule
# parse model and check conformance
def parse_and_check(state, m_cs, mm, descr: str):
def parse_and_check(state, m_cs, mm, descr: str, check_conformance=True):
try:
m = parser.parse_od(
state,
@ -15,10 +15,11 @@ def parse_and_check(state, m_cs, mm, descr: str):
e.add_note("While parsing model " + descr)
raise
try:
conf = Conformance(state, m, mm)
errors = conf.check_nominal()
if len(errors) > 0:
print(render_conformance_check_result(errors))
if check_conformance:
conf = Conformance(state, m, mm)
errors = conf.check_nominal()
if len(errors) > 0:
print(render_conformance_check_result(errors))
except Exception as e:
e.add_note("In model " + descr)
raise
@ -32,7 +33,7 @@ def read_file(filename):
KINDS = ["nac", "lhs", "rhs"]
# load model transformation rules
def load_rules(state, get_filename, rt_mm_ramified, rule_names):
def load_rules(state, get_filename, rt_mm_ramified, rule_names, check_conformance=True):
rules = {}
files_read = []
@ -50,7 +51,7 @@ def load_rules(state, get_filename, rt_mm_ramified, rule_names):
while True:
base, ext = os.path.splitext(filename)
processed_filename = base+suffix+ext
nac = parse_and_check(state, read_file(processed_filename), rt_mm_ramified, descr)
nac = parse_and_check(state, read_file(processed_filename), rt_mm_ramified, descr, check_conformance)
nacs.append(nac)
suffix = "2" if suffix == "" else str(int(suffix)+1)
files_read.append(processed_filename)
@ -60,7 +61,7 @@ def load_rules(state, get_filename, rt_mm_ramified, rule_names):
return nacs
elif kind == "lhs" or kind == "rhs":
try:
m = parse_and_check(state, read_file(filename), rt_mm_ramified, descr)
m = parse_and_check(state, read_file(filename), rt_mm_ramified, descr, check_conformance)
files_read.append(filename)
return m
except FileNotFoundError as e:
@ -70,7 +71,8 @@ def load_rules(state, get_filename, rt_mm_ramified, rule_names):
state,
"",
rt_mm_ramified,
descr="'"+filename+"'")
descr="'"+filename+"'",
check_conformance=check_conformance)
rules[rule_name] = Rule(*(parse(kind) for kind in KINDS))