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

Tab/space parsing issue #14

Open
Abhiroop opened this issue May 20, 2021 · 4 comments
Open

Tab/space parsing issue #14

Abhiroop opened this issue May 20, 2021 · 4 comments
Labels
bug Something isn't working frontend

Comments

@Abhiroop
Copy link
Collaborator

As evidenced in this commit: d3b3a69

Extraneous tabs/spaces result in the following incomprehensible error:

ParseErrorBundle {bundleErrors = TrivialError 104 (Just (Tokens ('=' :| ""))) (fromList [Tokens ('&' :| "&"),Tokens ('(' :| ""),Tokens ('(' :| ")"),Tokens ('*' :| ""),Tokens ('+' :| ""),Tokens ('-' :| ""),Tokens ('/' :| ""),Tokens (';' :| ""),Tokens ('<' :| ""),Tokens ('=' :| "="),Tokens ('>' :| ""),Tokens ('F' :| "alse"),Tokens ('T' :| "rue"),Tokens ('|' :| "|"),Label ('d' :| "igit"),Label ('i' :| "nteger"),Label ('l' :| "owercase letter"),Label ('u' :| "ppercase letter")]) :| [], bundlePosState = PosState {pstateInput = "chan : Channel Int\n;chan = channel ()\n\n;foo : ()\n;foo =\n  let v = sync (recv chan) in\n  foo\n      \nmain =\n  let _ = spawnExternal chan 0 in\n  foo;", pstateOffset = 0, pstateSourcePos = SourcePos {sourceName = "testcases/good14.cam", sourceLine = Pos 1, sourceColumn = Pos 1}, pstateTabWidth = Pos 8, pstateLinePrefix = ""}}

Can we catch this and emit a more friendly error message?

@Rewbert
Copy link
Collaborator

Rewbert commented May 20, 2021

I am quite confident that there's an issue in the preprocessor, especially when it comes to comments. I am guessing it's related. The preprocessor is quite greedy in its approach.

@Rewbert
Copy link
Collaborator

Rewbert commented May 20, 2021

nextToken :: PP (T.Text, Int)
nextToken = do
    (ST t i ti) <- get

    -- first split the input up in its leading whitespace/newline and the rest
    let (fluff, t')  = T.span (\c -> c == ' ' || c == '\n') t
    -- then extract the next token and the rest of the input
    let (token, t'') = T.span (\c -> c /= ' ' && c /= '\n') t'


    -- update the internal column counter
    updateColumn fluff
    c <- gets current

    -- emit the things we just cut off, to keep
    -- the annotated code as close to the source as possible
    tell fluff

    -- modify the internal state to reflect the rest of the input
    modify $ \(ST _ c i) -> ST t'' c i

    -- get the column of the current token and return the subsequent pair
    column <- gets current
    return (token, column)

Here it seems as if I am only considering spaces and newlines. If there's a tab in the commit you referenced, this is probably where the issue is. The good thing about the preprocessor is that it's quite short and simple, so changing it should not be too difficult, but a bad thing is that I've not documented it very well. @Abhiroop

@Abhiroop
Copy link
Collaborator Author

Here it seems as if I am only considering spaces and newlines.

Aha! Perhaps that's the fix! Good that you documented it here. This is nothing very urgent; we can push this change later.

@Abhiroop Abhiroop added bug Something isn't working frontend labels May 20, 2021
@Abhiroop
Copy link
Collaborator Author

This is not strictly a space/tab issue but this program:

main =
  let m = 3
  m

issues the following error:

ParseErrorBundle {bundleErrors = TrivialError 22 (Just (Tokens (';' :| ""))) (fromList [Tokens ('&' :| "&"),Tokens ('\'' :| ""),Tokens ('(' :| ""),Tokens ('(' :| ")"),Tokens ('*' :| ""),Tokens ('+' :| ""),Tokens ('-' :| ""),Tokens ('/' :| ""),Tokens ('<' :| ""),Tokens ('=' :| "="),Tokens ('>' :| ""),Tokens ('F' :| "alse"),Tokens ('T' :| "rue"),Tokens ('_' :| ""),Tokens ('i' :| "n"),Tokens ('|' :| "|"),Label ('d' :| "igit"),Label ('i' :| "nteger"),Label ('l' :| "etter"),Label ('l' :| "owercase letter"),Label ('u' :| "ppercase letter")]) :| [], bundlePosState = PosState {pstateInput = "main =\n  let m = 3\n  m;", pstateOffset = 0, pstateSourcePos = SourcePos {sourceName = "testcases/good16.cam", sourceLine = Pos 1, sourceColumn = Pos 1}, pstateTabWidth = Pos 8, pstateLinePrefix = ""}}

The in in let is missing. A more readable error message would help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working frontend
Projects
None yet
Development

No branches or pull requests

2 participants