lutaml / expressir

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

Allow accessing EXPRESS data model using Ruby #27

Closed ronaldtse closed 3 years ago

ronaldtse commented 3 years ago

Given an EXPRESS file like:

SCHEMA aic_curve_swept_solid '{iso standard 10303 part(523) version(2) object(1) aic_curve_swept_solid(1)}';

  USE FROM measure_schema; -- ISO 10303-41

  USE FROM geometry_schema  -- ISO 10303-42
    (axis2_placement_2d,
...

  ENTITY curve_swept_solid_shape_representation
    SUBTYPE OF (shape_representation);
  WHERE
  WR1: SIZEOF (QUERY (it <* SELF.items |
  ...
  END_ENTITY;

I want to be able to do something like this:

context = Reeper.load('aic_curve_swept_solid.xml')

x = context.find('aic_curve_swept_solid')
=> the SCHEMA object

x.use_from
=> <#UseFrom measure_schema>, <#UseFrom geometry_schema>...

x.find('curve_swept_solid_shape_representation')
=> <#Entity curve_swept_solid_shape_representation>

csssr = x.find('curve_swept_solid_shape_representation')
=> <#Entity curve_swept_solid_shape_representation>

csssr = context.find('curve_swept_solid_shape_representation')
=> <#Entity curve_swept_solid_shape_representation>

csssr_wr1 = context.where.first
=> <#WhereRule>

annotation = context.find("curve_swept_solid_shape_representation .ruled_surface_swept_area_solid")
=> <#Annotation ruled_surface_swept_area_solid>

annotation = context.find("ruled_surface_swept_area_solid")
=> <#Annotation ruled_surface_swept_area_solid>

annotation.target
=> "ruled_surface_swept_area_solid"

annotation.text
=> "A *ruled_surface_swept_area_solid* is a type of ..."

@zakjan we will need documentation on how to do things like this.

ronaldtse commented 3 years ago

This is somewhat overlapping with #16 , probably should be done with #16 together.

zakjan commented 3 years ago

SInce scope and visibility rules were already implemented in #11, it seems this can use the same implementation.

Code for find method could look like:

def find(path)
  path.split(".").reduce(self) do |acc, curr|
    if acc and acc.class.method_defined? children
      acc.children.find{|x| x.id == curr}
    end
  end
end
ronaldtse commented 3 years ago

Looks good @zakjan ! I want to confirm whether the dot (.) is a valid separator -- we should probably use a character that is not used in EXPRESS name definitions.

zakjan commented 3 years ago

Yes, . is a valid separator. EXPRESS name definitions can contain only letters, digits and _.

simple_id = letter { letter | digit | ’_’ } .
ronaldtse commented 3 years ago

Thank you @zakjan !