diff options
author | Alec Theriault <alec.theriault@gmail.com> | 2018-06-05 10:47:16 -0700 |
---|---|---|
committer | Alexander Biehl <alexbiehl@gmail.com> | 2018-06-05 19:47:16 +0200 |
commit | bea565ec5a029b8c19965aa22f34c23a112c0a7f (patch) | |
tree | a0a93b524acf85676c4e46206f73ce2a7a2aaa0f /hypsrc-test | |
parent | ee1ce11ceaf41d05973bb2c9ca7abd41a2ad078c (diff) |
Improve hyperlinker's 'spanToNewline' (#846)
'spanToNewline' is used to help break apart the source into lines which
can then be partioned into CPP and non-CPP chunks. It is important that
'spanToNewline' not break apart tokens, so it needs to properly handle
things like
* block comments, possibly nested
* string literals, possibly multi-line
* CPP macros, possibly multi-line
String literals in particular were not being properly handled. The fix
is to to fall back in 'Text.Read.lex' to help lex things that are not
comments.
Fixes #837.
Diffstat (limited to 'hypsrc-test')
-rw-r--r-- | hypsrc-test/ref/src/CPP.html | 216 | ||||
-rw-r--r-- | hypsrc-test/src/CPP.hs | 26 |
2 files changed, 242 insertions, 0 deletions
diff --git a/hypsrc-test/ref/src/CPP.html b/hypsrc-test/ref/src/CPP.html new file mode 100644 index 00000000..fb85bd2f --- /dev/null +++ b/hypsrc-test/ref/src/CPP.html @@ -0,0 +1,216 @@ +<html xmlns="http://www.w3.org/1999/xhtml" +><head + ><link rel="stylesheet" type="text/css" href="style.css" + /><script type="text/javascript" src="highlight.js" + ></script + ></head + ><body + ><pre + ><span class="hs-pragma" + >{-# LANGUAGE CPP #-}</span + ><span + > +</span + ><a name="line-2" + ></a + ><span class="hs-keyword" + >module</span + ><span + > </span + ><span class="hs-identifier" + >CPP</span + ><span + > </span + ><span class="hs-keyword" + >where</span + ><span + > +</span + ><a name="line-3" + ></a + ><span + > +</span + ><a name="line-4" + ></a + ><span class="hs-cpp" + >#define SOMETHING1 +</span + ><span + > +</span + ><a name="line-6" + ></a + ><span class="hs-identifier" + >foo</span + ><span + > </span + ><span class="hs-glyph" + >::</span + ><span + > </span + ><span class="hs-identifier hs-type" + >String</span + ><span + > +</span + ><a name="line-7" + ></a + ><a name="foo" + ><a href="CPP.html#foo" + ><span class="hs-identifier" + >foo</span + ></a + ></a + ><span + > </span + ><span class="hs-glyph" + >=</span + ><span + > </span + ><span class="hs-comment" + >{- " single quotes are fine in block comments + {- nested block comments are fine -} + -}</span + ><span + > </span + ><span class="hs-string" + >"foo"</span + ><span + > +</span + ><a name="line-10" + ></a + ><span + > +</span + ><a name="line-11" + ></a + ><span class="hs-cpp" + >#define SOMETHING2 +</span + ><span + > +</span + ><a name="line-13" + ></a + ><span class="hs-identifier" + >bar</span + ><span + > </span + ><span class="hs-glyph" + >::</span + ><span + > </span + ><span class="hs-identifier hs-type" + >String</span + ><span + > +</span + ><a name="line-14" + ></a + ><a name="bar" + ><a href="CPP.html#bar" + ><span class="hs-identifier" + >bar</span + ></a + ></a + ><span + > </span + ><span class="hs-glyph" + >=</span + ><span + > </span + ><span class="hs-string" + >"block comment in a string is not a comment {- "</span + ><span + > +</span + ><a name="line-15" + ></a + ><span + > +</span + ><a name="line-16" + ></a + ><span class="hs-cpp" + >#define SOMETHING3 +</span + ><span + > +</span + ><a name="line-18" + ></a + ><span class="hs-comment" + >-- " single quotes are fine in line comments</span + ><span + > +</span + ><a name="line-19" + ></a + ><span class="hs-comment" + >-- {- unclosed block comments are fine in line comments</span + ><span + > +</span + ><a name="line-20" + ></a + ><span + > +</span + ><a name="line-21" + ></a + ><span class="hs-comment" + >-- Multiline CPP is also fine</span + ><span + > +</span + ><a name="line-22" + ></a + ><span class="hs-cpp" + >#define FOO\ + 1 +</span + ><span + > +</span + ><a name="line-25" + ></a + ><span class="hs-identifier" + >baz</span + ><span + > </span + ><span class="hs-glyph" + >::</span + ><span + > </span + ><span class="hs-identifier hs-type" + >String</span + ><span + > +</span + ><a name="line-26" + ></a + ><a name="baz" + ><a href="CPP.html#baz" + ><span class="hs-identifier" + >baz</span + ></a + ></a + ><span + > </span + ><span class="hs-glyph" + >=</span + ><span + > </span + ><span class="hs-string" + >"line comment in a string is not a comment --"</span + ><span + > +</span + ><a name="line-27" + ></a + ></pre + ></body + ></html +>
\ No newline at end of file diff --git a/hypsrc-test/src/CPP.hs b/hypsrc-test/src/CPP.hs new file mode 100644 index 00000000..f00ce031 --- /dev/null +++ b/hypsrc-test/src/CPP.hs @@ -0,0 +1,26 @@ +{-# LANGUAGE CPP #-} +module CPP where + +#define SOMETHING1 + +foo :: String +foo = {- " single quotes are fine in block comments + {- nested block comments are fine -} + -} "foo" + +#define SOMETHING2 + +bar :: String +bar = "block comment in a string is not a comment {- " + +#define SOMETHING3 + +-- " single quotes are fine in line comments +-- {- unclosed block comments are fine in line comments + +-- Multiline CPP is also fine +#define FOO\ + 1 + +baz :: String +baz = "line comment in a string is not a comment --" |