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

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

changed the parser around object_block

File size: 46.2 KB
RevLine 
[4]1
[307]2class OpenEhr::ADL::Parser
[4]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
[21]30 {
31 result = val[0]
32 }
[4]33 | error
34
[21]35archetype: arch_identification arch_specialisation arch_concept arch_language arch_description arch_definition arch_invariant arch_ontology
36 {
[22]37 assert_at(__FILE__,__LINE__) do
[318]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)
[22]39 end
40
[26]41 archetype_id = val[0][:archetype_id]
[257]42 parent_archtype_id = val[1][:parent_archtype_id] if val[1]
[26]43 adl_version = val[0][:arch_head][:arch_meta_data][:adl_version]
[307]44 concept = val[2][:arch_concept]
[26]45 language = val[3][:arch_language]
[307]46 archetype = OpenEhr::AM::Archetype::ARCHETYPE.create(
[26]47 :archetype_id => archetype_id,
[257]48 :parent_archtype_id => parent_archtype_id,
[26]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
[283]57 @@logger.debug("#{__FILE__}:#{__LINE__}: archetype = #{archetype.to_yaml} at #{@filename}:#{@lineno}")
[26]58 result = archetype
[21]59 }
[4]60
61
62arch_identification: arch_head V_ARCHETYPE_ID
[24]63 {
64 result = {:arch_head => val[0], :archetype_id => val[1] }
65 }
[4]66 | SYM_ARCHETYPE error
[24]67 {
68 raise
69 }
[4]70
71arch_head: SYM_ARCHETYPE
[24]72 {
73 result = {:arch_meta_data => nil }
74 }
[4]75 | SYM_ARCHETYPE arch_meta_data
[24]76 {
[26]77 result = val[1]
[24]78 }
[4]79
80arch_meta_data: Left_parenthesis_code arch_meta_data_items Right_parenthesis_code
[24]81 {
[26]82 result = {:arch_meta_data => val[1] }
[24]83 }
[4]84
85arch_meta_data_items: arch_meta_data_item
[24]86 {
[26]87 result = val[0]
[24]88 }
[19]89 | arch_meta_data_items Semicolon_code arch_meta_data_item
[24]90 {
[26]91 result = val[0].merge(val[2])
[24]92 }
[4]93
[24]94
[4]95arch_meta_data_item: SYM_ADL_VERSION SYM_EQ V_VERSION_STRING
[24]96 {
[26]97 result = {:adl_version => val[2], :is_controlled => false }
[24]98 }
[4]99 | SYM_IS_CONTROLLED
[24]100 {
[26]101 result = {:is_controlled => true }
[24]102 }
[4]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
[257]108 {
109 result = {:parent_archtype_id => val[1]}
110 }
[4]111 | SYM_SPECIALIZE error
112
113arch_concept: SYM_CONCEPT V_LOCAL_TERM_CODE_REF
[26]114 {
115 result = {:arch_concept => val[1] }
116 }
[4]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
[26]124 {
[326]125 result = {:arch_language => ""}
[26]126 }
[4]127 | SYM_LANGUAGE dadl_section
[16]128 {
[328]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]}
[326]138 else
[328]139 raise OpenEhr::ADL::Exception::Parser::Error, "It should be 'original_language, but was #{dadl_section[:attr_id]}' at #{@filename}:#{@lineno} "
[326]140 end
[16]141 }
142 | SYM_LANGUAGE error
[4]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
[21]150 {
[326]151 args = Hash.new
152 val[1].each do |item|
[328]153 @@logger.debug("#{__FILE__}:#{__LINE__}: arch_description: item = #{item.to_yaml} at #{@filename}:#{@lineno}")
154 case item
[326]155 when "original_author"
156 unless item[:object_block][:type_identifier]
[328]157 args.merge!(Hash[:original_author => item[:untyped_multiple_attr_object_block]])
[326]158 else
159 raise OpenEhr::ADL::Exception::Parser::Error, "Needless type_identifier at #{@filename}:#{@lineno} "
160 end
161 when "details"
[328]162 unless item[:type_identifier]
163 args.merge!(Hash[:details => item[:untyped_multiple_attr_object_block]])
164 #args.merge!(Hash[:details => item[:object_block]])
[326]165 else
166 raise OpenEhr::ADL::Exception::Parser::Error, "Needless type_identifier at #{@filename}:#{@lineno} "
167 end
168 when "lifecycle_state"
[328]169 unless item[:type_identifier]
170 args.merge!(Hash[:lifecycle_state => item[:untyped_primitive_object_block]])
[326]171 else
172 raise OpenEhr::ADL::Exception::Parser::Error, "Needless type_identifier at #{@filename}:#{@lineno} "
173 end
174 when "other_contributors"
[328]175 unless item[:type_identifier]
176 args.merge!(Hash[:other_contributors => item[:untyped_multiple_attr_object_block]])
[326]177 else
178 raise OpenEhr::ADL::Exception::Parser::Error, "Needless type_identifier at #{@filename}:#{@lineno} "
179 end
180 when "other_details"
[328]181 unless item[:type_identifier]
182 args.merge!(Hash[:other_contributors => item[:untyped_multiple_attr_object_block]])
[326]183 else
184 raise OpenEhr::ADL::Exception::Parser::Error, "Needless type_identifier at #{@filename}:#{@lineno} "
185 end
186 else
[328]187 raise OpenEhr::ADL::Exception::Parser::Error, "Unknown case #{item} at #{@filename}:#{@lineno} "
[326]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)
[21]192 }
193 | SYM_DESCRIPTION error
194
[4]195#arch_definition: SYM_DEFINITION V_CADL_TEXT
196# | SYM_DEFINITION error
197arch_definition: SYM_DEFINITION cadl_section
[21]198 {
199 result = val[1]
200 }
[4]201 | SYM_DEFINITION error
202
203
204### cADL section
205cadl_section: c_complex_object
[35]206 {
[318]207 assert_at(__FILE__,__LINE__){val[0].instance_of?(OpenEhr::AM::Archetype::ConstraintModel::C_COMPLEX_OBJECT)}
[261]208 @@logger.debug("#{__FILE__}:#{__LINE__}: c_complex_object = #{val[0]} at #{@filename}:#{@lineno}")
[21]209 result = val[0]
210 }
[4]211 | assertions
[23]212 {
213 result = val[0]
214 }
[4]215# | error
216
[321]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}")
[318]222 result = OpenEhr::AM::Archetype::ConstraintModel::C_COMPLEX_OBJECT.create(:attributes => val[3]) do |c_complex_object|
[23]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
[21]227 }
[321]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
[21]230 {
[318]231 result = OpenEhr::AM::Archetype::ConstraintModel::C_COMPLEX_OBJECT.create(:attributes => val[3]) do |c_complex_object|
[23]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
[21]236 }
[321]237
[21]238# | c_complex_object_head error SYM_END_CBLOCK
[4]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
[23]242 {
[321]243 @@logger.debug("#{__FILE__}:#{__LINE__}: c_complex_object_head: c_complex_object_id => #{val[0]}, c_occurrences => #{val[1]}")
[23]244 result = {:c_complex_object_id => val[0], :c_occurrences => val[1]}
245 }
[4]246
247c_complex_object_id: type_identifier
[16]248 {
[23]249 result = {:type_identifier => val[0]}
[16]250 }
[4]251 | type_identifier V_LOCAL_TERM_CODE_REF
[16]252 {
[23]253 result = {:type_identifier => val[0], :local_term_code_ref => val[1]}
[16]254 }
[4]255
256c_complex_object_body: c_any #-- used to indicate that any value of a type is ok
257 | c_attributes
[22]258 {
[318]259 result = OpenEhr::AM::Archetype::ConstraintModel::C_COMPLEX_OBJECT.new(:attributes => val[0])
[22]260 }
[4]261
262
263#------------------------- node types -----------------------
[261]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
[32]276 {
[261]277 @@logger.debug("#{__FILE__}:#{__LINE__}: c_complex_object = #{val[0].inspect} at #{@filename}:#{@lineno}")
[22]278 result = val[0]
279 }
[4]280 | archetype_internal_ref
[32]281 {
[318]282 result = OpenEhr::AM::Archetype::ConstraintModel::ARCHETYPE_INTERNAL_REF.create do |archetype_internal_ref|
[32]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
[22]287 }
[4]288 | archetype_slot
[32]289 {
290 result = val[0]
[22]291 }
[4]292 | constraint_ref
[32]293 {
[318]294 result = OpenEhr::AM::Archetype::ConstraintModel::CONSTRAINT_REF.create do |constraint_ref|
[32]295 constraint_ref.reference = val[0]
296 end
[22]297 }
[4]298 | c_code_phrase
[32]299 {
[22]300 result = val[0]
301 }
[4]302 | c_ordinal
[32]303 {
[22]304 result = val[0]
305 }
[4]306 | c_primitive_object
[32]307 {
[22]308 result = val[0]
309 }
[261]310 | v_c_domain_type
311 {
312 result = val[0]
313 }
[19]314# | v_c_domain_type
[14]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
[307]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
[4]340 | ERR_C_DOMAIN_TYPE
341 | error
342
[16]343v_c_domain_type: START_V_C_DOMAIN_TYPE_BLOCK dadl_section END_V_C_DOMAIN_TYPE_BLOCK
[23]344 {
345 result = val[1]
346 }
[14]347
[4]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
[32]350 {
351 result = {:type_identifier => val[1], :c_occurrences => val[2], :absolute_path => val[3] }
352 }
[4]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
[32]357 {
[318]358 result = OpenEhr::AM::Archetype::ConstraintModel::ARCHETYPE_SLOT.create do |archetype_slot|
[32]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 }
[4]365c_archetype_slot_head: c_archetype_slot_id c_occurrences
[32]366 {
367 result = {:c_archetype_slot_id => val[0],:c_occurrences => val[1]}
368 }
[4]369
370c_archetype_slot_id: SYM_ALLOW_ARCHETYPE type_identifier
[32]371 {
372 result = val[1]
373 }
[4]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
[22]379 {
[318]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|
[32]382 c_primitive_object.item = val[0]
383 end
[22]384 }
[4]385
386c_primitive: c_integer
[21]387 {
[261]388 @@logger.debug("#{__FILE__}:#{__LINE__}: c_integer = #{val[0]} at #{@filename}:#{@lineno}")
[318]389 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_INTEGER.create do |c_integer|
[32]390 c_integer.list
391 c_integer.range
392 c_integer.assumed_value
393 end
[21]394 }
[4]395 | c_real
[22]396 {
[261]397 @@logger.debug("#{__FILE__}:#{__LINE__}: c_real = #{val[0]} at #{@filename}:#{@lineno}")
[318]398 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_REAL.new
[22]399 }
[4]400 | c_date
[22]401 {
[261]402 @@logger.debug("#{__FILE__}:#{__LINE__}: c_date = #{val[0]} at #{@filename}:#{@lineno}")
[318]403 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_DATE.new
[22]404 }
[4]405 | c_time
[22]406 {
[261]407 @@logger.debug("#{__FILE__}:#{__LINE__}: c_time = #{val[0]} at #{@filename}:#{@lineno}")
[318]408 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_TIME.new
[22]409 }
[4]410 | c_date_time
[22]411 {
[261]412 @@logger.debug("#{__FILE__}:#{__LINE__}: c_date_time = #{val[0]} at #{@filename}:#{@lineno}")
[318]413 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_DATE_TIME.new
[22]414 }
[4]415 | c_duration
[22]416 {
[261]417 @@logger.debug("#{__FILE__}:#{__LINE__}: c_duration = #{val[0]} at #{@filename}:#{@lineno}")
[318]418 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_DURATION.new
[22]419 }
[4]420 | c_string
[22]421 {
[261]422 @@logger.debug("#{__FILE__}:#{__LINE__}: c_string = #{val[0]} at #{@filename}:#{@lineno}")
[318]423 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_STRING.new
[22]424 }
[4]425 | c_boolean
[22]426 {
[318]427 assert_at(__FILE__,__LINE__){val[0].instance_of?(OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_BOOLEAN)}
[261]428 @@logger.debug("#{__FILE__}:#{__LINE__}: c_boolean = #{val[0]} at #{@filename}:#{@lineno}")
[22]429 result = val[0]
430 }
[4]431
432c_any: Star_code
433#c_any: '*'
434
435#---------------- BODY - relationships ----------------
436
437c_attributes: c_attribute
[22]438 {
439 result = [val[0]]
440 }
[4]441 | c_attributes c_attribute
[22]442 {
443 result = (val[0] << val[1])
444 }
[4]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
[22]448 {
[321]449 @@logger.debug("#{__FILE__}:#{__LINE__}:c_attribute: #{val[0]} matches #{val[3]}")
[318]450 assert_at(__FILE__,__LINE__){ val[0].kind_of?(OpenEhr::AM::Archetype::ConstraintModel::C_ATTRIBUTE)}
[22]451 c_attribute = val[0]
452 c_attribute.children = val[3]
453 result = c_attribute
454 }
[321]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]}}")
[318]458 assert_at(__FILE__,__LINE__){ val[0].kind_of?(OpenEhr::AM::Archetype::ConstraintModel::C_ATTRIBUTE)}
[22]459 result = val[0]
460 }
[321]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 }
[4]468 | c_attr_head SYM_MATCHES SYM_START_CBLOCK error SYM_END_CBLOCK
[22]469 {
[318]470 assert_at(__FILE__,__LINE__){ val[0].kind_of?(OpenEhr::AM::Archetype::ConstraintModel::C_ATTRIBUTE)}
[22]471 result = val[0]
472 }
[4]473
474
475c_attr_head: V_ATTRIBUTE_IDENTIFIER c_existence
[19]476 {
[261]477 @@logger.debug("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER = #{val[0]}, c_existence = #{val[1]} at #{@filename}")
[318]478 result = OpenEhr::AM::Archetype::ConstraintModel::C_SINGLE_ATTRIBUTE.new(
[22]479 :rm_attribute_name => val[0],
480 :existence => val[1]
481 )
482
[19]483 }
[4]484 | V_ATTRIBUTE_IDENTIFIER c_existence c_cardinality
[19]485 {
[318]486 assert_at(__FILE__,__LINE__){ val[2].instance_of?(OpenEhr::AM::Archetype::ConstraintModel::CARDINALITY) }
[261]487 @@logger.debug("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER: #{val[0]}, c_existence = #{val[1]}, c_cardinality = #{val[2]} at #{@filename}")
[318]488 result = OpenEhr::AM::Archetype::ConstraintModel::C_MULTIPLE_ATTRIBUTE.new(
[22]489 :rm_attribute_name => val[0],
490 :existence => val[1],
491 :cardinality => val[2]
492 )
[19]493 }
[4]494
495c_attr_values: c_object
[22]496 {
497 result = Array[val[0]]
498 }
[4]499 | c_attr_values c_object
[22]500 {
501 result = (val[0] << val[1])
502 }
[4]503 | c_any # -- to allow a property to have any value
[22]504 {
505 result = Array[val[0]]
506 }
[4]507
508c_includes: #-- Empty
[321]509 | SYM_INCLUDE assertions
[32]510{
[321]511 @@logger.debug("#{__FILE__}:#{__LINE__}: c_includes: assertions = #{val[1]}")
[32]512 result = val[1]
513}
[321]514### c_includes: #-- Empty
515### | SYM_INCLUDE invariants
[4]516
517c_excludes: #-- Empty
[321]518 | SYM_EXCLUDE assertions
519 {
520 @@logger.debug("#{__FILE__}:#{__LINE__}: c_excludes: assertions = #{val[1]}")
[32]521 result = val[1]
[321]522 }
523### c_excludes: #-- Empty
524### | SYM_EXCLUDE invariants
[4]525
526invariants: invariant
527 | invariants invariant
528
[321]529invariant: any_identifier Colon_code boolean_expression
[4]530 | boolean_expression
[321]531 | any_identifier Colon_code error
[4]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
[22]542 {
[26]543 dadl_section = val[1]
[328]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)
[22]576 }
[4]577 | SYM_ONTOLOGY error
578
579
580### dADL section
[318]581dadl_section: # no dadl section
582 | attr_vals
[307]583 {
[328]584 @@logger.debug("#{__FILE__}:#{__LINE__}:dadl_section::attr_vals = \n#{val[0].to_yaml}")
[307]585 result = val[0]
586 }
[4]587 | complex_object_block
[307]588 {
[328]589 #@@logger.debug("#{__FILE__}:#{__LINE__}:dadl_section::complex_object_block = \n#{val[0].to_yaml}")
[307]590 result = val[0]
591 }
[4]592# | error
593
594attr_vals: attr_val
[23]595 {
[328]596 attr_val = val[0]
597 result = Hash[attr_val[:attr_id] => attr_val[:object_block]]
[23]598 }
[4]599 | attr_vals attr_val
[23]600 {
[328]601 result = val[0].merge!(val[1])
[23]602 }
[19]603 | attr_vals Semicolon_code attr_val
[23]604 {
[328]605 result = val[0].merge!(val[2])
[23]606 }
[328]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### }
[4]619
620attr_val: attr_id SYM_EQ object_block
[19]621 {
[328]622 @@logger.debug("#{__FILE__}:#{__LINE__}:attr_val\n attr_id = #{val[0].to_yaml},\n object_block = #{val[2].to_yaml}")
[23]623 result = {:attr_id => val[0], :object_block => val[2]}
[19]624 }
[4]625
626attr_id: V_ATTRIBUTE_IDENTIFIER
[18]627 {
[307]628 @@logger.debug("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER = #{val[0]}")
[22]629 result = val[0]
[18]630 }
[4]631 | V_ATTRIBUTE_IDENTIFIER error
632
633object_block: complex_object_block
[22]634 {
635 result = val[0]
636 }
[4]637 | primitive_object_block
[22]638 {
639 result = val[0]
640 }
[4]641
642complex_object_block: single_attr_object_block
[22]643 {
644 result = val[0]
645 }
[4]646 | multiple_attr_object_block
[22]647 {
648 result = val[0]
649 }
[4]650
651multiple_attr_object_block: untyped_multiple_attr_object_block
[22]652 {
[328]653 @@logger.debug("#{__FILE__}:#{__LINE__}:multiple_attr_object_block::attr_val\n untyped_multiple_attr_object_block = #{val[0].to_yaml}")
[23]654 result = {:untyped_multiple_attr_object_block => val[0]}
[22]655 }
[4]656 | type_identifier untyped_multiple_attr_object_block
[22]657 {
[23]658 result = {:type_identifier => val[0], :untyped_multiple_attr_object_block => val[1]}
[22]659 }
[4]660
661untyped_multiple_attr_object_block: multiple_attr_object_block_head keyed_objects SYM_END_DBLOCK
[22]662 {
[328]663 @@logger.debug("#{__FILE__}:#{__LINE__}:untyped_multiple_attr_object_block::keyed_objects\n keyed_objects = #{val[1].to_yaml}")
[326]664 result = val[1]
[22]665 }
[4]666
667multiple_attr_object_block_head: SYM_START_DBLOCK
[22]668 {
669 result = val[0]
[20]670 }
[4]671
672keyed_objects: keyed_object
[23]673 {
674 result = Array[val[0]]
675 }
[4]676 | keyed_objects keyed_object
[23]677 {
678 result = (val[0] << val[1])
679 }
[4]680
681keyed_object: object_key SYM_EQ object_block
[20]682 {
[326]683 #@@logger.debug("#{__FILE__}:#{__LINE__}: keyed_object = #{val[0]} at #{@filename}:#{@lineno}")
684 #result = {:object_key => val[0], :object_block => val[2]}
[328]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]]
[326]688 else
689 raise OpenEhr::ADL::Exception::Parser::Error, "Missing type_identifier at #{@filename}:#{@lineno} "
690 end
[20]691 }
[4]692
693object_key: Left_bracket_code simple_value Right_bracket_code
[19]694 {
[261]695 @@logger.debug("object_key: [#{val[1]}] at #{@filename}:#{@lineno}")
[22]696 result = val[1]
[19]697 }
[4]698
699single_attr_object_block: untyped_single_attr_object_block
[23]700 {
701 result = {:untyped_single_attr_object_block => val[0]}
702 }
[4]703 | type_identifier untyped_single_attr_object_block
[23]704 {
705 result = {:type_identifier => val[0], :untyped_single_attr_object_block => val[1]}
706 }
707
[257]708untyped_single_attr_object_block: single_attr_object_complex_head SYM_END_DBLOCK # >
[22]709 {
[261]710 @@logger.debug("#{__FILE__}:#{__LINE__}: single_attr_object_complex_head = #{val[0]} at #{@filename}:#{@lineno}")
[326]711 result = []
[22]712 }
[4]713 | single_attr_object_complex_head attr_vals SYM_END_DBLOCK
[22]714 {
[328]715 @@logger.debug("#{__FILE__}:#{__LINE__}: untyped_single_attr_object_block::attr_vals = \n#{val[1].to_yaml} at #{@filename}:#{@lineno}")
[326]716 result = val[1]
[22]717 }
[4]718single_attr_object_complex_head: SYM_START_DBLOCK
[328]719
[4]720primitive_object_block: untyped_primitive_object_block
[22]721 {
[261]722 @@logger.debug("#{__FILE__}:#{__LINE__}: untyped_primitive_object_block = #{val[0]} at #{@filename}:#{@lineno}")
[23]723 result = {:untyped_primitive_object_block => val[0]}
[22]724 }
[4]725 | type_identifier untyped_primitive_object_block
[22]726 {
[261]727 @@logger.debug("#{__FILE__}:#{__LINE__}: type_identifier = #{val[0]}, untyped_primitive_object_block = #{val[1]} at #{@filename}:#{@lineno}")
[23]728 result = {:type_identifier => val[0], :untyped_primitive_object_block => val[1]}
[22]729 }
[4]730untyped_primitive_object_block: SYM_START_DBLOCK primitive_object_value SYM_END_DBLOCK
[20]731 {
[326]732 #@@logger.debug("#{__FILE__}:#{__LINE__}: primitive_object_block = <#{val[1]}> at #{@filename}:#{@lineno}")
[22]733 result = val[1]
[20]734 }
[4]735primitive_object_value: simple_value
[22]736 {
737 result = val[0]
738 }
[4]739 | simple_list_value
[22]740 {
741 result = val[0]
742 }
[4]743 | simple_interval_value
[22]744 {
745 result = val[0]
746 }
[4]747 | term_code
[22]748 {
749 result = val[0]
750 }
[4]751 | term_code_list_value
[22]752 {
753 result = val[0]
754 }
[4]755simple_value: string_value
[19]756 {
[261]757 @@logger.debug("string_value: #{val[0]} at #{@filename}:#{@lineno}")
[22]758 result = val[0]
[19]759 }
[4]760 | integer_value
[19]761 {
[261]762 @@logger.debug("integer_value: #{val[0]} at #{@filename}:#{@lineno}")
[22]763 result = val[0]
[19]764 }
[4]765 | real_value
[19]766 {
[261]767 @@logger.debug("real_value: #{val[0]} at #{@filename}:#{@lineno}")
[22]768 result = val[0]
[19]769 }
[4]770 | boolean_value
[19]771 {
[261]772 @@logger.debug("boolean_value: #{val[0]} at #{@filename}:#{@lineno}")
[22]773 result = val[0]
[19]774 }
[4]775 | character_value
[19]776 {
[261]777 @@logger.debug("character_value: #{val[0]} at #{@filename}:#{@lineno}")
[22]778 result = val[0]
[19]779 }
[4]780 | date_value
[19]781 {
[261]782 @@logger.debug("date_value: #{val[0]} at #{@filename}:#{@lineno}")
[22]783 result = val[0]
[19]784 }
[4]785 | time_value
[19]786 {
[261]787 @@logger.debug("time_value: #{val[0]} at #{@filename}:#{@lineno}")
[22]788 result = val[0]
[19]789 }
[4]790 | date_time_value
[19]791 {
[261]792 @@logger.debug("date_time_value: #{val[0]} at #{@filename}:#{@lineno}")
[22]793 result = val[0]
[19]794 }
[4]795 | duration_value
[19]796 {
[261]797 @@logger.debug("duration_value: #{val[0]} at #{@filename}:#{@lineno}")
[22]798 result = val[0]
[19]799 }
[4]800 | uri_value
[19]801 {
[261]802 @@logger.debug("uri_value: #{val[0]} at #{@filename}:#{@lineno}")
[22]803 result = val[0]
[19]804 }
[22]805
[4]806simple_list_value: string_list_value
[317]807 {
808 @@logger.debug("string_list_value: #{val[0]} at #{@filename}:#{@lineno}")
809 result = val[0]
810 }
[4]811 | integer_list_value
[317]812 {
813 result = val[0]
814 }
[4]815 | real_list_value
[317]816 {
817 result = val[0]
818 }
[4]819 | boolean_list_value
[317]820 {
821 result = val[0]
822 }
[4]823 | character_list_value
[317]824 {
825 result = val[0]
826 }
[4]827 | date_list_value
[317]828 {
829 result = val[0]
830 }
[4]831 | time_list_value
[317]832 {
833 result = val[0]
834 }
[4]835 | date_time_list_value
[317]836 {
837 result = val[0]
838 }
[4]839 | duration_list_value
[317]840 {
841 result = val[0]
842 }
[4]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
[19]852 {
[261]853 @@logger.debug("V_TYPE_IDENTIFIER: #{val[0]} at #{@filename}:#{@lineno}")
[22]854 result = val[0]
[19]855 }
[4]856 | V_GENERIC_TYPE_IDENTIFIER
[19]857 {
[261]858 @@logger.debug("V_GENERIC_TYPE_IDENTIFIER: #{val[0]} at #{@filename}:#{@lineno}")
[22]859 result = val[0]
[19]860 }
[4]861
862string_value: V_STRING
[18]863 {
[261]864 @@logger.debug("V_STRING: #{val[0]} at #{@filename}:#{@lineno}")
[22]865 result = val[0]
[18]866 }
[4]867
868string_list_value: V_STRING Comma_code V_STRING
[317]869 {
870 result = [val[0],val[2]]
871 }
[4]872 | string_list_value Comma_code V_STRING
[317]873 {
874 result = val[0] << val[2]
875 }
[4]876 | V_STRING Comma_code SYM_LIST_CONTINUE
[317]877 {
878 result = val[0]
879 }
[4]880
881integer_value: V_INTEGER
[22]882 {
883 begin
884 integer = Integer(val[0])
885 rescue
886 raise
887 end
888 result = integer
889 }
[18]890 | Plus_code V_INTEGER
[22]891 {
892 begin
893 integer = Integer(val[0])
894 rescue
895 raise
896 end
897 result = integer
898 }
[18]899 | Minus_code V_INTEGER
[22]900 {
901 begin
902 integer = Integer(val[0])
903 rescue
904 raise
905 end
906 result = - integer
907 }
[4]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
[23]924 {
925 begin
926 real = Float(val[0])
927 rescue
928 raise
929 end
930 result = real
931 }
[18]932 | Plus_code V_REAL
[23]933 {
934 begin
[25]935 real = Float(val[1])
[23]936 rescue
937 raise
938 end
939 result = real
940 }
[18]941 | Minus_code V_REAL
[23]942 {
943 begin
[25]944 real = Float(val[1])
[23]945 rescue
946 raise
947 end
948 result = - real
949 }
[4]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
[23]967 {
968 result = true
969 }
[4]970 | SYM_FALSE
[23]971 {
972 result = false
973 }
[4]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
[283]986 {
987 result = val[0]
988 }
[4]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
[320]1021 {
1022 @@logger.debug("V_ISO8601_EXTENDED_DATE_TIME: #{val[0]} at #{@filename}:#{@lineno}")
1023 result = val[0]
1024 }
[4]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
[19]1041 {
[261]1042 @@logger.debug("V_ISO8601_DURATION: #{val[0]} at #{@filename}:#{@lineno}")
[22]1043 result = val[0]
[19]1044 }
[4]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
[20]1061 {
[261]1062 @@logger.debug("#{__FILE__}:#{__LINE__}: V_QUALIFIED_TERM_CODE_REF = #{val[0]} at #{@filename}:#{@lineno}")
[26]1063 result = val[0]
[20]1064 }
[4]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
[20]1071 {
[261]1072 @@logger.debug("#{__FILE__}:#{__LINE__}: V_URI = #{val[0]} at #{@filename}:#{@lineno}")
[26]1073 result = val[0]
[20]1074 }
[4]1075
1076
1077#---------------------- ASSERTIONS ------------------------
1078
1079assertions: assertion
1080 | assertions assertion
1081
[321]1082assertion: any_identifier Colon_code boolean_expression
[4]1083 | boolean_expression
[321]1084 | any_identifier Colon_code error
[4]1085
1086#---------------------- expressions ---------------------
1087
1088boolean_expression: boolean_leaf
1089 | boolean_node
1090
1091boolean_node: SYM_EXISTS absolute_path
[321]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 }
[4]1098 | relative_path SYM_MATCHES SYM_START_CBLOCK c_primitive SYM_END_CBLOCK
[321]1099# | relative_path SYM_MATCHES SYM_START_CBLOCK Slash_code REGEXP_BODY Slash_code SYM_END_CBLOCK# added by akimichi
[4]1100 | SYM_NOT boolean_leaf
[321]1101 | arithmetic_expression Equal_code arithmetic_expression
[4]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
[323]1116arithmetic_node: arithmetic_expression Plus_code arithmetic_leaf
[321]1117 | arithmetic_expression Minus_code arithmetic_leaf
[4]1118 | arithmetic_expression Star_code arithmetic_leaf
1119 | arithmetic_expression Slash_code arithmetic_leaf
[321]1120 | arithmetic_expression Caret_code arithmetic_leaf
[4]1121
1122arithmetic_leaf: Left_parenthesis_code arithmetic_expression Right_parenthesis_code
1123 | integer_value
1124 | real_value
1125 | absolute_path
1126
[321]1127arithmetic_expression: arithmetic_leaf
1128 | arithmetic_node
[4]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
[321]1141 {
1142 @@logger.debug("#{__FILE__}:#{__LINE__}, relative_path = #{val[0]}")
1143 result = val[0]
1144 }
[4]1145 | relative_path Slash_code path_segment
[321]1146 {
1147 @@logger.debug("#{__FILE__}:#{__LINE__}, relative_path = #{val[0]}/#{val[2]}")
1148 result = [val[0],val[2]]
1149 }
[4]1150
1151path_segment: V_ATTRIBUTE_IDENTIFIER V_LOCAL_TERM_CODE_REF
[19]1152 {
[261]1153 @@logger.debug("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}")
[321]1154 result = [val[0],val[1]]
[19]1155 }
[4]1156 | V_ATTRIBUTE_IDENTIFIER
[19]1157 {
[261]1158 @@logger.debug("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}")
[321]1159 result = val[0]
[19]1160 }
[4]1161
1162
1163#-------------------------------- END SOURCE TAKEN FROM OG_PATH_VALIDATOR.Y ----------------------
1164
1165
1166#---------------- existence, occurrences, cardinality ----------------
1167
1168c_existence: #-- default to 1..1
[22]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 }
[4]1176
1177existence_spec: V_INTEGER #-- can only be 0 or 1
[22]1178 {
1179 begin
1180 integer = Integer(val[0])
1181 rescue
1182 raise
1183 end
1184 result = integer
1185 }
[4]1186 | V_INTEGER SYM_ELLIPSIS V_INTEGER #-- can only be 0..0, 0..1, 1..1
[22]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 }
[4]1196
1197c_cardinality: SYM_CARDINALITY SYM_MATCHES SYM_START_CBLOCK cardinality_spec SYM_END_CBLOCK
[22]1198 {
[318]1199 result = OpenEhr::AM::Archetype::ConstraintModel::CARDINALITY.new
[22]1200 }
[4]1201
1202cardinality_spec: occurrence_spec
[323]1203 {
1204 result = val[0]
1205 }
[4]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
[35]1215 {
1216 result = val[0]
1217 }
1218 | Star_code # '*'
1219 {
1220 result = val[0]
1221 }
[4]1222
[35]1223
[4]1224c_occurrences: #-- default to 1..1
1225 | SYM_OCCURRENCES SYM_MATCHES SYM_START_CBLOCK occurrence_spec SYM_END_CBLOCK
[23]1226 {
[307]1227 case val[3]
1228 when OpenEhr::RM::Support::AssumedTypes::Interval
1229 result = val[3]
1230 else
1231 result = val[3]
1232 end
[23]1233 }
[4]1234 | SYM_OCCURRENCES error
1235
1236occurrence_spec: cardinality_limit_value #-- single integer or '*'
[307]1237 {
1238 result = val[0]
1239 }
[4]1240 | V_INTEGER SYM_ELLIPSIS cardinality_limit_value
[307]1241 {
1242 result = OpenEhr::RM::Support::AssumedTypes::Interval.new(val[0], val[2])
1243 }
[4]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
[22]1307 {
[318]1308 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_BOOLEAN.new(:true_valid => true)
[22]1309 }
[4]1310 | SYM_FALSE
[22]1311 {
[318]1312 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_BOOLEAN.new(:true_valid => false)
[22]1313 }
[4]1314 | SYM_TRUE Comma_code SYM_FALSE
[22]1315 {
[318]1316 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_BOOLEAN.new(:true_valid => true,:false_valid => false)
[22]1317 }
[4]1318 | SYM_FALSE Comma_code SYM_TRUE
[22]1319 {
[318]1320 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_BOOLEAN.new(:true_valid => false,:false_valid => true)
[22]1321 }
[4]1322
1323c_boolean: c_boolean_spec
[22]1324 {
1325 result = val[0]
1326 }
[4]1327 | c_boolean_spec Semicolon_code boolean_value
[22]1328 {
[321]1329 result = val[0]
1330 #raise 'Not implemented yet'
[22]1331 }
[19]1332 | c_boolean_spec Semicolon_code error
[22]1333 {
1334 raise 'Not implemented yet'
1335 }
[4]1336
1337c_ordinal: c_ordinal_spec
1338 | c_ordinal_spec Semicolon_code integer_value
[19]1339 | c_ordinal_spec Semicolon_code error
[4]1340
1341c_ordinal_spec: ordinal
1342 | c_ordinal_spec Comma_code ordinal
1343
1344ordinal: integer_value SYM_INTERVAL_DELIM V_QUALIFIED_TERM_CODE_REF
[20]1345 {
1346 @in_interval = false
[261]1347 @@logger.debug("#{__FILE__}:#{__LINE__}, #{val[0]}|#{val[2]} at #{@filename}")
[20]1348 }
[4]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]"
[32]1352 {
1353 result = val[0]
1354 }
[4]1355 | V_QUALIFIED_TERM_CODE_REF
[32]1356 {
1357 result = val[0]
1358 }
[4]1359
[261]1360# [[a-zA-Z0-9\(\)\._\-]+::[ \t\n]* [[a-zA-Z0-9\._\-]*[ \t]*]
[4]1361term_code_constraint_section: START_TERM_CODE_CONSTRAINT term_code_body END_TERM_CODE_CONSTRAINT
[261]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
[4]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"
[32]1378 {
1379 result = val[0]
1380 }
[4]1381
1382any_identifier: type_identifier
[32]1383 {
1384 result = val[0]
1385 }
[4]1386 | V_ATTRIBUTE_IDENTIFIER
[19]1387 {
[261]1388 @@logger.debug("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{word} at #{@filename}")
[32]1389 result = val[0]
[19]1390 }
[4]1391
1392
1393#----------------- TAKEN FROM DADL_VALIDATOR.Y -------------------
1394#----------------- DO NOT MODIFY -------------------
1395#---------------------- BASIC DATA VALUES -----------------------
1396
1397duration_pattern: V_ISO8601_DURATION_CONSTRAINT_PATTERN
[318]1398 {
1399 result = OpenEhr::AM::Archetype::ConstraintModel::Primitive::C_DURATION.new #val[0]
[26]1400 }
[4]1401
1402
1403
1404---- header
1405
[49]1406
[4]1407$:.unshift File.join(File.dirname(__FILE__))
[17]1408require 'logger'
[283]1409require 'yaml'
[21]1410require 'rubygems'
[307]1411require 'open_ehr'
1412$DEBUG = true
[4]1413
1414
[17]1415
[4]1416---- inner
[17]1417
[22]1418def assert_at(file,line, message = "")
1419 unless yield
1420 raise "Assertion failed !: #{file}, #{line}: #{message}"
1421 end
1422end
1423
[49]1424if $DEBUG
[261]1425 @@logger = Logger.new('log/parser.log','daily')
[263]1426 @@logger.level = Logger::DEBUG
[49]1427else
[261]1428 @@logger = Logger.new(STDOUT)
1429 @@logger.level = Logger::WARN
[49]1430end
1431
[17]1432
[4]1433
1434###----------/* Scanner */ -----------------------------------------------
1435
[265]1436
[4]1437def scan
[261]1438 @@logger.debug("#{__FILE__}:#{__LINE__}: Entering scan at #{@filename}:#{@lineno}:")
[307]1439 scanner = OpenEhr::ADL::Scanner::ADLScanner.new(@adl_type, @filename)
[265]1440
[4]1441 until @data.nil? do
[283]1442 @data = scanner.scan(@data) do |sym, val|
[4]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
[265]1451
[328]1452def parse(data, filename = "", lineno = 1, debug = false)
[4]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
[14]1461 @in_c_domain_type = false
[4]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
[283]1470__END__
[4]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.