X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2Fparser%2FLexer.x;h=dca51e47267d1d64272bd7eefcdded2adb5945f5;hp=2c98f22725a53cfd850e8ef85e2bf7b0517822b6;hb=2fe38b5fb0957f9428864afd69ad3ccd82fae3d0;hpb=259cb7dd6b4e9bc7ac6ec4a8ae15947d7fb9b10e diff --git a/compiler/parser/Lexer.x b/compiler/parser/Lexer.x index 2c98f22..dca51e4 100644 --- a/compiler/parser/Lexer.x +++ b/compiler/parser/Lexer.x @@ -702,6 +702,14 @@ reservedSymsFM = listToUFM $ ,("→", ITrarrow, unicodeSyntaxEnabled) ,("←", ITlarrow, unicodeSyntaxEnabled) ,("⋯", ITdotdot, unicodeSyntaxEnabled) + + ,("⤙", ITlarrowtail, \i -> unicodeSyntaxEnabled i && arrowsEnabled i) + ,("⤚", ITrarrowtail, \i -> unicodeSyntaxEnabled i && arrowsEnabled i) + ,("⤛", ITLarrowtail, \i -> unicodeSyntaxEnabled i && arrowsEnabled i) + ,("⤜", ITRarrowtail, \i -> unicodeSyntaxEnabled i && arrowsEnabled i) + + ,("★", ITstar, unicodeSyntaxEnabled) + -- ToDo: ideally, → and ∷ should be "specials", so that they cannot -- form part of a large operator. This would let us have a better -- syntax for kinds: ɑ∷*→* would be a legal kind signature. (maybe). @@ -1127,7 +1135,7 @@ do_layout_left span _buf _len = do setLine :: Int -> Action setLine code span buf len = do let line = parseUnsignedInteger buf len 10 octDecDigit - setSrcLoc (mkSrcLoc (srcSpanFile span) (fromIntegral line - 1) 0) + setSrcLoc (mkSrcLoc (srcSpanFile span) (fromIntegral line - 1) 1) -- subtract one: the line number refers to the *following* line _ <- popLexState pushLexState code @@ -1983,7 +1991,9 @@ alternativeLayoutRuleToken t setNextToken t lexTokenAlr (_, ALRLayout _ col : ls, Just expectingOCurly) - | thisCol > col -> + | (thisCol > col) || + (thisCol == col && + isNonDecreasingIntentation expectingOCurly) -> do setAlrExpectingOCurly Nothing setALRContext (ALRLayout expectingOCurly thisCol : context) setNextToken t @@ -1998,26 +2008,30 @@ alternativeLayoutRuleToken t setALRContext (ALRLayout expectingOCurly thisCol : context) setNextToken t return (L thisLoc ITocurly) + -- We do the [] cases earlier than in the spec, as we + -- have an actual EOF token + (ITeof, ALRLayout _ _ : ls, _) -> + do setALRContext ls + setNextToken t + return (L thisLoc ITccurly) + (ITeof, _, _) -> + return t + -- the other ITeof case omitted; general case below covers it (ITin, ALRLayout ALRLayoutLet _ : ls, _) | newLine -> do setPendingImplicitTokens [t] setALRContext ls return (L thisLoc ITccurly) - (_, ls@(ALRLayout _ col : _), _) - | newLine && thisCol <= col -> - do let f ls'@(ALRLayout _ col' : ls'') - | thisCol < col' = case f ls'' of - (ts, ls''') -> - (L thisLoc ITccurly : ts, ls''') - | thisCol == col' = ([L thisLoc ITsemi], ls') - | otherwise = ([], ls') - f ls' = ([], ls') - case f ls of - (t' : ts, ls') -> - do setPendingImplicitTokens ts - setNextToken t - return t' - _ -> panic "Layout rule: [] when considering newline" + (_, ALRLayout _ col : ls, _) + | newLine && thisCol == col -> + do setNextToken t + return (L thisLoc ITsemi) + | newLine && thisCol < col -> + do setALRContext ls + setNextToken t + -- Note that we use lastLoc, as we may need to close + -- more layouts, or give a semicolon + return (L lastLoc ITccurly) (u, _, _) | isALRopen u -> do setALRContext (ALRNoLayout (containsCommas u) : context) @@ -2040,7 +2054,7 @@ alternativeLayoutRuleToken t do setALRContext ls setPendingImplicitTokens [t] return (L thisLoc ITccurly) - (ITin, _ : ls, _) -> + (ITin, ALRLayout _ _ : ls, _) -> do setALRContext ls setNextToken t return (L thisLoc ITccurly) @@ -2055,13 +2069,6 @@ alternativeLayoutRuleToken t setPendingImplicitTokens [t] return (L thisLoc ITccurly) -- the other ITwhere case omitted; general case below covers it - -- The first [] case comes before the general case, as we - -- have an actual EOF token - (ITeof, ALRLayout _ _ : ls, _) -> - do setALRContext ls - setNextToken t - return (L thisLoc ITccurly) - -- the other ITeof case omitted; general case below covers it (_, _, _) -> return t isALRopen :: Token -> Bool @@ -2084,6 +2091,10 @@ isALRclose ITccurly = True isALRclose ITcubxparen = True isALRclose _ = False +isNonDecreasingIntentation :: ALRLayout -> Bool +isNonDecreasingIntentation ALRLayoutDo = True +isNonDecreasingIntentation _ = False + containsCommas :: Token -> Bool containsCommas IToparen = True containsCommas ITobrack = True