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