Changeset 22 for ruby/trunk/adl_parser/lib/parser.y
- Timestamp:
- May 1, 2008, 1:34:51 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ruby/trunk/adl_parser/lib/parser.y
r21 r22 35 35 archetype: arch_identification arch_specialisation arch_concept arch_language arch_description arch_definition arch_invariant arch_ontology 36 36 { 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 37 41 result = OpenEHR::AM::Archetype::ARCHETYPE.new( 38 42 :description => val[4], 39 :definition => val[5] 43 :definition => val[5], 44 :ontology => val[7] 40 45 ) 41 46 } … … 100 105 cadl_section: c_complex_object 101 106 { 107 assert_at(__FILE__,__LINE__){val[0].instance_of?(OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT)} 108 102 109 result = val[0] 103 110 } … … 112 119 | c_complex_object_head SYM_MATCHES SYM_START_CBLOCK c_complex_object_body SYM_END_CBLOCK 113 120 { 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 ) 115 125 } 116 126 # | c_complex_object_head error SYM_END_CBLOCK … … 121 131 c_complex_object_id: type_identifier 122 132 { 123 result = {:c_complex_object_id => {:type_identifier => val[0]}}133 result = val[0] 124 134 } 125 135 | type_identifier V_LOCAL_TERM_CODE_REF … … 130 140 c_complex_object_body: c_any #-- used to indicate that any value of a type is ok 131 141 | c_attributes 142 { 143 result = OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT.new(:attributes => val[0]) 144 } 132 145 133 146 … … 135 148 136 149 c_object: v_c_domain_type 150 { 151 result = val[0] 152 } 137 153 | c_complex_object 154 { 155 result = OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT.new 156 } 138 157 | archetype_internal_ref 158 { 159 result = OpenEHR::AM::Archetype::Constraint_Model::ARCHETYPE_INTERNAL_REF.new 160 } 139 161 | archetype_slot 162 { 163 result = OpenEHR::AM::Archetype::Constraint_Model::ARCHETYPE_SLOT.new 164 } 140 165 | constraint_ref 166 { 167 result = OpenEHR::AM::Archetype::Constraint_Model::CONSTRAINT_REF.new 168 } 141 169 | c_code_phrase 170 { 171 result = val[0] 172 } 142 173 | c_ordinal 174 { 175 result = val[0] 176 } 143 177 | c_primitive_object 178 { 179 result = val[0] 180 } 144 181 # | v_c_domain_type 145 182 # | V_C_DOMAIN_TYPE … … 170 207 # 'c_primitive_object' is an node representing a constraint on a primitive object type. 171 208 c_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 } 172 213 173 214 c_primitive: c_integer 174 215 { 175 @@log.info("#{__FILE__}:#{__LINE__}: c_integer = #{val[0]} at #{@filename} ")176 result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_I nteger.new216 @@log.info("#{__FILE__}:#{__LINE__}: c_integer = #{val[0]} at #{@filename}:#{@lineno}") 217 result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_INTEGER.new 177 218 } 178 219 | 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 } 179 224 | 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 } 180 229 | 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 } 181 234 | 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 } 182 239 | 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 } 183 244 | 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 } 184 249 | 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 } 185 255 186 256 c_any: Star_code … … 190 260 191 261 c_attributes: c_attribute 262 { 263 result = [val[0]] 264 } 192 265 | c_attributes c_attribute 266 { 267 result = (val[0] << val[1]) 268 } 193 269 194 270 # 'c_attribute' is a node representing a constraint on an attribute in an object model. 195 271 c_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 } 196 278 | 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 } 197 283 | 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 } 198 288 199 289 … … 201 291 { 202 292 @@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 203 298 } 204 299 | V_ATTRIBUTE_IDENTIFIER c_existence c_cardinality 205 300 { 301 assert_at(__FILE__,__LINE__){ val[2].instance_of?(OpenEHR::AM::Archetype::Constraint_Model::CARDINALITY) } 206 302 @@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 ) 207 308 } 208 309 209 310 c_attr_values: c_object 311 { 312 result = Array[val[0]] 313 } 210 314 | c_attr_values c_object 315 { 316 result = (val[0] << val[1]) 317 } 211 318 | c_any # -- to allow a property to have any value 319 { 320 result = Array[val[0]] 321 } 212 322 213 323 ### c_includes: #-- Empty … … 237 347 238 348 arch_ontology: SYM_ONTOLOGY dadl_section 349 { 350 result = OpenEHR::AM::Archetype::Ontology::ARCHETYPE_ONTOLOGY.new 351 } 239 352 | SYM_ONTOLOGY error 240 353 … … 260 373 { 261 374 @@log.info("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}:#{@lineno}") 375 result = val[0] 262 376 } 263 377 | V_ATTRIBUTE_IDENTIFIER error 264 378 265 379 object_block: complex_object_block 380 { 381 result = val[0] 382 } 266 383 | primitive_object_block 384 { 385 result = val[0] 386 } 267 387 268 388 complex_object_block: single_attr_object_block 389 { 390 result = val[0] 391 } 269 392 | multiple_attr_object_block 393 { 394 result = val[0] 395 } 270 396 271 397 multiple_attr_object_block: untyped_multiple_attr_object_block 398 { 399 result = val[0] 400 } 272 401 | type_identifier untyped_multiple_attr_object_block 402 { 403 result = val[0] 404 } 273 405 274 406 untyped_multiple_attr_object_block: multiple_attr_object_block_head keyed_objects SYM_END_DBLOCK 407 { 408 result = val[0] 409 } 275 410 276 411 multiple_attr_object_block_head: SYM_START_DBLOCK 277 { 412 { 278 413 @@log.info("SYM_START_DBLOCK: #{val[0]} at #{@filename}:#{@lineno}") 414 result = val[0] 279 415 } 280 416 … … 290 426 { 291 427 @@log.info("object_key: [#{val[1]}] at #{@filename}:#{@lineno}") 428 result = val[1] 292 429 } 293 430 … … 295 432 | type_identifier untyped_single_attr_object_block 296 433 untyped_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 } 297 438 | 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 } 298 443 single_attr_object_complex_head: SYM_START_DBLOCK 299 444 primitive_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 } 300 449 | 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 } 301 454 untyped_primitive_object_block: SYM_START_DBLOCK primitive_object_value SYM_END_DBLOCK 302 455 { 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] 304 458 } 305 459 primitive_object_value: simple_value 460 { 461 result = val[0] 462 } 306 463 | simple_list_value 464 { 465 result = val[0] 466 } 307 467 | simple_interval_value 468 { 469 result = val[0] 470 } 308 471 | term_code 472 { 473 result = val[0] 474 } 309 475 | term_code_list_value 476 { 477 result = val[0] 478 } 310 479 simple_value: string_value 311 480 { 312 481 @@log.info("string_value: #{val[0]} at #{@filename}:#{@lineno}") 482 result = val[0] 313 483 } 314 484 | integer_value 315 485 { 316 486 @@log.info("integer_value: #{val[0]} at #{@filename}:#{@lineno}") 487 result = val[0] 317 488 } 318 489 | real_value 319 490 { 320 491 @@log.info("real_value: #{val[0]} at #{@filename}:#{@lineno}") 492 result = val[0] 321 493 } 322 494 | boolean_value 323 495 { 324 496 @@log.info("boolean_value: #{val[0]} at #{@filename}:#{@lineno}") 497 result = val[0] 325 498 } 326 499 | character_value 327 500 { 328 501 @@log.info("character_value: #{val[0]} at #{@filename}:#{@lineno}") 502 result = val[0] 329 503 } 330 504 | date_value 331 505 { 332 506 @@log.info("date_value: #{val[0]} at #{@filename}:#{@lineno}") 507 result = val[0] 333 508 } 334 509 | time_value 335 510 { 336 511 @@log.info("time_value: #{val[0]} at #{@filename}:#{@lineno}") 512 result = val[0] 337 513 } 338 514 | date_time_value 339 515 { 340 516 @@log.info("date_time_value: #{val[0]} at #{@filename}:#{@lineno}") 517 result = val[0] 341 518 } 342 519 | duration_value 343 520 { 344 521 @@log.info("duration_value: #{val[0]} at #{@filename}:#{@lineno}") 522 result = val[0] 345 523 } 346 524 | uri_value 347 525 { 348 526 @@log.info("uri_value: #{val[0]} at #{@filename}:#{@lineno}") 349 } 527 result = val[0] 528 } 529 350 530 simple_list_value: string_list_value 351 531 | integer_list_value … … 368 548 { 369 549 @@log.info("V_TYPE_IDENTIFIER: #{val[0]} at #{@filename}:#{@lineno}") 550 result = val[0] 370 551 } 371 552 | V_GENERIC_TYPE_IDENTIFIER 372 553 { 373 554 @@log.info("V_GENERIC_TYPE_IDENTIFIER: #{val[0]} at #{@filename}:#{@lineno}") 555 result = val[0] 374 556 } 375 557 … … 377 559 { 378 560 @@log.info("V_STRING: #{val[0]} at #{@filename}:#{@lineno}") 561 result = val[0] 379 562 } 380 563 … … 384 567 385 568 integer_value: V_INTEGER 569 { 570 begin 571 integer = Integer(val[0]) 572 rescue 573 raise 574 end 575 result = integer 576 } 386 577 | Plus_code V_INTEGER 578 { 579 begin 580 integer = Integer(val[0]) 581 rescue 582 raise 583 end 584 result = integer 585 } 387 586 | Minus_code V_INTEGER 587 { 588 begin 589 integer = Integer(val[0]) 590 rescue 591 raise 592 end 593 result = - integer 594 } 388 595 ### | '+' V_INTEGER 389 596 ### | '-' V_INTEGER … … 488 695 { 489 696 @@log.info("V_ISO8601_DURATION: #{val[0]} at #{@filename}:#{@lineno}") 697 result = val[0] 490 698 } 491 699 … … 598 806 599 807 c_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 } 601 815 602 816 existence_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 } 603 825 | 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 } 604 835 605 836 c_cardinality: SYM_CARDINALITY SYM_MATCHES SYM_START_CBLOCK cardinality_spec SYM_END_CBLOCK 837 { 838 result = OpenEHR::AM::Archetype::Constraint_Model::CARDINALITY.new 839 } 606 840 607 841 cardinality_spec: occurrence_spec … … 687 921 688 922 c_boolean_spec: SYM_TRUE 923 { 924 result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid => true) 925 } 689 926 | SYM_FALSE 927 { 928 result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid => false) 929 } 690 930 | 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 } 691 934 | 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 } 692 938 693 939 c_boolean: c_boolean_spec 940 { 941 result = val[0] 942 } 694 943 | c_boolean_spec Semicolon_code boolean_value 944 { 945 raise 'Not implemented yet' 946 } 695 947 | c_boolean_spec Semicolon_code error 696 # | c_boolean_spec ';' error 948 { 949 raise 'Not implemented yet' 950 } 697 951 698 952 c_ordinal: c_ordinal_spec 699 953 | c_ordinal_spec Semicolon_code integer_value 700 954 | c_ordinal_spec Semicolon_code error 701 # | c_ordinal_spec ';' error702 955 703 956 c_ordinal_spec: ordinal 704 957 | c_ordinal_spec Comma_code ordinal 705 # | c_ordinal_spec ',' ordinal706 958 707 959 ordinal: integer_value SYM_INTERVAL_DELIM V_QUALIFIED_TERM_CODE_REF … … 756 1008 757 1009 ---- inner 1010 1011 def assert_at(file,line, message = "") 1012 unless yield 1013 raise "Assertion failed !: #{file}, #{line}: #{message}" 1014 end 1015 end 758 1016 759 1017 @@log = Logger.new('log/parser.log','daily')
Note:
See TracChangeset
for help on using the changeset viewer.