Haskell diagrams-builder 解析错误
Parse error with Haskell diagrams-builder
我正在尝试将 diagrams-builder 包与 LaTeX 一起使用,以便在线生成图表。按照教程 here,我有一个名为 test.tex
的文件,其中包含以下内容:
\documentclass[10pt]{article}
\usepackage[backend=ps, extension=eps, outputdir=diagrams]{diagrams-latex}
\usepackage{graphicx}
\begin{document}
\begin{diagram}[width=300,height=200]
{-# LANGUAGE FlexibleContexts #-}
dia = circle 1
\end{diagram}
\end{document}
我创建了一个名为 diagrams
的空目录并尝试编译,结果却被告知 diagrams-builder-ps
.[=22 自动生成的文件看起来存在解析错误=]
$ pdflatex --enable-write18 --shell-escape test.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=pdflatex)
\write18 enabled.
entering extended mode
(./test.tex
LaTeX2e <2016/03/31>
Babel <3.9r> and hyphenation patterns for 83 language(s) loaded.
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/size10.clo))
(/Users/nhalford/Library/texmf/tex/diagrams-latex.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/moreverb/moreverb.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/tools/verbatim.sty))
(/usr/local/texlive/2016/texmf-dist/tex/latex/xkeyval/xkeyval.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/xkeyval/xkeyval.tex
(/usr/local/texlive/2016/texmf-dist/tex/generic/xkeyval/xkvutils.tex
(/usr/local/texlive/2016/texmf-dist/tex/generic/xkeyval/keyval.tex))))
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/ifthen.sty))
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)
(/usr/local/texlive/2016/texmf-dist/tex/latex/pdftex-def/pdftex.def
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/ltxcmds.sty))))
No file test.aux.
(/usr/local/texlive/2016/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
) (/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/ifluatex.sty)
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/ifpdf.sty))
(/usr/local/texlive/2016/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/oberdiek/grfext.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/kvdefinekeys.sty))
(/usr/local/texlive/2016/texmf-dist/tex/latex/oberdiek/kvoptions.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/etexcmds.sty)))
(/usr/local/texlive/2016/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
Opening diagrams-latex stream diagrams/test-diagrams-latex-fig1.hs Error while compiling diagrams/test-diagrams-latex-fig1.hs
/var/folders/2g/_6mplpfn4fl338wr3cj949440000gn/T/Diagram58258-0.hs:3:20: error:
parse error on input ‘-’
Package diagrams-latex Warning: Conversion of diagrams/test-diagrams-latex-fig1
.hs failed.
Package diagrams-latex Warning: Please convert diagrams/test-diagrams-latex-fig
1.hs manually.
(./test.aux) )
No pages of output.
Transcript written on test.log.
我在尝试直接在 .hs
文件上 运行 diagrams-builder-ps
或 diagrams-builder-cairo
时也遇到此错误:
$ cd diagrams
$ ls
test-diagrams-latex-fig1.hs
$ diagrams-builder-ps -w 300 -h 200 test-diagrams-latex-fig1.hs
Error while compiling test-diagrams-latex-fig1.hs
/var/folders/2g/_6mplpfn4fl338wr3cj949440000gn/T/Diagram58289-0.hs:3:20: error:
parse error on input ‘-’
$ diagrams-builder-cairo -w 300 -h 200 test-diagrams-latex-fig1.hs
Error while compiling test-diagrams-latex-fig1.hs
/var/folders/2g/_6mplpfn4fl338wr3cj949440000gn/T/Diagram58294-0.hs:3:20: error:
parse error on input ‘-’
$ cat test-diagrams-latex-fig1.hs
{-# LANGUAGE FlexibleContexts #-}
dia = circle 1
$
不幸的是,系统立即删除了带有解析错误的临时 .hs
文件,因此我无法检查该文件以查看究竟是什么导致了此问题。
感谢您的帮助!
哦,我想我只是想出了一定是错的,虽然我不确定修复它的最佳方法。关键是这一行:
/var/folders/2g/_6mplpfn4fl338wr3cj949440000gn/T/Diagram58289-0.hs:3:20: error:
注意临时文件的名称是Diagram58289-0.hs
。 diagrams-builder
调用 openTempFile
(see here) 然后使用结果文件的基本名称作为模块的名称。所以 Diagram58289-0.hs
的内容必须是这样的:
{-# LANGUAGE FlexibleContexts #-}
module Diagram58289-0 where
dia = circle 1
问题是连字符在模块名称中无效,因此出现解析错误(果然,它在第 3 行的第 20 列中)。
虽然documentation for openTempFile
says the created file will have a name of the form "fooXXX.ext
where XXX is some random number", obviously that is not what is happening here. And indeed, it looks like the behavior of openTempFile
changed recently;现在它将始终包含一个连字符。我猜这种行为在 base-4.10
中发生了变化,因此它会显示给使用 GHC 8.2 的任何人。
我有 created an issue on the diagrams-builder
issue tracker 来跟踪这个问题。目前,一种解决方案是降级到 GHC 8.0,但这可能不是一个非常有吸引力的选择。
我正在尝试将 diagrams-builder 包与 LaTeX 一起使用,以便在线生成图表。按照教程 here,我有一个名为 test.tex
的文件,其中包含以下内容:
\documentclass[10pt]{article}
\usepackage[backend=ps, extension=eps, outputdir=diagrams]{diagrams-latex}
\usepackage{graphicx}
\begin{document}
\begin{diagram}[width=300,height=200]
{-# LANGUAGE FlexibleContexts #-}
dia = circle 1
\end{diagram}
\end{document}
我创建了一个名为 diagrams
的空目录并尝试编译,结果却被告知 diagrams-builder-ps
.[=22 自动生成的文件看起来存在解析错误=]
$ pdflatex --enable-write18 --shell-escape test.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=pdflatex)
\write18 enabled.
entering extended mode
(./test.tex
LaTeX2e <2016/03/31>
Babel <3.9r> and hyphenation patterns for 83 language(s) loaded.
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/size10.clo))
(/Users/nhalford/Library/texmf/tex/diagrams-latex.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/moreverb/moreverb.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/tools/verbatim.sty))
(/usr/local/texlive/2016/texmf-dist/tex/latex/xkeyval/xkeyval.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/xkeyval/xkeyval.tex
(/usr/local/texlive/2016/texmf-dist/tex/generic/xkeyval/xkvutils.tex
(/usr/local/texlive/2016/texmf-dist/tex/generic/xkeyval/keyval.tex))))
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/ifthen.sty))
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)
(/usr/local/texlive/2016/texmf-dist/tex/latex/pdftex-def/pdftex.def
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/ltxcmds.sty))))
No file test.aux.
(/usr/local/texlive/2016/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
) (/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/ifluatex.sty)
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/ifpdf.sty))
(/usr/local/texlive/2016/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/oberdiek/grfext.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/kvdefinekeys.sty))
(/usr/local/texlive/2016/texmf-dist/tex/latex/oberdiek/kvoptions.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/etexcmds.sty)))
(/usr/local/texlive/2016/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
Opening diagrams-latex stream diagrams/test-diagrams-latex-fig1.hs Error while compiling diagrams/test-diagrams-latex-fig1.hs
/var/folders/2g/_6mplpfn4fl338wr3cj949440000gn/T/Diagram58258-0.hs:3:20: error:
parse error on input ‘-’
Package diagrams-latex Warning: Conversion of diagrams/test-diagrams-latex-fig1
.hs failed.
Package diagrams-latex Warning: Please convert diagrams/test-diagrams-latex-fig
1.hs manually.
(./test.aux) )
No pages of output.
Transcript written on test.log.
我在尝试直接在 .hs
文件上 运行 diagrams-builder-ps
或 diagrams-builder-cairo
时也遇到此错误:
$ cd diagrams
$ ls
test-diagrams-latex-fig1.hs
$ diagrams-builder-ps -w 300 -h 200 test-diagrams-latex-fig1.hs
Error while compiling test-diagrams-latex-fig1.hs
/var/folders/2g/_6mplpfn4fl338wr3cj949440000gn/T/Diagram58289-0.hs:3:20: error:
parse error on input ‘-’
$ diagrams-builder-cairo -w 300 -h 200 test-diagrams-latex-fig1.hs
Error while compiling test-diagrams-latex-fig1.hs
/var/folders/2g/_6mplpfn4fl338wr3cj949440000gn/T/Diagram58294-0.hs:3:20: error:
parse error on input ‘-’
$ cat test-diagrams-latex-fig1.hs
{-# LANGUAGE FlexibleContexts #-}
dia = circle 1
$
不幸的是,系统立即删除了带有解析错误的临时 .hs
文件,因此我无法检查该文件以查看究竟是什么导致了此问题。
感谢您的帮助!
哦,我想我只是想出了一定是错的,虽然我不确定修复它的最佳方法。关键是这一行:
/var/folders/2g/_6mplpfn4fl338wr3cj949440000gn/T/Diagram58289-0.hs:3:20: error:
注意临时文件的名称是Diagram58289-0.hs
。 diagrams-builder
调用 openTempFile
(see here) 然后使用结果文件的基本名称作为模块的名称。所以 Diagram58289-0.hs
的内容必须是这样的:
{-# LANGUAGE FlexibleContexts #-}
module Diagram58289-0 where
dia = circle 1
问题是连字符在模块名称中无效,因此出现解析错误(果然,它在第 3 行的第 20 列中)。
虽然documentation for openTempFile
says the created file will have a name of the form "fooXXX.ext
where XXX is some random number", obviously that is not what is happening here. And indeed, it looks like the behavior of openTempFile
changed recently;现在它将始终包含一个连字符。我猜这种行为在 base-4.10
中发生了变化,因此它会显示给使用 GHC 8.2 的任何人。
我有 created an issue on the diagrams-builder
issue tracker 来跟踪这个问题。目前,一种解决方案是降级到 GHC 8.0,但这可能不是一个非常有吸引力的选择。