X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2Fparser%2FLexer.x;h=96660128386e20adcb50a37006fb8aa47704f7e2;hp=c9b2e1cbf1a5d7d858c6f63bf53d3acda32c5bf8;hb=c5b178be60a5a44abd2f4ddf8c399857678326e2;hpb=7e95df790b34e11d7308e43dab0a7175b69b70fc diff --git a/compiler/parser/Lexer.x b/compiler/parser/Lexer.x index c9b2e1c..9666012 100644 --- a/compiler/parser/Lexer.x +++ b/compiler/parser/Lexer.x @@ -56,7 +56,7 @@ module Lexer ( getLexState, popLexState, pushLexState, extension, bangPatEnabled, datatypeContextsEnabled, addWarning, - incrBracketDepth, decrBracketDepth, getParserBrakDepth, + incrBracketDepth, incrBracketDepth1, decrBracketDepth, getParserBrakDepth, pushBracketDepth, popBracketDepth, lexTokenStream ) where @@ -72,6 +72,7 @@ import Module import Ctype import BasicTypes ( InlineSpec(..), RuleMatchInfo(..), FractionalLit(..) ) import Util ( readRational ) +import HsSyn (CodeFlavor(..)) import Control.Monad import Data.Bits @@ -330,6 +331,9 @@ $tab+ { warn Opt_WarnTabs (text "Warning: Tab character") } "<[" / { ifExtension hetMetEnabled `alexAndPred` notFollowedBySymbol } { special ITopenBrak } "]>" / { ifExtension hetMetEnabled } { special ITcloseBrak } + "<{" / { ifExtension hetMetEnabled `alexAndPred` notFollowedBySymbol } + { special ITopenBrak1 } + "}>" / { ifExtension hetMetEnabled } { special ITcloseBrak1 } "~~" / { ifExtension hetMetEnabled } { special ITescape } "%%" / { ifExtension hetMetEnabled } { special ITdoublePercent } "~~$" / { ifExtension hetMetEnabled } { special ITescapeDollar } @@ -503,6 +507,7 @@ data Token | ITvbar | ITlarrow | ITrarrow + | ITkappa | ITat | ITtilde | ITdarrow @@ -582,6 +587,8 @@ data Token -- Heterogeneous Metaprogramming extension | ITopenBrak -- <[ | ITcloseBrak -- ]> + | ITopenBrak1 -- <{ + | ITcloseBrak1 -- }> | ITescape -- ~~ | ITescapeDollar -- ~~$ | ITdoublePercent -- %% @@ -702,6 +709,7 @@ reservedSymsFM = listToUFM $ ,("|", ITvbar, always) ,("<-", ITlarrow, always) ,("->", ITrarrow, always) + ,("~~>", ITkappa, always) ,("@", ITat, always) ,("~", ITtilde, always) ,("=>", ITdarrow, always) @@ -1548,7 +1556,8 @@ data PState = PState { -- Have we just had the '}' for a let block? If so, than an 'in' -- token doesn't need to close anything: alr_justClosedExplicitLetBlock :: Bool, - code_type_bracket_depth :: Int + code_type_bracket_depth :: [CodeFlavor], + code_type_bracket_depth_stack :: [CodeFlavor] } -- last_loc and last_len are used when generating error messages, -- and in pushCurrentContext only. Sigh, if only Happy passed the @@ -1616,10 +1625,20 @@ setSrcLoc :: RealSrcLoc -> P () setSrcLoc new_loc = P $ \s -> POk s{loc=new_loc} () incrBracketDepth :: P () -incrBracketDepth = P $ \s -> POk (s{code_type_bracket_depth = (code_type_bracket_depth s)+1}) () +incrBracketDepth = P $ \s -> POk (s{code_type_bracket_depth = KappaFlavor:(code_type_bracket_depth s)}) () +incrBracketDepth1 :: P () +incrBracketDepth1 = P $ \s -> POk (s{code_type_bracket_depth = LambdaFlavor:(code_type_bracket_depth s)}) () decrBracketDepth :: P () -decrBracketDepth = P $ \s -> POk (s{code_type_bracket_depth = (code_type_bracket_depth s)-1}) () -getParserBrakDepth :: P Int +decrBracketDepth = P $ \s -> POk (s{code_type_bracket_depth = tail (code_type_bracket_depth s)}) () +pushBracketDepth :: P () +pushBracketDepth = P $ \s -> POk (s{code_type_bracket_depth = tail (code_type_bracket_depth s), + code_type_bracket_depth_stack = (head (code_type_bracket_depth s)):(code_type_bracket_depth_stack s) + }) () +popBracketDepth :: P () +popBracketDepth = P $ \s -> POk (s{code_type_bracket_depth = (head (code_type_bracket_depth_stack s)):(code_type_bracket_depth s), + code_type_bracket_depth_stack = tail (code_type_bracket_depth_stack s) + }) () +getParserBrakDepth :: P [CodeFlavor] getParserBrakDepth = P $ \s -> POk s (code_type_bracket_depth s) getSrcLoc :: P RealSrcLoc @@ -1905,7 +1924,8 @@ mkPState flags buf loc = alr_context = [], alr_expecting_ocurly = Nothing, alr_justClosedExplicitLetBlock = False, - code_type_bracket_depth = 0 + code_type_bracket_depth = [], + code_type_bracket_depth_stack = [] } where bitmap = ffiBit `setBitIf` xopt Opt_ForeignFunctionInterface flags