source: ruby/trunk/lib/adl_parser/lib/parser.y@ 318

Last change on this file since 318 was 318, checked in by Tatsukawa, Akimichi, 15 years ago

successfully parsing all the adl files under http://www.openehr.org/svn/knowledge/archetypes/dev/adl/openehr/ehr directory

File size: 42.2 KB
RevLine 
[4]1
[307]2class OpenEhr::ADL::Parser
[4]3
4#options omit_action_call
5
6prechigh
7
8 nonassoc UMINUS UPLUS
9 left '*' '/'
10 left '+' '-'
11
12 nonassoc SYM_EQ
13 nonassoc SYM_NE
14 nonassoc SYM_LT
15 nonassoc SYM_START_DBLOCK
16 nonassoc SYM_START_CBLOCK
17 nonassoc SYM_GT
18 nonassoc SYM_END_CBLOCK
19 nonassoc SYM_END_DBLOCK
20 nonassoc SYM_LE
21 nonassoc SYM_GE
22
23preclow
24
25
26rule
27### http://svn.openehr.org/ref_impl_eiffel/TRUNK/components/adl_parser/src/syntax/adl/parser/adl_validator.y
28
29input: archetype EOF
[21]30 {
31 result = val[0]
32 }
[4]33 | error
34
[21]35archetype: arch_identification arch_specialisation arch_concept arch_language arch_description arch_definition arch_invariant arch_ontology
36 {
[22]37 assert_at(__FILE__,__LINE__) do
[318]38 val[4].instance_of?(OpenEhr::AM::Archetype::Archetype_Description::ARCHETYPE_DESCRIPTION) and val[5].instance_of?(OpenEhr::AM::Archetype::ConstraintModel::C_COMPLEX_OBJECT) and val[7].instance_of?(OpenEhr::AM::Archetype::Ontology::ARCHETYPE_ONTOLOGY)
[22]39 end
40
[26]41 archetype_id = val[0][:archetype_id]
[257]42 parent_archtype_id = val[1][:parent_archtype_id] if val[1]
[26]43 adl_version = val[0][:arch_head][:arch_meta_data][:adl_version]
[307]44 concept = val[2][:arch_concept]
[26]45 language = val[3][:arch_language]
[307]46 archetype = OpenEhr::AM::Archetype::ARCHETYPE.create(
[26]47 :archetype_id => archetype_id,
[257]48 :parent_archtype_id => parent_archtype_id,
[26]49 :adl_version => adl_version,
50 :concept => concept,
51 :description => val[4],
52 :definition => val[5],
53 :ontology => val[7]
54 ) do |archetype|
55 archetype.original_language = language
56 end
[283]57 @@logger.debug("#{__FILE__}:#{__LINE__}: archetype = #{archetype.to_yaml} at #{@filename}:#{@lineno}")
[26]58 result = archetype
[21]59 }
[4]60
61
62arch_identification: arch_head V_ARCHETYPE_ID
[24]63 {
64 result = {:arch_head => val[0], :archetype_id => val[1] }
65 }
[4]66 | SYM_ARCHETYPE error
[24]67 {
68 raise
69 }
[4]70
71arch_head: SYM_ARCHETYPE
[24]72 {
73 result = {:arch_meta_data => nil }
74 }
[4]75 | SYM_ARCHETYPE arch_meta_data
[24]76 {
[26]77 result = val[1]
[24]78 }
[4]79
80arch_meta_data: Left_parenthesis_code arch_meta_data_items Right_parenthesis_code
[24]81 {
[26]82 result = {:arch_meta_data => val[1] }
[24]83 }
[4]84
85arch_meta_data_items: arch_meta_data_item
[24]86 {
[26]87 result = val[0]
[24]88 }
[19]89 | arch_meta_data_items Semicolon_code arch_meta_data_item
[24]90 {
[26]91 result = val[0].merge(val[2])
[24]92 }
[4]93
[24]94
[4]95arch_meta_data_item: SYM_ADL_VERSION SYM_EQ V_VERSION_STRING
[24]96 {
[26]97 result = {:adl_version => val[2], :is_controlled => false }
[24]98 }
[4]99 | SYM_IS_CONTROLLED
[24]100 {
[26]101 result = {:is_controlled => true }
[24]102 }
[4]103
104# Define specialization in which its constraints are narrower than those of the parent.
105# Any data created via the use of the specialized archetype shall be conformant both to it and its parent.
106arch_specialisation: #-- empty is ok
107 | SYM_SPECIALIZE V_ARCHETYPE_ID
[257]108 {
109 result = {:parent_archtype_id => val[1]}
110 }
[4]111 | SYM_SPECIALIZE error
112
113arch_concept: SYM_CONCEPT V_LOCAL_TERM_CODE_REF
[26]114 {
115 result = {:arch_concept => val[1] }
116 }
[4]117 | SYM_CONCEPT error
118
119#arch_language: #-- empty is ok for ADL 1.4 tools
120# | SYM_LANGUAGE V_DADL_TEXT
121# | SYM_LANGUAGE error
122
123arch_language: #-- empty is ok for ADL 1.4 tools
[26]124 {
125 result = {:arch_language => nil}
126 }
[4]127 | SYM_LANGUAGE dadl_section
[16]128 {
[26]129 result = {:arch_language => val[1]}
[16]130 }
131 | SYM_LANGUAGE error
[4]132
133#arch_description: #-- no meta-data ok
134# | SYM_DESCRIPTION V_DADL_TEXT
135# | SYM_DESCRIPTION error
136
137arch_description: #-- no meta-data ok
138 | SYM_DESCRIPTION dadl_section
[21]139 {
[307]140 result = OpenEhr::AM::Archetype::Archetype_Description::ARCHETYPE_DESCRIPTION.new(:details => val[1])
[21]141 }
142 | SYM_DESCRIPTION error
143
[4]144#arch_definition: SYM_DEFINITION V_CADL_TEXT
145# | SYM_DEFINITION error
146arch_definition: SYM_DEFINITION cadl_section
[21]147 {
148 result = val[1]
149 }
[4]150 | SYM_DEFINITION error
151
152
153### cADL section
154cadl_section: c_complex_object
[35]155 {
[318]156 assert_at(__FILE__,__LINE__){val[0].instance_of?(OpenEhr::AM::Archetype::ConstraintModel::C_COMPLEX_OBJECT)}
[261]157 @@logger.debug("#{__FILE__}:#{__LINE__}: c_complex_object = #{val[0]} at #{@filename}:#{@lineno}")
[21]158 result = val[0]
159 }
[4]160 | assertions
[23]161 {
162 result = val[0]
163 }
[4]164# | error
165
166#c_complex_object: c_complex_object_head SYM_MATCHES SYM_START_CBLOCK c_complex_object_body SYM_END_CBLOCK
[32]167c_complex_object: c_complx_object_head SYM_MATCHES START_REGEXP_BLOCK REGEXP_BODY END_REGEXP_BLOCK # added by akimichi
[21]168 {
[318]169 result = OpenEhr::AM::Archetype::ConstraintModel::C_COMPLEX_OBJECT.create(:attributes => val[3]) do |c_complex_object|
[23]170 c_complex_object.node_id = val[0][:c_complex_object_id][:local_term_code_ref]
171 c_complex_object.rm_type_name = val[0][:c_complex_object_id][:type_identifier]
172 c_complex_object.occurrences = val[0][:c_occurrences]
173 end
[21]174 }
[4]175 | c_complex_object_head SYM_MATCHES SYM_START_CBLOCK c_complex_object_body SYM_END_CBLOCK
[21]176 {
[318]177 result = OpenEhr::AM::Archetype::ConstraintModel::C_COMPLEX_OBJECT.create(:attributes => val[3]) do |c_complex_object|
[23]178 c_complex_object.node_id = val[0][:c_complex_object_id][:local_term_code_ref]
179 c_complex_object.rm_type_name = val[0][:c_complex_object_id][:type_identifier]
180 c_complex_object.occurrences = val[0][:c_occurrences]
181 end
[21]182 }
183# | c_complex_object_head error SYM_END_CBLOCK
[4]184# | c_complex_object_head SYM_MATCHES SYM_START_CBLOCK c_complex_object_body c_invariants SYM_END_CBLOCK
185
186c_complex_object_head: c_complex_object_id c_occurrences
[23]187 {
188 result = {:c_complex_object_id => val[0], :c_occurrences => val[1]}
189 }
[4]190
191c_complex_object_id: type_identifier
[16]192 {
[23]193 result = {:type_identifier => val[0]}
[16]194 }
[4]195 | type_identifier V_LOCAL_TERM_CODE_REF
[16]196 {
[23]197 result = {:type_identifier => val[0], :local_term_code_ref => val[1]}
[16]198 }
[4]199
200c_complex_object_body: c_any #-- used to indicate that any value of a type is ok
201 | c_attributes
[22]202 {
[318]203 result = OpenEhr::AM::Archetype::ConstraintModel::C_COMPLEX_OBJECT.new(:attributes => val[0])
[22]204 }
[4]205
206
207#------------------------- node types -----------------------
[261]208### http://www.openehr.org/svn/ref_impl_eiffel/TRUNK/components/adl_parser/src/syntax/cadl/parser/cadl_validator.html
209### c_object: c_complex_object
210### | archetype_internal_ref
211### | archetype_slot
212### | constraint_ref
213### | c_code_phrase
214### | c_ordinal
215### | c_primitive_object
216### | V_C_DOMAIN_TYPE
217### | ERR_C_DOMAIN_TYPE
218### | error
219c_object: c_complex_object
[32]220 {
[261]221 @@logger.debug("#{__FILE__}:#{__LINE__}: c_complex_object = #{val[0].inspect} at #{@filename}:#{@lineno}")
[22]222 result = val[0]
223 }
[4]224 | archetype_internal_ref
[32]225 {
[318]226 result = OpenEhr::AM::Archetype::ConstraintModel::ARCHETYPE_INTERNAL_REF.create do |archetype_internal_ref|
[32]227 archetype_internal_ref.target_path = val[0][:absolute_path]
228 archetype_internal_ref.rm_type_name = val[0][:type_identifier]
229 archetype_internal_ref.occurrences = val[0][:c_occurrences]
230 end
[22]231 }
[4]232 | archetype_slot
[32]233 {
234 result = val[0]
[22]235 }
[4]236 | constraint_ref
[32]237 {
[318]238 result = OpenEhr::AM::Archetype::ConstraintModel::CONSTRAINT_REF.create do |constraint_ref|
[32]239 constraint_ref.reference = val[0]
240 end
[22]241 }
[4]242 | c_code_phrase
[32]243 {
[22]244 result = val[0]
245 }
[4]246 | c_ordinal
[32]247 {
[22]248 result = val[0]
249 }
[4]250 | c_primitive_object
[32]251 {
[22]252 result = val[0]
253 }
[261]254 | v_c_domain_type
255 {
256 result = val[0]
257 }
[19]258# | v_c_domain_type
[14]259# | V_C_DOMAIN_TYPE
260 # this is an attempt to match a dADL section inside cADL. It will
261 # probably never work 100% properly since there can be '>' inside "||"
262 # ranges, and also strings containing any character, e.g. units string
263 # contining "{}" chars. The real solution is to use the dADL parser on
264 # the buffer from the current point on and be able to fast-forward the
265 # cursor to the last character matched by the dADL scanner
[307]266### ----------/* V_C_DOMAIN_TYPE - sections of dADL syntax */ ------------------------------------------------- ----------/* V_C_DOMAIN_TYPE - sections of dADL syntax */ -------------------------------------------------
267
268
269### [A-Z][a-zA-Z0-9_]*[ \n]*< { -- match a pattern like 'Type_Identifier whitespace <' [A-Z][a-zA-Z0-9_]*[ \n]*< { -- match a pattern like 'Type_Identifier whitespace <'
270### set_start_condition (IN_C_DOMAIN_TYPE) set_start_condition (IN_C_DOMAIN_TYPE)
271### } }
272
273### <IN_C_DOMAIN_TYPE>[^}>]*>[ \n]*[^>}A-Z] { -- match up to next > not followed by a '}' or '>' <IN_C_DOMAIN_TYPE>[^}>]*>[ \n]*[^>}A-Z] { -- match up to next > not followed by a '}' or '>'
274### in_buffer.append_string (text) in_buffer.append_string (text)
275### } }
276
277### <IN_C_DOMAIN_TYPE>[^}>]*>+[ \n]*[}A-Z] { -- final section - '...> whitespace } or beginning of a type identifier' <IN_C_DOMAIN_TYPE>[^}>]*>+[ \n]*[}A-Z] { -- final section - '...> whitespace } or beginning of a type identifier'
278
279### <IN_C_DOMAIN_TYPE>[^}>]*[ \n]*} { -- match up to next '}' not preceded by a '>' <IN_C_DOMAIN_TYPE>[^}>]*[ \n]*} { -- match up to next '}' not preceded by a '>'
280### in_buffer.append_string (text) in_buffer.append_string (text)
281### } }
282
283
[4]284 | ERR_C_DOMAIN_TYPE
285 | error
286
[16]287v_c_domain_type: START_V_C_DOMAIN_TYPE_BLOCK dadl_section END_V_C_DOMAIN_TYPE_BLOCK
[23]288 {
289 result = val[1]
290 }
[14]291
[4]292# 'archetype_internal_ref' is a node that refers to a previously defined object node in the same archetype.
293archetype_internal_ref: SYM_USE_NODE type_identifier c_occurrences absolute_path
[32]294 {
295 result = {:type_identifier => val[1], :c_occurrences => val[2], :absolute_path => val[3] }
296 }
[4]297 | SYM_USE_NODE type_identifier error
298
299# 'archetype_slot' is a node whose statements define a constraint that determines which other archetypes may appear at that point in the current archetype.
300archetype_slot: c_archetype_slot_head SYM_MATCHES SYM_START_CBLOCK c_includes c_excludes SYM_END_CBLOCK
[32]301 {
[318]302 result = OpenEhr::AM::Archetype::ConstraintModel::ARCHETYPE_SLOT.create do |archetype_slot|
[32]303 archetype_slot.includes = val[3]
304 archetype_slot.excludes = val[4]
305 archetype_slot.rm_type_name = val[0][:c_archetype_slot_id]
306 archetype_slot.occurrences = val[0][:c_occurrences]
307 end
308 }
[4]309c_archetype_slot_head: c_archetype_slot_id c_occurrences
[32]310 {
311 result = {:c_archetype_slot_id => val[0],:c_occurrences => val[1]}
312 }
[4]313
314c_archetype_slot_id: SYM_ALLOW_ARCHETYPE type_identifier
[32]315 {
316 result = val[1]
317 }
[4]318 | SYM_ALLOW_ARCHETYPE type_identifier V_LOCAL_TERM_CODE_REF
319 | SYM_ALLOW_ARCHETYPE error
320
321# 'c_primitive_object' is an node representing a constraint on a primitive object type.
322c_primitive_object: c_primitive
[22]323 {
[318]324 assert_at(__FILE__,__LINE__){val[0].kind_of?(OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_PRIMITIVE)}
325 result = OpenEhr::AM::Archetype::ConstraintModel::C_PRIMITIVE_OBJECT.create do |c_primitive_object|
[32]326 c_primitive_object.item = val[0]
327 end
[22]328 }
[4]329
330c_primitive: c_integer
[21]331 {
[261]332 @@logger.debug("#{__FILE__}:#{__LINE__}: c_integer = #{val[0]} at #{@filename}:#{@lineno}")
[318]333 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_INTEGER.create do |c_integer|
[32]334 c_integer.list
335 c_integer.range
336 c_integer.assumed_value
337 end
[21]338 }
[4]339 | c_real
[22]340 {
[261]341 @@logger.debug("#{__FILE__}:#{__LINE__}: c_real = #{val[0]} at #{@filename}:#{@lineno}")
[318]342 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_REAL.new
[22]343 }
[4]344 | c_date
[22]345 {
[261]346 @@logger.debug("#{__FILE__}:#{__LINE__}: c_date = #{val[0]} at #{@filename}:#{@lineno}")
[318]347 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_DATE.new
[22]348 }
[4]349 | c_time
[22]350 {
[261]351 @@logger.debug("#{__FILE__}:#{__LINE__}: c_time = #{val[0]} at #{@filename}:#{@lineno}")
[318]352 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_TIME.new
[22]353 }
[4]354 | c_date_time
[22]355 {
[261]356 @@logger.debug("#{__FILE__}:#{__LINE__}: c_date_time = #{val[0]} at #{@filename}:#{@lineno}")
[318]357 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_DATE_TIME.new
[22]358 }
[4]359 | c_duration
[22]360 {
[261]361 @@logger.debug("#{__FILE__}:#{__LINE__}: c_duration = #{val[0]} at #{@filename}:#{@lineno}")
[318]362 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_DURATION.new
[22]363 }
[4]364 | c_string
[22]365 {
[261]366 @@logger.debug("#{__FILE__}:#{__LINE__}: c_string = #{val[0]} at #{@filename}:#{@lineno}")
[318]367 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_STRING.new
[22]368 }
[4]369 | c_boolean
[22]370 {
[318]371 assert_at(__FILE__,__LINE__){val[0].instance_of?(OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_BOOLEAN)}
[261]372 @@logger.debug("#{__FILE__}:#{__LINE__}: c_boolean = #{val[0]} at #{@filename}:#{@lineno}")
[22]373 result = val[0]
374 }
[4]375
376c_any: Star_code
377#c_any: '*'
378
379#---------------- BODY - relationships ----------------
380
381c_attributes: c_attribute
[22]382 {
383 result = [val[0]]
384 }
[4]385 | c_attributes c_attribute
[22]386 {
387 result = (val[0] << val[1])
388 }
[4]389
390# 'c_attribute' is a node representing a constraint on an attribute in an object model.
391c_attribute: c_attr_head SYM_MATCHES SYM_START_CBLOCK c_attr_values SYM_END_CBLOCK
[22]392 {
[318]393 assert_at(__FILE__,__LINE__){ val[0].kind_of?(OpenEhr::AM::Archetype::ConstraintModel::C_ATTRIBUTE)}
[22]394 c_attribute = val[0]
395 c_attribute.children = val[3]
396 result = c_attribute
397 }
[4]398 | c_attr_head SYM_MATCHES START_REGEXP_BLOCK REGEXP_BODY END_REGEXP_BLOCK # added by akimichi
[22]399 {
[318]400 assert_at(__FILE__,__LINE__){ val[0].kind_of?(OpenEhr::AM::Archetype::ConstraintModel::C_ATTRIBUTE)}
[22]401 result = val[0]
402 }
[4]403 | c_attr_head SYM_MATCHES SYM_START_CBLOCK error SYM_END_CBLOCK
[22]404 {
[318]405 assert_at(__FILE__,__LINE__){ val[0].kind_of?(OpenEhr::AM::Archetype::ConstraintModel::C_ATTRIBUTE)}
[22]406 result = val[0]
407 }
[4]408
409
410c_attr_head: V_ATTRIBUTE_IDENTIFIER c_existence
[19]411 {
[261]412 @@logger.debug("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER = #{val[0]}, c_existence = #{val[1]} at #{@filename}")
[318]413 result = OpenEhr::AM::Archetype::ConstraintModel::C_SINGLE_ATTRIBUTE.new(
[22]414 :rm_attribute_name => val[0],
415 :existence => val[1]
416 )
417
[19]418 }
[4]419 | V_ATTRIBUTE_IDENTIFIER c_existence c_cardinality
[19]420 {
[318]421 assert_at(__FILE__,__LINE__){ val[2].instance_of?(OpenEhr::AM::Archetype::ConstraintModel::CARDINALITY) }
[261]422 @@logger.debug("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER: #{val[0]}, c_existence = #{val[1]}, c_cardinality = #{val[2]} at #{@filename}")
[318]423 result = OpenEhr::AM::Archetype::ConstraintModel::C_MULTIPLE_ATTRIBUTE.new(
[22]424 :rm_attribute_name => val[0],
425 :existence => val[1],
426 :cardinality => val[2]
427 )
[19]428 }
[4]429
430c_attr_values: c_object
[22]431 {
432 result = Array[val[0]]
433 }
[4]434 | c_attr_values c_object
[22]435 {
436 result = (val[0] << val[1])
437 }
[4]438 | c_any # -- to allow a property to have any value
[22]439 {
440 result = Array[val[0]]
441 }
[4]442
443### c_includes: #-- Empty
444### | SYM_INCLUDE assertions
445c_includes: #-- Empty
446 | SYM_INCLUDE invariants
[32]447{
448 result = val[1]
449}
[4]450
451### c_excludes: #-- Empty
452### | SYM_EXCLUDE assertions
453c_excludes: #-- Empty
454 | SYM_EXCLUDE invariants
[32]455{
456 result = val[1]
457}
[4]458
459invariants: invariant
460 | invariants invariant
461
462invariant: any_identifier ':' boolean_expression
463 | boolean_expression
464 | any_identifier ':' error
465
466arch_invariant: #-- no invariant ok
467 | SYM_INVARIANT V_ASSERTION_TEXT
468 | SYM_INVARIANT error
469
470# define all linguistic entries in this part as dADL.
471#arch_ontology: SYM_ONTOLOGY V_DADL_TEXT
472# | SYM_ONTOLOGY error
473
474arch_ontology: SYM_ONTOLOGY dadl_section
[22]475 {
[26]476 dadl_section = val[1]
[307]477 result = OpenEhr::AM::Archetype::Ontology::ARCHETYPE_ONTOLOGY.new
[22]478 }
[4]479 | SYM_ONTOLOGY error
480
481
482### dADL section
[318]483dadl_section: # no dadl section
484 | attr_vals
[307]485 {
486 @@logger.debug("#{__FILE__}:#{__LINE__}:dadl_section attr_vals = \n#{val[0].to_yaml}")
487 result = val[0]
488 }
[4]489 | complex_object_block
[307]490 {
491 @@logger.debug("#{__FILE__}:#{__LINE__}:dadl_section complex_object_block = \n#{val[0].to_yaml}")
492 result = val[0]
493 }
[4]494# | error
495
496attr_vals: attr_val
[23]497 {
498 result = Array[val[0]]
499 }
[4]500 | attr_vals attr_val
[23]501 {
502 result = (val[0] << val[1])
503 }
[19]504 | attr_vals Semicolon_code attr_val
[23]505 {
506 result = (val[0] << val[2])
507 }
[4]508
509attr_val: attr_id SYM_EQ object_block
[19]510 {
[307]511 @@logger.debug("#{__FILE__}:#{__LINE__}:attr_val\n attr_id = #{val[0]}, object_block = #{val[1]}")
[23]512 result = {:attr_id => val[0], :object_block => val[2]}
[19]513 }
[4]514
515attr_id: V_ATTRIBUTE_IDENTIFIER
[18]516 {
[307]517 @@logger.debug("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER = #{val[0]}")
[22]518 result = val[0]
[18]519 }
[4]520 | V_ATTRIBUTE_IDENTIFIER error
521
522object_block: complex_object_block
[22]523 {
524 result = val[0]
525 }
[4]526 | primitive_object_block
[22]527 {
528 result = val[0]
529 }
[4]530
531complex_object_block: single_attr_object_block
[22]532 {
533 result = val[0]
534 }
[4]535 | multiple_attr_object_block
[22]536 {
537 result = val[0]
538 }
[4]539
540multiple_attr_object_block: untyped_multiple_attr_object_block
[22]541 {
[23]542 result = {:untyped_multiple_attr_object_block => val[0]}
[22]543 }
[4]544 | type_identifier untyped_multiple_attr_object_block
[22]545 {
[23]546 result = {:type_identifier => val[0], :untyped_multiple_attr_object_block => val[1]}
[22]547 }
[4]548
549untyped_multiple_attr_object_block: multiple_attr_object_block_head keyed_objects SYM_END_DBLOCK
[22]550 {
[23]551 result = {:multiple_attr_object_block_head => val[0], :keyed_objects => val[1]}
[22]552 }
[4]553
554multiple_attr_object_block_head: SYM_START_DBLOCK
[22]555 {
556 result = val[0]
[20]557 }
[4]558
559keyed_objects: keyed_object
[23]560 {
561 result = Array[val[0]]
562 }
[4]563 | keyed_objects keyed_object
[23]564 {
565 result = (val[0] << val[1])
566 }
[4]567
568keyed_object: object_key SYM_EQ object_block
[20]569 {
[261]570 @@logger.debug("#{__FILE__}:#{__LINE__}: keyed_object = #{val[0]} at #{@filename}:#{@lineno}")
[283]571 result = {:object_key => val[0], :object_block => val[2]}
[20]572 }
[4]573
574object_key: Left_bracket_code simple_value Right_bracket_code
[19]575 {
[261]576 @@logger.debug("object_key: [#{val[1]}] at #{@filename}:#{@lineno}")
[22]577 result = val[1]
[19]578 }
[4]579
580single_attr_object_block: untyped_single_attr_object_block
[23]581 {
582 result = {:untyped_single_attr_object_block => val[0]}
583 }
[4]584 | type_identifier untyped_single_attr_object_block
[23]585 {
586 result = {:type_identifier => val[0], :untyped_single_attr_object_block => val[1]}
587 }
588
[257]589untyped_single_attr_object_block: single_attr_object_complex_head SYM_END_DBLOCK # >
[22]590 {
[261]591 @@logger.debug("#{__FILE__}:#{__LINE__}: single_attr_object_complex_head = #{val[0]} at #{@filename}:#{@lineno}")
[23]592 result = {:single_attr_object_complex_head => val[0]}
[22]593 }
[4]594 | single_attr_object_complex_head attr_vals SYM_END_DBLOCK
[22]595 {
[261]596 @@logger.debug("#{__FILE__}:#{__LINE__}: attr_vals = #{val[1]} at #{@filename}:#{@lineno}")
[23]597 result = {:single_attr_object_complex_head => val[0], :attr_vals => val[1]}
[22]598 }
[4]599single_attr_object_complex_head: SYM_START_DBLOCK
600primitive_object_block: untyped_primitive_object_block
[22]601 {
[261]602 @@logger.debug("#{__FILE__}:#{__LINE__}: untyped_primitive_object_block = #{val[0]} at #{@filename}:#{@lineno}")
[23]603 result = {:untyped_primitive_object_block => val[0]}
[22]604 }
[4]605 | type_identifier untyped_primitive_object_block
[22]606 {
[261]607 @@logger.debug("#{__FILE__}:#{__LINE__}: type_identifier = #{val[0]}, untyped_primitive_object_block = #{val[1]} at #{@filename}:#{@lineno}")
[23]608 result = {:type_identifier => val[0], :untyped_primitive_object_block => val[1]}
[22]609 }
[4]610untyped_primitive_object_block: SYM_START_DBLOCK primitive_object_value SYM_END_DBLOCK
[20]611 {
[261]612 @@logger.debug("#{__FILE__}:#{__LINE__}: primitive_object_block = <#{val[1]}> at #{@filename}:#{@lineno}")
[22]613 result = val[1]
[20]614 }
[4]615primitive_object_value: simple_value
[22]616 {
617 result = val[0]
618 }
[4]619 | simple_list_value
[22]620 {
621 result = val[0]
622 }
[4]623 | simple_interval_value
[22]624 {
625 result = val[0]
626 }
[4]627 | term_code
[22]628 {
629 result = val[0]
630 }
[4]631 | term_code_list_value
[22]632 {
633 result = val[0]
634 }
[4]635simple_value: string_value
[19]636 {
[261]637 @@logger.debug("string_value: #{val[0]} at #{@filename}:#{@lineno}")
[22]638 result = val[0]
[19]639 }
[4]640 | integer_value
[19]641 {
[261]642 @@logger.debug("integer_value: #{val[0]} at #{@filename}:#{@lineno}")
[22]643 result = val[0]
[19]644 }
[4]645 | real_value
[19]646 {
[261]647 @@logger.debug("real_value: #{val[0]} at #{@filename}:#{@lineno}")
[22]648 result = val[0]
[19]649 }
[4]650 | boolean_value
[19]651 {
[261]652 @@logger.debug("boolean_value: #{val[0]} at #{@filename}:#{@lineno}")
[22]653 result = val[0]
[19]654 }
[4]655 | character_value
[19]656 {
[261]657 @@logger.debug("character_value: #{val[0]} at #{@filename}:#{@lineno}")
[22]658 result = val[0]
[19]659 }
[4]660 | date_value
[19]661 {
[261]662 @@logger.debug("date_value: #{val[0]} at #{@filename}:#{@lineno}")
[22]663 result = val[0]
[19]664 }
[4]665 | time_value
[19]666 {
[261]667 @@logger.debug("time_value: #{val[0]} at #{@filename}:#{@lineno}")
[22]668 result = val[0]
[19]669 }
[4]670 | date_time_value
[19]671 {
[261]672 @@logger.debug("date_time_value: #{val[0]} at #{@filename}:#{@lineno}")
[22]673 result = val[0]
[19]674 }
[4]675 | duration_value
[19]676 {
[261]677 @@logger.debug("duration_value: #{val[0]} at #{@filename}:#{@lineno}")
[22]678 result = val[0]
[19]679 }
[4]680 | uri_value
[19]681 {
[261]682 @@logger.debug("uri_value: #{val[0]} at #{@filename}:#{@lineno}")
[22]683 result = val[0]
[19]684 }
[22]685
[4]686simple_list_value: string_list_value
[317]687 {
688 @@logger.debug("string_list_value: #{val[0]} at #{@filename}:#{@lineno}")
689 result = val[0]
690 }
[4]691 | integer_list_value
[317]692 {
693 result = val[0]
694 }
[4]695 | real_list_value
[317]696 {
697 result = val[0]
698 }
[4]699 | boolean_list_value
[317]700 {
701 result = val[0]
702 }
[4]703 | character_list_value
[317]704 {
705 result = val[0]
706 }
[4]707 | date_list_value
[317]708 {
709 result = val[0]
710 }
[4]711 | time_list_value
[317]712 {
713 result = val[0]
714 }
[4]715 | date_time_list_value
[317]716 {
717 result = val[0]
718 }
[4]719 | duration_list_value
[317]720 {
721 result = val[0]
722 }
[4]723
724simple_interval_value: integer_interval_value
725 | real_interval_value
726 | date_interval_value
727 | time_interval_value
728 | date_time_interval_value
729 | duration_interval_value
730
731type_identifier: V_TYPE_IDENTIFIER
[19]732 {
[261]733 @@logger.debug("V_TYPE_IDENTIFIER: #{val[0]} at #{@filename}:#{@lineno}")
[22]734 result = val[0]
[19]735 }
[4]736 | V_GENERIC_TYPE_IDENTIFIER
[19]737 {
[261]738 @@logger.debug("V_GENERIC_TYPE_IDENTIFIER: #{val[0]} at #{@filename}:#{@lineno}")
[22]739 result = val[0]
[19]740 }
[4]741
742string_value: V_STRING
[18]743 {
[261]744 @@logger.debug("V_STRING: #{val[0]} at #{@filename}:#{@lineno}")
[22]745 result = val[0]
[18]746 }
[4]747
748string_list_value: V_STRING Comma_code V_STRING
[317]749 {
750 result = [val[0],val[2]]
751 }
[4]752 | string_list_value Comma_code V_STRING
[317]753 {
754 result = val[0] << val[2]
755 }
[4]756 | V_STRING Comma_code SYM_LIST_CONTINUE
[317]757 {
758 result = val[0]
759 }
[4]760
761integer_value: V_INTEGER
[22]762 {
763 begin
764 integer = Integer(val[0])
765 rescue
766 raise
767 end
768 result = integer
769 }
[18]770 | Plus_code V_INTEGER
[22]771 {
772 begin
773 integer = Integer(val[0])
774 rescue
775 raise
776 end
777 result = integer
778 }
[18]779 | Minus_code V_INTEGER
[22]780 {
781 begin
782 integer = Integer(val[0])
783 rescue
784 raise
785 end
786 result = - integer
787 }
[18]788### | '+' V_INTEGER
789### | '-' V_INTEGER
[4]790
791integer_list_value: integer_value Comma_code integer_value
792 | integer_list_value Comma_code integer_value
793 | integer_value Comma_code SYM_LIST_CONTINUE
794
795integer_interval_value: SYM_INTERVAL_DELIM integer_value SYM_ELLIPSIS integer_value SYM_INTERVAL_DELIM
796 | SYM_INTERVAL_DELIM SYM_GT integer_value SYM_ELLIPSIS integer_value SYM_INTERVAL_DELIM
797 | SYM_INTERVAL_DELIM integer_value SYM_ELLIPSIS SYM_LT integer_value SYM_INTERVAL_DELIM
798 | SYM_INTERVAL_DELIM SYM_GT integer_value SYM_ELLIPSIS SYM_LT integer_value SYM_INTERVAL_DELIM
799 | SYM_INTERVAL_DELIM SYM_LT integer_value SYM_INTERVAL_DELIM
800 | SYM_INTERVAL_DELIM SYM_LE integer_value SYM_INTERVAL_DELIM
801 | SYM_INTERVAL_DELIM SYM_GT integer_value SYM_INTERVAL_DELIM
802 | SYM_INTERVAL_DELIM SYM_GE integer_value SYM_INTERVAL_DELIM
803 | SYM_INTERVAL_DELIM integer_value SYM_INTERVAL_DELIM
804
805real_value: V_REAL
[23]806 {
807 begin
808 real = Float(val[0])
809 rescue
810 raise
811 end
812 result = real
813 }
[18]814 | Plus_code V_REAL
[23]815 {
816 begin
[25]817 real = Float(val[1])
[23]818 rescue
819 raise
820 end
821 result = real
822 }
[18]823 | Minus_code V_REAL
[23]824 {
825 begin
[25]826 real = Float(val[1])
[23]827 rescue
828 raise
829 end
830 result = - real
831 }
[4]832
833real_list_value: real_value Comma_code real_value
834 | real_list_value Comma_code real_value
835 | real_value Comma_code SYM_LIST_CONTINUE
836
837real_interval_value: SYM_INTERVAL_DELIM real_value SYM_ELLIPSIS real_value SYM_INTERVAL_DELIM
838 | SYM_INTERVAL_DELIM SYM_GT real_value SYM_ELLIPSIS real_value SYM_INTERVAL_DELIM
839 | SYM_INTERVAL_DELIM real_value SYM_ELLIPSIS SYM_LT real_value SYM_INTERVAL_DELIM
840 | SYM_INTERVAL_DELIM SYM_GT real_value SYM_ELLIPSIS SYM_LT real_value SYM_INTERVAL_DELIM
841 | SYM_INTERVAL_DELIM SYM_LT real_value SYM_INTERVAL_DELIM
842 | SYM_INTERVAL_DELIM SYM_LE real_value SYM_INTERVAL_DELIM
843 | SYM_INTERVAL_DELIM SYM_GT real_value SYM_INTERVAL_DELIM
844 | SYM_INTERVAL_DELIM SYM_GE real_value SYM_INTERVAL_DELIM
845 | SYM_INTERVAL_DELIM real_value SYM_INTERVAL_DELIM
846
847
848boolean_value: SYM_TRUE
[23]849 {
850 result = true
851 }
[4]852 | SYM_FALSE
[23]853 {
854 result = false
855 }
[4]856
857boolean_list_value: boolean_value Comma_code boolean_value
858 | boolean_list_value Comma_code boolean_value
859 | boolean_value Comma_code SYM_LIST_CONTINUE
860
861character_value: V_CHARACTER
862
863character_list_value: character_value Comma_code character_value
864 | character_list_value Comma_code character_value
865 | character_value Comma_code SYM_LIST_CONTINUE
866
867date_value: V_ISO8601_EXTENDED_DATE
[283]868 {
869 result = val[0]
870 }
[4]871
872date_list_value: date_value Comma_code date_value
873 | date_list_value Comma_code date_value
874 | date_value Comma_code SYM_LIST_CONTINUE
875
876date_interval_value: SYM_INTERVAL_DELIM date_value SYM_ELLIPSIS date_value SYM_INTERVAL_DELIM
877 | SYM_INTERVAL_DELIM SYM_GT date_value SYM_ELLIPSIS date_value SYM_INTERVAL_DELIM
878 | SYM_INTERVAL_DELIM date_value SYM_ELLIPSIS SYM_LT date_value SYM_INTERVAL_DELIM
879 | SYM_INTERVAL_DELIM SYM_GT date_value SYM_ELLIPSIS SYM_LT date_value SYM_INTERVAL_DELIM
880 | SYM_INTERVAL_DELIM SYM_LT date_value SYM_INTERVAL_DELIM
881 | SYM_INTERVAL_DELIM SYM_LE date_value SYM_INTERVAL_DELIM
882 | SYM_INTERVAL_DELIM SYM_GT date_value SYM_INTERVAL_DELIM
883 | SYM_INTERVAL_DELIM SYM_GE date_value SYM_INTERVAL_DELIM
884 | SYM_INTERVAL_DELIM date_value SYM_INTERVAL_DELIM
885
886time_value: V_ISO8601_EXTENDED_TIME
887
888time_list_value: time_value Comma_code time_value
889 | time_list_value Comma_code time_value
890 | time_value Comma_code SYM_LIST_CONTINUE
891
892time_interval_value: SYM_INTERVAL_DELIM time_value SYM_ELLIPSIS time_value SYM_INTERVAL_DELIM
893 | SYM_INTERVAL_DELIM SYM_GT time_value SYM_ELLIPSIS time_value SYM_INTERVAL_DELIM
894 | SYM_INTERVAL_DELIM time_value SYM_ELLIPSIS SYM_LT time_value SYM_INTERVAL_DELIM
895 | SYM_INTERVAL_DELIM SYM_GT time_value SYM_ELLIPSIS SYM_LT time_value SYM_INTERVAL_DELIM
896 | SYM_INTERVAL_DELIM SYM_LT time_value SYM_INTERVAL_DELIM
897 | SYM_INTERVAL_DELIM SYM_LE time_value SYM_INTERVAL_DELIM
898 | SYM_INTERVAL_DELIM SYM_GT time_value SYM_INTERVAL_DELIM
899 | SYM_INTERVAL_DELIM SYM_GE time_value SYM_INTERVAL_DELIM
900 | SYM_INTERVAL_DELIM time_value SYM_INTERVAL_DELIM
901
902date_time_value: V_ISO8601_EXTENDED_DATE_TIME
903
904date_time_list_value: date_time_value Comma_code date_time_value
905 | date_time_list_value Comma_code date_time_value
906 | date_time_value Comma_code SYM_LIST_CONTINUE
907
908date_time_interval_value: SYM_INTERVAL_DELIM date_time_value SYM_ELLIPSIS date_time_value SYM_INTERVAL_DELIM
909 | SYM_INTERVAL_DELIM SYM_GT date_time_value SYM_ELLIPSIS date_time_value SYM_INTERVAL_DELIM
910 | SYM_INTERVAL_DELIM date_time_value SYM_ELLIPSIS SYM_LT date_time_value SYM_INTERVAL_DELIM
911 | SYM_INTERVAL_DELIM SYM_GT date_time_value SYM_ELLIPSIS SYM_LT date_time_value SYM_INTERVAL_DELIM
912 | SYM_INTERVAL_DELIM SYM_LT date_time_value SYM_INTERVAL_DELIM
913 | SYM_INTERVAL_DELIM SYM_LE date_time_value SYM_INTERVAL_DELIM
914 | SYM_INTERVAL_DELIM SYM_GT date_time_value SYM_INTERVAL_DELIM
915 | SYM_INTERVAL_DELIM SYM_GE date_time_value SYM_INTERVAL_DELIM
916 | SYM_INTERVAL_DELIM date_time_value SYM_INTERVAL_DELIM
917
918duration_value: V_ISO8601_DURATION
[19]919 {
[261]920 @@logger.debug("V_ISO8601_DURATION: #{val[0]} at #{@filename}:#{@lineno}")
[22]921 result = val[0]
[19]922 }
[4]923
924duration_list_value: duration_value Comma_code duration_value
925 | duration_list_value Comma_code duration_value
926 | duration_value Comma_code SYM_LIST_CONTINUE
927
928duration_interval_value: SYM_INTERVAL_DELIM duration_value SYM_ELLIPSIS duration_value SYM_INTERVAL_DELIM
929 | SYM_INTERVAL_DELIM SYM_GT duration_value SYM_ELLIPSIS duration_value SYM_INTERVAL_DELIM
930 | SYM_INTERVAL_DELIM duration_value SYM_ELLIPSIS SYM_LT duration_value SYM_INTERVAL_DELIM
931 | SYM_INTERVAL_DELIM SYM_GT duration_value SYM_ELLIPSIS SYM_LT duration_value SYM_INTERVAL_DELIM
932 | SYM_INTERVAL_DELIM SYM_LT duration_value SYM_INTERVAL_DELIM
933 | SYM_INTERVAL_DELIM SYM_LE duration_value SYM_INTERVAL_DELIM
934 | SYM_INTERVAL_DELIM SYM_GT duration_value SYM_INTERVAL_DELIM
935 | SYM_INTERVAL_DELIM SYM_GE duration_value SYM_INTERVAL_DELIM
936 | SYM_INTERVAL_DELIM duration_value SYM_INTERVAL_DELIM
937
938term_code: V_QUALIFIED_TERM_CODE_REF
[20]939 {
[261]940 @@logger.debug("#{__FILE__}:#{__LINE__}: V_QUALIFIED_TERM_CODE_REF = #{val[0]} at #{@filename}:#{@lineno}")
[26]941 result = val[0]
[20]942 }
[4]943
944term_code_list_value: term_code Comma_code term_code
945 | term_code_list_value Comma_code term_code
946 | term_code Comma_code SYM_LIST_CONTINUE
947
948uri_value: V_URI
[20]949 {
[261]950 @@logger.debug("#{__FILE__}:#{__LINE__}: V_URI = #{val[0]} at #{@filename}:#{@lineno}")
[26]951 result = val[0]
[20]952 }
[4]953
954
955#---------------------- ASSERTIONS ------------------------
956
957assertions: assertion
958 | assertions assertion
959
960assertion: any_identifier ':' boolean_expression
961 | boolean_expression
962 | any_identifier ':' error
963
964#---------------------- expressions ---------------------
965
966boolean_expression: boolean_leaf
967 | boolean_node
968
969boolean_node: SYM_EXISTS absolute_path
970# | absolute_path
971 | SYM_EXISTS error
972 | relative_path SYM_MATCHES SYM_START_CBLOCK c_primitive SYM_END_CBLOCK
973 | relative_path SYM_MATCHES START_REGEXP_BLOCK REGEXP_BODY END_REGEXP_BLOCK # added by akimichi
974 | SYM_NOT boolean_leaf
975 | arithmetic_expression '=' arithmetic_expression
976 | arithmetic_expression SYM_NE arithmetic_expression
977 | arithmetic_expression SYM_LT arithmetic_expression
978 | arithmetic_expression SYM_GT arithmetic_expression
979 | arithmetic_expression SYM_LE arithmetic_expression
980 | arithmetic_expression SYM_GE arithmetic_expression
981 | boolean_expression SYM_AND boolean_expression
982 | boolean_expression SYM_OR boolean_expression
983 | boolean_expression SYM_XOR boolean_expression
984 | boolean_expression SYM_IMPLIES boolean_expression
985
986boolean_leaf: Left_parenthesis_code boolean_expression Right_parenthesis_code
987 | SYM_TRUE
988 | SYM_FALSE
989
990arithmetic_expression: arithmetic_leaf
991 | arithmetic_node
992
993arithmetic_node: arithmetic_expression '+' arithmetic_leaf
994 | arithmetic_expression '-' arithmetic_leaf
995 | arithmetic_expression Star_code arithmetic_leaf
996 | arithmetic_expression Slash_code arithmetic_leaf
997 | arithmetic_expression '^' arithmetic_leaf
998
999arithmetic_leaf: Left_parenthesis_code arithmetic_expression Right_parenthesis_code
1000 | integer_value
1001 | real_value
1002 | absolute_path
1003
1004
1005#--------------- THE FOLLOWING SOURCE TAKEN FROM OG_PATH_VALIDATOR.Y -------------
1006#--------------- except to remove movable_path ----------------------------------------------------
1007
1008
1009absolute_path: Slash_code
1010 | Slash_code relative_path
1011# | absolute_path Slash_code relative_path
1012
1013
1014
1015relative_path: path_segment
1016 | relative_path Slash_code path_segment
1017
1018path_segment: V_ATTRIBUTE_IDENTIFIER V_LOCAL_TERM_CODE_REF
[19]1019 {
[261]1020 @@logger.debug("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}")
[19]1021 }
[4]1022 | V_ATTRIBUTE_IDENTIFIER
[19]1023 {
[261]1024 @@logger.debug("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}")
[19]1025 }
[4]1026
1027
1028#-------------------------------- END SOURCE TAKEN FROM OG_PATH_VALIDATOR.Y ----------------------
1029
1030
1031#---------------- existence, occurrences, cardinality ----------------
1032
1033c_existence: #-- default to 1..1
[22]1034 {
1035 result = Range.new(1,1)
1036 }
1037 | SYM_EXISTENCE SYM_MATCHES SYM_START_CBLOCK existence_spec SYM_END_CBLOCK
1038 {
1039 result = val[3]
1040 }
[4]1041
1042existence_spec: V_INTEGER #-- can only be 0 or 1
[22]1043 {
1044 begin
1045 integer = Integer(val[0])
1046 rescue
1047 raise
1048 end
1049 result = integer
1050 }
[4]1051 | V_INTEGER SYM_ELLIPSIS V_INTEGER #-- can only be 0..0, 0..1, 1..1
[22]1052 {
1053 begin
1054 from_integer = Integer(val[0])
1055 to_integer = Integer(val[2])
1056 rescue
1057 raise
1058 end
1059 result = Range.new(from_integer,to_integer)
1060 }
[4]1061
1062c_cardinality: SYM_CARDINALITY SYM_MATCHES SYM_START_CBLOCK cardinality_spec SYM_END_CBLOCK
[22]1063 {
[318]1064 result = OpenEhr::AM::Archetype::ConstraintModel::CARDINALITY.new
[22]1065 }
[4]1066
1067cardinality_spec: occurrence_spec
1068 | occurrence_spec Semicolon_code SYM_ORDERED
1069 | occurrence_spec Semicolon_code SYM_UNORDERED
1070 | occurrence_spec Semicolon_code SYM_UNIQUE
1071 | occurrence_spec Semicolon_code SYM_ORDERED Semicolon_code SYM_UNIQUE
1072 | occurrence_spec Semicolon_code SYM_UNORDERED Semicolon_code SYM_UNIQUE
1073 | occurrence_spec Semicolon_code SYM_UNIQUE Semicolon_code SYM_ORDERED
1074 | occurrence_spec Semicolon_code SYM_UNIQUE Semicolon_code SYM_UNORDERED
1075
1076cardinality_limit_value: integer_value
[35]1077 {
1078 result = val[0]
1079 }
1080 | Star_code # '*'
1081 {
1082 result = val[0]
1083 }
[4]1084
[35]1085
[4]1086c_occurrences: #-- default to 1..1
1087 | SYM_OCCURRENCES SYM_MATCHES SYM_START_CBLOCK occurrence_spec SYM_END_CBLOCK
[23]1088 {
[307]1089 case val[3]
1090 when OpenEhr::RM::Support::AssumedTypes::Interval
1091 result = val[3]
1092 else
1093 result = val[3]
1094 end
[23]1095 }
[4]1096 | SYM_OCCURRENCES error
1097
1098occurrence_spec: cardinality_limit_value #-- single integer or '*'
[307]1099 {
1100 result = val[0]
1101 }
[4]1102 | V_INTEGER SYM_ELLIPSIS cardinality_limit_value
[307]1103 {
1104 result = OpenEhr::RM::Support::AssumedTypes::Interval.new(val[0], val[2])
1105 }
[4]1106
1107#---------------------- leaf constraint types -----------------------
1108
1109c_integer_spec: integer_value
1110 | integer_list_value
1111 | integer_interval_value
1112
1113c_integer: c_integer_spec
1114 | c_integer_spec Semicolon_code integer_value
1115 | c_integer_spec Semicolon_code error
1116
1117c_real_spec: real_value
1118 | real_list_value
1119 | real_interval_value
1120
1121c_real: c_real_spec
1122 | c_real_spec Semicolon_code real_value
1123 | c_real_spec Semicolon_code error
1124
1125c_date_constraint: V_ISO8601_DATE_CONSTRAINT_PATTERN
1126 | date_value
1127 | date_interval_value
1128
1129c_date: c_date_constraint
1130 | c_date_constraint Semicolon_code date_value
1131 | c_date_constraint Semicolon_code error
1132
1133c_time_constraint: V_ISO8601_TIME_CONSTRAINT_PATTERN
1134 | time_value
1135 | time_interval_value
1136
1137c_time: c_time_constraint
1138 | c_time_constraint Semicolon_code time_value
1139 | c_time_constraint Semicolon_code error
1140
1141c_date_time_constraint: V_ISO8601_DATE_TIME_CONSTRAINT_PATTERN
1142 | date_time_value
1143 | date_time_interval_value
1144
1145c_date_time: c_date_time_constraint
1146 | c_date_time_constraint Semicolon_code date_time_value
1147 | c_date_time_constraint Semicolon_code error
1148
1149c_duration_constraint: duration_pattern
1150 | duration_pattern Slash_code duration_interval_value
1151 | duration_value
1152 | duration_interval_value
1153
1154c_duration: c_duration_constraint
1155 | c_duration_constraint Semicolon_code duration_value
1156 | c_duration_constraint Semicolon_code error
1157
1158c_string_spec: V_STRING #-- single value, generates closed list
1159 | string_list_value #-- closed list
1160 | string_list_value Comma_code SYM_LIST_CONTINUE #-- open list
1161# | string_list_value ',' SYM_LIST_CONTINUE #-- open list
1162# | V_REGEXP #-- regular expression with "//" or "^^" delimiters
1163
1164c_string: c_string_spec
1165 | c_string_spec Semicolon_code string_value
1166 | c_string_spec Semicolon_code error
1167
1168c_boolean_spec: SYM_TRUE
[22]1169 {
[318]1170 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_BOOLEAN.new(:true_valid => true)
[22]1171 }
[4]1172 | SYM_FALSE
[22]1173 {
[318]1174 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_BOOLEAN.new(:true_valid => false)
[22]1175 }
[4]1176 | SYM_TRUE Comma_code SYM_FALSE
[22]1177 {
[318]1178 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_BOOLEAN.new(:true_valid => true,:false_valid => false)
[22]1179 }
[4]1180 | SYM_FALSE Comma_code SYM_TRUE
[22]1181 {
[318]1182 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_BOOLEAN.new(:true_valid => false,:false_valid => true)
[22]1183 }
[4]1184
1185c_boolean: c_boolean_spec
[22]1186 {
1187 result = val[0]
1188 }
[4]1189 | c_boolean_spec Semicolon_code boolean_value
[22]1190 {
1191 raise 'Not implemented yet'
1192 }
[19]1193 | c_boolean_spec Semicolon_code error
[22]1194 {
1195 raise 'Not implemented yet'
1196 }
[4]1197
1198c_ordinal: c_ordinal_spec
1199 | c_ordinal_spec Semicolon_code integer_value
[19]1200 | c_ordinal_spec Semicolon_code error
[4]1201
1202c_ordinal_spec: ordinal
1203 | c_ordinal_spec Comma_code ordinal
1204
1205ordinal: integer_value SYM_INTERVAL_DELIM V_QUALIFIED_TERM_CODE_REF
[20]1206 {
1207 @in_interval = false
[261]1208 @@logger.debug("#{__FILE__}:#{__LINE__}, #{val[0]}|#{val[2]} at #{@filename}")
[20]1209 }
[4]1210
1211#c_code_phrase: V_TERM_CODE_CONSTRAINT #-- e.g. "[local::at0040, at0041; at0040]"
1212c_code_phrase: term_code_constraint_section #-- e.g. "[local::at0040, at0041; at0040]"
[32]1213 {
1214 result = val[0]
1215 }
[4]1216 | V_QUALIFIED_TERM_CODE_REF
[32]1217 {
1218 result = val[0]
1219 }
[4]1220
[261]1221# [[a-zA-Z0-9\(\)\._\-]+::[ \t\n]* [[a-zA-Z0-9\._\-]*[ \t]*]
[4]1222term_code_constraint_section: START_TERM_CODE_CONSTRAINT term_code_body END_TERM_CODE_CONSTRAINT
[261]1223 {
1224 @@logger.debug("#{__FILE__}:#{__LINE__}, START_TERM_CODE_CONSTRAINT = #{val[0]} at #{@filename}")
1225 @@logger.debug("#{__FILE__}:#{__LINE__}, term_code_body = #{val[1]}")
1226 @@logger.debug("#{__FILE__}:#{__LINE__}, END_TERM_CODE_CONSTRAINT = #{val[2]}")
1227 result = val[1]
1228 }
1229
1230
[4]1231term_code_body: # empty
1232 | TERM_CODE
1233 | term_code_body TERM_CODE
1234### term_code_body: TERM_CODE
1235### | term_code_body TERM_CODE
1236
1237# A Constraint_Ref is a proxy for a set of constraints on an object.
1238constraint_ref: V_LOCAL_TERM_CODE_REF #-- e.g. "ac0003"
[32]1239 {
1240 result = val[0]
1241 }
[4]1242
1243any_identifier: type_identifier
[32]1244 {
1245 result = val[0]
1246 }
[4]1247 | V_ATTRIBUTE_IDENTIFIER
[19]1248 {
[261]1249 @@logger.debug("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{word} at #{@filename}")
[32]1250 result = val[0]
[19]1251 }
[4]1252
1253
1254#----------------- TAKEN FROM DADL_VALIDATOR.Y -------------------
1255#----------------- DO NOT MODIFY -------------------
1256#---------------------- BASIC DATA VALUES -----------------------
1257
1258duration_pattern: V_ISO8601_DURATION_CONSTRAINT_PATTERN
[318]1259 {
1260 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_DURATION.new #val[0]
[26]1261 }
[4]1262
1263
1264
1265---- header
1266
[49]1267
[4]1268$:.unshift File.join(File.dirname(__FILE__))
[17]1269require 'logger'
[283]1270require 'yaml'
[21]1271require 'rubygems'
[307]1272require 'open_ehr'
1273#require 'adl_parser.rb'
1274#require 'am.rb'
1275#require 'rm.rb'
1276#require 'rm/support/assumed_types.rb'
1277#require 'assumed_library_types.rb'
1278$DEBUG = true
[4]1279
1280
[17]1281
[4]1282---- inner
[17]1283
[22]1284def assert_at(file,line, message = "")
1285 unless yield
1286 raise "Assertion failed !: #{file}, #{line}: #{message}"
1287 end
1288end
1289
[49]1290if $DEBUG
[261]1291 @@logger = Logger.new('log/parser.log','daily')
[263]1292 @@logger.level = Logger::DEBUG
[49]1293else
[261]1294 @@logger = Logger.new(STDOUT)
1295 @@logger.level = Logger::WARN
[49]1296end
1297
[17]1298
[4]1299###----------/* keywords */ ---------------------------------------------
1300@@adl_reserved = {
1301 'archetype' => :SYM_ARCHETYPE,
1302 'adl_version' => :SYM_ADL_VERSION,
1303 'controlled' => :SYM_IS_CONTROLLED,
1304 'specialize' => :SYM_SPECIALIZE,
1305 'concept' => :SYM_CONCEPT,
1306 'language' => :SYM_LANGUAGE,
1307 'description' => :SYM_DESCRIPTION,
1308 'definition' => :SYM_DEFINITION,
1309 'invariant' => :SYM_INVARIANT,
1310 'ontology' => :SYM_ONTOLOGY,
1311 'matches' => :SYM_MATCHES,
1312 'is_in' => :SYM_MATCHES,
1313 'occurrences' => :SYM_OCCURRENCES,
1314 'true' => :SYM_TRUE, #[Tt][Rr][Uu][Ee] -- -> SYM_TRUE
1315 'false' => :SYM_FALSE, # [Ff][Aa][Ll][Ss][Ee] -- -> SYM_FALSE
1316 'infinity' => :SYM_INFINITY # [Ii][Nn][Ff][Ii][Nn][Ii][Tt][Yy] -- -> SYM_INFINITY
1317}
1318
1319@@dadl_reserved = {
1320 'true' => :SYM_TRUE, #[Tt][Rr][Uu][Ee] -- -> SYM_TRUE
1321 'false' => :SYM_FALSE, # [Ff][Aa][Ll][Ss][Ee] -- -> SYM_FALSE
1322 'infinity' => :SYM_INFINITY # [Ii][Nn][Ff][Ii][Nn][Ii][Tt][Yy] -- -> SYM_INFINITY
1323}
1324
1325@@cadl_reserved = {
1326 'then' => :SYM_THEN, # [Tt][Hh][Ee][Nn]
1327 'else' => :SYM_ELSE, # [Ee][Ll][Ss][Ee]
1328 'and' => :SYM_AND, # [Aa][Nn][Dd]
1329 'or' => :SYM_OR, # [Oo][Rr]
1330 'xor' => :SYM_XOR, # [Xx][Oo][Rr]
1331 'not' => :SYM_NOT, # [Nn][Oo][Tt]
1332 'implies' => :SYM_IMPLIES, # [Ii][Mm][Pp][Ll][Ii][Ee][Ss]
1333 'true' => :SYM_TRUE, #[Tt][Rr][Uu][Ee] -- -> SYM_TRUE
1334 'false' => :SYM_FALSE, # [Ff][Aa][Ll][Ss][Ee] -- -> SYM_FALSE
1335 'forall' => :SYM_FORALL, # [Ff][Oo][Rr][_][Aa][Ll][Ll]
1336 'exists' => :SYM_EXISTS, # [Ee][Xx][Ii][Ss][Tt][Ss]
1337 'existence' => :SYM_EXISTENCE, # [Ee][Xx][Iu][Ss][Tt][Ee][Nn][Cc][Ee]
1338 'occurrences' => :SYM_OCCURRENCES, # [Oo][Cc][Cc][Uu][Rr][Rr][Ee][Nn][Cc][Ee][Ss]
1339 'cardinality' => :SYM_CARDINALITY, # [Cc][Aa][Rr][Dd][Ii][Nn][Aa][Ll][Ii][Tt][Yy]
1340 'ordered' => :SYM_ORDERED, # [Oo][Rr][Dd][Ee][Rr][Ee][Dd]
1341 'unordered' => :SYM_UNORDERED, # [Uu][Nn][Oo][Rr][Dd][Ee][Rr][Ee][Dd]
1342 'unique' => :SYM_UNIQUE, # [Uu][Nn][Ii][Qq][Uu][Ee]
1343 'matches' => :SYM_MATCHES, # [Mm][Aa][Tt][Cc][Hh][Ee][Ss]
1344 'is_in' => :SYM_MATCHES, # [Ii][Ss][_][Ii][Nn]
1345 'invariant' => :SYM_INVARIANT, # [Ii][Nn][Vv][Aa][Rr][Ii][Aa][Nn][Tt]
1346 'infinity' => :SYM_INFINITY, # [Ii][Nn][Ff][Ii][Nn][Ii][Tt][Yy] -- -> SYM_INFINITY
1347 'use_node' => :SYM_USE_NODE, # [Uu][Ss][Ee][_][Nn][Oo][Dd][Ee]
1348 'use_archetype' => :SYM_ALLOW_ARCHETYPE, # [Uu][Ss][Ee][_][Aa][Rr][Cc][Hh][Ee][Tt][Yy][Pp][Ee]
1349 'allow_archetype' => :SYM_ALLOW_ARCHETYPE, # [Aa][Ll][Ll][Oo][Ww][_][Aa][Rr][Cc][Hh][Ee][Tt][Yy][Pp][Ee]
1350 'include' => :SYM_INCLUDE, # [Ii][Nn][Cc][Ll][Uu][Dd][Ee]
1351 'exclude' => :SYM_EXCLUDE # [Ee][Xx][Cc][Ll][Uu][Dd][Ee]
1352}
1353
1354
1355###----------/* Scanner */ -----------------------------------------------
1356
[265]1357
[4]1358def scan
[261]1359 @@logger.debug("#{__FILE__}:#{__LINE__}: Entering scan at #{@filename}:#{@lineno}:")
[307]1360 scanner = OpenEhr::ADL::Scanner::ADLScanner.new(@adl_type, @filename)
[265]1361
[4]1362 until @data.nil? do
[283]1363 @data = scanner.scan(@data) do |sym, val|
[4]1364 yield sym, val
1365 end
1366 @data = $' # variable $' receives the string after the match
1367 end
1368 yield :EOF, nil
1369 yield false, '$'
1370end # of scan
1371
[265]1372
[4]1373def parse(data, filename, lineno = 1, debug = false)
1374 @yydebug = true
1375 @parsestring = data
1376 @data = data
1377 @lineno = lineno
1378 @filename = filename
1379 @adl_type = [:adl] # {:adl, :cadl, :dadl}
1380 @in_regexp = false
1381 @in_interval = false
[14]1382 @in_c_domain_type = false
[4]1383 yyparse self, :scan
1384end
1385
1386def on_error( t, v, values)
1387 raise Racc::ParseError, "#{@filename}:#{@lineno}: Inline syntax error on #{v.inspect}"
1388end
1389
1390
[283]1391__END__
[4]1392
1393
1394
1395
1396### Local Variables:
1397### mode:ruby
1398### mode:font-lock
1399### comment-column:0
1400### comment-start: "### "
1401### comment-end:""
1402### End:
1403
1404
1405
1406
Note: See TracBrowser for help on using the repository browser.