【问题标题】:Suppress certain Haskell Alex/Happy compilation messages抑制某些 Haskell Alex/Happy 编译消息
【发布时间】:2023-04-02 12:58:01
【问题描述】:

当使用 Alex lexer 生成器或 Happy 解析器生成器创建 Lexer.xParser.y 解析器时,将它们编译成 Haskell 文件,然后将它们编译成目标文件,默认情况下会生成以下“警告” :

$ ghc Lexer
line-map.c: file "<command-line>" left but not entered
line-map.c: file "<command-line>" left but not entered
[1 of 1] Compiling Lexer            ( Lexer.hs, Lexer.o )
$ happy Parser.y
$ ghc Parser
line-map.c: file "<command-line>" left but not entered
line-map.c: file "<command-line>" left but not entered
[2 of 2] Compiling Parser           ( Parser.hs, Parser.o )

这些行是由于生成的.hs 文件中嵌入了以下行:

{-# LINE 1 "<command-line>" #-}

为什么要包含这些行,如果命令行显然没有用于生成的词法分析器和解析器中的任何内容,是否有办法抑制这些消息?

【问题讨论】:

    标签: haskell parser-generator happy alex


    【解决方案1】:

    谷歌搜索“left but not enter”表明这样的消息表明配置错误的gcc。这是生成消息的 Apple 版本中的代码:

    void
    linemap_check_files_exited (struct line_maps *set)
    {
      struct line_map *map;
      /* Depending upon whether we are handling preprocessed input or
         not, this can be a user error or an ICE.  */
      for (map = &set->maps[set->used - 1]; ! MAIN_FILE_P (map);
           map = INCLUDED_FROM (set, map))
        fprintf (stderr, "line-map.c: file \"%s\" entered but not left\n",
             map->to_file);
    }
    

    (来自http://www.opensource.apple.com/source/gcc/gcc-5484/libcpp/line-map.c

    这里的“ICE”指的是“内部编译器错误”。

    插入#LINE 指令以便 ghc 可以根据 .x 或 .y 文件中的位置报告错误。它说以下行实际上是来自另一个文件的某一行。伪文件名&lt;command-line&gt;&lt;built-in&gt; 的#LINE 指令可以忽略,因为它们后面总是紧跟一个真实文件名的#LINE 指令,例如:

    ...
    {-# LINE 1 "<built-in>" #-}
    {-# LINE 1 "<command-line>" #-}
    {-# LINE 1 "templates/wrappers.hs" #-}
    ...
    {-# LINE 1 "<built-in>" #-}
    {-# LINE 1 "<command-line>" #-}
    {-# LINE 1 "templates/GenericTemplate.hs" #-}
    ...
    

    作为测试,您可以简单地删除&lt;command-line&gt; 的#LINE 指令,然后查看警告是否消失。我也会尝试重新安装/升级您的 gcc 和/或 Haskell 平台。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多