source: ruby/branches/0.5/lib/adl_parser/lib/parser.y@ 290

Last change on this file since 290 was 290, checked in by KOBAYASHI, Shinji, 15 years ago

merged latest trunc change to branches/0.5

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