代码之家  ›  专栏  ›  技术社区  ›  SoftTimur

通过makefile或手动添加模块

  •  0
  • SoftTimur  · 技术社区  · 3 年前

    我有一个用传统makefile构建的大项目。我想添加一种错误处理机制,如 this project 我的项目。

    在示例项目中,模块 UnitActionsParser 由以下沙丘规则生成:

    ;; The following two rules create a copy of the file parser.mly named
    ;; unitActionsParser.mly. This is a copy of the grammar where the semantic
    ;; actions have been removed and replaced with unit values. It is compiled
    ;; by Menhir's table back-end to obtain the module UnitActionsParser.
    
    ;; The use of [--external-tokens Parser] is required for the two parsers
    ;; to share a single [token] type. This makes them usable with the same
    ;; lexer.
    
    (rule
      (action
        (with-stdout-to unitActionsParser.mly
          (run menhir
            %{dep:parser.mly}
            --only-preprocess-u
    ))))
    
    (menhir
      (modules unitActionsParser)
      (flags --table --external-tokens Parser)
    )
    

    目前 makefile 我的项目包含如下内容:

    OCAMLYACC=      $(OCAMLPREFIX)menhir -v
    
    %.ml %.mli: %.mly
        $(OCAMLYACC) $*.mly
    

    所以现在,我想知道如何构建这样一个 UnitActionsParser 单元最好是修改我的 生成文件 ,有人知道怎么做吗?否则,我们也可以首先手动添加它。我试过在命令行 $ menhir --table --external-tokens Parser ,但它让我回来了 Usage: menhir <options> <filenames> 。有人能帮忙吗?

    0 回复  |  直到 3 年前
        1
  •  2
  •   octachron    3 年前

    您可以直接将规则添加到Makefile中。直接翻译 dune 文件将是

    unitActionsParser.mly: parser.mly
        $(OCAMLYACC) --only-preprocess-u $< > $@