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

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

refactoring scanner for regex

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