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

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

start implementing semantic function in ADL parser

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