Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lexical error with tab character in literate Agda text #5581

Closed
wadler opened this issue Oct 1, 2021 · 4 comments · Fixed by #5582
Closed

Lexical error with tab character in literate Agda text #5581

wadler opened this issue Oct 1, 2021 · 4 comments · Fixed by #5582
Assignees
Labels
lexer type: bug Issues and pull requests about actual bugs
Milestone

Comments

@wadler
Copy link

wadler commented Oct 1, 2021

Agda reports a lexical error when there is a tab in the source code, even if the tab appears in a commented-out part of the source.

@andreasabel
Copy link
Member

Phil @wadler, would you attach a file with MWE? I cannot reproduce this, tabs in comments seem ok.

@andreasabel andreasabel added lexer status: info-needed More information is needed from the bug reporter to confirm the issue. labels Oct 4, 2021
@nad
Copy link
Contributor

nad commented Oct 4, 2021

@andreasabel, try putting the following text into Bug.lagda.md:

A tab character: '	'.

Result:

Bug.lagda.md:1,1: Lexical error (you may want to replace tabs with spaces):
<ERROR>
	  
...

@nad nad added type: bug Issues and pull requests about actual bugs and removed status: info-needed More information is needed from the bug reporter to confirm the issue. labels Oct 4, 2021
@andreasabel andreasabel changed the title Bizarre lexical error Lexical error with tab character in literate Agda text Oct 4, 2021
@andreasabel
Copy link
Member

The problem is that literate stuff in a .lagda file is bleached, meaning non-whitespace is replaced by space characters. However, tabs, being ws, are kept, failing the Agda lexer.

illiterate :: [Layer] -> String
illiterate xs = concat
[ (if isCode layerRole then id else bleach) layerContent
| Layer{layerRole, layerContent} <- xs
]
-- | Replaces non-space characters in a string with spaces.
bleach :: String -> String
bleach s = map go s
where
go c | isSpace c = c
go _ = ' '

A fix would be to replace tabs by single spaces, that would preserve the character position.

@andreasabel
Copy link
Member

A fix would be to replace tabs by single spaces, that would preserve the character position.

Implemented this in #5582.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lexer type: bug Issues and pull requests about actual bugs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants