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

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

created remote_adl_test.rb

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