Commit eab69a1e authored by POTTIER Francois's avatar POTTIER Francois
Browse files

Concrete syntax for $endpos($0).

Also, fix the test that $i is within range -- it was incomplete.
parent 16dffbe7
......@@ -102,8 +102,10 @@ let actiondef grammar symbol branch =
PAnnot (PVar "_eRR", texn) ::
PAnnot (PVar "_startpos", tposition) ::
PAnnot (PVar "_endpos", tposition) ::
PAnnot (PVar "_endpos__0_", tposition) ::
PAnnot (PVar "_startofs", tint) ::
PAnnot (PVar "_endofs", tint) ::
PAnnot (PVar "_endofs__0_", tint) ::
formals
in
......
......@@ -39,18 +39,21 @@
(* Check that only allowed indices are used in semantic actions. *)
let check_producers_indices allowed_producers pkeywords =
List.iter (function
| { value = Keyword.PDollar idx; position } ->
if idx - 1 >= Array.length allowed_producers then
Error.error [position]
"$%d refers to a nonexistent symbol." idx
else begin match allowed_producers.(idx - 1) with
| None ->
List.iter (fun pkeyword ->
match Positions.value pkeyword with
| Keyword.PPosition (Keyword.PRightDollar 0, Keyword.WhereEnd, _) ->
(* As a special case, [$endpos($0)] is allowed. *)
()
| Some x ->
Error.error [position]
| Keyword.PDollar idx
| Keyword.PPosition (Keyword.PRightDollar idx, _, _) ->
if not (0 <= idx - 1 && idx - 1 < Array.length allowed_producers) then
Error.error [ Positions.position pkeyword ]
"$%d refers to a nonexistent symbol." idx
else
allowed_producers.(idx - 1) |> Option.iter (fun x ->
Error.error [ Positions.position pkeyword ]
"please do not say: $%d. Instead, say: %s." idx x
end
)
| _ ->
()
) pkeywords
......@@ -136,6 +139,7 @@
in
let rewrite_subject = function
| PLeft -> Left
| PRightDollar 0 -> Before
| PRightDollar i -> RightNamed (rewrite_index i)
| PRightNamed n -> RightNamed n
in
......
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