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

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

merged latest trunc change to branches/0.5

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