lutaml / expressir

Ruby parser for the ISO EXPRESS language
3 stars 3 forks source link

Expressir::ExpressExp::Parser to parse remark tags #12

Closed ronaldtse closed 4 years ago

ronaldtse commented 4 years ago

The current parser Expressir::ExpressExp::Parser does not handle remark tags.

Given contents of an EXPRESS file of:

  ENTITY action_directive_relationship;
    ...
   WHERE
    WR1 : acyclic_action_directive_relationship(SELF, [related], 'ACTION_SCHEMA.ACTION_DIRECTIVE_RELATIONSHIP');
  END_ENTITY;
...

(*"action_directive_relationship.WR1"
A *action_directive_relationship* shall not participate in its own definition.
*)

We want to be able to access the remark tags of a model via something like this:

file = '../annotated-express/data/resources/action_schema/action_schema.exp'

repo = Expressir::ExpressExp::Parser.from_exp(file)
schema = repo.schemas.find{|schema| schema.id == "action_schema"}
entity = schema.entities.find{|entity| entity.id == "action_directive_relationship"}
where = entity.where.find{|where| where.id == "WR1"}
where.tagged_remarks
# => ["A *action_directive_relationship* shall not participate in its own definition.", ...]

Of course this will also be useful:

repo = Expressir::ExpressExp::Parser.from_exp(file)
repo.path('action_schema.action_directive_relationship.WR1').tagged_remarks
# or
repo.tagged_remarks('action_schema.action_directive_relationship.WR1')