Strings in-between constructors in ocamlyacc rules

Lines 177-183 of pfff/parser_php.mly at develop · returntocorp/pfff · GitHub contain the following code :

(*-----------------------------------------*)
(* Punctuation tokens *)
(*-----------------------------------------*)

%token <Parse_info.t>
 T_OBJECT_OPERATOR "->" T_ARROW "=>" T_DOUBLE_ARROW "==>"
 T_OPEN_TAG  T_CLOSE_TAG T_OPEN_TAG_WITH_ECHO T_CLOSE_TAG_OF_ECHO

I understand that it will (among other things) declare the final token type as
type token = T_OBJECT_OPERATOR of Parse_info.t | T_ARROW of Parse_info.t , etc.

But what do those inserted strings mean in ocamlyacc ?
I was unable to find an explanation in the Ocaml manual.

The only constructs appearing in section 13.4.2 of Ocaml 4.11 manual are the constructs %token constr … constr and %token < typexpr > constr … constr.

They are a feature of menhir, not present in ocamlyacc. The strings act as aliases of the token, which helps readability in the parsing rules. From Menhir’s manual:

image

Cheers,
Nicolas

2 Likes