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

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

commit from Pittsburgh

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