Commit d17dd810 authored by POTTIER Francois's avatar POTTIER Francois

Renamings.

parent 6c87ce16
...@@ -197,12 +197,12 @@ let inline grammar = ...@@ -197,12 +197,12 @@ let inline grammar =
r r
in in
(* Inline the non terminals that can be inlined in [b]. We use the (* Inline the non terminals that can be inlined in [caller]. We use the
ListMonad to combine the results. *) ListMonad to combine the results. *)
let rec expand_branch (b : branch) : branch ListMonad.m = let rec expand_branch (caller : branch) : branch ListMonad.m =
try try
(* [c] is the identifier under which the callee is known. *) (* [c] is the identifier under which the callee is known inside the caller. *)
let prefix, producer, suffix = find_inlining_site grammar ([], b.producers) in let prefix, producer, suffix = find_inlining_site grammar ([], caller.producers) in
let nt = producer_symbol producer in let nt = producer_symbol producer in
let p = StringMap.find nt grammar.rules in (* cannot fail *) let p = StringMap.find nt grammar.rules in (* cannot fail *)
let c = producer_identifier producer in let c = producer_identifier producer in
...@@ -212,24 +212,24 @@ let inline grammar = ...@@ -212,24 +212,24 @@ let inline grammar =
let used = StringSet.union (names prefix) (names suffix) in let used = StringSet.union (names prefix) (names suffix) in
(* Inline a branch of [nt] at position [prefix] ... [suffix] in (* Inline a branch of [nt] at position [prefix] ... [suffix] in
the branch [b]. *) the branch [b]. *)
let inline_branch (pb : branch) : branch = let inline_branch (callee : branch) : branch =
(* 2015/11/18. The interaction of %prec and %inline is not documented. (* 2015/11/18. The interaction of %prec and %inline is not documented.
It used to be the case that we would disallow marking a production It used to be the case that we would disallow marking a production
both %inline and %prec. Now, we allow it, but we check that (1) it both %inline and %prec. Now, we allow it, but we check that (1) it
is inlined at the last position of the host production and (2) the is inlined at the last position of the host production and (2) the
host production does not already have a %prec annotation. *) host production does not already have a %prec annotation. *)
pb.branch_prec_annotation |> Option.iter (fun callee_prec -> callee.branch_prec_annotation |> Option.iter (fun callee_prec ->
(* The callee has a %prec annotation. *) (* The callee has a %prec annotation. *)
(* Check condition 1. *) (* Check condition 1. *)
if List.length suffix > 0 then if List.length suffix > 0 then
Error.error [ Positions.position callee_prec; b.branch_position ] Error.error [ Positions.position callee_prec; caller.branch_position ]
"this production carries a %%prec annotation,\n\ "this production carries a %%prec annotation,\n\
and the nonterminal symbol %s is marked %%inline.\n\ and the nonterminal symbol %s is marked %%inline.\n\
For this reason, %s can be used only in tail position." For this reason, %s can be used only in tail position."
nt nt; nt nt;
(* Check condition 2. *) (* Check condition 2. *)
b.branch_prec_annotation |> Option.iter (fun caller_prec -> caller.branch_prec_annotation |> Option.iter (fun caller_prec ->
Error.error [ Positions.position callee_prec; Positions.position caller_prec ] Error.error [ Positions.position callee_prec; Positions.position caller_prec ]
"this production carries a %%prec annotation,\n\ "this production carries a %%prec annotation,\n\
and the nonterminal symbol %s is marked %%inline.\n\ and the nonterminal symbol %s is marked %%inline.\n\
...@@ -241,7 +241,7 @@ let inline grammar = ...@@ -241,7 +241,7 @@ let inline grammar =
(* Rename the producers of this branch if they conflict with (* Rename the producers of this branch if they conflict with
the name of the host's producers. *) the name of the host's producers. *)
let phi, inlined_producers = rename used pb.producers in let phi, inlined_producers = rename used callee.producers in
(* After inlining, the producers are as follows. *) (* After inlining, the producers are as follows. *)
let producers = prefix @ inlined_producers @ suffix in let producers = prefix @ inlined_producers @ suffix in
...@@ -316,9 +316,9 @@ let inline grammar = ...@@ -316,9 +316,9 @@ let inline grammar =
(* Rename the outer and inner semantic action. *) (* Rename the outer and inner semantic action. *)
let outer_action = let outer_action =
Action.rename (rename_sw_outer (c, startp, endp)) [] b.action Action.rename (rename_sw_outer (c, startp, endp)) [] caller.action
and action' = and action' =
Action.rename (rename_sw_inner beforeendp) phi pb.action Action.rename (rename_sw_inner beforeendp) phi callee.action
in in
(* 2015/11/18. If the callee has a %prec annotation (which implies (* 2015/11/18. If the callee has a %prec annotation (which implies
...@@ -326,15 +326,15 @@ let inline grammar = ...@@ -326,15 +326,15 @@ let inline grammar =
position in the caller) then the annotation is inherited. This position in the caller) then the annotation is inherited. This
seems reasonable, but remains undocumented. *) seems reasonable, but remains undocumented. *)
let branch_prec_annotation = let branch_prec_annotation =
match pb.branch_prec_annotation with match callee.branch_prec_annotation with
| (Some _) as annotation -> | (Some _) as annotation ->
assert (b.branch_prec_annotation = None); assert (caller.branch_prec_annotation = None);
annotation annotation
| None -> | None ->
b.branch_prec_annotation caller.branch_prec_annotation
in in
{ b with { caller with
producers; producers;
action = Action.compose c action' outer_action; action = Action.compose c action' outer_action;
branch_prec_annotation; branch_prec_annotation;
...@@ -343,7 +343,7 @@ let inline grammar = ...@@ -343,7 +343,7 @@ let inline grammar =
List.map inline_branch p.branches >>= expand_branch List.map inline_branch p.branches >>= expand_branch
with NoInlining -> with NoInlining ->
return b return caller
(* Expand a rule if necessary. *) (* Expand a rule if necessary. *)
and expand_rule k r = and expand_rule k r =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment