runner.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # Model transformation experiment
  2. from state.devstate import DevState
  3. from bootstrap.scd import bootstrap_scd
  4. from uuid import UUID
  5. from services.scd import SCD
  6. from framework.conformance import Conformance
  7. from services.od import OD
  8. from transformation.matcher import match_od
  9. from transformation.ramify import ramify
  10. from transformation.cloner import clone_od
  11. from transformation import rewriter
  12. from services.bottom.V0 import Bottom
  13. from services.primitives.integer_type import Integer
  14. from concrete_syntax.plantuml import renderer as plantuml
  15. from concrete_syntax.plantuml.make_url import make_url as make_plantuml_url
  16. from concrete_syntax.textual_od import parser, renderer
  17. from util.timer import Timer
  18. if __name__ == "__main__":
  19. state = DevState()
  20. root = state.read_root() # id: 0
  21. # Meta-meta-model: a class diagram that describes the language of class diagrams
  22. scd_mmm_id = bootstrap_scd(state)
  23. int_mm_id = UUID(state.read_value(state.read_dict(state.read_root(), "Integer")))
  24. string_mm_id = UUID(state.read_value(state.read_dict(state.read_root(), "String")))
  25. dsl_mm_cs = """
  26. Rare:Class
  27. Many:Class
  28. ManyB:Class
  29. Other:Class
  30. OtherB:Class
  31. OtherC:Class
  32. ass:Association(Many->ManyB)
  33. """
  34. dsl_mm_id = parser.parse_od(state, dsl_mm_cs, mm=scd_mmm_id)
  35. dsl_m_cs = """
  36. rare:Rare
  37. many0:Many
  38. many1:Many
  39. many2:Many
  40. many3:Many
  41. many4:Many
  42. many5:ManyB
  43. many6:ManyB
  44. many7:ManyB
  45. many8:ManyB
  46. :ass (many2->many6)
  47. :ass (many3->many8)
  48. # other0:Other
  49. # other1:OtherC
  50. # other2:Other
  51. # other3:Other
  52. # other4:Other
  53. # other5:OtherB
  54. # other6:OtherB
  55. # other7:OtherB
  56. # other8:OtherB
  57. # other9:OtherB
  58. # other10:OtherB
  59. # other11:OtherC
  60. # other12:OtherC
  61. # other13:OtherC
  62. # other14:OtherC
  63. # other1099:OtherB
  64. # other1199:OtherC
  65. # other1299:OtherC
  66. # other1399:OtherC
  67. # other1499:OtherC
  68. """
  69. dsl_m_id = parser.parse_od(state, dsl_m_cs, mm=dsl_mm_id)
  70. # RAMify MM
  71. prefix = "RAM_" # all ramified types can be prefixed to distinguish them a bit more
  72. ramified_mm_id = ramify(state, dsl_mm_id, prefix)
  73. ramified_int_mm_id = ramify(state, int_mm_id, prefix)
  74. # LHS - pattern to match
  75. # TODO: enable more powerful constraints
  76. pattern_cs = f"""
  77. # object to match
  78. rare:{prefix}Rare {{
  79. }}
  80. many:{prefix}Many
  81. manyB:{prefix}ManyB
  82. manyB2:{prefix}ManyB
  83. """
  84. pattern_id = parser.parse_od(state, pattern_cs, mm=ramified_mm_id)
  85. with Timer("find all matches"):
  86. matches = list(match_od(state, dsl_m_id, dsl_mm_id, pattern_id, ramified_mm_id))
  87. for match in matches:
  88. print("\nMATCH:\n", match)
  89. print(len(matches), 'matches')