summaryrefslogtreecommitdiff
path: root/compiler/parser/Lexer.x
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/parser/Lexer.x')
-rw-r--r--compiler/parser/Lexer.x31
1 files changed, 27 insertions, 4 deletions
diff --git a/compiler/parser/Lexer.x b/compiler/parser/Lexer.x
index 11d849ab71..c97d38f506 100644
--- a/compiler/parser/Lexer.x
+++ b/compiler/parser/Lexer.x
@@ -362,14 +362,14 @@ $tab+ { warn Opt_WarnTabs (text "Tab character") }
@qual @varid { idtoken qvarid }
@qual @conid { idtoken qconid }
@varid { varid }
- @conid { idtoken conid }
+ @conid { conid }
}
<0> {
@qual @varid "#"+ / { ifExtension magicHashEnabled } { idtoken qvarid }
@qual @conid "#"+ / { ifExtension magicHashEnabled } { idtoken qconid }
@varid "#"+ / { ifExtension magicHashEnabled } { varid }
- @conid "#"+ / { ifExtension magicHashEnabled } { idtoken conid }
+ @conid "#"+ / { ifExtension magicHashEnabled } { conid }
}
-- ToDo: - move `var` and (sym) into lexical syntax?
@@ -475,6 +475,9 @@ data Token
| ITgroup
| ITby
| ITusing
+ | ITnominal
+ | ITrepresentational
+ | ITphantom
-- Pragmas
| ITinline_prag InlineSpec RuleMatchInfo
@@ -669,6 +672,14 @@ reservedWordsFM = listToUFM $
( "proc", ITproc, bit arrowsBit)
]
+reservedUpcaseWordsFM :: UniqFM (Token, Int)
+reservedUpcaseWordsFM = listToUFM $
+ map (\(x, y, z) -> (mkFastString x, (y, z)))
+ [ ( "N", ITnominal, 0 ), -- no extension bit for better error msgs
+ ( "R", ITrepresentational, 0 ),
+ ( "P", ITphantom, 0 )
+ ]
+
reservedSymsFM :: UniqFM (Token, Int -> Bool)
reservedSymsFM = listToUFM $
map (\ (x,y,z) -> (mkFastString x,(y,z)))
@@ -1014,8 +1025,20 @@ varid span buf len =
where
!fs = lexemeToFastString buf len
-conid :: StringBuffer -> Int -> Token
-conid buf len = ITconid $! lexemeToFastString buf len
+conid :: Action
+conid span buf len =
+ case lookupUFM reservedUpcaseWordsFM fs of
+ Just (keyword, 0) -> return $ L span keyword
+
+ Just (keyword, exts) -> do
+ extsEnabled <- extension $ \i -> exts .&. i /= 0
+ if extsEnabled
+ then return $ L span keyword
+ else return $ L span $ ITconid fs
+
+ Nothing -> return $ L span $ ITconid fs
+ where
+ !fs = lexemeToFastString buf len
qvarsym, qconsym, prefixqvarsym, prefixqconsym :: StringBuffer -> Int -> Token
qvarsym buf len = ITqvarsym $! splitQualName buf len False