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

Last change on this file since 326 was 326, checked in by Tatsukawa, Akimichi, 14 years ago

start implementing semantic function in ADL parser

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