From 482b15d2d3d08ced4cbee7e0cc2fb9aefc1002fc Mon Sep 17 00:00:00 2001 From: autotaker Date: Tue, 12 Mar 2019 20:12:06 +0900 Subject: [PATCH] Add `:` to `isOpSymbol` This patch fixes the issue that `@:` is lexed as `[At, ConSym ":"]`. Now it is lexed as `[VarSym "@:"]`. --- src/Language/Haskell/Exts/InternalLexer.hs | 3 +- tests/examples/T326.hs | 4 + tests/examples/T326.hs.exactprinter.golden | 1 + tests/examples/T326.hs.parser.golden | 116 ++++++++++++++++++++ tests/examples/T326.hs.prettyparser.golden | 1 + tests/examples/T326.hs.prettyprinter.golden | 3 + 6 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 tests/examples/T326.hs create mode 100644 tests/examples/T326.hs.exactprinter.golden create mode 100644 tests/examples/T326.hs.parser.golden create mode 100644 tests/examples/T326.hs.prettyparser.golden create mode 100644 tests/examples/T326.hs.prettyprinter.golden diff --git a/src/Language/Haskell/Exts/InternalLexer.hs b/src/Language/Haskell/Exts/InternalLexer.hs index c4d40c5a..887e2090 100644 --- a/src/Language/Haskell/Exts/InternalLexer.hs +++ b/src/Language/Haskell/Exts/InternalLexer.hs @@ -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 isOpSymbol :: Char -> Bool -isOpSymbol c = c `elem` "!#$%&*+./<=>?@\\^|-~" +isOpSymbol c = c `elem` ":!#$%&*+./<=>?@\\^|-~" -- | Checks whether the character would be legal in some position of a qvar. -- Means that '..' and "AAA" will pass the test. diff --git a/tests/examples/T326.hs b/tests/examples/T326.hs new file mode 100644 index 00000000..89bc3d95 --- /dev/null +++ b/tests/examples/T326.hs @@ -0,0 +1,4 @@ +{-# LANGUAGE TypeApplications #-} +module T326 where + +(@:) a b = a diff --git a/tests/examples/T326.hs.exactprinter.golden b/tests/examples/T326.hs.exactprinter.golden new file mode 100644 index 00000000..1796dc27 --- /dev/null +++ b/tests/examples/T326.hs.exactprinter.golden @@ -0,0 +1 @@ +Match diff --git a/tests/examples/T326.hs.parser.golden b/tests/examples/T326.hs.parser.golden new file mode 100644 index 00000000..89b7f316 --- /dev/null +++ b/tests/examples/T326.hs.parser.golden @@ -0,0 +1,116 @@ +ParseOk + ( Module + SrcSpanInfo + { srcInfoSpan = SrcSpan "tests/examples/T326.hs" 1 1 5 1 + , srcInfoPoints = + [ SrcSpan "tests/examples/T326.hs" 1 1 1 1 + , SrcSpan "tests/examples/T326.hs" 2 1 2 1 + , SrcSpan "tests/examples/T326.hs" 2 1 2 1 + , SrcSpan "tests/examples/T326.hs" 4 1 4 1 + , SrcSpan "tests/examples/T326.hs" 5 1 5 1 + , SrcSpan "tests/examples/T326.hs" 5 1 5 1 + ] + } + (Just + (ModuleHead + SrcSpanInfo + { srcInfoSpan = SrcSpan "tests/examples/T326.hs" 2 1 2 18 + , srcInfoPoints = + [ SrcSpan "tests/examples/T326.hs" 2 1 2 7 + , SrcSpan "tests/examples/T326.hs" 2 13 2 18 + ] + } + (ModuleName + SrcSpanInfo + { srcInfoSpan = SrcSpan "tests/examples/T326.hs" 2 8 2 12 + , srcInfoPoints = [] + } + "T326") + Nothing + Nothing)) + [ LanguagePragma + SrcSpanInfo + { srcInfoSpan = SrcSpan "tests/examples/T326.hs" 1 1 1 34 + , srcInfoPoints = + [ SrcSpan "tests/examples/T326.hs" 1 1 1 13 + , SrcSpan "tests/examples/T326.hs" 1 31 1 34 + ] + } + [ Ident + SrcSpanInfo + { srcInfoSpan = SrcSpan "tests/examples/T326.hs" 1 14 1 30 + , srcInfoPoints = [] + } + "TypeApplications" + ] + ] + [] + [ FunBind + SrcSpanInfo + { srcInfoSpan = SrcSpan "tests/examples/T326.hs" 4 1 4 13 + , srcInfoPoints = [] + } + [ Match + SrcSpanInfo + { srcInfoSpan = SrcSpan "tests/examples/T326.hs" 4 1 4 13 + , srcInfoPoints = + [ SrcSpan "tests/examples/T326.hs" 4 1 4 2 + , SrcSpan "tests/examples/T326.hs" 4 2 4 4 + , SrcSpan "tests/examples/T326.hs" 4 4 4 5 + ] + } + (Symbol + SrcSpanInfo + { srcInfoSpan = SrcSpan "tests/examples/T326.hs" 4 2 4 4 + , srcInfoPoints = [] + } + "@:") + [ PVar + SrcSpanInfo + { srcInfoSpan = SrcSpan "tests/examples/T326.hs" 4 6 4 7 + , srcInfoPoints = [] + } + (Ident + SrcSpanInfo + { srcInfoSpan = SrcSpan "tests/examples/T326.hs" 4 6 4 7 + , srcInfoPoints = [] + } + "a") + , PVar + SrcSpanInfo + { srcInfoSpan = SrcSpan "tests/examples/T326.hs" 4 8 4 9 + , srcInfoPoints = [] + } + (Ident + SrcSpanInfo + { srcInfoSpan = SrcSpan "tests/examples/T326.hs" 4 8 4 9 + , srcInfoPoints = [] + } + "b") + ] + (UnGuardedRhs + SrcSpanInfo + { srcInfoSpan = SrcSpan "tests/examples/T326.hs" 4 10 4 13 + , srcInfoPoints = [ SrcSpan "tests/examples/T326.hs" 4 10 4 11 ] + } + (Var + SrcSpanInfo + { srcInfoSpan = SrcSpan "tests/examples/T326.hs" 4 12 4 13 + , srcInfoPoints = [] + } + (UnQual + SrcSpanInfo + { srcInfoSpan = SrcSpan "tests/examples/T326.hs" 4 12 4 13 + , srcInfoPoints = [] + } + (Ident + SrcSpanInfo + { srcInfoSpan = SrcSpan "tests/examples/T326.hs" 4 12 4 13 + , srcInfoPoints = [] + } + "a")))) + Nothing + ] + ] + , [] + ) diff --git a/tests/examples/T326.hs.prettyparser.golden b/tests/examples/T326.hs.prettyparser.golden new file mode 100644 index 00000000..1796dc27 --- /dev/null +++ b/tests/examples/T326.hs.prettyparser.golden @@ -0,0 +1 @@ +Match diff --git a/tests/examples/T326.hs.prettyprinter.golden b/tests/examples/T326.hs.prettyprinter.golden new file mode 100644 index 00000000..6a734e0d --- /dev/null +++ b/tests/examples/T326.hs.prettyprinter.golden @@ -0,0 +1,3 @@ +{-# LANGUAGE TypeApplications #-} +module T326 where +(@:) a b = a