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

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

refactoring scanner for regex

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