Ignore:
Timestamp:
May 1, 2008, 1:34:51 AM (16 years ago)
Author:
Tatsukawa, Akimichi
Message:

integrating am and adl_parser

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ruby/trunk/adl_parser/lib/parser.y

    r21 r22  
    3535archetype: arch_identification arch_specialisation arch_concept arch_language arch_description arch_definition arch_invariant arch_ontology
    3636  {
     37    assert_at(__FILE__,__LINE__) do
     38      val[4].instance_of?(OpenEHR::AM::Archetype::Archetype_Description::ARCHETYPE_DESCRIPTION) and val[5].instance_of?(OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT) and val[7].instance_of?(OpenEHR::AM::Archetype::Ontology::ARCHETYPE_ONTOLOGY)
     39    end
     40   
    3741    result = OpenEHR::AM::Archetype::ARCHETYPE.new(
    3842                                                   :description => val[4],
    39                                                    :definition => val[5]
     43                                                   :definition => val[5],
     44                                                   :ontology => val[7]
    4045                                                   )
    4146  }
     
    100105cadl_section: c_complex_object
    101106  {
     107    assert_at(__FILE__,__LINE__){val[0].instance_of?(OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT)}
     108                     
    102109    result = val[0]
    103110  }
     
    112119    | c_complex_object_head SYM_MATCHES SYM_START_CBLOCK c_complex_object_body SYM_END_CBLOCK
    113120  {
    114     result = OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT.new
     121    result = OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT.new(
     122                                                                            :assumed_value => val[0],
     123                                                                            :attributes => val[2]
     124                                                                            )
    115125  }
    116126#    | c_complex_object_head error SYM_END_CBLOCK
     
    121131c_complex_object_id: type_identifier
    122132  {
    123     result = {:c_complex_object_id => {:type_identifier => val[0]}}
     133    result = val[0]
    124134  }
    125135  | type_identifier V_LOCAL_TERM_CODE_REF
     
    130140c_complex_object_body: c_any #-- used to indicate that any value of a type is ok
    131141  | c_attributes
     142  {
     143    result = OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT.new(:attributes => val[0])
     144  }
    132145
    133146
     
    135148
    136149c_object: v_c_domain_type
     150  {
     151    result = val[0]
     152  }
    137153  | c_complex_object
     154  {
     155    result = OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT.new
     156  }
    138157  | archetype_internal_ref
     158  {
     159    result = OpenEHR::AM::Archetype::Constraint_Model::ARCHETYPE_INTERNAL_REF.new
     160  }
    139161  | archetype_slot
     162  {
     163    result = OpenEHR::AM::Archetype::Constraint_Model::ARCHETYPE_SLOT.new
     164  }
    140165  | constraint_ref
     166  {
     167    result = OpenEHR::AM::Archetype::Constraint_Model::CONSTRAINT_REF.new
     168  }
    141169  | c_code_phrase
     170  {
     171    result = val[0]
     172  }
    142173  | c_ordinal
     174  {
     175    result = val[0]
     176  }
    143177  | c_primitive_object
     178  {
     179    result = val[0]
     180  }
    144181#  | v_c_domain_type
    145182#  | V_C_DOMAIN_TYPE
     
    170207# 'c_primitive_object' is an node representing a constraint on a primitive object type.
    171208c_primitive_object: c_primitive
     209  {
     210    assert_at(__FILE__,__LINE__){val[0].kind_of?(OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_PRIMITIVE)}
     211    result = OpenEHR::AM::Archetype::Constraint_Model::C_PRIMITIVE_OBJECT.new(:item => val[0])
     212  }
    172213
    173214c_primitive: c_integer
    174215  {
    175     @@log.info("#{__FILE__}:#{__LINE__}: c_integer = #{val[0]} at #{@filename}")
    176     result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_Integer.new
     216    @@log.info("#{__FILE__}:#{__LINE__}: c_integer = #{val[0]} at #{@filename}:#{@lineno}")
     217    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_INTEGER.new
    177218  }
    178219  | c_real
     220  {
     221    @@log.info("#{__FILE__}:#{__LINE__}: c_real = #{val[0]} at #{@filename}:#{@lineno}")
     222    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_REAL.new
     223  }
    179224  | c_date
     225  {
     226    @@log.info("#{__FILE__}:#{__LINE__}: c_date = #{val[0]} at #{@filename}:#{@lineno}")
     227    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_DATE.new
     228  }
    180229  | c_time
     230  {
     231    @@log.info("#{__FILE__}:#{__LINE__}: c_time = #{val[0]} at #{@filename}:#{@lineno}")
     232    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_TIME.new
     233  }
    181234  | c_date_time
     235  {
     236    @@log.info("#{__FILE__}:#{__LINE__}: c_date_time = #{val[0]} at #{@filename}:#{@lineno}")
     237    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_DATE_TIME.new
     238  }
    182239  | c_duration
     240  {
     241    @@log.info("#{__FILE__}:#{__LINE__}: c_duration = #{val[0]} at #{@filename}:#{@lineno}")
     242    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_DURATION.new
     243  }
    183244  | c_string
     245  {
     246    @@log.info("#{__FILE__}:#{__LINE__}: c_string = #{val[0]} at #{@filename}:#{@lineno}")
     247    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_STRING.new
     248  }
    184249  | c_boolean
     250  {
     251    assert_at(__FILE__,__LINE__){val[0].instance_of?(OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN)}
     252    @@log.info("#{__FILE__}:#{__LINE__}: c_boolean = #{val[0]} at #{@filename}:#{@lineno}")
     253    result = val[0]
     254  }
    185255
    186256c_any: Star_code
     
    190260
    191261c_attributes: c_attribute
     262  {
     263    result = [val[0]]
     264  }
    192265  | c_attributes c_attribute
     266  {
     267    result = (val[0] << val[1])
     268  }
    193269
    194270# 'c_attribute' is a node representing a constraint on an attribute in an object model.
    195271c_attribute: c_attr_head SYM_MATCHES SYM_START_CBLOCK c_attr_values SYM_END_CBLOCK
     272  {
     273    assert_at(__FILE__,__LINE__){ val[0].kind_of?(OpenEHR::AM::Archetype::Constraint_Model::C_ATTRIBUTE)}
     274    c_attribute = val[0]
     275    c_attribute.children = val[3]
     276    result = c_attribute
     277  }
    196278  | c_attr_head SYM_MATCHES START_REGEXP_BLOCK REGEXP_BODY END_REGEXP_BLOCK # added by akimichi
     279  {
     280    assert_at(__FILE__,__LINE__){ val[0].kind_of?(OpenEHR::AM::Archetype::Constraint_Model::C_ATTRIBUTE)}
     281    result = val[0]
     282  }
    197283  | c_attr_head SYM_MATCHES SYM_START_CBLOCK error SYM_END_CBLOCK
     284  {
     285    assert_at(__FILE__,__LINE__){ val[0].kind_of?(OpenEHR::AM::Archetype::Constraint_Model::C_ATTRIBUTE)}
     286    result = val[0]
     287  }
    198288
    199289
     
    201291  {
    202292    @@log.info("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER = #{val[0]}, c_existence = #{val[1]} at #{@filename}")
     293    result = OpenEHR::AM::Archetype::Constraint_Model::C_SINGLE_ATTRIBUTE.new(
     294                                                                              :rm_attribute_name => val[0],
     295                                                                              :existence => val[1]
     296                                                                              )
     297
    203298  }
    204299  | V_ATTRIBUTE_IDENTIFIER c_existence c_cardinality
    205300  {
     301    assert_at(__FILE__,__LINE__){ val[2].instance_of?(OpenEHR::AM::Archetype::Constraint_Model::CARDINALITY) }
    206302    @@log.info("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER: #{val[0]}, c_existence = #{val[1]}, c_cardinality = #{val[2]} at #{@filename}")
     303    result = OpenEHR::AM::Archetype::Constraint_Model::C_MULTIPLE_ATTRIBUTE.new(
     304                                                                                :rm_attribute_name => val[0],
     305                                                                                :existence => val[1],
     306                                                                                :cardinality => val[2]
     307                                                                                )
    207308  }
    208309
    209310c_attr_values: c_object
     311  {
     312    result = Array[val[0]]
     313  }
    210314  | c_attr_values c_object
     315  {
     316    result = (val[0] << val[1])
     317  }
    211318  | c_any # -- to allow a property to have any value
     319  {
     320    result = Array[val[0]]
     321  }
    212322
    213323### c_includes: #-- Empty
     
    237347
    238348arch_ontology: SYM_ONTOLOGY dadl_section
     349  {
     350    result = OpenEHR::AM::Archetype::Ontology::ARCHETYPE_ONTOLOGY.new
     351  }
    239352  | SYM_ONTOLOGY error
    240353
     
    260373  {
    261374    @@log.info("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}:#{@lineno}")
     375    result = val[0]
    262376  }
    263377  | V_ATTRIBUTE_IDENTIFIER error
    264378
    265379object_block: complex_object_block
     380  {
     381    result = val[0]
     382  }
    266383  | primitive_object_block
     384  {
     385    result = val[0]
     386  }
    267387
    268388complex_object_block: single_attr_object_block
     389  {
     390    result = val[0]
     391  }
    269392  | multiple_attr_object_block
     393  {
     394    result = val[0]
     395  }
    270396
    271397multiple_attr_object_block: untyped_multiple_attr_object_block
     398  {
     399    result = val[0]
     400  }
    272401  | type_identifier untyped_multiple_attr_object_block
     402  {
     403    result = val[0]
     404  }
    273405
    274406untyped_multiple_attr_object_block: multiple_attr_object_block_head keyed_objects SYM_END_DBLOCK
     407  {
     408    result = val[0]
     409  }
    275410
    276411multiple_attr_object_block_head: SYM_START_DBLOCK
    277   {
     412  { 
    278413    @@log.info("SYM_START_DBLOCK: #{val[0]} at #{@filename}:#{@lineno}")
     414    result = val[0]
    279415  }
    280416
     
    290426  {
    291427    @@log.info("object_key: [#{val[1]}] at #{@filename}:#{@lineno}")
     428    result = val[1]
    292429  }
    293430
     
    295432  | type_identifier untyped_single_attr_object_block
    296433untyped_single_attr_object_block: single_attr_object_complex_head SYM_END_DBLOCK # <>
     434  {
     435    @@log.info("#{__FILE__}:#{__LINE__}: single_attr_object_complex_head = #{val[0]} at #{@filename}:#{@lineno}")
     436    result = val[0]
     437  }
    297438  | single_attr_object_complex_head attr_vals SYM_END_DBLOCK
     439  {
     440    @@log.info("#{__FILE__}:#{__LINE__}: single_attr_object_complex_head = #{val[0]}, attr_vals = #{val[1]} at #{@filename}:#{@lineno}")
     441    result = val[0]
     442  }
    298443single_attr_object_complex_head: SYM_START_DBLOCK
    299444primitive_object_block: untyped_primitive_object_block
     445  {
     446    @@log.info("#{__FILE__}:#{__LINE__}: untyped_primitive_object_block = #{val[0]} at #{@filename}:#{@lineno}")
     447    result = val[0]
     448  }
    300449  | type_identifier untyped_primitive_object_block
     450  {
     451    @@log.info("#{__FILE__}:#{__LINE__}: type_identifier = #{val[0]}, untyped_primitive_object_block = #{val[1]} at #{@filename}:#{@lineno}")
     452    result = val[0]
     453  }
    301454untyped_primitive_object_block: SYM_START_DBLOCK primitive_object_value SYM_END_DBLOCK
    302455  {
    303     @@log.info("#{__FILE__}:#{__LINE__}: primitive_object_block = <#{val[2]}> at #{@filename}:#{@lineno}")
     456    @@log.info("#{__FILE__}:#{__LINE__}: primitive_object_block = <#{val[1]}> at #{@filename}:#{@lineno}")
     457    result = val[1]
    304458  }
    305459primitive_object_value: simple_value
     460  {
     461    result = val[0]
     462  }
    306463  | simple_list_value
     464  {
     465    result = val[0]
     466  }
    307467  | simple_interval_value
     468  {
     469    result = val[0]
     470  }
    308471  | term_code
     472  {
     473    result = val[0]
     474  }
    309475  | term_code_list_value
     476  {
     477    result = val[0]
     478  }
    310479simple_value: string_value
    311480  {
    312481    @@log.info("string_value: #{val[0]} at #{@filename}:#{@lineno}")
     482    result = val[0]
    313483  }
    314484  | integer_value
    315485  {
    316486    @@log.info("integer_value: #{val[0]} at #{@filename}:#{@lineno}")
     487    result = val[0]
    317488  }
    318489  | real_value
    319490  {
    320491    @@log.info("real_value: #{val[0]} at #{@filename}:#{@lineno}")
     492    result = val[0]
    321493  }
    322494  | boolean_value
    323495  {
    324496    @@log.info("boolean_value: #{val[0]} at #{@filename}:#{@lineno}")
     497    result = val[0]
    325498  }
    326499  | character_value
    327500  {
    328501    @@log.info("character_value: #{val[0]} at #{@filename}:#{@lineno}")
     502    result = val[0]
    329503  }
    330504  | date_value
    331505  {
    332506    @@log.info("date_value: #{val[0]} at #{@filename}:#{@lineno}")
     507    result = val[0]
    333508  }
    334509  | time_value
    335510  {
    336511    @@log.info("time_value: #{val[0]} at #{@filename}:#{@lineno}")
     512    result = val[0]
    337513  }
    338514  | date_time_value
    339515  {
    340516    @@log.info("date_time_value: #{val[0]} at #{@filename}:#{@lineno}")
     517    result = val[0]
    341518  }
    342519  | duration_value
    343520  {
    344521    @@log.info("duration_value: #{val[0]} at #{@filename}:#{@lineno}")
     522    result = val[0]
    345523  }
    346524  | uri_value
    347525  {
    348526    @@log.info("uri_value: #{val[0]} at #{@filename}:#{@lineno}")
    349   }
     527    result = val[0]
     528  }
     529
    350530simple_list_value: string_list_value
    351531  | integer_list_value
     
    368548  {
    369549    @@log.info("V_TYPE_IDENTIFIER: #{val[0]} at #{@filename}:#{@lineno}")
     550    result = val[0]
    370551  }
    371552  | V_GENERIC_TYPE_IDENTIFIER
    372553  {
    373554    @@log.info("V_GENERIC_TYPE_IDENTIFIER: #{val[0]} at #{@filename}:#{@lineno}")
     555    result = val[0]
    374556  }
    375557
     
    377559  {
    378560    @@log.info("V_STRING: #{val[0]} at #{@filename}:#{@lineno}")
     561    result = val[0]
    379562  }
    380563
     
    384567
    385568integer_value: V_INTEGER
     569  {
     570    begin
     571      integer = Integer(val[0])
     572    rescue
     573      raise
     574    end
     575    result = integer
     576  }
    386577  | Plus_code V_INTEGER
     578  {
     579    begin
     580      integer = Integer(val[0])
     581    rescue
     582      raise
     583    end
     584    result = integer
     585  }
    387586  | Minus_code V_INTEGER
     587  {
     588    begin
     589      integer = Integer(val[0])
     590    rescue
     591      raise
     592    end
     593    result = - integer
     594  }
    388595###   | '+' V_INTEGER
    389596###   | '-' V_INTEGER
     
    488695  {
    489696    @@log.info("V_ISO8601_DURATION: #{val[0]} at #{@filename}:#{@lineno}")
     697    result = val[0]
    490698  }
    491699
     
    598806
    599807c_existence: #-- default to 1..1
    600     | SYM_EXISTENCE SYM_MATCHES SYM_START_CBLOCK existence_spec SYM_END_CBLOCK
     808    {
     809    result = Range.new(1,1)
     810  }
     811  | SYM_EXISTENCE SYM_MATCHES SYM_START_CBLOCK existence_spec SYM_END_CBLOCK
     812  {
     813    result = val[3]
     814  }
    601815
    602816existence_spec:  V_INTEGER #-- can only be 0 or 1
     817  {
     818    begin
     819      integer = Integer(val[0])
     820    rescue
     821      raise
     822    end
     823    result = integer
     824  }
    603825  | V_INTEGER SYM_ELLIPSIS V_INTEGER #-- can only be 0..0, 0..1, 1..1
     826  {
     827    begin
     828      from_integer = Integer(val[0])
     829      to_integer = Integer(val[2])
     830    rescue
     831      raise
     832    end
     833    result = Range.new(from_integer,to_integer)
     834  }
    604835
    605836c_cardinality: SYM_CARDINALITY SYM_MATCHES SYM_START_CBLOCK cardinality_spec SYM_END_CBLOCK
     837  {
     838    result = OpenEHR::AM::Archetype::Constraint_Model::CARDINALITY.new
     839  }
    606840
    607841cardinality_spec: occurrence_spec
     
    687921
    688922c_boolean_spec: SYM_TRUE
     923  {
     924    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid => true)
     925  }
    689926  | SYM_FALSE
     927  {
     928    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid => false)
     929  }
    690930  | SYM_TRUE Comma_code SYM_FALSE
     931  {
     932    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid => true,:false_valid => false)
     933  }
    691934  | SYM_FALSE Comma_code SYM_TRUE
     935  {
     936    result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid => false,:false_valid => true)
     937  }
    692938
    693939c_boolean: c_boolean_spec
     940  {
     941    result = val[0]
     942  }
    694943  | c_boolean_spec Semicolon_code boolean_value
     944  {
     945    raise 'Not implemented yet'
     946  }
    695947  | c_boolean_spec Semicolon_code error
    696 #  | c_boolean_spec ';' error
     948  {
     949    raise 'Not implemented yet'
     950  }
    697951
    698952c_ordinal: c_ordinal_spec
    699953  | c_ordinal_spec Semicolon_code integer_value
    700954  | c_ordinal_spec Semicolon_code error
    701 #  | c_ordinal_spec ';' error
    702955
    703956c_ordinal_spec: ordinal
    704957  | c_ordinal_spec Comma_code ordinal
    705 #  | c_ordinal_spec ',' ordinal
    706958
    707959ordinal: integer_value SYM_INTERVAL_DELIM V_QUALIFIED_TERM_CODE_REF
     
    7561008
    7571009---- inner
     1010
     1011def assert_at(file,line, message = "")
     1012  unless yield
     1013    raise "Assertion failed !: #{file}, #{line}: #{message}"
     1014  end
     1015end
    7581016
    7591017@@log = Logger.new('log/parser.log','daily')
Note: See TracChangeset for help on using the changeset viewer.