Lexical Error In String/character Literal At End Of Input
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack haskell lexical error at character Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack haskell lexical error at character '\8217' Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Haskell: lexical error haskell multiline string in string/character literal at character 'i' up vote 5 down vote favorite I'm fairly new to Haskell programming and I'm having trouble understanding why I'm receiving this error in my code. My problem is as follows: Any positive integer i can be expressed as i = 2^n*k, where k is odd, that is, as a power of 2 times an odd number. We call n the exponent of 2 in i. For example, the exponent of 2 in 40 is 3 (because 40 = 2^3*5) whereas the exponent of 2 in 42 is 1. If i itself is odd, then n is zero. If, on the other hand, i is even, that means it can be divided by 2. Write a function exponentOfTwo for finding the exponent of 2 in its argument. I understand the psuedocode and it seems fairly simple: recursively divide i by 2 until result is odd, the number of times the division happens is n here is my code (line 31-32): exponentOfTwo :: Int -> Int exponentOfTwo i = if odd i then 0 else 1 + exponentOfTwo (i 'div' 2) I'm receiving the error "lexical error in string/character literal at character 'i'" on line 32 column 62. I've tried searching for a solution to this error everywhere and so far I've had no luck. haskell recursion lexical share|improve this question edited Feb 5 '11 at 22:14 delnan 71.1k6101185 asked Feb 5 '11 at 22:08 Gus 5514 add a comment| 2 Answers 2 active oldest votes up vote 5 down vote accepted To use a function in infix for, surround it with backticks (`), not with single quotes ('). The latter are for character literals, which, well are only one character long. share|improve this answer answered Feb 5 '11 at 22:13 delnan 71.1k6101185 add a comment| up vote 1 down vote Are the characters around div backquotes rather than normal quotes? They need to be to allow a function name to be used as an infix operator. I changed that in your definition and the code worked for me. share|improve this answer answered Feb 5 '11 at 22:12 Jeremiah Willcock 18.9k24869 Oh wow that was an easy fix, I feel kind of stupid now. I never knew that had to be that way. Thank you very much! &nda
support for Eclipse beta Brought to you by: jpmoresmau, leiffrenzel, serras, ttencate Summary Files Reviews Support Wiki Mailing Lists Backlog Discussion Create Topic Stats Graph Forums Help 267 Open Discussion 9 Help Formatting Help lexical error at end of input Forum: Help Creator: Han Joosten Created: 2011-08-05 Updated: 2012-12-06 Han Joosten - 2011-08-05 I have the version 2.0.4 installed. This works great, and the performance is much better than in a release I tried half a year ago. Ausum! However, in my project, some haskell files (not all of them…) show a problem at the end of the file. The problem says: lexical error in string/character literal at http://stackoverflow.com/questions/4910017/haskell-lexical-error-in-string-character-literal-at-character-i end of input. However, these files compile fine with ghc. No problem at all. I presume that the scanner/parser used to generate the messages is another than ghc uses. This specific error is annoying, so I would like to find out what causes it. I tried to 'solve' the problem by modifying my haskell source file, but I cannot find the cause. Can you tell anything about how this parsing is https://sourceforge.net/p/eclipsefp/discussion/371922/thread/a8ab3be2/ exactly done? If you would like to refer to this comment somewhere else in this project, copy and paste the following link: JP Moresmau - 2011-08-05 The parsing should be done by GHC itself. However, the lexing that is used for syntax highlighting does some processing on the source, so maybe the issue is here. Can you share an example of a source file that exhibits the error? The area to watch for is preprocessor commands, since these are stripped out before the source is passed to the lexer. If you would like to refer to this comment somewhere else in this project, copy and paste the following link: Han Joosten - 2011-08-06 No problem. It is online at https://sourceforge.net/apps/trac/ampersand/export/121/src/DatabaseDesign/Ampersand/Input/ADL1/CC.hs The project uses a subversion repo, which can be found at https://sourceforge.net/projects/ampersand/ (be careful however, it doesn't fully compile for the time being) If you would like to refer to this comment somewhere else in this project, copy and paste the following link: JP Moresmau - 2011-08-08 This is weird. It's nothing to do with our code, as I don't find the message anywhere, but can find trace of it on the web, so it's a GHC message. I've narrowed it down: it doesn't like list comprehensions when there
Sign in Pricing Blog Support Search GitHub This repository Watch 60 Star 770 Fork 238 haskell/haskell-mode Code Issues 93 Pull requests 3 Projects 0 Wiki Pulse Graphs New issue Multiline string literal not terminated by syntax highlighter #497 Closed eallik opened this https://github.com/haskell/haskell-mode/issues/497 Issue Mar 8, 2015 · 6 comments Projects None yet Labels None yet Milestone No milestone Assignees No one assigned 3 participants eallik commented Mar 8, 2015 Going through the RWH book, I ended up having the following 2 definitions: raw = "\ \#define X_FOOBAR /* a foobar */\n\ \#define X_QUUX /* a quux */\n\ \#define Y_BLAH /* a blah */\n\ \#define X_BLAH /* a blah */\n\ \" defs = map sndWord . (lines >>> filter lexical error ("#define X_" `isPrefixOf`)) where sndWord = (!! 1) . words (coincidentally, GitHub's markdown has the same bug :)) Inserting a space between the \ and " results in correct behavior (but obviously also a different string value stored in raw): Note that both snippets compile, i.e. \" as the last line of a multiline string is perfectly legal and not the same as ending a single-line string with a backslach. eallik changed the title from multiline string literal haskell lexical error incorrectly not terminated by syntax highlighter to multiline string literal not terminated by syntax highlighter Mar 8, 2015 eallik referenced this issue in github/markup Mar 8, 2015 Closed multiline string literal in haskell syntax highlighter not terminated #467 gracjan commented Mar 8, 2015 @eallik: After a quick test program: str = "\" gives error in compilation: T2.hs:3:10: lexical error in string/character literal at character '\n' Where this program compiles as it should: str = "\"" So if you backslash-escape last doublequote you get unterminated string constant and lexical error. Having said that I like the idea of treating unescaped newline as string terminating for the purpose of font-lock. I'm not sure though how hard it is to get in emacs as currently define dquote to be pair to another dquote and backslash as escape character and we just let emacs do the font locking. gracjan commented Mar 8, 2015 Note that other emacs modes highlight the same, for example c-mode: char *str = "unterimanted\" void main() { } will font-lock as string till the end of file. gracjan commented Mar 8, 2015 @eallik: I would love to see unterminated strings in error face font. Are you into emacs lisp enough to have a go at this problem? ivan-m commented Mar 9, 2015 @gracjan except that that's the correct syntax for multiline strings: test :: String test = "hello\n\ \" This is a valid definition