[tools] parse IndexOfBlock inside procedures

a procedure can only see its own blocks
This commit is contained in:
Gautier Hattenberger
2014-09-09 13:08:36 +02:00
parent c181d72e30
commit 1eb6585eb8
2 changed files with 6 additions and 5 deletions
+1 -1
View File
@@ -55,7 +55,7 @@ let sprint = fun ?call_assoc expr ->
sprintf "%s(%s)" op (eval e1)
| CallOperator (_,_) -> failwith "Operator should be binary or unary"
| Call (i, [Ident s]) when Some i = n ->
let index = try List.assoc s l with Not_found -> failwith (sprintf "Unknown block: '%s'" s) in
let index = try List.assoc s l with Not_found -> failwith (sprintf "Expr_syntax call_assoc not found: '%s'" s) in
sprintf "%d" index
| Call (i, es) ->
let ses = List.map eval es in
+5 -4
View File
@@ -43,18 +43,19 @@ let parse_expression = fun s ->
s (Lexing.lexeme_char lexbuf 0);
exit 1
| Parsing.Parse_error ->
fprintf stderr "Parsing error in '%s', token '%s' ?\n"
fprintf stderr "Fp_proc: Parsing error in '%s', token '%s' ?\n"
s (Lexing.lexeme lexbuf);
exit 1
open Latlong
let subst_expression = fun env e ->
let subst_expression = fun (name, env) e ->
let rec sub = fun e ->
match e with
Ident i -> Ident (try List.assoc i env with Not_found -> i)
| Int _ | Float _ | Field _ -> e
| Call ("IndexOfBlock", [Ident s]) -> Call ("IndexOfBlock", [ Ident ("'"^name^"."^s^"'") ]) (* prefix block name *)
| Call (i, es) -> Call (i, List.map sub es)
| CallOperator (i, es) -> CallOperator (i, List.map sub es)
| Index (i,e) -> Index (i,sub e)
@@ -230,8 +231,8 @@ let parse_include = fun dir flight_plan include_xml ->
and sectors = get_children "sectors" proc
and header = get_pc_data "header" proc in
let exceptions = List.map (transform_exception prefix reroutes env) exceptions
and blocks = List.map (transform_block prefix reroutes env) blocks in
let exceptions = List.map (transform_exception prefix reroutes (proc_name, env)) exceptions
and blocks = List.map (transform_block prefix reroutes (proc_name, env)) blocks in
List.fold_right
append_children