equal
deleted
inserted
replaced
450 fun struct_trfuns structs = |
450 fun struct_trfuns structs = |
451 ([], [("_struct", struct_tr structs)], [], [("_struct", struct_ast_tr' structs)]); |
451 ([], [("_struct", struct_tr structs)], [], [("_struct", struct_ast_tr' structs)]); |
452 |
452 |
453 |
453 |
454 |
454 |
455 exception TRANSLATION of string * exn |
|
456 |
|
457 (** pts_to_asts **) |
455 (** pts_to_asts **) |
|
456 |
|
457 exception TRANSLATION of string * exn; |
458 |
458 |
459 fun pts_to_asts trf pts = |
459 fun pts_to_asts trf pts = |
460 let |
460 let |
461 fun trans a args = |
461 fun trans a args = |
462 (case trf a of |
462 (case trf a of |
465 |
465 |
466 (*translate pt bottom-up*) |
466 (*translate pt bottom-up*) |
467 fun ast_of (Parser.Node (a, pts)) = trans a (map ast_of pts) |
467 fun ast_of (Parser.Node (a, pts)) = trans a (map ast_of pts) |
468 | ast_of (Parser.Tip tok) = Ast.Variable (Lexicon.str_of_token tok); |
468 | ast_of (Parser.Tip tok) = Ast.Variable (Lexicon.str_of_token tok); |
469 |
469 |
470 val exn_results = |
470 val exn_results = map (capture ast_of) pts; |
471 map (fn pt => Result (ast_of pt) handle exn => Exn exn) pts; |
|
472 val exns = mapfilter get_exn exn_results; |
471 val exns = mapfilter get_exn exn_results; |
473 val results = mapfilter get_result exn_results |
472 val results = mapfilter get_result exn_results |
474 in |
473 in |
475 case results of |
474 (case (results, exns) of |
476 [] => (case exns of |
475 ([], TRANSLATION (a, exn) :: _) => |
477 TRANSLATION (a, exn) :: _ => |
476 (writeln ("Error in parse ast translation for " ^ quote a); raise exn) |
478 (writeln ("Error in parse ast translation for " ^ quote a); raise exn) |
477 | _ => results) |
479 | _ => []) |
|
480 | _ => results |
|
481 end; |
478 end; |
482 |
479 |
483 |
480 |
484 |
481 |
485 (** asts_to_terms **) |
482 (** asts_to_terms **) |
497 trans a (map term_of asts) |
494 trans a (map term_of asts) |
498 | term_of (Ast.Appl (ast :: (asts as _ :: _))) = |
495 | term_of (Ast.Appl (ast :: (asts as _ :: _))) = |
499 Term.list_comb (term_of ast, map term_of asts) |
496 Term.list_comb (term_of ast, map term_of asts) |
500 | term_of (ast as Ast.Appl _) = raise Ast.AST ("ast_to_term: malformed ast", [ast]); |
497 | term_of (ast as Ast.Appl _) = raise Ast.AST ("ast_to_term: malformed ast", [ast]); |
501 |
498 |
502 val exn_results = |
499 val exn_results = map (capture term_of) asts; |
503 map (fn t => Result (term_of t) handle exn => Exn exn) asts; |
|
504 val exns = mapfilter get_exn exn_results; |
500 val exns = mapfilter get_exn exn_results; |
505 val results = mapfilter get_result exn_results |
501 val results = mapfilter get_result exn_results |
506 in |
502 in |
507 case results of |
503 (case (results, exns) of |
508 [] => (case exns of |
504 ([], TRANSLATION (a, exn) :: _) => |
509 TRANSLATION (a, exn) :: _ => |
505 (writeln ("Error in parse translation for " ^ quote a); raise exn) |
510 (writeln ("Error in parse translation for " ^ quote a); raise exn) |
506 | _ => results) |
511 | _ => []) |
|
512 | _ => results |
|
513 end; |
507 end; |
514 |
508 |
515 end; |
509 end; |