lutaml / expressir

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

Ability to include untagged remarks into parse tree and formatter output #64

Open zakjan opened 3 years ago

zakjan commented 3 years ago

The challenge is that Express formatting is different between original and formatted code. I'll probably need to introduce some sort of attach points where untagged remarks can attach to (e.g. after each item in a list). With this approach, slight variances would still be possible.

zakjan commented 3 years ago

Probably depends on #65, because it can clarify what are expected attach points.

ronaldtse commented 5 months ago

We need to parse untagged remarks and also include it in the output of Formatter.

e.g.

action_schema.exp

(*
$Id: action_schema.exp,v 1.36 2021/05/06 16:23:00 kevin Exp $
ISO 10303 TC184/SC4/WG12 N10693

EXPRESS Source:
ISO 10303-41 ed7 Fundamentals of product description and support - Action schema

The following permission notice and disclaimer shall be included in all copies of this EXPRESS schema ("the Schema"), 
and derivations of the Schema:
...
*)

SCHEMA action_schema '{iso standard 10303 part(41) version(9) object(1) action_schema(1)}';
  REFERENCE FROM basic_attribute_schema (   -- ISO 10303-41
    description_attribute, 
    description_attribute_select,
    get_description_value, 
    get_id_value, 
    get_name_value,
    get_role, 
    id_attribute, 
    id_attribute_select,
    name_attribute,
    name_attribute_select,
    object_role,
    role_select,
    role_association);

  REFERENCE FROM support_resource_schema ( -- ISO 10303-41
    bag_to_set, 
    identifier, 
    label, 
    text);

The first part:

(*
$Id: action_schema.exp,v 1.36 2021/05/06 16:23:00 kevin Exp $
ISO 10303 TC184/SC4/WG12 N10693
...
*)

This is an "untagged remark" because a "tagged remark" is attached to an object and looks like this:

(*"object_name.xxx"
...
*)

Right now Expressir is not rendering the untagged remarks.

For example: In iso-10303-srl:

exp_file = "schemas/resources/action_schema/action_schema.exp"
repository = Expressir::Express::Parser.from_files([exp_file])
formatter  = Class.new(Expressir::Express::Formatter) do
    def format_remark(node, remark)
      [
        [
          '(*',
          '"',
          node.path || node.id,
          '"',
        ].join(''),
        remark,
        '*)'
      ].join("\n")
  end
end

puts formatter.format(repository)

This gives you the pretty formatted version but without the untagged remark (the tagged remarks exist)

SCHEMA action_schema '{iso standard 10303 part(41) version(9) object(1) action_schema(1)}';

REFERENCE FROM basic_attribute_schema
  (description_attribute,
   description_attribute_select,
   get_description_value,
   get_id_value,
   get_name_value,
   get_role,
   id_attribute,
   id_attribute_select,
   name_attribute,
   name_attribute_select,
   object_role,
   role_select,
   role_association);
...
(*"action_schema"
...
*)