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

Add : to isOpSymbol (#326) #430

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

autotaker
Copy link

This patch fixes the issue #326 that @: is lexed as [At, ConSym ":"].
Now it is lexed as [VarSym "@:"].

This patch fixes the issue that `@:` is lexed as `[At, ConSym ":"]`.
Now it is lexed as `[VarSym "@:"]`.
@@ -368,8 +368,9 @@ isPragmaChar c = isAlphaNum c || c == '_'
-- Used in the lexing of type applications
-- Why is it like this? I don't know exactly but this is how it is in
-- GHC's parser.
-- Symbol `:` is added so that `@:` is lexed as `VarSym "@:"`. See Issue #326
Copy link
Author

@autotaker autotaker Mar 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GHC's counterpart notFollowedBySymbol does not contain :.

notFollowedBySymbol :: AlexAccPred ExtsBitmap
notFollowedBySymbol _ _ _ (AI _ buf)
  = nextCharIsNot buf (`elem` "!#$%&*+./<=>?@\\^|-~")

There are two rules that matches for @: in Lexer.x.

  -- See Note [Lexing type applications]
<0> {
    [^ $idchar \) ] ^
  "@"
    / { ifExtension TypeApplicationsBit `alexAndPred` notFollowedBySymbol }
    { token ITtypeApp }
}

and

<0> {
  @varsym                                          { varsym }
  ...
}

Then, alex chooses the rule that consumes the longest prefix. Thus it is recognized as an operator "@:".

When the input stream matches more than one rule, the rule which matches the longest prefix of the input stream wins. If there are still several rules which match an equal number of characters, then the rule which appears earliest in the file wins.

(Cited from 3.2. Syntax of Alex files)

This patch may be ad-hoc. Nonetheless it is correct because isOpSymbol is only used for TypeApplications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant