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

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

generated openehr_models_0.0.3 gem and working on bridge between adl and rm

File size: 64.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]
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 @@log.info("#{__FILE__}:#{__LINE__}: archetype = #{archetype} 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 @@log.info("#{__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
209c_object: v_c_domain_type
210 {
211 result = val[0]
212 }
213 | c_complex_object
214 {
215 @@log.info("#{__FILE__}:#{__LINE__}: c_complex_object = #{val[0].inspect} at #{@filename}:#{@lineno}")
216 result = val[0]
217 }
218 | archetype_internal_ref
219 {
220 result = OpenEHR::AM::Archetype::Constraint_Model::ARCHETYPE_INTERNAL_REF.create do |archetype_internal_ref|
221 archetype_internal_ref.target_path = val[0][:absolute_path]
222 archetype_internal_ref.rm_type_name = val[0][:type_identifier]
223 archetype_internal_ref.occurrences = val[0][:c_occurrences]
224 end
225 }
226 | archetype_slot
227 {
228 result = val[0]
229 }
230 | constraint_ref
231 {
232 result = OpenEHR::AM::Archetype::Constraint_Model::CONSTRAINT_REF.create do |constraint_ref|
233 constraint_ref.reference = val[0]
234 end
235 }
236 | c_code_phrase
237 {
238 result = val[0]
239 }
240 | c_ordinal
241 {
242 result = val[0]
243 }
244 | c_primitive_object
245 {
246 result = val[0]
247 }
248# | v_c_domain_type
249# | V_C_DOMAIN_TYPE
250 # this is an attempt to match a dADL section inside cADL. It will
251 # probably never work 100% properly since there can be '>' inside "||"
252 # ranges, and also strings containing any character, e.g. units string
253 # contining "{}" chars. The real solution is to use the dADL parser on
254 # the buffer from the current point on and be able to fast-forward the
255 # cursor to the last character matched by the dADL scanner
256 | ERR_C_DOMAIN_TYPE
257 | error
258
259v_c_domain_type: START_V_C_DOMAIN_TYPE_BLOCK dadl_section END_V_C_DOMAIN_TYPE_BLOCK
260 {
261 result = val[1]
262 }
263
264# 'archetype_internal_ref' is a node that refers to a previously defined object node in the same archetype.
265archetype_internal_ref: SYM_USE_NODE type_identifier c_occurrences absolute_path
266 {
267 result = {:type_identifier => val[1], :c_occurrences => val[2], :absolute_path => val[3] }
268 }
269 | SYM_USE_NODE type_identifier error
270
271# 'archetype_slot' is a node whose statements define a constraint that determines which other archetypes may appear at that point in the current archetype.
272archetype_slot: c_archetype_slot_head SYM_MATCHES SYM_START_CBLOCK c_includes c_excludes SYM_END_CBLOCK
273 {
274 result = OpenEHR::AM::Archetype::Constraint_Model::ARCHETYPE_SLOT.create do |archetype_slot|
275 archetype_slot.includes = val[3]
276 archetype_slot.excludes = val[4]
277 archetype_slot.rm_type_name = val[0][:c_archetype_slot_id]
278 archetype_slot.occurrences = val[0][:c_occurrences]
279 end
280 }
281c_archetype_slot_head: c_archetype_slot_id c_occurrences
282 {
283 result = {:c_archetype_slot_id => val[0],:c_occurrences => val[1]}
284 }
285
286c_archetype_slot_id: SYM_ALLOW_ARCHETYPE type_identifier
287 {
288 result = val[1]
289 }
290 | SYM_ALLOW_ARCHETYPE type_identifier V_LOCAL_TERM_CODE_REF
291 | SYM_ALLOW_ARCHETYPE error
292
293# 'c_primitive_object' is an node representing a constraint on a primitive object type.
294c_primitive_object: c_primitive
295 {
296 assert_at(__FILE__,__LINE__){val[0].kind_of?(OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_PRIMITIVE)}
297 result = OpenEHR::AM::Archetype::Constraint_Model::C_PRIMITIVE_OBJECT.create do |c_primitive_object|
298 c_primitive_object.item = val[0]
299 end
300 }
301
302c_primitive: c_integer
303 {
304 @@log.info("#{__FILE__}:#{__LINE__}: c_integer = #{val[0]} at #{@filename}:#{@lineno}")
305 result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_INTEGER.create do |c_integer|
306 c_integer.list
307 c_integer.range
308 c_integer.assumed_value
309 end
310 }
311 | c_real
312 {
313 @@log.info("#{__FILE__}:#{__LINE__}: c_real = #{val[0]} at #{@filename}:#{@lineno}")
314 result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_REAL.new
315 }
316 | c_date
317 {
318 @@log.info("#{__FILE__}:#{__LINE__}: c_date = #{val[0]} at #{@filename}:#{@lineno}")
319 result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_DATE.new
320 }
321 | c_time
322 {
323 @@log.info("#{__FILE__}:#{__LINE__}: c_time = #{val[0]} at #{@filename}:#{@lineno}")
324 result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_TIME.new
325 }
326 | c_date_time
327 {
328 @@log.info("#{__FILE__}:#{__LINE__}: c_date_time = #{val[0]} at #{@filename}:#{@lineno}")
329 result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_DATE_TIME.new
330 }
331 | c_duration
332 {
333 @@log.info("#{__FILE__}:#{__LINE__}: c_duration = #{val[0]} at #{@filename}:#{@lineno}")
334 result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_DURATION.new
335 }
336 | c_string
337 {
338 @@log.info("#{__FILE__}:#{__LINE__}: c_string = #{val[0]} at #{@filename}:#{@lineno}")
339 result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_STRING.new
340 }
341 | c_boolean
342 {
343 assert_at(__FILE__,__LINE__){val[0].instance_of?(OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN)}
344 @@log.info("#{__FILE__}:#{__LINE__}: c_boolean = #{val[0]} at #{@filename}:#{@lineno}")
345 result = val[0]
346 }
347
348c_any: Star_code
349#c_any: '*'
350
351#---------------- BODY - relationships ----------------
352
353c_attributes: c_attribute
354 {
355 result = [val[0]]
356 }
357 | c_attributes c_attribute
358 {
359 result = (val[0] << val[1])
360 }
361
362# 'c_attribute' is a node representing a constraint on an attribute in an object model.
363c_attribute: c_attr_head SYM_MATCHES SYM_START_CBLOCK c_attr_values SYM_END_CBLOCK
364 {
365 assert_at(__FILE__,__LINE__){ val[0].kind_of?(OpenEHR::AM::Archetype::Constraint_Model::C_ATTRIBUTE)}
366 c_attribute = val[0]
367 c_attribute.children = val[3]
368 result = c_attribute
369 }
370 | c_attr_head SYM_MATCHES START_REGEXP_BLOCK REGEXP_BODY END_REGEXP_BLOCK # added by akimichi
371 {
372 assert_at(__FILE__,__LINE__){ val[0].kind_of?(OpenEHR::AM::Archetype::Constraint_Model::C_ATTRIBUTE)}
373 result = val[0]
374 }
375 | c_attr_head SYM_MATCHES SYM_START_CBLOCK error SYM_END_CBLOCK
376 {
377 assert_at(__FILE__,__LINE__){ val[0].kind_of?(OpenEHR::AM::Archetype::Constraint_Model::C_ATTRIBUTE)}
378 result = val[0]
379 }
380
381
382c_attr_head: V_ATTRIBUTE_IDENTIFIER c_existence
383 {
384 @@log.info("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER = #{val[0]}, c_existence = #{val[1]} at #{@filename}")
385 result = OpenEHR::AM::Archetype::Constraint_Model::C_SINGLE_ATTRIBUTE.new(
386 :rm_attribute_name => val[0],
387 :existence => val[1]
388 )
389
390 }
391 | V_ATTRIBUTE_IDENTIFIER c_existence c_cardinality
392 {
393 assert_at(__FILE__,__LINE__){ val[2].instance_of?(OpenEHR::AM::Archetype::Constraint_Model::CARDINALITY) }
394 @@log.info("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER: #{val[0]}, c_existence = #{val[1]}, c_cardinality = #{val[2]} at #{@filename}")
395 result = OpenEHR::AM::Archetype::Constraint_Model::C_MULTIPLE_ATTRIBUTE.new(
396 :rm_attribute_name => val[0],
397 :existence => val[1],
398 :cardinality => val[2]
399 )
400 }
401
402c_attr_values: c_object
403 {
404 result = Array[val[0]]
405 }
406 | c_attr_values c_object
407 {
408 result = (val[0] << val[1])
409 }
410 | c_any # -- to allow a property to have any value
411 {
412 result = Array[val[0]]
413 }
414
415### c_includes: #-- Empty
416### | SYM_INCLUDE assertions
417c_includes: #-- Empty
418 | SYM_INCLUDE invariants
419{
420 result = val[1]
421}
422
423### c_excludes: #-- Empty
424### | SYM_EXCLUDE assertions
425c_excludes: #-- Empty
426 | SYM_EXCLUDE invariants
427{
428 result = val[1]
429}
430
431invariants: invariant
432 | invariants invariant
433
434invariant: any_identifier ':' boolean_expression
435 | boolean_expression
436 | any_identifier ':' error
437
438arch_invariant: #-- no invariant ok
439 | SYM_INVARIANT V_ASSERTION_TEXT
440 | SYM_INVARIANT error
441
442# define all linguistic entries in this part as dADL.
443#arch_ontology: SYM_ONTOLOGY V_DADL_TEXT
444# | SYM_ONTOLOGY error
445
446arch_ontology: SYM_ONTOLOGY dadl_section
447 {
448 dadl_section = val[1]
449 result = OpenEHR::AM::Archetype::Ontology::ARCHETYPE_ONTOLOGY.new
450 }
451 | SYM_ONTOLOGY error
452
453
454### dADL section
455dadl_section: dadl_input
456
457dadl_input: attr_vals
458 | complex_object_block
459# | error
460
461attr_vals: attr_val
462 {
463 result = Array[val[0]]
464 }
465 | attr_vals attr_val
466 {
467 result = (val[0] << val[1])
468 }
469 | attr_vals Semicolon_code attr_val
470 {
471 result = (val[0] << val[2])
472 }
473
474attr_val: attr_id SYM_EQ object_block
475 {
476 @@log.info("#{__FILE__}:#{__LINE__}: attr_id = #{val[0]}, object_block = #{val[2]} at #{@filename}:#{@lineno}")
477 result = {:attr_id => val[0], :object_block => val[2]}
478 }
479
480attr_id: V_ATTRIBUTE_IDENTIFIER
481 {
482 @@log.info("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}:#{@lineno}")
483 result = val[0]
484 }
485 | V_ATTRIBUTE_IDENTIFIER error
486
487object_block: complex_object_block
488 {
489 result = val[0]
490 }
491 | primitive_object_block
492 {
493 result = val[0]
494 }
495
496complex_object_block: single_attr_object_block
497 {
498 result = val[0]
499 }
500 | multiple_attr_object_block
501 {
502 result = val[0]
503 }
504
505multiple_attr_object_block: untyped_multiple_attr_object_block
506 {
507 result = {:untyped_multiple_attr_object_block => val[0]}
508 }
509 | type_identifier untyped_multiple_attr_object_block
510 {
511 result = {:type_identifier => val[0], :untyped_multiple_attr_object_block => val[1]}
512 }
513
514untyped_multiple_attr_object_block: multiple_attr_object_block_head keyed_objects SYM_END_DBLOCK
515 {
516 result = {:multiple_attr_object_block_head => val[0], :keyed_objects => val[1]}
517 }
518
519multiple_attr_object_block_head: SYM_START_DBLOCK
520 {
521 @@log.info("SYM_START_DBLOCK: #{val[0]} at #{@filename}:#{@lineno}")
522 result = val[0]
523 }
524
525keyed_objects: keyed_object
526 {
527 result = Array[val[0]]
528 }
529 | keyed_objects keyed_object
530 {
531 result = (val[0] << val[1])
532 }
533
534keyed_object: object_key SYM_EQ object_block
535 {
536 @@log.info("#{__FILE__}:#{__LINE__}: keyed_object = #{val[0]}, object_block = #{val[2]} at #{@filename}:#{@lineno}")
537 result = {:object_key => val[0], :object_block => val[1]}
538 }
539
540object_key: Left_bracket_code simple_value Right_bracket_code
541 {
542 @@log.info("object_key: [#{val[1]}] at #{@filename}:#{@lineno}")
543 result = val[1]
544 }
545
546single_attr_object_block: untyped_single_attr_object_block
547 {
548 result = {:untyped_single_attr_object_block => val[0]}
549 }
550 | type_identifier untyped_single_attr_object_block
551 {
552 result = {:type_identifier => val[0], :untyped_single_attr_object_block => val[1]}
553 }
554
555untyped_single_attr_object_block: single_attr_object_complex_head SYM_END_DBLOCK # >
556 {
557 @@log.info("#{__FILE__}:#{__LINE__}: single_attr_object_complex_head = #{val[0]} at #{@filename}:#{@lineno}")
558 result = {:single_attr_object_complex_head => val[0]}
559 }
560 | single_attr_object_complex_head attr_vals SYM_END_DBLOCK
561 {
562 @@log.info("#{__FILE__}:#{__LINE__}: single_attr_object_complex_head = #{val[0]}, attr_vals = #{val[1]} at #{@filename}:#{@lineno}")
563 result = {:single_attr_object_complex_head => val[0], :attr_vals => val[1]}
564 }
565single_attr_object_complex_head: SYM_START_DBLOCK
566primitive_object_block: untyped_primitive_object_block
567 {
568 @@log.info("#{__FILE__}:#{__LINE__}: untyped_primitive_object_block = #{val[0]} at #{@filename}:#{@lineno}")
569 result = {:untyped_primitive_object_block => val[0]}
570 }
571 | type_identifier untyped_primitive_object_block
572 {
573 @@log.info("#{__FILE__}:#{__LINE__}: type_identifier = #{val[0]}, untyped_primitive_object_block = #{val[1]} at #{@filename}:#{@lineno}")
574 result = {:type_identifier => val[0], :untyped_primitive_object_block => val[1]}
575 }
576untyped_primitive_object_block: SYM_START_DBLOCK primitive_object_value SYM_END_DBLOCK
577 {
578 @@log.info("#{__FILE__}:#{__LINE__}: primitive_object_block = <#{val[1]}> at #{@filename}:#{@lineno}")
579 result = val[1]
580 }
581primitive_object_value: simple_value
582 {
583 result = val[0]
584 }
585 | simple_list_value
586 {
587 result = val[0]
588 }
589 | simple_interval_value
590 {
591 result = val[0]
592 }
593 | term_code
594 {
595 result = val[0]
596 }
597 | term_code_list_value
598 {
599 result = val[0]
600 }
601simple_value: string_value
602 {
603 @@log.info("string_value: #{val[0]} at #{@filename}:#{@lineno}")
604 result = val[0]
605 }
606 | integer_value
607 {
608 @@log.info("integer_value: #{val[0]} at #{@filename}:#{@lineno}")
609 result = val[0]
610 }
611 | real_value
612 {
613 @@log.info("real_value: #{val[0]} at #{@filename}:#{@lineno}")
614 result = val[0]
615 }
616 | boolean_value
617 {
618 @@log.info("boolean_value: #{val[0]} at #{@filename}:#{@lineno}")
619 result = val[0]
620 }
621 | character_value
622 {
623 @@log.info("character_value: #{val[0]} at #{@filename}:#{@lineno}")
624 result = val[0]
625 }
626 | date_value
627 {
628 @@log.info("date_value: #{val[0]} at #{@filename}:#{@lineno}")
629 result = val[0]
630 }
631 | time_value
632 {
633 @@log.info("time_value: #{val[0]} at #{@filename}:#{@lineno}")
634 result = val[0]
635 }
636 | date_time_value
637 {
638 @@log.info("date_time_value: #{val[0]} at #{@filename}:#{@lineno}")
639 result = val[0]
640 }
641 | duration_value
642 {
643 @@log.info("duration_value: #{val[0]} at #{@filename}:#{@lineno}")
644 result = val[0]
645 }
646 | uri_value
647 {
648 @@log.info("uri_value: #{val[0]} at #{@filename}:#{@lineno}")
649 result = val[0]
650 }
651
652simple_list_value: string_list_value
653 | integer_list_value
654 | real_list_value
655 | boolean_list_value
656 | character_list_value
657 | date_list_value
658 | time_list_value
659 | date_time_list_value
660 | duration_list_value
661
662simple_interval_value: integer_interval_value
663 | real_interval_value
664 | date_interval_value
665 | time_interval_value
666 | date_time_interval_value
667 | duration_interval_value
668
669type_identifier: V_TYPE_IDENTIFIER
670 {
671 @@log.info("V_TYPE_IDENTIFIER: #{val[0]} at #{@filename}:#{@lineno}")
672 result = val[0]
673 }
674 | V_GENERIC_TYPE_IDENTIFIER
675 {
676 @@log.info("V_GENERIC_TYPE_IDENTIFIER: #{val[0]} at #{@filename}:#{@lineno}")
677 result = val[0]
678 }
679
680string_value: V_STRING
681 {
682 @@log.info("V_STRING: #{val[0]} at #{@filename}:#{@lineno}")
683 result = val[0]
684 }
685
686string_list_value: V_STRING Comma_code V_STRING
687 | string_list_value Comma_code V_STRING
688 | V_STRING Comma_code SYM_LIST_CONTINUE
689
690integer_value: V_INTEGER
691 {
692 begin
693 integer = Integer(val[0])
694 rescue
695 raise
696 end
697 result = integer
698 }
699 | Plus_code V_INTEGER
700 {
701 begin
702 integer = Integer(val[0])
703 rescue
704 raise
705 end
706 result = integer
707 }
708 | Minus_code V_INTEGER
709 {
710 begin
711 integer = Integer(val[0])
712 rescue
713 raise
714 end
715 result = - integer
716 }
717### | '+' V_INTEGER
718### | '-' V_INTEGER
719
720integer_list_value: integer_value Comma_code integer_value
721 | integer_list_value Comma_code integer_value
722 | integer_value Comma_code SYM_LIST_CONTINUE
723
724integer_interval_value: SYM_INTERVAL_DELIM integer_value SYM_ELLIPSIS integer_value SYM_INTERVAL_DELIM
725 | SYM_INTERVAL_DELIM SYM_GT integer_value SYM_ELLIPSIS integer_value SYM_INTERVAL_DELIM
726 | SYM_INTERVAL_DELIM integer_value SYM_ELLIPSIS SYM_LT integer_value SYM_INTERVAL_DELIM
727 | SYM_INTERVAL_DELIM SYM_GT integer_value SYM_ELLIPSIS SYM_LT integer_value SYM_INTERVAL_DELIM
728 | SYM_INTERVAL_DELIM SYM_LT integer_value SYM_INTERVAL_DELIM
729 | SYM_INTERVAL_DELIM SYM_LE integer_value SYM_INTERVAL_DELIM
730 | SYM_INTERVAL_DELIM SYM_GT integer_value SYM_INTERVAL_DELIM
731 | SYM_INTERVAL_DELIM SYM_GE integer_value SYM_INTERVAL_DELIM
732 | SYM_INTERVAL_DELIM integer_value SYM_INTERVAL_DELIM
733
734real_value: V_REAL
735 {
736 begin
737 real = Float(val[0])
738 rescue
739 raise
740 end
741 result = real
742 }
743 | Plus_code V_REAL
744 {
745 begin
746 real = Float(val[1])
747 rescue
748 raise
749 end
750 result = real
751 }
752 | Minus_code V_REAL
753 {
754 begin
755 real = Float(val[1])
756 rescue
757 raise
758 end
759 result = - real
760 }
761
762real_list_value: real_value Comma_code real_value
763 | real_list_value Comma_code real_value
764 | real_value Comma_code SYM_LIST_CONTINUE
765
766real_interval_value: SYM_INTERVAL_DELIM real_value SYM_ELLIPSIS real_value SYM_INTERVAL_DELIM
767 | SYM_INTERVAL_DELIM SYM_GT real_value SYM_ELLIPSIS real_value SYM_INTERVAL_DELIM
768 | SYM_INTERVAL_DELIM real_value SYM_ELLIPSIS SYM_LT real_value SYM_INTERVAL_DELIM
769 | SYM_INTERVAL_DELIM SYM_GT real_value SYM_ELLIPSIS SYM_LT real_value SYM_INTERVAL_DELIM
770 | SYM_INTERVAL_DELIM SYM_LT real_value SYM_INTERVAL_DELIM
771 | SYM_INTERVAL_DELIM SYM_LE real_value SYM_INTERVAL_DELIM
772 | SYM_INTERVAL_DELIM SYM_GT real_value SYM_INTERVAL_DELIM
773 | SYM_INTERVAL_DELIM SYM_GE real_value SYM_INTERVAL_DELIM
774 | SYM_INTERVAL_DELIM real_value SYM_INTERVAL_DELIM
775
776
777boolean_value: SYM_TRUE
778 {
779 result = true
780 }
781 | SYM_FALSE
782 {
783 result = false
784 }
785
786boolean_list_value: boolean_value Comma_code boolean_value
787 | boolean_list_value Comma_code boolean_value
788 | boolean_value Comma_code SYM_LIST_CONTINUE
789
790character_value: V_CHARACTER
791
792character_list_value: character_value Comma_code character_value
793 | character_list_value Comma_code character_value
794 | character_value Comma_code SYM_LIST_CONTINUE
795
796date_value: V_ISO8601_EXTENDED_DATE
797
798date_list_value: date_value Comma_code date_value
799 | date_list_value Comma_code date_value
800 | date_value Comma_code SYM_LIST_CONTINUE
801
802date_interval_value: SYM_INTERVAL_DELIM date_value SYM_ELLIPSIS date_value SYM_INTERVAL_DELIM
803 | SYM_INTERVAL_DELIM SYM_GT date_value SYM_ELLIPSIS date_value SYM_INTERVAL_DELIM
804 | SYM_INTERVAL_DELIM date_value SYM_ELLIPSIS SYM_LT date_value SYM_INTERVAL_DELIM
805 | SYM_INTERVAL_DELIM SYM_GT date_value SYM_ELLIPSIS SYM_LT date_value SYM_INTERVAL_DELIM
806 | SYM_INTERVAL_DELIM SYM_LT date_value SYM_INTERVAL_DELIM
807 | SYM_INTERVAL_DELIM SYM_LE date_value SYM_INTERVAL_DELIM
808 | SYM_INTERVAL_DELIM SYM_GT date_value SYM_INTERVAL_DELIM
809 | SYM_INTERVAL_DELIM SYM_GE date_value SYM_INTERVAL_DELIM
810 | SYM_INTERVAL_DELIM date_value SYM_INTERVAL_DELIM
811
812time_value: V_ISO8601_EXTENDED_TIME
813
814time_list_value: time_value Comma_code time_value
815 | time_list_value Comma_code time_value
816 | time_value Comma_code SYM_LIST_CONTINUE
817
818time_interval_value: SYM_INTERVAL_DELIM time_value SYM_ELLIPSIS time_value SYM_INTERVAL_DELIM
819 | SYM_INTERVAL_DELIM SYM_GT time_value SYM_ELLIPSIS time_value SYM_INTERVAL_DELIM
820 | SYM_INTERVAL_DELIM time_value SYM_ELLIPSIS SYM_LT time_value SYM_INTERVAL_DELIM
821 | SYM_INTERVAL_DELIM SYM_GT time_value SYM_ELLIPSIS SYM_LT time_value SYM_INTERVAL_DELIM
822 | SYM_INTERVAL_DELIM SYM_LT time_value SYM_INTERVAL_DELIM
823 | SYM_INTERVAL_DELIM SYM_LE time_value SYM_INTERVAL_DELIM
824 | SYM_INTERVAL_DELIM SYM_GT time_value SYM_INTERVAL_DELIM
825 | SYM_INTERVAL_DELIM SYM_GE time_value SYM_INTERVAL_DELIM
826 | SYM_INTERVAL_DELIM time_value SYM_INTERVAL_DELIM
827
828date_time_value: V_ISO8601_EXTENDED_DATE_TIME
829
830date_time_list_value: date_time_value Comma_code date_time_value
831 | date_time_list_value Comma_code date_time_value
832 | date_time_value Comma_code SYM_LIST_CONTINUE
833
834date_time_interval_value: SYM_INTERVAL_DELIM date_time_value SYM_ELLIPSIS date_time_value SYM_INTERVAL_DELIM
835 | SYM_INTERVAL_DELIM SYM_GT date_time_value SYM_ELLIPSIS date_time_value SYM_INTERVAL_DELIM
836 | SYM_INTERVAL_DELIM date_time_value SYM_ELLIPSIS SYM_LT date_time_value SYM_INTERVAL_DELIM
837 | SYM_INTERVAL_DELIM SYM_GT date_time_value SYM_ELLIPSIS SYM_LT date_time_value SYM_INTERVAL_DELIM
838 | SYM_INTERVAL_DELIM SYM_LT date_time_value SYM_INTERVAL_DELIM
839 | SYM_INTERVAL_DELIM SYM_LE date_time_value SYM_INTERVAL_DELIM
840 | SYM_INTERVAL_DELIM SYM_GT date_time_value SYM_INTERVAL_DELIM
841 | SYM_INTERVAL_DELIM SYM_GE date_time_value SYM_INTERVAL_DELIM
842 | SYM_INTERVAL_DELIM date_time_value SYM_INTERVAL_DELIM
843
844duration_value: V_ISO8601_DURATION
845 {
846 @@log.info("V_ISO8601_DURATION: #{val[0]} at #{@filename}:#{@lineno}")
847 result = val[0]
848 }
849
850duration_list_value: duration_value Comma_code duration_value
851 | duration_list_value Comma_code duration_value
852 | duration_value Comma_code SYM_LIST_CONTINUE
853
854duration_interval_value: SYM_INTERVAL_DELIM duration_value SYM_ELLIPSIS duration_value SYM_INTERVAL_DELIM
855 | SYM_INTERVAL_DELIM SYM_GT duration_value SYM_ELLIPSIS duration_value SYM_INTERVAL_DELIM
856 | SYM_INTERVAL_DELIM duration_value SYM_ELLIPSIS SYM_LT duration_value SYM_INTERVAL_DELIM
857 | SYM_INTERVAL_DELIM SYM_GT duration_value SYM_ELLIPSIS SYM_LT duration_value SYM_INTERVAL_DELIM
858 | SYM_INTERVAL_DELIM SYM_LT duration_value SYM_INTERVAL_DELIM
859 | SYM_INTERVAL_DELIM SYM_LE duration_value SYM_INTERVAL_DELIM
860 | SYM_INTERVAL_DELIM SYM_GT duration_value SYM_INTERVAL_DELIM
861 | SYM_INTERVAL_DELIM SYM_GE duration_value SYM_INTERVAL_DELIM
862 | SYM_INTERVAL_DELIM duration_value SYM_INTERVAL_DELIM
863
864term_code: V_QUALIFIED_TERM_CODE_REF
865 {
866 @@log.info("#{__FILE__}:#{__LINE__}: V_QUALIFIED_TERM_CODE_REF = #{val[0]} at #{@filename}:#{@lineno}")
867 result = val[0]
868 }
869
870term_code_list_value: term_code Comma_code term_code
871 | term_code_list_value Comma_code term_code
872 | term_code Comma_code SYM_LIST_CONTINUE
873
874uri_value: V_URI
875 {
876 @@log.info("#{__FILE__}:#{__LINE__}: V_URI = #{val[0]} at #{@filename}:#{@lineno}")
877 result = val[0]
878 }
879
880
881#---------------------- ASSERTIONS ------------------------
882
883assertions: assertion
884 | assertions assertion
885
886assertion: any_identifier ':' boolean_expression
887 | boolean_expression
888 | any_identifier ':' error
889
890#---------------------- expressions ---------------------
891
892boolean_expression: boolean_leaf
893 | boolean_node
894
895boolean_node: SYM_EXISTS absolute_path
896# | absolute_path
897 | SYM_EXISTS error
898 | relative_path SYM_MATCHES SYM_START_CBLOCK c_primitive SYM_END_CBLOCK
899 | relative_path SYM_MATCHES START_REGEXP_BLOCK REGEXP_BODY END_REGEXP_BLOCK # added by akimichi
900 | SYM_NOT boolean_leaf
901 | arithmetic_expression '=' arithmetic_expression
902 | arithmetic_expression SYM_NE arithmetic_expression
903 | arithmetic_expression SYM_LT arithmetic_expression
904 | arithmetic_expression SYM_GT arithmetic_expression
905 | arithmetic_expression SYM_LE arithmetic_expression
906 | arithmetic_expression SYM_GE arithmetic_expression
907 | boolean_expression SYM_AND boolean_expression
908 | boolean_expression SYM_OR boolean_expression
909 | boolean_expression SYM_XOR boolean_expression
910 | boolean_expression SYM_IMPLIES boolean_expression
911
912boolean_leaf: Left_parenthesis_code boolean_expression Right_parenthesis_code
913 | SYM_TRUE
914 | SYM_FALSE
915
916arithmetic_expression: arithmetic_leaf
917 | arithmetic_node
918
919arithmetic_node: arithmetic_expression '+' arithmetic_leaf
920 | arithmetic_expression '-' arithmetic_leaf
921 | arithmetic_expression Star_code arithmetic_leaf
922 | arithmetic_expression Slash_code arithmetic_leaf
923 | arithmetic_expression '^' arithmetic_leaf
924
925arithmetic_leaf: Left_parenthesis_code arithmetic_expression Right_parenthesis_code
926 | integer_value
927 | real_value
928 | absolute_path
929
930
931#--------------- THE FOLLOWING SOURCE TAKEN FROM OG_PATH_VALIDATOR.Y -------------
932#--------------- except to remove movable_path ----------------------------------------------------
933
934
935absolute_path: Slash_code
936 | Slash_code relative_path
937# | absolute_path Slash_code relative_path
938
939
940
941relative_path: path_segment
942 | relative_path Slash_code path_segment
943
944path_segment: V_ATTRIBUTE_IDENTIFIER V_LOCAL_TERM_CODE_REF
945 {
946 @@log.info("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}")
947 }
948 | V_ATTRIBUTE_IDENTIFIER
949 {
950 @@log.info("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}")
951 }
952
953
954#-------------------------------- END SOURCE TAKEN FROM OG_PATH_VALIDATOR.Y ----------------------
955
956
957#---------------- existence, occurrences, cardinality ----------------
958
959c_existence: #-- default to 1..1
960 {
961 result = Range.new(1,1)
962 }
963 | SYM_EXISTENCE SYM_MATCHES SYM_START_CBLOCK existence_spec SYM_END_CBLOCK
964 {
965 result = val[3]
966 }
967
968existence_spec: V_INTEGER #-- can only be 0 or 1
969 {
970 begin
971 integer = Integer(val[0])
972 rescue
973 raise
974 end
975 result = integer
976 }
977 | V_INTEGER SYM_ELLIPSIS V_INTEGER #-- can only be 0..0, 0..1, 1..1
978 {
979 begin
980 from_integer = Integer(val[0])
981 to_integer = Integer(val[2])
982 rescue
983 raise
984 end
985 result = Range.new(from_integer,to_integer)
986 }
987
988c_cardinality: SYM_CARDINALITY SYM_MATCHES SYM_START_CBLOCK cardinality_spec SYM_END_CBLOCK
989 {
990 result = OpenEHR::AM::Archetype::Constraint_Model::CARDINALITY.new
991 }
992
993cardinality_spec: occurrence_spec
994 | occurrence_spec Semicolon_code SYM_ORDERED
995 | occurrence_spec Semicolon_code SYM_UNORDERED
996 | occurrence_spec Semicolon_code SYM_UNIQUE
997 | occurrence_spec Semicolon_code SYM_ORDERED Semicolon_code SYM_UNIQUE
998 | occurrence_spec Semicolon_code SYM_UNORDERED Semicolon_code SYM_UNIQUE
999 | occurrence_spec Semicolon_code SYM_UNIQUE Semicolon_code SYM_ORDERED
1000 | occurrence_spec Semicolon_code SYM_UNIQUE Semicolon_code SYM_UNORDERED
1001
1002cardinality_limit_value: integer_value
1003 {
1004 result = val[0]
1005 }
1006 | Star_code # '*'
1007 {
1008 result = val[0]
1009 }
1010
1011
1012c_occurrences: #-- default to 1..1
1013 | SYM_OCCURRENCES SYM_MATCHES SYM_START_CBLOCK occurrence_spec SYM_END_CBLOCK
1014 {
1015 result = val[3]
1016 }
1017 | SYM_OCCURRENCES error
1018
1019occurrence_spec: cardinality_limit_value #-- single integer or '*'
1020 | V_INTEGER SYM_ELLIPSIS cardinality_limit_value
1021
1022#---------------------- leaf constraint types -----------------------
1023
1024c_integer_spec: integer_value
1025 | integer_list_value
1026 | integer_interval_value
1027
1028c_integer: c_integer_spec
1029 | c_integer_spec Semicolon_code integer_value
1030 | c_integer_spec Semicolon_code error
1031
1032c_real_spec: real_value
1033 | real_list_value
1034 | real_interval_value
1035
1036c_real: c_real_spec
1037 | c_real_spec Semicolon_code real_value
1038 | c_real_spec Semicolon_code error
1039
1040c_date_constraint: V_ISO8601_DATE_CONSTRAINT_PATTERN
1041 | date_value
1042 | date_interval_value
1043
1044c_date: c_date_constraint
1045 | c_date_constraint Semicolon_code date_value
1046 | c_date_constraint Semicolon_code error
1047
1048c_time_constraint: V_ISO8601_TIME_CONSTRAINT_PATTERN
1049 | time_value
1050 | time_interval_value
1051
1052c_time: c_time_constraint
1053 | c_time_constraint Semicolon_code time_value
1054 | c_time_constraint Semicolon_code error
1055
1056c_date_time_constraint: V_ISO8601_DATE_TIME_CONSTRAINT_PATTERN
1057 | date_time_value
1058 | date_time_interval_value
1059
1060c_date_time: c_date_time_constraint
1061 | c_date_time_constraint Semicolon_code date_time_value
1062 | c_date_time_constraint Semicolon_code error
1063
1064c_duration_constraint: duration_pattern
1065 | duration_pattern Slash_code duration_interval_value
1066 | duration_value
1067 | duration_interval_value
1068
1069c_duration: c_duration_constraint
1070 | c_duration_constraint Semicolon_code duration_value
1071 | c_duration_constraint Semicolon_code error
1072
1073c_string_spec: V_STRING #-- single value, generates closed list
1074 | string_list_value #-- closed list
1075 | string_list_value Comma_code SYM_LIST_CONTINUE #-- open list
1076# | string_list_value ',' SYM_LIST_CONTINUE #-- open list
1077# | V_REGEXP #-- regular expression with "//" or "^^" delimiters
1078
1079c_string: c_string_spec
1080 | c_string_spec Semicolon_code string_value
1081 | c_string_spec Semicolon_code error
1082
1083c_boolean_spec: SYM_TRUE
1084 {
1085 result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid => true)
1086 }
1087 | SYM_FALSE
1088 {
1089 result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid => false)
1090 }
1091 | SYM_TRUE Comma_code SYM_FALSE
1092 {
1093 result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid => true,:false_valid => false)
1094 }
1095 | SYM_FALSE Comma_code SYM_TRUE
1096 {
1097 result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid => false,:false_valid => true)
1098 }
1099
1100c_boolean: c_boolean_spec
1101 {
1102 result = val[0]
1103 }
1104 | c_boolean_spec Semicolon_code boolean_value
1105 {
1106 raise 'Not implemented yet'
1107 }
1108 | c_boolean_spec Semicolon_code error
1109 {
1110 raise 'Not implemented yet'
1111 }
1112
1113c_ordinal: c_ordinal_spec
1114 | c_ordinal_spec Semicolon_code integer_value
1115 | c_ordinal_spec Semicolon_code error
1116
1117c_ordinal_spec: ordinal
1118 | c_ordinal_spec Comma_code ordinal
1119
1120ordinal: integer_value SYM_INTERVAL_DELIM V_QUALIFIED_TERM_CODE_REF
1121 {
1122 @in_interval = false
1123 @@log.info("#{__FILE__}:#{__LINE__}, #{val[0]}|#{val[2]} at #{@filename}")
1124 }
1125
1126#c_code_phrase: V_TERM_CODE_CONSTRAINT #-- e.g. "[local::at0040, at0041; at0040]"
1127c_code_phrase: term_code_constraint_section #-- e.g. "[local::at0040, at0041; at0040]"
1128 {
1129 result = val[0]
1130 }
1131 | V_QUALIFIED_TERM_CODE_REF
1132 {
1133 result = val[0]
1134 }
1135
1136#term_code_constraint_section: START_TERM_CODE_CONSTRAINT term_code_body Right_bracket_code
1137term_code_constraint_section: START_TERM_CODE_CONSTRAINT term_code_body END_TERM_CODE_CONSTRAINT
1138term_code_body: # empty
1139 | TERM_CODE
1140 | term_code_body TERM_CODE
1141### term_code_constraint_section: START_TERM_CODE_CONSTRAINT term_code_body END_TERM_CODE_CONSTRAINT
1142### term_code_body: TERM_CODE
1143### | term_code_body TERM_CODE
1144
1145# A Constraint_Ref is a proxy for a set of constraints on an object.
1146constraint_ref: V_LOCAL_TERM_CODE_REF #-- e.g. "ac0003"
1147 {
1148 result = val[0]
1149 }
1150
1151any_identifier: type_identifier
1152 {
1153 result = val[0]
1154 }
1155 | V_ATTRIBUTE_IDENTIFIER
1156 {
1157 @@log.info("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{word} at #{@filename}")
1158 result = val[0]
1159 }
1160
1161
1162#----------------- TAKEN FROM DADL_VALIDATOR.Y -------------------
1163#----------------- DO NOT MODIFY -------------------
1164#---------------------- BASIC DATA VALUES -----------------------
1165
1166duration_pattern: V_ISO8601_DURATION_CONSTRAINT_PATTERN
1167 {
1168 result = val[0]
1169 }
1170
1171
1172
1173---- header
1174
1175
1176$:.unshift File.join(File.dirname(__FILE__))
1177require 'logger'
1178#require 'lib/adl_parser.rb'
1179require 'rubygems'
1180require 'adl_parser.rb'
1181require 'am.rb'
1182require 'rm.rb'
1183
1184
1185
1186---- inner
1187
1188def assert_at(file,line, message = "")
1189 unless yield
1190 raise "Assertion failed !: #{file}, #{line}: #{message}"
1191 end
1192end
1193
1194if $DEBUG
1195 @@log = Logger.new('log/parser.log','daily')
1196 @@log.level = Logger::INFO
1197else
1198 @@log = Logger.new(STDOUT)
1199 @@log.level = Logger::WARN
1200end
1201
1202@@dadl_scanner = OpenEHR::ADL::Scanner::DADL::RootScanner.new
1203@@cadl_scanner = OpenEHR::ADL::Scanner::CADL::RootScanner.new
1204
1205###----------/* keywords */ ---------------------------------------------
1206@@adl_reserved = {
1207 'archetype' => :SYM_ARCHETYPE,
1208 'adl_version' => :SYM_ADL_VERSION,
1209 'controlled' => :SYM_IS_CONTROLLED,
1210 'specialize' => :SYM_SPECIALIZE,
1211 'concept' => :SYM_CONCEPT,
1212 'language' => :SYM_LANGUAGE,
1213 'description' => :SYM_DESCRIPTION,
1214 'definition' => :SYM_DEFINITION,
1215 'invariant' => :SYM_INVARIANT,
1216 'ontology' => :SYM_ONTOLOGY,
1217 'matches' => :SYM_MATCHES,
1218 'is_in' => :SYM_MATCHES,
1219 'occurrences' => :SYM_OCCURRENCES,
1220 'true' => :SYM_TRUE, #[Tt][Rr][Uu][Ee] -- -> SYM_TRUE
1221 'false' => :SYM_FALSE, # [Ff][Aa][Ll][Ss][Ee] -- -> SYM_FALSE
1222 'infinity' => :SYM_INFINITY # [Ii][Nn][Ff][Ii][Nn][Ii][Tt][Yy] -- -> SYM_INFINITY
1223}
1224
1225@@dadl_reserved = {
1226 'true' => :SYM_TRUE, #[Tt][Rr][Uu][Ee] -- -> SYM_TRUE
1227 'false' => :SYM_FALSE, # [Ff][Aa][Ll][Ss][Ee] -- -> SYM_FALSE
1228 'infinity' => :SYM_INFINITY # [Ii][Nn][Ff][Ii][Nn][Ii][Tt][Yy] -- -> SYM_INFINITY
1229}
1230
1231@@cadl_reserved = {
1232 'then' => :SYM_THEN, # [Tt][Hh][Ee][Nn]
1233 'else' => :SYM_ELSE, # [Ee][Ll][Ss][Ee]
1234 'and' => :SYM_AND, # [Aa][Nn][Dd]
1235 'or' => :SYM_OR, # [Oo][Rr]
1236 'xor' => :SYM_XOR, # [Xx][Oo][Rr]
1237 'not' => :SYM_NOT, # [Nn][Oo][Tt]
1238 'implies' => :SYM_IMPLIES, # [Ii][Mm][Pp][Ll][Ii][Ee][Ss]
1239 'true' => :SYM_TRUE, #[Tt][Rr][Uu][Ee] -- -> SYM_TRUE
1240 'false' => :SYM_FALSE, # [Ff][Aa][Ll][Ss][Ee] -- -> SYM_FALSE
1241 'forall' => :SYM_FORALL, # [Ff][Oo][Rr][_][Aa][Ll][Ll]
1242 'exists' => :SYM_EXISTS, # [Ee][Xx][Ii][Ss][Tt][Ss]
1243 'existence' => :SYM_EXISTENCE, # [Ee][Xx][Iu][Ss][Tt][Ee][Nn][Cc][Ee]
1244 'occurrences' => :SYM_OCCURRENCES, # [Oo][Cc][Cc][Uu][Rr][Rr][Ee][Nn][Cc][Ee][Ss]
1245 'cardinality' => :SYM_CARDINALITY, # [Cc][Aa][Rr][Dd][Ii][Nn][Aa][Ll][Ii][Tt][Yy]
1246 'ordered' => :SYM_ORDERED, # [Oo][Rr][Dd][Ee][Rr][Ee][Dd]
1247 'unordered' => :SYM_UNORDERED, # [Uu][Nn][Oo][Rr][Dd][Ee][Rr][Ee][Dd]
1248 'unique' => :SYM_UNIQUE, # [Uu][Nn][Ii][Qq][Uu][Ee]
1249 'matches' => :SYM_MATCHES, # [Mm][Aa][Tt][Cc][Hh][Ee][Ss]
1250 'is_in' => :SYM_MATCHES, # [Ii][Ss][_][Ii][Nn]
1251 'invariant' => :SYM_INVARIANT, # [Ii][Nn][Vv][Aa][Rr][Ii][Aa][Nn][Tt]
1252 'infinity' => :SYM_INFINITY, # [Ii][Nn][Ff][Ii][Nn][Ii][Tt][Yy] -- -> SYM_INFINITY
1253 'use_node' => :SYM_USE_NODE, # [Uu][Ss][Ee][_][Nn][Oo][Dd][Ee]
1254 'use_archetype' => :SYM_ALLOW_ARCHETYPE, # [Uu][Ss][Ee][_][Aa][Rr][Cc][Hh][Ee][Tt][Yy][Pp][Ee]
1255 'allow_archetype' => :SYM_ALLOW_ARCHETYPE, # [Aa][Ll][Ll][Oo][Ww][_][Aa][Rr][Cc][Hh][Ee][Tt][Yy][Pp][Ee]
1256 'include' => :SYM_INCLUDE, # [Ii][Nn][Cc][Ll][Uu][Dd][Ee]
1257 'exclude' => :SYM_EXCLUDE # [Ee][Xx][Cc][Ll][Uu][Dd][Ee]
1258}
1259
1260
1261###----------/* Scanner */ -----------------------------------------------
1262
1263def scan
1264 until @data.nil? do
1265 case @adl_type.last
1266 when :adl
1267 @data = scan_adl(@data) do |sym, val|
1268 yield sym, val
1269 end
1270 when :dadl
1271 @data = scan_dadl(@data) do |sym, val|
1272 yield sym, val
1273 end
1274 when :cadl
1275 @data = scan_cadl(@data) do |sym, val|
1276 yield sym, val
1277 end
1278 when :regexp
1279 @data = scan_regexp(@data) do |sym, val|
1280 yield sym, val
1281 end
1282 else
1283 raise
1284 end
1285 @data = $' # variable $' receives the string after the match
1286 end
1287 yield :EOF, nil
1288 yield false, '$'
1289end # of scan
1290
1291def scan_adl(data)
1292 until data.nil? do
1293 case @adl_type.last
1294 when :adl
1295# puts "Entering scan_adl"
1296 case data
1297 when /\A\n/ # carriage return
1298 @lineno += 1
1299 ;
1300 when /\A[ \t\r\f]+/ #just drop it
1301 ;
1302 when /\A--.*\n/ # single line comment
1303 @lineno += 1
1304 @@log.info("#{__FILE__}:#{__LINE__}: scan_adl: COMMENT = #{$&} at #{@filename}:#{@lineno}")
1305 ;
1306 when /\Adescription/ # description
1307 yield :SYM_DESCRIPTION, :SYM_DESCRIPTION
1308 when /\Adefinition/ # definition
1309 yield :SYM_DEFINITION, :SYM_DEFINITION
1310# @adl_type.push(:cadl)
1311 ###----------/* symbols */ -------------------------------------------------
1312 when /\A[A-Z][a-zA-Z0-9_]*/
1313 yield :V_TYPE_IDENTIFIER, $&
1314# when /\A[a-zA-Z][a-zA-Z0-9_-]+\.[a-zA-Z][a-zA-Z0-9_-]+\.[a-zA-Z0-9]+/ #V_ARCHETYPE_ID
1315 when /\A(\w+)-(\w+)-(\w+)\.(\w+)(-\w+)?\.(v[0-9]+)/ #V_ARCHETYPE_ID
1316 object_id, rm_originator, rm_name, rm_entity, concept_name, specialisation, version_id = $&, $1, $2, $3, $4, $5, $6
1317 archetype_id = OpenEHR::RM::Support::Identification::Archetype_ID.new(object_id, concept_name, rm_name, rm_entity, rm_originator, specialisation, version_id)
1318# yield :V_ARCHETYPE_ID, $&
1319 yield :V_ARCHETYPE_ID, archetype_id
1320 when /\A[a-z][a-zA-Z0-9_]*/
1321# word = $&.downcase
1322 word = $&
1323 if @@adl_reserved[word]
1324 @@log.info("#{__FILE__}:#{__LINE__}: scan_adl: @@adl_reserved = #{@@adl_reserved[word]} at #{@filename}:#{@lineno}")
1325 yield @@adl_reserved[word], @@adl_reserved[word]
1326 elsif #/\A[A-Z][a-zA-Z0-9_]*/
1327 @@log.info("#{__FILE__}:#{__LINE__}: scan_adl: V_ATTRIBUTE_IDENTIFIER = #{$&} at #{@filename}:#{@lineno}")
1328 yield :V_ATTRIBUTE_IDENTIFIER, $&
1329 end
1330 when /\A\=/ # =
1331 yield :SYM_EQ, :SYM_EQ
1332 when /\A\>=/ # >=
1333 yield :SYM_GE, :SYM_GE
1334 when /\A\<=/ # <=
1335 yield :SYM_LE, :SYM_LE
1336 when /\A\</ # <
1337 if @in_interval
1338# @start_block_received = false
1339 yield :SYM_LT, :SYM_LT
1340 else
1341# @start_block_received = true
1342 @adl_type.push(:dadl)
1343 yield :SYM_START_DBLOCK, $&
1344 end
1345 when /\A\>/ # >
1346 if @in_interval
1347 yield :SYM_GT, :SYM_GT
1348 else
1349 adl_type = @adl_type.pop
1350# puts "Escaping #{adl_type}"
1351 assert_at(__FILE__,__LINE__){adl_type == :dadl}
1352 yield :SYM_END_DBLOCK, :SYM_END_DBLOCK
1353 end
1354 when /\A\{/ # {
1355 @adl_type.push(:cadl)
1356 @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: entering cADL at #{@filename}:#{@lineno}")
1357 yield :SYM_START_CBLOCK, :SYM_START_CBLOCK
1358 when /\A\}/ # }
1359 adl_type = @adl_type.pop
1360# puts "Escaping #{adl_type}"
1361 assert_at(__FILE__,__LINE__){adl_type == :cadl}
1362 @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: exiting cADL at #{@filename}:#{@lineno}")
1363 yield :SYM_END_CBLOCK, $&
1364 when /\A\-/ # -
1365 yield :Minus_code, :Minus_code
1366 when /\A\+/ # +
1367 yield :Plus_code, :Plus_code
1368 when /\A\*/ # *
1369 yield :Star_code, :Star_code
1370 when /\A\// # /
1371 yield :Slash_code, :Slash_code
1372 when /\A\^/ # ^
1373 yield :Caret_code, :Caret_code
1374 when /\A\=/ # =
1375 yield :Equal_code, :Equal_code
1376 when /\A\.\.\./ # ...
1377 yield :SYM_LIST_CONTINUE, :SYM_LIST_CONTINUE
1378 when /\A\.\./ # ..
1379 yield :SYM_ELLIPSIS, :SYM_ELLIPSIS
1380 when /\A\./ # .
1381 yield :Dot_code, :Dot_code
1382 when /\A\;/ # ;
1383 yield :Semicolon_code, :Semicolon_code
1384 when /\A\,/ # ,
1385 yield :Comma_code, :Comma_code
1386 when /\A\:/ # :
1387 yield :Colon_code, :Colon_code
1388 when /\A\!/ # !
1389 yield :Exclamation_code, :Exclamation_code
1390 when /\A\(/ # (
1391 yield :Left_parenthesis_code, :Left_parenthesis_code
1392 when /\A\)/ # )
1393 yield :Right_parenthesis_code, :Right_parenthesis_code
1394 when /\A\$/ # $
1395 yield :Dollar_code, :Dollar_code
1396 when /\A\?\?/ # ??
1397 yield :SYM_DT_UNKNOWN, :SYM_DT_UNKNOWN
1398 when /\A\?/ # ?
1399 yield :Question_mark_code, :Question_mark_code
1400 when /\A[0-9]+\.[0-9]+(\.[0-9]+)*/ # ?
1401 yield :V_VERSION_STRING, $&
1402 when /\A\|/ # |
1403 if @in_interval
1404 @in_interval = false
1405 else
1406 @in_interval = true
1407 end
1408 yield :SYM_INTERVAL_DELIM, :SYM_INTERVAL_DELIM
1409 when /\A\[[a-zA-Z0-9()\._-]+::[a-zA-Z0-9\._-]+\]/
1410# when /\A\[[a-zA-Z0-9()\._-]+\:\:[a-zA-Z0-9\._-]+\]/ #V_QUALIFIED_TERM_CODE_REF form [ICD10AM(1998)::F23]
1411 yield :V_QUALIFIED_TERM_CODE_REF, $&
1412 when /\A\[[a-zA-Z0-9][a-zA-Z0-9._\-]*\]/ #V_LOCAL_TERM_CODE_REF
1413 yield :V_LOCAL_TERM_CODE_REF, $&
1414 when /\A\[/ # [
1415 yield :Left_bracket_code, :Left_bracket_code
1416 when /\A\]/ # ]
1417 yield :Right_bracket_code, :Right_bracket_code
1418
1419 when /\A"([^"]*)"/m #V_STRING
1420 yield :V_STRING, $1
1421 when /\A\[[a-zA-Z0-9._\- ]+::[a-zA-Z0-9._\- ]+\]/ #ERR_V_QUALIFIED_TERM_CODE_REF
1422 yield :ERR_V_QUALIFIED_TERM_CODE_REF, $&
1423 when /\Aa[ct][0-9.]+/ #V_LOCAL_CODE
1424 yield :V_LOCAL_CODE, $&
1425 when /\A[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9](,[0-9]+)?(Z|[+-][0-9]{4})?|[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-6][0-9](Z|[+-][0-9]{4})?|[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9](Z|[+-][0-9]{4})?/ #V_ISO8601_EXTENDED_DATE_TIME YYYY-MM-DDThh:mm:ss[,sss][Z|+/- -n-n-n-n-]-
1426 yield :V_ISO8601_EXTENDED_DATE_TIME, $&
1427 when /\A[0-2][0-9]:[0-6][0-9]:[0-6][0-9](,[0-9]+)?(Z|[+-][0-9]{4})?|[0-2][0-9]:[0-6][0-9](Z|[+-][0-9]{4})? / #V_ISO8601_EXTENDED_TIME hh:mm:ss[,sss][Z|+/-nnnn]
1428 yield :V_ISO8601_EXTENDED_TIME, $&
1429 when /\A[0-9]{4}-[0-1][0-9]-[0-3][0-9]|[0-9]{4}-[0-1][0-9]/ #V_ISO8601_EXTENDED_DATE YYYY-MM-DD
1430 yield :V_ISO8601_EXTENDED_DATE, $&
1431 when /\A[A-Z][a-zA-Z0-9_]*<[a-zA-Z0-9,_<>]+>/ #V_GENERIC_TYPE_IDENTIFIER
1432 yield :V_GENERIC_TYPE_IDENTIFIER, $&
1433 when /\A[0-9]+|[0-9]+[eE][+-]?[0-9]+/ #V_INTEGER
1434 yield :V_INTEGER, $&
1435 when /\A[0-9]+\.[0-9]+|[0-9]+\.[0-9]+[eE][+-]?[0-9]+ / #V_REAL
1436 yield :V_REAL, $&
1437 # when /\A"((?:[^"\\]+|\\.)*)"/ #V_STRING
1438 when /\A[a-z]+:\/\/[^<>|\\{}^~"\[\] ]*/ #V_URI
1439 yield :V_URI, $&
1440 when /\AP([0-9]+[yY])?([0-9]+[mM])?([0-9]+[wW])?([0-9]+[dD])?T([0-9]+[hH])?([0-9]+[mM])?([0-9]+[sS])?|P([0-9]+[yY])?([0-9]+[mM])?([0-9]+[wW])?([0-9]+[dD])?/ #V_ISO8601_DURATION PnYnMnWnDTnnHnnMnnS
1441 yield :V_ISO8601_DURATION, $&
1442 when /\A\S/ #UTF8CHAR
1443 yield :UTF8CHAR, $&
1444 end
1445 data = $' # variable $' receives the string after the match
1446 when :dadl
1447# puts "Entering scan_dadl"
1448 data = scan_dadl(data) do |sym, val|
1449 yield sym, val
1450 end
1451 when :cadl
1452# puts "Entering scan_cadl"
1453 data = scan_cadl(data) do |sym, val|
1454 yield sym, val
1455 end
1456 when :regexp
1457# puts "Entering scan_regexp"
1458 data = scan_regexp(data) do |sym, val|
1459 yield sym, val
1460 end
1461 when :term_constraint
1462# puts "Entering scan_term_constraint"
1463 data = scan_term_constraint(data) do |sym, val|
1464 yield sym, val
1465 end
1466 else
1467 raise
1468 end
1469 end
1470end # scan_adl
1471
1472
1473def scan_cadl(data)
1474 until data.nil? do
1475 case @adl_type.last
1476 when :cadl
1477# puts "Entering scan_cadl"
1478 case scanned = @@cadl_scanner.parse(data)
1479 when Yaparc::Result::OK
1480 if scanned.value[0] == :START_V_C_DOMAIN_TYPE_BLOCK
1481 @in_c_domain_type = true
1482 @adl_type.push(:dadl)
1483 yield scanned.value
1484 else
1485 yield scanned.value
1486 end
1487 data = scanned.input
1488 end
1489
1490 case data
1491 when /\A\n/ # carriage return
1492 @lineno += 1
1493 ;
1494 when /\A[ \t\r\f]+/ #just drop it
1495 ;
1496 when /\A--.*\n/ # single line comment
1497 @lineno += 1
1498 @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: COMMENT = #{$&} at #{@filename}:#{@lineno}")
1499 ;
1500 ###----------/* symbols */ -------------------------------------------------
1501 when /\A\=/ # =
1502 yield :SYM_EQ, :SYM_EQ
1503 when /\A\>=/ # >=
1504 yield :SYM_GE, :SYM_GE
1505 when /\A\<=/ # <=
1506 yield :SYM_LE, :SYM_LE
1507### when /\A[A-Z][a-zA-Z0-9_]*[ \n]*\</ # V_C_DOMAIN_TYPE
1508### @in_c_domain_type = true
1509### @adl_type.push(:dadl)
1510### yield :START_V_C_DOMAIN_TYPE_BLOCK, $&
1511 when /\A\</ # <
1512 if @in_interval
1513 yield :SYM_LT, :SYM_LT
1514 else
1515 @adl_type.push(:dadl)
1516 yield :SYM_START_DBLOCK, $&
1517 end
1518 when /\A\>/ # >
1519 if @in_interval
1520 yield :SYM_GT, :SYM_GT
1521 else
1522 adl_type = @adl_type.pop
1523# puts "Escaping #{adl_type}"
1524 assert_at(__FILE__,__LINE__){adl_type == :dadl}
1525 yield :SYM_END_DBLOCK, :SYM_END_DBLOCK
1526 end
1527 when /\A\-/ # -
1528 yield :Minus_code, :Minus_code
1529 when /\A\+/ # +
1530 yield :Plus_code, :Plus_code
1531 when /\A\*/ # *
1532 yield :Star_code, :Star_code
1533 when /\A\// # /
1534 yield :Slash_code, :Slash_code
1535 when /\A\^/ # ^
1536 yield :Caret_code, :Caret_code
1537 when /\A\.\.\./ # ...
1538 yield :SYM_LIST_CONTINUE, :SYM_LIST_CONTINUE
1539 when /\A\.\./ # ..
1540 yield :SYM_ELLIPSIS, :SYM_ELLIPSIS
1541 when /\A\./ # .
1542 yield :Dot_code, :Dot_code
1543 when /\A\;/ # ;
1544 yield :Semicolon_code, :Semicolon_code
1545 when /\A\,/ # ,
1546 yield :Comma_code, :Comma_code
1547 when /\A\:/ # :
1548 yield :Colon_code, :Colon_code
1549 when /\A\!/ # !
1550 yield :Exclamation_code, :Exclamation_code
1551 when /\A\(/ # (
1552 yield :Left_parenthesis_code, :Left_parenthesis_code
1553 when /\A\)/ # )
1554 yield :Right_parenthesis_code, :Right_parenthesis_code
1555 when /\A\{\// #V_REGEXP
1556 if @adl_type.last != :regexp
1557 @in_regexp = true
1558 @adl_type.push(:regexp)
1559 yield :START_REGEXP_BLOCK, :START_REGEXP_BLOCK
1560 else
1561 raise
1562 end
1563# yield :V_REGEXP, :V_REGEXP
1564 when /\A\{/ # {
1565 @adl_type.push(:cadl)
1566 @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: entering cADL at #{@filename}:#{@lineno}")
1567 yield :SYM_START_CBLOCK, :SYM_START_CBLOCK
1568 when /\A\}/ # }
1569 adl_type = @adl_type.pop
1570# puts "Escaping #{adl_type}"
1571 assert_at(__FILE__,__LINE__){adl_type == :cadl}
1572 @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: exiting cADL at #{@filename}:#{@lineno}")
1573 yield :SYM_END_CBLOCK, :SYM_END_CBLOCK
1574 when /\A\$/ # $
1575 yield :Dollar_code, :Dollar_code
1576 when /\A\?\?/ # ??
1577 yield :SYM_DT_UNKNOWN, :SYM_DT_UNKNOWN
1578 when /\A\?/ # ?
1579 yield :Question_mark_code, :Question_mark_code
1580 when /\A\|/ # |
1581 @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: @in_interval = #{@in_interval} at #{@filename}:#{@lineno}")
1582 if @in_interval
1583 @in_interval = false
1584 else
1585# @in_interval = false
1586 @in_interval = true
1587 end
1588 @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: SYM_INTERVAL_DELIM at #{@filename}:#{@lineno}")
1589 yield :SYM_INTERVAL_DELIM, :SYM_INTERVAL_DELIM
1590
1591 when /\A\[[a-zA-Z0-9._\-]+::[a-zA-Z0-9._\-]+\]/ #V_QUALIFIED_TERM_CODE_REF form [ICD10AM(1998)::F23]
1592 yield :V_QUALIFIED_TERM_CODE_REF, $&
1593 when /\A\[[a-zA-Z0-9._\- ]+::[a-zA-Z0-9._\- ]+\]/ #ERR_V_QUALIFIED_TERM_CODE_REF
1594 yield :ERR_V_QUALIFIED_TERM_CODE_REF, $&
1595 when /\A\[([a-zA-Z0-9()._\-]+::[a-zA-Z0-9._\_-]+)\]/
1596 yield :V_TERM_CODE_CONSTRAINT, :V_TERM_CODE_CONSTRAINT
1597 when /\A\[[a-zA-Z0-9\(\)\._\-]+::[ \t\n]*/
1598 @adl_type.push(:term_constraint)
1599 yield :START_TERM_CODE_CONSTRAINT, $&
1600 when /\A\[[a-zA-Z0-9][a-zA-Z0-9._\-]*\]/ #V_LOCAL_TERM_CODE_REF
1601 yield :V_LOCAL_TERM_CODE_REF, $&
1602 when /\A\[/ # [
1603 yield :Left_bracket_code, :Left_bracket_code
1604 when /\A\]/ # ]
1605 yield :Right_bracket_code, :Right_bracket_code
1606 when /\A[A-Z][a-zA-Z0-9_]*<[a-zA-Z0-9,_<>]+>/ #V_GENERIC_TYPE_IDENTIFIER
1607 yield :V_GENERIC_TYPE_IDENTIFIER, $&
1608 when /\A[yY][yY][yY][yY]-[mM?X][mM?X]-[dD?X][dD?X][T\t][hH?X][hH?X]:[mM?X][mM?X]:[sS?X][sS?X]/
1609 yield :V_ISO8601_DATE_TIME_CONSTRAINT_PATTERN, $&
1610 when /\A[yY][yY][yY][yY]-[mM?X][mM?X]-[dD?X][dD?X]/
1611 yield :V_ISO8601_DATE_CONSTRAINT_PATTERN, $&
1612 when /\A[hH][hH]:[mM?X][mM?X]:[sS?X][sS?X]/
1613 yield :V_ISO8601_TIME_CONSTRAINT_PATTERN, $&
1614 when /\A[a-z][a-zA-Z0-9_]*/
1615 word = $&.dup
1616 if @@cadl_reserved[word.downcase]
1617 yield @@cadl_reserved[word.downcase], @@cadl_reserved[word.downcase]
1618 else
1619 @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: V_ATTRIBUTE_IDENTIFIER = #{word} at #{@filename}:#{@lineno}")
1620 yield :V_ATTRIBUTE_IDENTIFIER, word #V_ATTRIBUTE_IDENTIFIER /\A[a-z][a-zA-Z0-9_]*/
1621 end
1622 when /\A[A-Z][a-zA-Z0-9_]*/
1623 word = $&.dup
1624 if @@cadl_reserved[word.downcase]
1625 yield @@cadl_reserved[word.downcase], @@cadl_reserved[word.downcase]
1626 else
1627 yield :V_TYPE_IDENTIFIER, $&
1628 end
1629 when /\Aa[ct][0-9.]+/ #V_LOCAL_CODE
1630 yield :V_LOCAL_CODE, $&
1631 when /\A[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9](,[0-9]+)?(Z|[+-][0-9]{4})?|[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-6][0-9](Z|[+-][0-9]{4})?|[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9](Z|[+-][0-9]{4})?/ #V_ISO8601_EXTENDED_DATE_TIME YYYY-MM-DDThh:mm:ss[,sss][Z|+/- -n-n-n-n-]-
1632 yield :V_ISO8601_EXTENDED_DATE_TIME, $&
1633 when /\A[0-2][0-9]:[0-6][0-9]:[0-6][0-9](,[0-9]+)?(Z|[+-][0-9]{4})?|[0-2][0-9]:[0-6][0-9](Z|[+-][0-9]{4})? / #V_ISO8601_EXTENDED_TIME hh:mm:ss[,sss][Z|+/-nnnn]
1634 yield :V_ISO8601_EXTENDED_TIME, $&
1635 when /\A[0-9]{4}-[0-1][0-9]-[0-3][0-9]|[0-9]{4}-[0-1][0-9]/ #V_ISO8601_EXTENDED_DATE YYYY-MM-DD
1636 yield :V_ISO8601_EXTENDED_DATE, $&
1637 when /\A[0-9]+|[0-9]+[eE][+-]?[0-9]+/ #V_INTEGER
1638 yield :V_INTEGER, $&
1639 when /\A[0-9]+\.[0-9]+|[0-9]+\.[0-9]+[eE][+-]?[0-9]+ / #V_REAL
1640 yield :V_REAL, $&
1641 when /\A"((?:[^"\\]+|\\.)*)"/ #V_STRING
1642 when /\A"([^"]*)"/m #V_STRING
1643 yield :V_STRING, $1
1644 when /\A[a-z]+:\/\/[^<>|\\{}^~"\[\] ]*/ #V_URI
1645 yield :V_URI, $&
1646### when /\AP([0-9]+[yY])?([0-9]+[mM])?([0-9]+[wW])?([0-9]+[dD])?T([0-9]+[hH])?([0-9]+[mM])?([0-9]+[sS])?|P([0-9]+[yY])?([0-9]+[mM])?([0-9]+[wW])?([0-9]+[dD])?/ #V_ISO8601_DURATION PnYnMnWnDTnnHnnMnnS
1647### yield :V_ISO8601_DURATION, $&
1648 when /\A\S/ #UTF8CHAR
1649 yield :UTF8CHAR, $&
1650 else
1651 raise
1652 end
1653 data = $' # variable $' receives the string after the match
1654 when :adl
1655# puts "Entering scan_adl"
1656 data = scan_adl(data) do |sym, val|
1657 yield sym, val
1658 end
1659 when :dadl
1660# puts "Entering scan_dadl"
1661 data = scan_dadl(data) do |sym, val|
1662 yield sym, val
1663 end
1664 when :regexp
1665# puts "Entering scan_regexp"
1666 data = scan_regexp(data) do |sym, val|
1667 yield sym, val
1668 end
1669 when :term_constraint
1670# puts "Entering scan_term_constraint"
1671 data = scan_term_constraint(data) do |sym, val|
1672 yield sym, val
1673 end
1674 else
1675 raise
1676 end
1677 end # of until
1678end # of scan_cadl
1679
1680def scan_dadl(data)
1681 until data.nil? do
1682 case @adl_type.last
1683 when :dadl
1684# puts "Entering scan_dadl"
1685 case scanned = @@dadl_scanner.parse(data)
1686 when Yaparc::Result::OK
1687 yield scanned.value
1688 data = scanned.input
1689 else
1690 end
1691
1692 case data
1693 when /\A\n/ # carriage return
1694 @lineno += 1
1695 ;
1696 when /\A[ \t\r\f]+/ #just drop it
1697 ;
1698 when /\A--.*\n/ # single line comment
1699 @lineno += 1
1700 @@log.info("#{__FILE__}:#{__LINE__}: scan_dadl: COMMENT = #{$&} at #{@filename}:#{@lineno}")
1701 ;
1702 ###----------/* symbols */ -------------------------------------------------
1703 when /\A\=/ # =
1704 yield :SYM_EQ, :SYM_EQ
1705 when /\A\>\=/ # >=
1706 yield :SYM_GE, :SYM_GE
1707 when /\A\<\=/ # <=
1708 yield :SYM_LE, :SYM_LE
1709 when /\A\</ # <
1710 if @in_interval
1711 yield :SYM_LT, :SYM_LT
1712 else
1713 @adl_type.push(:dadl)
1714 yield :SYM_START_DBLOCK, :SYM_START_DBLOCK
1715 end
1716 when /\A\>/ # >
1717 if @in_interval
1718# @in_interval = false
1719 yield :SYM_GT, :SYM_GT
1720 elsif @in_c_domain_type == true
1721 assert_at(__FILE__,__LINE__){@adl_type.last == :dadl}
1722 adl_type = @adl_type.pop
1723 if @adl_type.last == :cadl
1724 @in_c_domain_type = false
1725 yield :END_V_C_DOMAIN_TYPE_BLOCK, $&
1726 else
1727 yield :SYM_END_DBLOCK, $&
1728 end
1729 elsif @in_c_domain_type == false
1730 adl_type = @adl_type.pop
1731# puts "Escaping #{adl_type}"
1732 assert_at(__FILE__,__LINE__){adl_type == :dadl}
1733 yield :SYM_END_DBLOCK, $&
1734 else
1735 raise
1736 end
1737 when /\A\-/ # -
1738 yield :Minus_code, :Minus_code
1739 when /\A\+/ # +
1740 yield :Plus_code, :Plus_code
1741 when /\A\*/ # *
1742 yield :Star_code, :Star_code
1743 when /\A\// # /
1744 yield :Slash_code, :Slash_code
1745 when /\A\^/ # ^
1746 yield :Caret_code, :Caret_code
1747 when /\A\.\.\./ # ...
1748 yield :SYM_LIST_CONTINUE, :SYM_LIST_CONTINUE
1749 when /\A\.\./ # ..
1750 yield :SYM_ELLIPSIS, :SYM_ELLIPSIS
1751 when /\A\./ # .
1752 yield :Dot_code, :Dot_code
1753 when /\A\;/ # ;
1754 yield :Semicolon_code, :Semicolon_code
1755 when /\A\,/ # ,
1756 yield :Comma_code, :Comma_code
1757 when /\A\:/ # :
1758 yield :Colon_code, :Colon_code
1759 when /\A\!/ # !
1760 yield :Exclamation_code, :Exclamation_code
1761 when /\A\(/ # (
1762 yield :Left_parenthesis_code, :Left_parenthesis_code
1763 when /\A\)/ # )
1764 yield :Right_parenthesis_code, :Right_parenthesis_code
1765 when /\A\$/ # $
1766 yield :Dollar_code, :Dollar_code
1767 when /\A\?\?/ # ??
1768 yield :SYM_DT_UNKNOWN, :SYM_DT_UNKNOWN
1769 when /\A\?/ # ?
1770 yield :Question_mark_code, :Question_mark_code
1771 when /\A\|/ # |
1772 @@log.info("#{__FILE__}:#{__LINE__}: scan_dadl: @in_interval = #{@in_interval} at #{@filename}:#{@lineno}")
1773 if @in_interval
1774 @in_interval = false
1775 else
1776# @in_interval = false
1777 @in_interval = true
1778 end
1779 @@log.info("#{__FILE__}:#{__LINE__}: scan_dadl: SYM_INTERVAL_DELIM at #{@filename}:#{@lineno}")
1780 yield :SYM_INTERVAL_DELIM, :SYM_INTERVAL_DELIM
1781### when /\A\[[a-zA-Z0-9()\._-]+::[a-zA-Z0-9\._-]+\]/ #V_QUALIFIED_TERM_CODE_REF form [ICD10AM(1998)::F23]
1782### yield :V_QUALIFIED_TERM_CODE_REF, $&
1783### when /\A\[[a-zA-Z0-9][a-zA-Z0-9._\-]*\]/ #V_LOCAL_TERM_CODE_REF
1784### yield :V_LOCAL_TERM_CODE_REF, $&
1785### when /\A\[[a-zA-Z0-9._\- ]+::[a-zA-Z0-9._\- ]+\]/ #ERR_V_QUALIFIED_TERM_CODE_REF
1786### yield :ERR_V_QUALIFIED_TERM_CODE_REF, $&
1787 when /\A\[/ # [
1788 yield :Left_bracket_code, :Left_bracket_code
1789 when /\A\]/ # ]
1790 yield :Right_bracket_code, :Right_bracket_code
1791### when /\A[A-Z][a-zA-Z0-9_-]*/
1792### yield :V_TYPE_IDENTIFIER, $&
1793### when /\A[A-Z][a-zA-Z0-9_]*<[a-zA-Z0-9,_<>]+>/ #V_GENERIC_TYPE_IDENTIFIER
1794### yield :V_GENERIC_TYPE_IDENTIFIER, $&
1795### when /\A[a-z][a-zA-Z0-9_]*/
1796### word = $&.downcase
1797### if @@dadl_reserved[word]
1798### yield @@dadl_reserved[word], @@dadl_reserved[word]
1799### else
1800### yield :V_ATTRIBUTE_IDENTIFIER, $&
1801### end
1802### when /\Aa[ct][0-9.]+/ #V_LOCAL_CODE
1803### yield :V_LOCAL_CODE, $&
1804 when /\A[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9](,[0-9]+)?(Z|[+-][0-9]{4})?|[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-6][0-9](Z|[+-][0-9]{4})?|[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9](Z|[+-][0-9]{4})?/ #V_ISO8601_EXTENDED_DATE_TIME YYYY-MM-DDThh:mm:ss[,sss][Z|+/- -n-n-n-n-]-
1805 yield :V_ISO8601_EXTENDED_DATE_TIME, $&
1806 when /\A[0-2][0-9]:[0-6][0-9]:[0-6][0-9](,[0-9]+)?(Z|[+-][0-9]{4})?|[0-2][0-9]:[0-6][0-9](Z|[+-][0-9]{4})? / #V_ISO8601_EXTENDED_TIME hh:mm:ss[,sss][Z|+/-nnnn]
1807 yield :V_ISO8601_EXTENDED_TIME, $&
1808 when /\A[0-9]{4}-[0-1][0-9]-[0-3][0-9]|[0-9]{4}-[0-1][0-9]/ #V_ISO8601_EXTENDED_DATE YYYY-MM-DD
1809 yield :V_ISO8601_EXTENDED_DATE, $&
1810 when /\A[A-Z][a-zA-Z0-9_]*<[a-zA-Z0-9,_<>]+>/ #V_GENERIC_TYPE_IDENTIFIER
1811 yield :V_GENERIC_TYPE_IDENTIFIER, $&
1812 when /\A[0-9]+|[0-9]+[eE][+-]?[0-9]+/ #V_INTEGER
1813 yield :V_INTEGER, $&
1814### when /\A[0-9]+\.[0-9]+|[0-9]+\.[0-9]+[eE][+-]?[0-9]+ / #V_REAL
1815### yield :V_REAL, $&
1816 # when /\A"((?:[^"\\]+|\\.)*)"/ #V_STRING
1817### when /\A"([^"]*)"/m #V_STRING
1818### yield :V_STRING, $1
1819 when /\A[a-z]+:\/\/[^<>|\\{}^~"\[\] ]*/ #V_URI
1820 yield :V_URI, $&
1821### when /\AP([0-9]+[yY])?([0-9]+[mM])?([0-9]+[wW])?([0-9]+[dD])?T([0-9]+[hH])?([0-9]+[mM])?([0-9]+[sS])?|P([0-9]+[yY])?([0-9]+[mM])?([0-9]+[wW])?([0-9]+[dD])?/ #V_ISO8601_DURATION PnYnMnWnDTnnHnnMnnS
1822### yield :V_ISO8601_DURATION, $&
1823 when /\A\S/ #UTF8CHAR
1824 yield :UTF8CHAR, $&
1825 end
1826 data = $' # variable $' receives the string after the match
1827 when :adl
1828# puts "Entering scan_adl"
1829 data = scan_adl(data) do |sym, val|
1830 yield sym, val
1831 end
1832 when :cadl
1833# puts "Entering scan_cadl"
1834 data = scan_cadl(data) do |sym, val|
1835 yield sym, val
1836 end
1837 when :regexp
1838# puts "Entering scan_regexp"
1839 data = scan_regexp(data) do |sym, val|
1840 yield sym, val
1841 end
1842 when :term_constraint
1843# puts "Entering scan_term_constraint"
1844 data = scan_term_constraint(data) do |sym, val|
1845 yield sym, val
1846 end
1847 else
1848 raise
1849 end
1850 end
1851end # of scan_dadl
1852
1853def scan_regexp(data)
1854 until data.nil? do
1855 case @adl_type.last
1856 when :regexp
1857# puts "Entering scan_regexp"
1858 case data
1859 when /\A\/\}/ #V_REGEXP
1860 if @adl_type.last == :regexp
1861 @in_regexp = false
1862 @adl_type.pop
1863 yield :END_REGEXP_BLOCK, :END_REGEXP_BLOCK
1864 else
1865 raise
1866 end
1867 when /\A(.*)(\/\})/ #V_REGEXP
1868 yield :REGEXP_BODY, $1
1869 if @adl_type.last == :regexp
1870 @in_regexp = false
1871 @adl_type.pop
1872 yield :END_REGEXP_BLOCK, :END_REGEXP_BLOCK
1873 else
1874 raise
1875 end
1876 else
1877 raise data
1878 end
1879 data = $' # variable $' receives the string after the match
1880 when :adl
1881# puts "Entering scan_adl"
1882 data = scan_adl(data) do |sym, val|
1883 yield sym, val
1884 end
1885 when :dadl
1886# puts "Entering scan_dadl"
1887 data = scan_dadl(data) do |sym, val|
1888 yield sym, val
1889 end
1890 when :cadl
1891# puts "Entering scan_cadl"
1892 data = scan_cadl(data) do |sym, val|
1893 yield sym, val
1894 end
1895 when :term_constraint
1896# puts "Entering scan_term_constraint"
1897 data = scan_term_constraint(data) do |sym, val|
1898 yield sym, val
1899 end
1900 else
1901 raise
1902 end
1903 end
1904end # of scan_regexp
1905
1906def scan_term_constraint(data)
1907 until data.nil? do
1908 case @adl_type.last
1909 when :term_constraint
1910# puts "Entering scan_term_constraint"
1911 case data
1912 when /\A\n/ # carriage return
1913 @lineno += 1
1914 ;
1915 when /\A[ \t\r\f]+/ #just drop it
1916 ;
1917 when /\A--.*$/ # single line comment
1918 @lineno += 1
1919 @@log.info("#{__FILE__}:#{__LINE__}: scan_term_constraint: COMMENT = #{$&} at #{@filename}:#{@lineno}")
1920 ;
1921 when /\A[a-zA-Z0-9\._\-]+[ \t]*,/ # match any line, with ',' termination
1922 yield :TERM_CODE, $&
1923 when /\A[a-zA-Z0-9\._\-]+[ \t]*;/ #match second last line with ';' termination (assumed value)
1924 yield :TERM_CODE, $&
1925# when /\A[a-zA-Z0-9\._\-]+[ \t]*\]/ # match final line, terminating in ']'
1926 when /\A[a-zA-Z0-9\._\-]*[ \t]*\]/ # match final line, terminating in ']'
1927 adl_type = @adl_type.pop
1928 assert_at(__FILE__,__LINE__){adl_type == :term_constraint}
1929 yield :END_TERM_CODE_CONSTRAINT, $&
1930 else
1931 raise "data = #{data}"
1932 end
1933 data = $' # variable $' receives the string after the match
1934 when :adl
1935# puts "Entering scan_adl"
1936 data = scan_adl(data) do |sym, val|
1937 yield sym, val
1938 end
1939 when :dadl
1940# puts "Entering scan_dadl"
1941 data = scan_dadl(data) do |sym, val|
1942 yield sym, val
1943 end
1944 when :cadl
1945# puts "Entering scan_cadl"
1946 data = scan_cadl(data) do |sym, val|
1947 yield sym, val
1948 end
1949 else
1950 raise
1951 end
1952 end
1953end # of scan_term_constraint
1954
1955
1956def parse(data, filename, lineno = 1, debug = false)
1957 @yydebug = true
1958 @parsestring = data
1959 @data = data
1960 @lineno = lineno
1961 @filename = filename
1962 @adl_type = [:adl] # {:adl, :cadl, :dadl}
1963 @in_regexp = false
1964 @in_interval = false
1965 @in_c_domain_type = false
1966 yyparse self, :scan
1967end
1968
1969def on_error( t, v, values)
1970 raise Racc::ParseError, "#{@filename}:#{@lineno}: Inline syntax error on #{v.inspect}"
1971end
1972
1973
1974
1975
1976
1977
1978
1979### Local Variables:
1980### mode:ruby
1981### mode:font-lock
1982### comment-column:0
1983### comment-start: "### "
1984### comment-end:""
1985### End:
1986
1987
1988
1989
Note: See TracBrowser for help on using the repository browser.