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

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

trying to solve parsing problem on term coding

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$DEBUG = true
1184
1185
1186
1187---- inner
1188
1189def assert_at(file,line, message = "")
1190 unless yield
1191 raise "Assertion failed !: #{file}, #{line}: #{message}"
1192 end
1193end
1194
1195if $DEBUG
1196 @@log = Logger.new('log/parser.log','daily')
1197 @@log.level = Logger::INFO
1198else
1199 @@log = Logger.new(STDOUT)
1200 @@log.level = Logger::WARN
1201end
1202
1203@@dadl_scanner = OpenEHR::ADL::Scanner::DADL::RootScanner.new
1204@@cadl_scanner = OpenEHR::ADL::Scanner::CADL::RootScanner.new
1205
1206###----------/* keywords */ ---------------------------------------------
1207@@adl_reserved = {
1208 'archetype' => :SYM_ARCHETYPE,
1209 'adl_version' => :SYM_ADL_VERSION,
1210 'controlled' => :SYM_IS_CONTROLLED,
1211 'specialize' => :SYM_SPECIALIZE,
1212 'concept' => :SYM_CONCEPT,
1213 'language' => :SYM_LANGUAGE,
1214 'description' => :SYM_DESCRIPTION,
1215 'definition' => :SYM_DEFINITION,
1216 'invariant' => :SYM_INVARIANT,
1217 'ontology' => :SYM_ONTOLOGY,
1218 'matches' => :SYM_MATCHES,
1219 'is_in' => :SYM_MATCHES,
1220 'occurrences' => :SYM_OCCURRENCES,
1221 'true' => :SYM_TRUE, #[Tt][Rr][Uu][Ee] -- -> SYM_TRUE
1222 'false' => :SYM_FALSE, # [Ff][Aa][Ll][Ss][Ee] -- -> SYM_FALSE
1223 'infinity' => :SYM_INFINITY # [Ii][Nn][Ff][Ii][Nn][Ii][Tt][Yy] -- -> SYM_INFINITY
1224}
1225
1226@@dadl_reserved = {
1227 'true' => :SYM_TRUE, #[Tt][Rr][Uu][Ee] -- -> SYM_TRUE
1228 'false' => :SYM_FALSE, # [Ff][Aa][Ll][Ss][Ee] -- -> SYM_FALSE
1229 'infinity' => :SYM_INFINITY # [Ii][Nn][Ff][Ii][Nn][Ii][Tt][Yy] -- -> SYM_INFINITY
1230}
1231
1232@@cadl_reserved = {
1233 'then' => :SYM_THEN, # [Tt][Hh][Ee][Nn]
1234 'else' => :SYM_ELSE, # [Ee][Ll][Ss][Ee]
1235 'and' => :SYM_AND, # [Aa][Nn][Dd]
1236 'or' => :SYM_OR, # [Oo][Rr]
1237 'xor' => :SYM_XOR, # [Xx][Oo][Rr]
1238 'not' => :SYM_NOT, # [Nn][Oo][Tt]
1239 'implies' => :SYM_IMPLIES, # [Ii][Mm][Pp][Ll][Ii][Ee][Ss]
1240 'true' => :SYM_TRUE, #[Tt][Rr][Uu][Ee] -- -> SYM_TRUE
1241 'false' => :SYM_FALSE, # [Ff][Aa][Ll][Ss][Ee] -- -> SYM_FALSE
1242 'forall' => :SYM_FORALL, # [Ff][Oo][Rr][_][Aa][Ll][Ll]
1243 'exists' => :SYM_EXISTS, # [Ee][Xx][Ii][Ss][Tt][Ss]
1244 'existence' => :SYM_EXISTENCE, # [Ee][Xx][Iu][Ss][Tt][Ee][Nn][Cc][Ee]
1245 'occurrences' => :SYM_OCCURRENCES, # [Oo][Cc][Cc][Uu][Rr][Rr][Ee][Nn][Cc][Ee][Ss]
1246 'cardinality' => :SYM_CARDINALITY, # [Cc][Aa][Rr][Dd][Ii][Nn][Aa][Ll][Ii][Tt][Yy]
1247 'ordered' => :SYM_ORDERED, # [Oo][Rr][Dd][Ee][Rr][Ee][Dd]
1248 'unordered' => :SYM_UNORDERED, # [Uu][Nn][Oo][Rr][Dd][Ee][Rr][Ee][Dd]
1249 'unique' => :SYM_UNIQUE, # [Uu][Nn][Ii][Qq][Uu][Ee]
1250 'matches' => :SYM_MATCHES, # [Mm][Aa][Tt][Cc][Hh][Ee][Ss]
1251 'is_in' => :SYM_MATCHES, # [Ii][Ss][_][Ii][Nn]
1252 'invariant' => :SYM_INVARIANT, # [Ii][Nn][Vv][Aa][Rr][Ii][Aa][Nn][Tt]
1253 'infinity' => :SYM_INFINITY, # [Ii][Nn][Ff][Ii][Nn][Ii][Tt][Yy] -- -> SYM_INFINITY
1254 'use_node' => :SYM_USE_NODE, # [Uu][Ss][Ee][_][Nn][Oo][Dd][Ee]
1255 'use_archetype' => :SYM_ALLOW_ARCHETYPE, # [Uu][Ss][Ee][_][Aa][Rr][Cc][Hh][Ee][Tt][Yy][Pp][Ee]
1256 'allow_archetype' => :SYM_ALLOW_ARCHETYPE, # [Aa][Ll][Ll][Oo][Ww][_][Aa][Rr][Cc][Hh][Ee][Tt][Yy][Pp][Ee]
1257 'include' => :SYM_INCLUDE, # [Ii][Nn][Cc][Ll][Uu][Dd][Ee]
1258 'exclude' => :SYM_EXCLUDE # [Ee][Xx][Cc][Ll][Uu][Dd][Ee]
1259}
1260
1261
1262###----------/* Scanner */ -----------------------------------------------
1263
1264def scan
1265 until @data.nil? do
1266 case @adl_type.last
1267 when :adl
1268 @data = scan_adl(@data) do |sym, val|
1269 yield sym, val
1270 end
1271 when :dadl
1272 @data = scan_dadl(@data) do |sym, val|
1273 yield sym, val
1274 end
1275 when :cadl
1276 @data = scan_cadl(@data) do |sym, val|
1277 yield sym, val
1278 end
1279 when :regexp
1280 @data = scan_regexp(@data) do |sym, val|
1281 yield sym, val
1282 end
1283 else
1284 raise
1285 end
1286 @data = $' # variable $' receives the string after the match
1287 end
1288 yield :EOF, nil
1289 yield false, '$'
1290end # of scan
1291
1292def scan_adl(data)
1293 until data.nil? do
1294 case @adl_type.last
1295 when :adl
1296# puts "Entering scan_adl"
1297 case data
1298 when /\A\n/ # carriage return
1299 @lineno += 1
1300 ;
1301 when /\A[ \t\r\f]+/ #just drop it
1302 ;
1303 when /\A--.*\n/ # single line comment
1304 @lineno += 1
1305 @@log.info("#{__FILE__}:#{__LINE__}: scan_adl: COMMENT = #{$&} at #{@filename}:#{@lineno}")
1306 ;
1307 when /\Adescription/ # description
1308 yield :SYM_DESCRIPTION, :SYM_DESCRIPTION
1309 when /\Adefinition/ # definition
1310 yield :SYM_DEFINITION, :SYM_DEFINITION
1311# @adl_type.push(:cadl)
1312 ###----------/* symbols */ -------------------------------------------------
1313 when /\A[A-Z][a-zA-Z0-9_]*/
1314 yield :V_TYPE_IDENTIFIER, $&
1315# when /\A[a-zA-Z][a-zA-Z0-9_-]+\.[a-zA-Z][a-zA-Z0-9_-]+\.[a-zA-Z0-9]+/ #V_ARCHETYPE_ID
1316 when /\A(\w+)-(\w+)-(\w+)\.(\w+)(-\w+)?\.(v[0-9]+)/ #V_ARCHETYPE_ID
1317 object_id, rm_originator, rm_name, rm_entity, concept_name, specialisation, version_id = $&, $1, $2, $3, $4, $5, $6
1318 archetype_id = OpenEHR::RM::Support::Identification::Archetype_ID.new(object_id, concept_name, rm_name, rm_entity, rm_originator, specialisation, version_id)
1319# yield :V_ARCHETYPE_ID, $&
1320 yield :V_ARCHETYPE_ID, archetype_id
1321 when /\A[a-z][a-zA-Z0-9_]*/
1322# word = $&.downcase
1323 word = $&
1324 if @@adl_reserved[word]
1325 @@log.info("#{__FILE__}:#{__LINE__}: scan_adl: @@adl_reserved = #{@@adl_reserved[word]} at #{@filename}:#{@lineno}")
1326 yield @@adl_reserved[word], @@adl_reserved[word]
1327 elsif #/\A[A-Z][a-zA-Z0-9_]*/
1328 @@log.info("#{__FILE__}:#{__LINE__}: scan_adl: V_ATTRIBUTE_IDENTIFIER = #{$&} at #{@filename}:#{@lineno}")
1329 yield :V_ATTRIBUTE_IDENTIFIER, $&
1330 end
1331 when /\A\=/ # =
1332 yield :SYM_EQ, :SYM_EQ
1333 when /\A\>=/ # >=
1334 yield :SYM_GE, :SYM_GE
1335 when /\A\<=/ # <=
1336 yield :SYM_LE, :SYM_LE
1337 when /\A\</ # <
1338 if @in_interval
1339# @start_block_received = false
1340 yield :SYM_LT, :SYM_LT
1341 else
1342# @start_block_received = true
1343 @adl_type.push(:dadl)
1344 yield :SYM_START_DBLOCK, $&
1345 end
1346 when /\A\>/ # >
1347 if @in_interval
1348 yield :SYM_GT, :SYM_GT
1349 else
1350 adl_type = @adl_type.pop
1351# puts "Escaping #{adl_type}"
1352 assert_at(__FILE__,__LINE__){adl_type == :dadl}
1353 yield :SYM_END_DBLOCK, :SYM_END_DBLOCK
1354 end
1355 when /\A\{/ # {
1356 @adl_type.push(:cadl)
1357 @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: entering cADL at #{@filename}:#{@lineno}")
1358 yield :SYM_START_CBLOCK, :SYM_START_CBLOCK
1359 when /\A\}/ # }
1360 adl_type = @adl_type.pop
1361# puts "Escaping #{adl_type}"
1362 assert_at(__FILE__,__LINE__){adl_type == :cadl}
1363 @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: exiting cADL at #{@filename}:#{@lineno}")
1364 yield :SYM_END_CBLOCK, $&
1365 when /\A\-/ # -
1366 yield :Minus_code, :Minus_code
1367 when /\A\+/ # +
1368 yield :Plus_code, :Plus_code
1369 when /\A\*/ # *
1370 yield :Star_code, :Star_code
1371 when /\A\// # /
1372 yield :Slash_code, :Slash_code
1373 when /\A\^/ # ^
1374 yield :Caret_code, :Caret_code
1375 when /\A\=/ # =
1376 yield :Equal_code, :Equal_code
1377 when /\A\.\.\./ # ...
1378 yield :SYM_LIST_CONTINUE, :SYM_LIST_CONTINUE
1379 when /\A\.\./ # ..
1380 yield :SYM_ELLIPSIS, :SYM_ELLIPSIS
1381 when /\A\./ # .
1382 yield :Dot_code, :Dot_code
1383 when /\A\;/ # ;
1384 yield :Semicolon_code, :Semicolon_code
1385 when /\A\,/ # ,
1386 yield :Comma_code, :Comma_code
1387 when /\A\:/ # :
1388 yield :Colon_code, :Colon_code
1389 when /\A\!/ # !
1390 yield :Exclamation_code, :Exclamation_code
1391 when /\A\(/ # (
1392 yield :Left_parenthesis_code, :Left_parenthesis_code
1393 when /\A\)/ # )
1394 yield :Right_parenthesis_code, :Right_parenthesis_code
1395 when /\A\$/ # $
1396 yield :Dollar_code, :Dollar_code
1397 when /\A\?\?/ # ??
1398 yield :SYM_DT_UNKNOWN, :SYM_DT_UNKNOWN
1399 when /\A\?/ # ?
1400 yield :Question_mark_code, :Question_mark_code
1401 when /\A[0-9]+\.[0-9]+(\.[0-9]+)*/ # ?
1402 yield :V_VERSION_STRING, $&
1403 when /\A\|/ # |
1404 if @in_interval
1405 @in_interval = false
1406 else
1407 @in_interval = true
1408 end
1409 yield :SYM_INTERVAL_DELIM, :SYM_INTERVAL_DELIM
1410 when /\A\[[a-zA-Z0-9()\._-]+::[a-zA-Z0-9\._-]+\]/
1411# when /\A\[[a-zA-Z0-9()\._-]+\:\:[a-zA-Z0-9\._-]+\]/ #V_QUALIFIED_TERM_CODE_REF form [ICD10AM(1998)::F23]
1412 yield :V_QUALIFIED_TERM_CODE_REF, $&
1413 when /\A\[[a-zA-Z0-9][a-zA-Z0-9._\-]*\]/ #V_LOCAL_TERM_CODE_REF
1414 yield :V_LOCAL_TERM_CODE_REF, $&
1415 when /\A\[/ # [
1416 yield :Left_bracket_code, :Left_bracket_code
1417 when /\A\]/ # ]
1418 yield :Right_bracket_code, :Right_bracket_code
1419
1420 when /\A"([^"]*)"/m #V_STRING
1421 yield :V_STRING, $1
1422 when /\A\[[a-zA-Z0-9._\- ]+::[a-zA-Z0-9._\- ]+\]/ #ERR_V_QUALIFIED_TERM_CODE_REF
1423 yield :ERR_V_QUALIFIED_TERM_CODE_REF, $&
1424 when /\Aa[ct][0-9.]+/ #V_LOCAL_CODE
1425 yield :V_LOCAL_CODE, $&
1426 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-]-
1427 yield :V_ISO8601_EXTENDED_DATE_TIME, $&
1428 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]
1429 yield :V_ISO8601_EXTENDED_TIME, $&
1430 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
1431 yield :V_ISO8601_EXTENDED_DATE, $&
1432 when /\A[A-Z][a-zA-Z0-9_]*<[a-zA-Z0-9,_<>]+>/ #V_GENERIC_TYPE_IDENTIFIER
1433 yield :V_GENERIC_TYPE_IDENTIFIER, $&
1434 when /\A[0-9]+|[0-9]+[eE][+-]?[0-9]+/ #V_INTEGER
1435 yield :V_INTEGER, $&
1436 when /\A[0-9]+\.[0-9]+|[0-9]+\.[0-9]+[eE][+-]?[0-9]+ / #V_REAL
1437 yield :V_REAL, $&
1438 # when /\A"((?:[^"\\]+|\\.)*)"/ #V_STRING
1439 when /\A[a-z]+:\/\/[^<>|\\{}^~"\[\] ]*/ #V_URI
1440 yield :V_URI, $&
1441 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
1442 yield :V_ISO8601_DURATION, $&
1443 when /\A\S/ #UTF8CHAR
1444 yield :UTF8CHAR, $&
1445 end
1446 data = $' # variable $' receives the string after the match
1447 when :dadl
1448# puts "Entering scan_dadl"
1449 data = scan_dadl(data) do |sym, val|
1450 yield sym, val
1451 end
1452 when :cadl
1453# puts "Entering scan_cadl"
1454 data = scan_cadl(data) do |sym, val|
1455 yield sym, val
1456 end
1457 when :regexp
1458# puts "Entering scan_regexp"
1459 data = scan_regexp(data) do |sym, val|
1460 yield sym, val
1461 end
1462 when :term_constraint
1463# puts "Entering scan_term_constraint"
1464 data = scan_term_constraint(data) do |sym, val|
1465 yield sym, val
1466 end
1467 else
1468 raise
1469 end
1470 end
1471end # scan_adl
1472
1473
1474def scan_cadl(data)
1475 until data.nil? do
1476 case @adl_type.last
1477 when :cadl
1478# puts "Entering scan_cadl"
1479 case scanned = @@cadl_scanner.parse(data)
1480 when Yaparc::Result::OK
1481 if scanned.value[0] == :START_V_C_DOMAIN_TYPE_BLOCK
1482 @in_c_domain_type = true
1483 @adl_type.push(:dadl)
1484 yield scanned.value
1485 else
1486 yield scanned.value
1487 end
1488 data = scanned.input
1489 end
1490
1491 case data
1492 when /\A\n/ # carriage return
1493 @lineno += 1
1494 ;
1495 when /\A[ \t\r\f]+/ #just drop it
1496 ;
1497 when /\A--.*\n/ # single line comment
1498 @lineno += 1
1499 @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: COMMENT = #{$&} at #{@filename}:#{@lineno}")
1500 ;
1501 ###----------/* symbols */ -------------------------------------------------
1502 when /\A\=/ # =
1503 yield :SYM_EQ, :SYM_EQ
1504 when /\A\>=/ # >=
1505 yield :SYM_GE, :SYM_GE
1506 when /\A\<=/ # <=
1507 yield :SYM_LE, :SYM_LE
1508### when /\A[A-Z][a-zA-Z0-9_]*[ \n]*\</ # V_C_DOMAIN_TYPE
1509### @in_c_domain_type = true
1510### @adl_type.push(:dadl)
1511### yield :START_V_C_DOMAIN_TYPE_BLOCK, $&
1512 when /\A\</ # <
1513 if @in_interval
1514 yield :SYM_LT, :SYM_LT
1515 else
1516 @adl_type.push(:dadl)
1517 yield :SYM_START_DBLOCK, $&
1518 end
1519 when /\A\>/ # >
1520 if @in_interval
1521 yield :SYM_GT, :SYM_GT
1522 else
1523 adl_type = @adl_type.pop
1524# puts "Escaping #{adl_type}"
1525 assert_at(__FILE__,__LINE__){adl_type == :dadl}
1526 yield :SYM_END_DBLOCK, :SYM_END_DBLOCK
1527 end
1528 when /\A\-/ # -
1529 yield :Minus_code, :Minus_code
1530 when /\A\+/ # +
1531 yield :Plus_code, :Plus_code
1532 when /\A\*/ # *
1533 yield :Star_code, :Star_code
1534 when /\A\// # /
1535 yield :Slash_code, :Slash_code
1536 when /\A\^/ # ^
1537 yield :Caret_code, :Caret_code
1538 when /\A\.\.\./ # ...
1539 yield :SYM_LIST_CONTINUE, :SYM_LIST_CONTINUE
1540 when /\A\.\./ # ..
1541 yield :SYM_ELLIPSIS, :SYM_ELLIPSIS
1542 when /\A\./ # .
1543 yield :Dot_code, :Dot_code
1544 when /\A\;/ # ;
1545 yield :Semicolon_code, :Semicolon_code
1546 when /\A\,/ # ,
1547 yield :Comma_code, :Comma_code
1548 when /\A\:/ # :
1549 yield :Colon_code, :Colon_code
1550 when /\A\!/ # !
1551 yield :Exclamation_code, :Exclamation_code
1552 when /\A\(/ # (
1553 yield :Left_parenthesis_code, :Left_parenthesis_code
1554 when /\A\)/ # )
1555 yield :Right_parenthesis_code, :Right_parenthesis_code
1556 when /\A\{\// #V_REGEXP
1557 if @adl_type.last != :regexp
1558 @in_regexp = true
1559 @adl_type.push(:regexp)
1560 yield :START_REGEXP_BLOCK, :START_REGEXP_BLOCK
1561 else
1562 raise
1563 end
1564# yield :V_REGEXP, :V_REGEXP
1565 when /\A\{/ # {
1566 @adl_type.push(:cadl)
1567 @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: entering cADL at #{@filename}:#{@lineno}")
1568 yield :SYM_START_CBLOCK, :SYM_START_CBLOCK
1569 when /\A\}/ # }
1570 adl_type = @adl_type.pop
1571# puts "Escaping #{adl_type}"
1572 assert_at(__FILE__,__LINE__){adl_type == :cadl}
1573 @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: exiting cADL at #{@filename}:#{@lineno}")
1574 yield :SYM_END_CBLOCK, :SYM_END_CBLOCK
1575 when /\A\$/ # $
1576 yield :Dollar_code, :Dollar_code
1577 when /\A\?\?/ # ??
1578 yield :SYM_DT_UNKNOWN, :SYM_DT_UNKNOWN
1579 when /\A\?/ # ?
1580 yield :Question_mark_code, :Question_mark_code
1581 when /\A\|/ # |
1582 @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: @in_interval = #{@in_interval} at #{@filename}:#{@lineno}")
1583 if @in_interval
1584 @in_interval = false
1585 else
1586# @in_interval = false
1587 @in_interval = true
1588 end
1589 @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: SYM_INTERVAL_DELIM at #{@filename}:#{@lineno}")
1590 yield :SYM_INTERVAL_DELIM, :SYM_INTERVAL_DELIM
1591
1592 when /\A\[[a-zA-Z0-9._\-]+::[a-zA-Z0-9._\-]+\]/ #V_QUALIFIED_TERM_CODE_REF form [ICD10AM(1998)::F23]
1593 yield :V_QUALIFIED_TERM_CODE_REF, $&
1594 when /\A\[[a-zA-Z0-9._\- ]+::[a-zA-Z0-9._\- ]+\]/ #ERR_V_QUALIFIED_TERM_CODE_REF
1595 yield :ERR_V_QUALIFIED_TERM_CODE_REF, $&
1596 when /\A\[([a-zA-Z0-9()._\-]+::[a-zA-Z0-9._\_-]+)\]/
1597 yield :V_TERM_CODE_CONSTRAINT, :V_TERM_CODE_CONSTRAINT
1598 when /\A\[[a-zA-Z0-9\(\)\._\-]+::[ \t\n]*/
1599 @adl_type.push(:term_constraint)
1600 yield :START_TERM_CODE_CONSTRAINT, $&
1601 when /\A\[[a-zA-Z0-9][a-zA-Z0-9._\-]*\]/ #V_LOCAL_TERM_CODE_REF
1602 yield :V_LOCAL_TERM_CODE_REF, $&
1603 when /\A\[/ # [
1604 yield :Left_bracket_code, :Left_bracket_code
1605 when /\A\]/ # ]
1606 yield :Right_bracket_code, :Right_bracket_code
1607 when /\A[A-Z][a-zA-Z0-9_]*<[a-zA-Z0-9,_<>]+>/ #V_GENERIC_TYPE_IDENTIFIER
1608 yield :V_GENERIC_TYPE_IDENTIFIER, $&
1609 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]/
1610 yield :V_ISO8601_DATE_TIME_CONSTRAINT_PATTERN, $&
1611 when /\A[yY][yY][yY][yY]-[mM?X][mM?X]-[dD?X][dD?X]/
1612 yield :V_ISO8601_DATE_CONSTRAINT_PATTERN, $&
1613 when /\A[hH][hH]:[mM?X][mM?X]:[sS?X][sS?X]/
1614 yield :V_ISO8601_TIME_CONSTRAINT_PATTERN, $&
1615 when /\A[a-z][a-zA-Z0-9_]*/
1616 word = $&.dup
1617 if @@cadl_reserved[word.downcase]
1618 yield @@cadl_reserved[word.downcase], @@cadl_reserved[word.downcase]
1619 else
1620 @@log.info("#{__FILE__}:#{__LINE__}: scan_cadl: V_ATTRIBUTE_IDENTIFIER = #{word} at #{@filename}:#{@lineno}")
1621 yield :V_ATTRIBUTE_IDENTIFIER, word #V_ATTRIBUTE_IDENTIFIER /\A[a-z][a-zA-Z0-9_]*/
1622 end
1623 when /\A[A-Z][a-zA-Z0-9_]*/
1624 word = $&.dup
1625 if @@cadl_reserved[word.downcase]
1626 yield @@cadl_reserved[word.downcase], @@cadl_reserved[word.downcase]
1627 else
1628 yield :V_TYPE_IDENTIFIER, $&
1629 end
1630 when /\Aa[ct][0-9.]+/ #V_LOCAL_CODE
1631 yield :V_LOCAL_CODE, $&
1632 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-]-
1633 yield :V_ISO8601_EXTENDED_DATE_TIME, $&
1634 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]
1635 yield :V_ISO8601_EXTENDED_TIME, $&
1636 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
1637 yield :V_ISO8601_EXTENDED_DATE, $&
1638 when /\A[0-9]+|[0-9]+[eE][+-]?[0-9]+/ #V_INTEGER
1639 yield :V_INTEGER, $&
1640 when /\A[0-9]+\.[0-9]+|[0-9]+\.[0-9]+[eE][+-]?[0-9]+ / #V_REAL
1641 yield :V_REAL, $&
1642 when /\A"((?:[^"\\]+|\\.)*)"/ #V_STRING
1643 when /\A"([^"]*)"/m #V_STRING
1644 yield :V_STRING, $1
1645 when /\A[a-z]+:\/\/[^<>|\\{}^~"\[\] ]*/ #V_URI
1646 yield :V_URI, $&
1647### 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
1648### yield :V_ISO8601_DURATION, $&
1649 when /\A\S/ #UTF8CHAR
1650 yield :UTF8CHAR, $&
1651 else
1652 raise
1653 end
1654 data = $' # variable $' receives the string after the match
1655 when :adl
1656# puts "Entering scan_adl"
1657 data = scan_adl(data) do |sym, val|
1658 yield sym, val
1659 end
1660 when :dadl
1661# puts "Entering scan_dadl"
1662 data = scan_dadl(data) do |sym, val|
1663 yield sym, val
1664 end
1665 when :regexp
1666# puts "Entering scan_regexp"
1667 data = scan_regexp(data) do |sym, val|
1668 yield sym, val
1669 end
1670 when :term_constraint
1671# puts "Entering scan_term_constraint"
1672 data = scan_term_constraint(data) do |sym, val|
1673 yield sym, val
1674 end
1675 else
1676 raise
1677 end
1678 end # of until
1679end # of scan_cadl
1680
1681def scan_dadl(data)
1682 until data.nil? do
1683 case @adl_type.last
1684 when :dadl
1685# puts "Entering scan_dadl"
1686 case scanned = @@dadl_scanner.parse(data)
1687 when Yaparc::Result::OK
1688 yield scanned.value
1689 data = scanned.input
1690 else
1691 end
1692
1693 case data
1694 when /\A\n/ # carriage return
1695 @lineno += 1
1696 ;
1697 when /\A[ \t\r\f]+/ #just drop it
1698 ;
1699 when /\A--.*\n/ # single line comment
1700 @lineno += 1
1701 @@log.info("#{__FILE__}:#{__LINE__}: scan_dadl: COMMENT = #{$&} at #{@filename}:#{@lineno}")
1702 ;
1703 ###----------/* symbols */ -------------------------------------------------
1704 when /\A\=/ # =
1705 yield :SYM_EQ, :SYM_EQ
1706 when /\A\>\=/ # >=
1707 yield :SYM_GE, :SYM_GE
1708 when /\A\<\=/ # <=
1709 yield :SYM_LE, :SYM_LE
1710 when /\A\</ # <
1711 if @in_interval
1712 yield :SYM_LT, :SYM_LT
1713 else
1714 @adl_type.push(:dadl)
1715 yield :SYM_START_DBLOCK, :SYM_START_DBLOCK
1716 end
1717 when /\A\>/ # >
1718 if @in_interval
1719# @in_interval = false
1720 yield :SYM_GT, :SYM_GT
1721 elsif @in_c_domain_type == true
1722 assert_at(__FILE__,__LINE__){@adl_type.last == :dadl}
1723 adl_type = @adl_type.pop
1724 if @adl_type.last == :cadl
1725 @in_c_domain_type = false
1726 yield :END_V_C_DOMAIN_TYPE_BLOCK, $&
1727 else
1728 yield :SYM_END_DBLOCK, $&
1729 end
1730 elsif @in_c_domain_type == false
1731 adl_type = @adl_type.pop
1732# puts "Escaping #{adl_type}"
1733 assert_at(__FILE__,__LINE__){adl_type == :dadl}
1734 yield :SYM_END_DBLOCK, $&
1735 else
1736 raise
1737 end
1738 when /\A\-/ # -
1739 yield :Minus_code, :Minus_code
1740 when /\A\+/ # +
1741 yield :Plus_code, :Plus_code
1742 when /\A\*/ # *
1743 yield :Star_code, :Star_code
1744 when /\A\// # /
1745 yield :Slash_code, :Slash_code
1746 when /\A\^/ # ^
1747 yield :Caret_code, :Caret_code
1748 when /\A\.\.\./ # ...
1749 yield :SYM_LIST_CONTINUE, :SYM_LIST_CONTINUE
1750 when /\A\.\./ # ..
1751 yield :SYM_ELLIPSIS, :SYM_ELLIPSIS
1752 when /\A\./ # .
1753 yield :Dot_code, :Dot_code
1754 when /\A\;/ # ;
1755 yield :Semicolon_code, :Semicolon_code
1756 when /\A\,/ # ,
1757 yield :Comma_code, :Comma_code
1758 when /\A\:/ # :
1759 yield :Colon_code, :Colon_code
1760 when /\A\!/ # !
1761 yield :Exclamation_code, :Exclamation_code
1762 when /\A\(/ # (
1763 yield :Left_parenthesis_code, :Left_parenthesis_code
1764 when /\A\)/ # )
1765 yield :Right_parenthesis_code, :Right_parenthesis_code
1766 when /\A\$/ # $
1767 yield :Dollar_code, :Dollar_code
1768 when /\A\?\?/ # ??
1769 yield :SYM_DT_UNKNOWN, :SYM_DT_UNKNOWN
1770 when /\A\?/ # ?
1771 yield :Question_mark_code, :Question_mark_code
1772 when /\A\|/ # |
1773 @@log.info("#{__FILE__}:#{__LINE__}: scan_dadl: @in_interval = #{@in_interval} at #{@filename}:#{@lineno}")
1774 if @in_interval
1775 @in_interval = false
1776 else
1777# @in_interval = false
1778 @in_interval = true
1779 end
1780 @@log.info("#{__FILE__}:#{__LINE__}: scan_dadl: SYM_INTERVAL_DELIM at #{@filename}:#{@lineno}")
1781 yield :SYM_INTERVAL_DELIM, :SYM_INTERVAL_DELIM
1782### when /\A\[[a-zA-Z0-9()\._-]+::[a-zA-Z0-9\._-]+\]/ #V_QUALIFIED_TERM_CODE_REF form [ICD10AM(1998)::F23]
1783### yield :V_QUALIFIED_TERM_CODE_REF, $&
1784### when /\A\[[a-zA-Z0-9][a-zA-Z0-9._\-]*\]/ #V_LOCAL_TERM_CODE_REF
1785### yield :V_LOCAL_TERM_CODE_REF, $&
1786### when /\A\[[a-zA-Z0-9._\- ]+::[a-zA-Z0-9._\- ]+\]/ #ERR_V_QUALIFIED_TERM_CODE_REF
1787### yield :ERR_V_QUALIFIED_TERM_CODE_REF, $&
1788 when /\A\[/ # [
1789 yield :Left_bracket_code, :Left_bracket_code
1790 when /\A\]/ # ]
1791 yield :Right_bracket_code, :Right_bracket_code
1792### when /\A[A-Z][a-zA-Z0-9_-]*/
1793### yield :V_TYPE_IDENTIFIER, $&
1794### when /\A[A-Z][a-zA-Z0-9_]*<[a-zA-Z0-9,_<>]+>/ #V_GENERIC_TYPE_IDENTIFIER
1795### yield :V_GENERIC_TYPE_IDENTIFIER, $&
1796### when /\A[a-z][a-zA-Z0-9_]*/
1797### word = $&.downcase
1798### if @@dadl_reserved[word]
1799### yield @@dadl_reserved[word], @@dadl_reserved[word]
1800### else
1801### yield :V_ATTRIBUTE_IDENTIFIER, $&
1802### end
1803### when /\Aa[ct][0-9.]+/ #V_LOCAL_CODE
1804### yield :V_LOCAL_CODE, $&
1805 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-]-
1806 yield :V_ISO8601_EXTENDED_DATE_TIME, $&
1807 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]
1808 yield :V_ISO8601_EXTENDED_TIME, $&
1809 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
1810 yield :V_ISO8601_EXTENDED_DATE, $&
1811 when /\A[A-Z][a-zA-Z0-9_]*<[a-zA-Z0-9,_<>]+>/ #V_GENERIC_TYPE_IDENTIFIER
1812 yield :V_GENERIC_TYPE_IDENTIFIER, $&
1813 when /\A[0-9]+|[0-9]+[eE][+-]?[0-9]+/ #V_INTEGER
1814 yield :V_INTEGER, $&
1815### when /\A[0-9]+\.[0-9]+|[0-9]+\.[0-9]+[eE][+-]?[0-9]+ / #V_REAL
1816### yield :V_REAL, $&
1817 # when /\A"((?:[^"\\]+|\\.)*)"/ #V_STRING
1818### when /\A"([^"]*)"/m #V_STRING
1819### yield :V_STRING, $1
1820 when /\A[a-z]+:\/\/[^<>|\\{}^~"\[\] ]*/ #V_URI
1821 yield :V_URI, $&
1822### 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
1823### yield :V_ISO8601_DURATION, $&
1824 when /\A\S/ #UTF8CHAR
1825 yield :UTF8CHAR, $&
1826 end
1827 data = $' # variable $' receives the string after the match
1828 when :adl
1829# puts "Entering scan_adl"
1830 data = scan_adl(data) do |sym, val|
1831 yield sym, val
1832 end
1833 when :cadl
1834# puts "Entering scan_cadl"
1835 data = scan_cadl(data) do |sym, val|
1836 yield sym, val
1837 end
1838 when :regexp
1839# puts "Entering scan_regexp"
1840 data = scan_regexp(data) do |sym, val|
1841 yield sym, val
1842 end
1843 when :term_constraint
1844# puts "Entering scan_term_constraint"
1845 data = scan_term_constraint(data) do |sym, val|
1846 yield sym, val
1847 end
1848 else
1849 raise
1850 end
1851 end
1852end # of scan_dadl
1853
1854def scan_regexp(data)
1855 until data.nil? do
1856 case @adl_type.last
1857 when :regexp
1858# puts "Entering scan_regexp"
1859 case data
1860 when /\A\/\}/ #V_REGEXP
1861 if @adl_type.last == :regexp
1862 @in_regexp = false
1863 @adl_type.pop
1864 yield :END_REGEXP_BLOCK, :END_REGEXP_BLOCK
1865 else
1866 raise
1867 end
1868 when /\A(.*)(\/\})/ #V_REGEXP
1869 yield :REGEXP_BODY, $1
1870 if @adl_type.last == :regexp
1871 @in_regexp = false
1872 @adl_type.pop
1873 yield :END_REGEXP_BLOCK, :END_REGEXP_BLOCK
1874 else
1875 raise
1876 end
1877 else
1878 raise data
1879 end
1880 data = $' # variable $' receives the string after the match
1881 when :adl
1882# puts "Entering scan_adl"
1883 data = scan_adl(data) do |sym, val|
1884 yield sym, val
1885 end
1886 when :dadl
1887# puts "Entering scan_dadl"
1888 data = scan_dadl(data) do |sym, val|
1889 yield sym, val
1890 end
1891 when :cadl
1892# puts "Entering scan_cadl"
1893 data = scan_cadl(data) do |sym, val|
1894 yield sym, val
1895 end
1896 when :term_constraint
1897# puts "Entering scan_term_constraint"
1898 data = scan_term_constraint(data) do |sym, val|
1899 yield sym, val
1900 end
1901 else
1902 raise
1903 end
1904 end
1905end # of scan_regexp
1906
1907def scan_term_constraint(data)
1908 until data.nil? do
1909 case @adl_type.last
1910 when :term_constraint
1911# puts "Entering scan_term_constraint"
1912 case data
1913 when /\A\n/ # carriage return
1914 @lineno += 1
1915 ;
1916 when /\A[ \t\r\f]+/ #just drop it
1917 ;
1918 when /\A--.*$/ # single line comment
1919 @lineno += 1
1920 @@log.info("#{__FILE__}:#{__LINE__}: scan_term_constraint: COMMENT = #{$&} at #{@filename}:#{@lineno}")
1921 ;
1922 when /\A[a-zA-Z0-9\._\-]+[ \t]*,/ # match any line, with ',' termination
1923 yield :TERM_CODE, $&
1924 when /\A[a-zA-Z0-9\._\-]+[ \t]*;/ #match second last line with ';' termination (assumed value)
1925 yield :TERM_CODE, $&
1926# when /\A[a-zA-Z0-9\._\-]+[ \t]*\]/ # match final line, terminating in ']'
1927 when /\A[a-zA-Z0-9\._\-]*[ \t]*\]/ # match final line, terminating in ']'
1928 adl_type = @adl_type.pop
1929 assert_at(__FILE__,__LINE__){adl_type == :term_constraint}
1930 yield :END_TERM_CODE_CONSTRAINT, $&
1931 else
1932 raise "data = #{data}"
1933 end
1934 data = $' # variable $' receives the string after the match
1935 when :adl
1936# puts "Entering scan_adl"
1937 data = scan_adl(data) do |sym, val|
1938 yield sym, val
1939 end
1940 when :dadl
1941# puts "Entering scan_dadl"
1942 data = scan_dadl(data) do |sym, val|
1943 yield sym, val
1944 end
1945 when :cadl
1946# puts "Entering scan_cadl"
1947 data = scan_cadl(data) do |sym, val|
1948 yield sym, val
1949 end
1950 else
1951 raise
1952 end
1953 end
1954end # of scan_term_constraint
1955
1956
1957def parse(data, filename, lineno = 1, debug = false)
1958 @yydebug = true
1959 @parsestring = data
1960 @data = data
1961 @lineno = lineno
1962 @filename = filename
1963 @adl_type = [:adl] # {:adl, :cadl, :dadl}
1964 @in_regexp = false
1965 @in_interval = false
1966 @in_c_domain_type = false
1967 yyparse self, :scan
1968end
1969
1970def on_error( t, v, values)
1971 raise Racc::ParseError, "#{@filename}:#{@lineno}: Inline syntax error on #{v.inspect}"
1972end
1973
1974
1975
1976
1977
1978
1979
1980### Local Variables:
1981### mode:ruby
1982### mode:font-lock
1983### comment-column:0
1984### comment-start: "### "
1985### comment-end:""
1986### End:
1987
1988
1989
1990
Note: See TracBrowser for help on using the repository browser.