Create a table containing tokens visible for both .mly and .mll by menhir

I would like to define keyword_tablewhich displays some rows for some tokens, and I would like to make this table visible to both parser.mly, and for lexer.mll.

It seems that the table should be defined in parser.mly,

%{ 
  open Utility (* where hash_table is defined to make a table from a list *)
  let keyword_table = hash_table [
      "Call", CALL; "Case", CASE; "Close", CLOSE; "Const", CONST; 
      "Declare", DECLARE; "DefBool", DEFBOOL; "DefByte", DEFBYTE ]
%}

However, I could not use it in lexer.mll, for example

{
open Parser
let x = keyword_table (* doesn't work *)
let x = Parser.keyword_table (* doesn't work *)
let x = Parsing.keyword_table (* doesn't work *)
}

As this comment , menhirhas a solution for this, can anyone tell me any details?

+3
source share
2 answers

- .mly. menhir --only-tokens , type token, , --external-tokens.

, , , , .

. %parameter<module signature> , . , , ( ).

menhir , , calc-two, calc-param, .

+3

keyword_table lexer.mll, parser.mly. lexer.mll, parser.mly ( parser.mly?), keyword.ml Keyword.keyword_table ( open Keyword keyword_table).

0

All Articles