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

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

changed the parser around object_block

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