300 fun add_fun_decl decl {types, vars, consts, funs} = |
300 fun add_fun_decl decl {types, vars, consts, funs} = |
301 {types = types, vars = vars, consts = consts, |
301 {types = types, vars = vars, consts = consts, |
302 funs = update decl funs} |
302 funs = update decl funs} |
303 handle Symtab.DUP s => error ("Duplicate function " ^ s); |
303 handle Symtab.DUP s => error ("Duplicate function " ^ s); |
304 |
304 |
305 val type_decl = $$$ "type" |-- !!! (identifier --| $$$ "=" -- |
305 fun type_decl x = ($$$ "type" |-- !!! (identifier --| $$$ "=" -- |
306 ( identifier >> Basic_Type |
306 ( identifier >> Basic_Type |
307 || $$$ "(" |-- !!! (list1 identifier --| $$$ ")") >> Enum_Type |
307 || $$$ "(" |-- !!! (list1 identifier --| $$$ ")") >> Enum_Type |
308 || $$$ "array" |-- !!! ($$$ "[" |-- list1 identifier --| $$$ "]" --| |
308 || $$$ "array" |-- !!! ($$$ "[" |-- list1 identifier --| $$$ "]" --| |
309 $$$ "of" -- identifier) >> Array_Type |
309 $$$ "of" -- identifier) >> Array_Type |
310 || $$$ "record" |-- !!! (enum1 ";" |
310 || $$$ "record" |-- !!! (enum1 ";" |
311 (list1 identifier -- !!! ($$$ ":" |-- identifier)) --| |
311 (list1 identifier -- !!! ($$$ ":" |-- identifier)) --| |
312 $$$ "end") >> Record_Type |
312 $$$ "end") >> Record_Type |
313 || $$$ "pending" >> K Pending_Type)) >> add_type_decl; |
313 || $$$ "pending" >> K Pending_Type)) >> add_type_decl) x; |
314 |
314 |
315 val const_decl = $$$ "const" |-- !!! (identifier --| $$$ ":" -- identifier --| |
315 fun const_decl x = ($$$ "const" |-- !!! (identifier --| $$$ ":" -- identifier --| |
316 $$$ "=" --| $$$ "pending") >> add_const_decl; |
316 $$$ "=" --| $$$ "pending") >> add_const_decl) x; |
317 |
317 |
318 val var_decl = $$$ "var" |-- !!! (list1 identifier --| $$$ ":" -- identifier) >> |
318 fun var_decl x = ($$$ "var" |-- !!! (list1 identifier --| $$$ ":" -- identifier) >> |
319 add_var_decl; |
319 add_var_decl) x; |
320 |
320 |
321 val fun_decl = $$$ "function" |-- !!! (identifier -- |
321 fun fun_decl x = ($$$ "function" |-- !!! (identifier -- |
322 (Scan.optional ($$$ "(" |-- !!! (list1 identifier --| $$$ ")")) [] --| |
322 (Scan.optional ($$$ "(" |-- !!! (list1 identifier --| $$$ ")")) [] --| |
323 $$$ ":" -- identifier)) >> add_fun_decl; |
323 $$$ ":" -- identifier)) >> add_fun_decl) x; |
324 |
324 |
325 val declarations = |
325 fun declarations x = |
326 $$$ "title" |-- subprogram_kind -- identifier --| $$$ ";" -- |
326 ($$$ "title" |-- subprogram_kind -- identifier --| $$$ ";" -- |
327 (Scan.repeat ((type_decl || const_decl || var_decl || fun_decl) --| |
327 (Scan.repeat ((type_decl || const_decl || var_decl || fun_decl) --| |
328 !!! ($$$ ";")) >> (fn ds => apply ds empty_decls)) --| |
328 !!! ($$$ ";")) >> (fn ds => apply ds empty_decls)) --| |
329 $$$ "end" --| $$$ ";" |
329 $$$ "end" --| $$$ ";") x; |
330 |
330 |
331 fun parse_declarations pos s = |
331 fun parse_declarations pos s = |
332 s |> |
332 s |> |
333 Fdl_Lexer.tokenize (Scan.succeed ()) Fdl_Lexer.curly_comment pos |> |
333 Fdl_Lexer.tokenize (Scan.succeed ()) Fdl_Lexer.curly_comment pos |> |
334 snd |> filter Fdl_Lexer.is_proper |> |
334 snd |> filter Fdl_Lexer.is_proper |> |