1 |
|
---|
2 |
|
---|
3 | class OpenEHR::ADLParser
|
---|
4 |
|
---|
5 | #options omit_action_call
|
---|
6 |
|
---|
7 | prechigh
|
---|
8 |
|
---|
9 | nonassoc UMINUS UPLUS
|
---|
10 | left '*' '/'
|
---|
11 | left '+' '-'
|
---|
12 |
|
---|
13 | # left DOUBLE_BAR
|
---|
14 |
|
---|
15 | nonassoc SYM_EQ
|
---|
16 | nonassoc SYM_NE
|
---|
17 | nonassoc SYM_LT
|
---|
18 | nonassoc SYM_START_DBLOCK
|
---|
19 | nonassoc SYM_GT
|
---|
20 | nonassoc SYM_END_DBLOCK
|
---|
21 | nonassoc SYM_LE
|
---|
22 | nonassoc SYM_GE
|
---|
23 |
|
---|
24 | preclow
|
---|
25 |
|
---|
26 |
|
---|
27 | rule
|
---|
28 | ### http://svn.openehr.org/ref_impl_eiffel/TRUNK/components/adl_parser/src/syntax/adl/parser/adl_validator.y
|
---|
29 |
|
---|
30 | input: archetype
|
---|
31 | # | error
|
---|
32 |
|
---|
33 | archetype: arch_identification
|
---|
34 | arch_specialisation
|
---|
35 | arch_concept
|
---|
36 | arch_language
|
---|
37 | arch_description
|
---|
38 | arch_definition
|
---|
39 | arch_invariant
|
---|
40 | arch_ontology
|
---|
41 |
|
---|
42 |
|
---|
43 | arch_identification: arch_head V_ARCHETYPE_ID
|
---|
44 | # | SYM_ARCHETYPE error
|
---|
45 |
|
---|
46 | arch_head: SYM_ARCHETYPE
|
---|
47 | | SYM_ARCHETYPE arch_meta_data
|
---|
48 |
|
---|
49 | arch_meta_data: Left_parenthesis_code arch_meta_data_items Right_parenthesis_code
|
---|
50 |
|
---|
51 | arch_meta_data_items: arch_meta_data_item
|
---|
52 | | arch_meta_data_items ';' arch_meta_data_item
|
---|
53 |
|
---|
54 | arch_meta_data_item: SYM_ADL_VERSION SYM_EQ V_VERSION_STRING
|
---|
55 | | SYM_IS_CONTROLLED
|
---|
56 |
|
---|
57 | # Define specialization in which its constraints are narrower than those of the parent.
|
---|
58 | # Any data created via the use of the specialized archetype shall be conformant both to it and its parent.
|
---|
59 | arch_specialisation: #-- empty is ok
|
---|
60 | | SYM_SPECIALIZE V_ARCHETYPE_ID
|
---|
61 | # | SYM_SPECIALIZE error
|
---|
62 |
|
---|
63 | arch_concept: SYM_CONCEPT V_LOCAL_TERM_CODE_REF
|
---|
64 | # | SYM_CONCEPT error
|
---|
65 |
|
---|
66 | arch_language: #-- empty is ok for ADL 1.4 tools
|
---|
67 | | SYM_LANGUAGE V_DADL_TEXT
|
---|
68 | # | SYM_LANGUAGE error
|
---|
69 |
|
---|
70 | arch_description: #-- no meta-data ok
|
---|
71 | | SYM_DESCRIPTION V_DADL_TEXT
|
---|
72 | # | SYM_DESCRIPTION error
|
---|
73 |
|
---|
74 | arch_definition: SYM_DEFINITION V_CADL_TEXT
|
---|
75 | # | SYM_DEFINITION error
|
---|
76 |
|
---|
77 | arch_invariant: #-- no invariant ok
|
---|
78 | | SYM_INVARIANT V_ASSERTION_TEXT
|
---|
79 | # | SYM_INVARIANT error
|
---|
80 |
|
---|
81 | # define all linguistic entries in this part as dADL.
|
---|
82 | arch_ontology: SYM_ONTOLOGY V_DADL_TEXT
|
---|
83 | # | SYM_ONTOLOGY error
|
---|
84 |
|
---|
85 |
|
---|
86 | ---- header
|
---|
87 |
|
---|
88 | $:.unshift File.join(File.dirname(__FILE__))
|
---|
89 | $DEBUG = false
|
---|
90 |
|
---|
91 |
|
---|
92 | ---- inner
|
---|
93 | ###----------/* keywords */ ---------------------------------------------
|
---|
94 | @@reserved = {
|
---|
95 | 'archetype' => :SYM_ARCHETYPE,
|
---|
96 | 'adl_version' => :SYM_ADL_VERSION,
|
---|
97 | 'controlled' => :SYM_IS_CONTROLLED,
|
---|
98 | 'specialize' => :SYM_SPECIALIZE,
|
---|
99 | 'concept' => :SYM_CONCEPT,
|
---|
100 | 'language' => :SYM_LANGUAGE,
|
---|
101 | 'description' => :SYM_DESCRIPTION,
|
---|
102 | 'definition' => :SYM_DEFINITION,
|
---|
103 | 'invariant' => :SYM_INVARIANT,
|
---|
104 | 'ontology' => :SYM_ONTOLOGY,
|
---|
105 | 'true' => :SYM_TRUE, #[Tt][Rr][Uu][Ee] -- -> SYM_TRUE
|
---|
106 | 'false' => :SYM_FALSE, # [Ff][Aa][Ll][Ss][Ee] -- -> SYM_FALSE
|
---|
107 | 'infinity' => :SYM_INFINITY # [Ii][Nn][Ff][Ii][Nn][Ii][Tt][Yy] -- -> SYM_INFINITY
|
---|
108 | }
|
---|
109 |
|
---|
110 | ###----------/* Scanner */ -----------------------------------------------
|
---|
111 |
|
---|
112 | def scan
|
---|
113 | until @data.nil? do
|
---|
114 | case @data
|
---|
115 | when /\A\n/ # carriage return
|
---|
116 | @lineno += 1
|
---|
117 | ;
|
---|
118 | when /\A[ \t\r\f]+/ #just drop it
|
---|
119 | ;
|
---|
120 | when /\A--.*\n/ # single line comment
|
---|
121 | @lineno += 1
|
---|
122 | ;
|
---|
123 | ###----------/* symbols */ -------------------------------------------------
|
---|
124 | when /\A[a-zA-Z][a-zA-Z0-9_-]+\.[a-zA-Z][a-zA-Z0-9_-]+\.[a-zA-Z0-9]+/ #V_ARCHETYPE_ID
|
---|
125 | yield :V_ARCHETYPE_ID, $&
|
---|
126 | when /\A[a-z][a-zA-Z0-9_]*/
|
---|
127 | word = $&.downcase
|
---|
128 | if @@reserved[word]
|
---|
129 | yield @@reserved[word], @@reserved[word]
|
---|
130 | end
|
---|
131 | when /\A\=/ # =
|
---|
132 | yield :SYM_EQ, :SYM_EQ
|
---|
133 | when /\A\>=/ # >=
|
---|
134 | yield :SYM_GE, :SYM_GE
|
---|
135 | when /\A\<=/ # <=
|
---|
136 | yield :SYM_LE, :SYM_LE
|
---|
137 | when /\A\</ # <
|
---|
138 | if @in_interval
|
---|
139 | @start_block_received = false
|
---|
140 | yield :SYM_LT, :SYM_LT
|
---|
141 | else
|
---|
142 | @start_block_received = true
|
---|
143 | yield :SYM_START_DBLOCK, :SYM_START_DBLOCK
|
---|
144 | end
|
---|
145 | when /\A\>/ # >
|
---|
146 | if @in_interval
|
---|
147 | yield :SYM_GT, :SYM_GT
|
---|
148 | else
|
---|
149 | yield :SYM_END_DBLOCK, :SYM_END_DBLOCK
|
---|
150 | end
|
---|
151 | when /\A\-/ # -
|
---|
152 | yield :Minus_code, :Minus_code
|
---|
153 | when /\A\+/ # +
|
---|
154 | yield :Plus_code, :Plus_code
|
---|
155 | when /\A\*/ # *
|
---|
156 | yield :Star_code, :Star_code
|
---|
157 | when /\A\// # /
|
---|
158 | yield :Slash_code, :Slash_code
|
---|
159 | when /\A\^/ # ^
|
---|
160 | yield :Caret_code, :Caret_code
|
---|
161 | when /\A\=/ # =
|
---|
162 | yield :Equal_code, :Equal_code
|
---|
163 | when /\A\./ # .
|
---|
164 | yield :Dot_code, :Dot_code
|
---|
165 | when /\A\;/ # ;
|
---|
166 | yield :Semicolon_code, :Semicolon_code
|
---|
167 | when /\A\,/ # ,
|
---|
168 | yield :Comma_code, :Comma_code
|
---|
169 | when /\A\:/ # :
|
---|
170 | yield :Colon_code, :Colon_code
|
---|
171 | when /\A\!/ # !
|
---|
172 | yield :Exclamation_code, :Exclamation_code
|
---|
173 | when /\A\(/ # (
|
---|
174 | yield :Left_parenthesis_code, :Left_parenthesis_code
|
---|
175 | when /\A\)/ # )
|
---|
176 | yield :Right_parenthesis_code, :Right_parenthesis_code
|
---|
177 | when /\A\$/ # $
|
---|
178 | yield :Dollar_code, :Dollar_code
|
---|
179 | when /\A\?\?/ # ??
|
---|
180 | yield :SYM_DT_UNKNOWN, :SYM_DT_UNKNOWN
|
---|
181 | when /\A\?/ # ?
|
---|
182 | yield :Question_mark_code, :Question_mark_code
|
---|
183 | when /\A[0-9]+\.[0-9]+(\.[0-9]+)*/ # ?
|
---|
184 | yield :V_VERSION_STRING, :V_VERSION_STRING
|
---|
185 | when /\A\[[a-zA-Z0-9][a-zA-Z0-9._\-]*\]/ #V_LOCAL_TERM_CODE_REF
|
---|
186 | yield :V_LOCAL_TERM_CODE_REF, $&
|
---|
187 | when /\A[a-zA-Z][a-zA-Z0-9_]*/
|
---|
188 | yield :V_IDENTIFIER, $&
|
---|
189 | when /\A\|/ # |
|
---|
190 | if @in_interval
|
---|
191 | @in_interval = false
|
---|
192 | elsif @start_block_received
|
---|
193 | @in_interval = true
|
---|
194 | @start_block_received = false
|
---|
195 | end
|
---|
196 | yield :SYM_INTERVAL_DELIM, :SYM_INTERVAL_DELIM
|
---|
197 | when /\A\[/ # [
|
---|
198 | yield :Left_bracket_code, :Left_bracket_code
|
---|
199 | when /\A\]/ # ]
|
---|
200 | yield :Right_bracket_code, :Right_bracket_code
|
---|
201 | when /\A\../ # ..
|
---|
202 | yield :SYM_ELLIPSIS, :SYM_ELLIPSIS
|
---|
203 | when /\A\.../ # ...
|
---|
204 | yield :SYM_LIST_CONTINUE, :SYM_LIST_CONTINUE
|
---|
205 |
|
---|
206 | when /\A\[[a-zA-Z0-9._\-]+::[a-zA-Z0-9._\-]+\]/ #V_QUALIFIED_TERM_CODE_REF form [ICD10AM(1998)::F23]
|
---|
207 | yield :V_QUALIFIED_TERM_CODE_REF, $&
|
---|
208 | when /\A\[[a-zA-Z0-9._\- ]+::[a-zA-Z0-9._\- ]+\]/ #ERR_V_QUALIFIED_TERM_CODE_REF
|
---|
209 | yield :ERR_V_QUALIFIED_TERM_CODE_REF, $&
|
---|
210 | when /\Aa[ct][0-9.]+/ #V_LOCAL_CODE
|
---|
211 | yield :V_LOCAL_CODE, $&
|
---|
212 | when /\A[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9](,[0-9]+)?(Z|[+-][0-9]{4})?|[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-6][0-9](Z|[+-][0-9]{4})?|[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9](Z|[+-][0-9]{4})?/ #V_ISO8601_EXTENDED_DATE_TIME YYYY-MM-DDThh:mm:ss[,sss][Z|+/- -n-n-n-n-]-
|
---|
213 | yield :V_ISO8601_EXTENDED_DATE_TIME, $&
|
---|
214 | when /\A[0-2][0-9]:[0-6][0-9]:[0-6][0-9](,[0-9]+)?(Z|[+-][0-9]{4})?|[0-2][0-9]:[0-6][0-9](Z|[+-][0-9]{4})? / #V_ISO8601_EXTENDED_TIME hh:mm:ss[,sss][Z|+/-nnnn]
|
---|
215 | yield :V_ISO8601_EXTENDED_TIME, $&
|
---|
216 | when /\A[0-9]{4}-[0-1][0-9]-[0-3][0-9]|[0-9]{4}-[0-1][0-9]/ #V_ISO8601_EXTENDED_DATE YYYY-MM-DD
|
---|
217 | yield :V_ISO8601_EXTENDED_DATE, $&
|
---|
218 | when /\AP([0-9]+[yY])?([0-9]+[mM])?([0-9]+[wW])?([0-9]+[dD])?T([0-9]+[hH])?([0-9]+[mM])?([0-9]+[sS])?|P([0-9]+[yY])?([0-9]+[mM])?([0-9]+[wW])?([0-9]+[dD])?/ #V_ISO8601_DURATION PnYnMnWnDTnnHnnMnnS
|
---|
219 | yield :V_ISO8601_DURATION, $&
|
---|
220 | when /\A[A-Z][a-zA-Z0-9_]*/ #V_TYPE_IDENTIFIER
|
---|
221 | yield :V_ISO8601_DURATION, $&
|
---|
222 | when /\A[A-Z][a-zA-Z0-9_]*<[a-zA-Z0-9,_<>]+>/ #V_GENERIC_TYPE_IDENTIFIER
|
---|
223 | yield :V_GENERIC_TYPE_IDENTIFIER, $&
|
---|
224 | when /\A[0-9]+|[0-9]+[eE][+-]?[0-9]+/ #V_INTEGER
|
---|
225 | yield :V_INTEGER, $&
|
---|
226 | when /\A[0-9]+\.[0-9]+|[0-9]+\.[0-9]+[eE][+-]?[0-9]+ / #V_REAL
|
---|
227 | yield :V_REAL, $&
|
---|
228 | # when /\A"((?:[^"\\]+|\\.)*)"/ #V_STRING
|
---|
229 | when /\A"([^"]*)"/m #V_STRING
|
---|
230 | yield :V_STRING, $1
|
---|
231 | # \"[^\\\n"]*\"
|
---|
232 | # \"[^\\\n"]*{ -- beginning of a multi-line string
|
---|
233 | # <IN_STR> {
|
---|
234 | # \\\\ -- match escaped backslash, i.e. \\ -> \
|
---|
235 | # \\\" -- match escaped double quote, i.e. \” -> “
|
---|
236 | # {UTF8CHAR}+ -- match UTF8 chars
|
---|
237 | # [^\\\n"]+ -- match any other characters
|
---|
238 | # \\\n[ \t\r]* -- match LF in line
|
---|
239 | # [^\\\n"]*\" -- match final end of string
|
---|
240 | # .|\n |
|
---|
241 | # <<EOF>> -- unclosed String -> ERR_STRING
|
---|
242 | # }
|
---|
243 | # ###----------/* V_CHARACTER */ --------------------------------------------
|
---|
244 | # \'[^\\\n']\' -- normal character in 0-127
|
---|
245 | # \'\\n\ -- \n
|
---|
246 | # \'\\r\ -- \r
|
---|
247 | # \'\\t\ -- \t
|
---|
248 | # \'\\'\ -- \’
|
---|
249 | # \'\\\\ -- \\
|
---|
250 | # \'{UTF8CHAR}\' -- UTF8 char
|
---|
251 | # \'.{1,2} |
|
---|
252 | # \'\\[0-9]+(\/)? -- invalid character -> ERR_CHARACTER
|
---|
253 | when /\A[a-z]+:\/\/[^<>|\\{}^~"\[\] ]*/ #V_URI
|
---|
254 | yield :V_URI, $&
|
---|
255 | when /\A\S/ #UTF8CHAR
|
---|
256 | yield :UTF8CHAR, $&
|
---|
257 | end
|
---|
258 | @data = $' # variable $' receives the string after the match
|
---|
259 | end
|
---|
260 | yield :EOF, nil
|
---|
261 | yield false, '$'
|
---|
262 | end # of scan
|
---|
263 |
|
---|
264 |
|
---|
265 | def parse(data, filename, lineno = 1, debug = false)
|
---|
266 | @yydebug = true
|
---|
267 | @parsestring = data
|
---|
268 | @data = data
|
---|
269 | @lineno = lineno
|
---|
270 | @filename = filename
|
---|
271 | @in_interval = false
|
---|
272 | @start_block_received = false
|
---|
273 | @start_block_received = false
|
---|
274 | yyparse self, :scan
|
---|
275 | end
|
---|
276 |
|
---|
277 | def on_error( t, v, values)
|
---|
278 | raise Racc::ParseError, "#{@filename}:#{@lineno}: Inline syntax error on #{v.inspect}"
|
---|
279 | end
|
---|
280 |
|
---|
281 | # ###----------/* CADL Blocks */ -------------------------------------------
|
---|
282 | # \{[^{}]* -- beginning of CADL block
|
---|
283 | # <IN_CADL_BLOCK>\{[^{}]* -- got an open brace
|
---|
284 | # <IN_CADL_BLOCK>[^{}]*\} -- got a close brace
|
---|
285 |
|
---|
286 |
|
---|
287 |
|
---|
288 |
|
---|
289 |
|
---|
290 |
|
---|
291 | ### Local Variables:
|
---|
292 | ### mode:ruby
|
---|
293 | ### mode:font-lock
|
---|
294 | ### comment-column:0
|
---|
295 | ### comment-start: "### "
|
---|
296 | ### comment-end:""
|
---|
297 | ### End:
|
---|
298 |
|
---|
299 |
|
---|
300 |
|
---|
301 |
|
---|