diff --git a/ChangeLog.md b/ChangeLog.md index 84c3350d..f0690683 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -3,6 +3,8 @@ ## 2.1 * Added `--numeric-version` CLI flag. +* Documented and implemented the new feature "Resumptive parsing with ``catch``" +* Documented (and reimplemented) the "Reporting expected tokens" feature ## 2.0.2 diff --git a/doc/using.rst b/doc/using.rst index caa43b30..e19ac3e0 100644 --- a/doc/using.rst +++ b/doc/using.rst @@ -991,11 +991,187 @@ and the occurrence of the ``in`` symbol generates a parse error, which is interp .. index:: yacc -Note for ``yacc`` users: this form of error recovery is strictly more limited than that provided by ``yacc``. -During a parse error condition, ``yacc`` attempts to discard states and tokens in order to get back into a state where parsing may continue; Happy doesn't do this. -The reason is that normal ``yacc`` error recovery is notoriously hard to describe, and the semantics depend heavily on the workings of a shift-reduce parser. -Furthermore, different implementations of ``yacc`` appear to implement error recovery differently. -Happy's limited error recovery on the other hand is well-defined, as is just sufficient to implement the Haskell layout rule (which is why it was added in the first place). +Note for ``yacc``/``bison``/``menhir`` users: this form of error recovery is +quite different to the one provided by other parser generators. +If you are looking for ``yacc``-style error recovery, have a look at :ref:`The ``catch`` token `. +For historic reasons, the main reason for happy's ``error`` token has been to +implement the Haskell 2010 layout rule, which has +:ref:`its own set of drawbacks `. + +.. _sec-catch: + +Resumptive parsing with ``catch`` +--------------------------------- + +.. index:: catch token + +Since version 2.1, happy supports a form of error recovery that is less-limited +(but perhaps more fickle) than ``error``. +This form of error handling is enabled by the special ``catch`` +token, which works quite similar to the ``error`` token in :ref:`bison +`. + +The main motivation for ``catch`` is that one wants to resume parsing after +encountering a syntax error. +It is quite hard for a parser generator to determine where to resume parsing +all by itself; hence the user must guide the resumption process via judicious +use of ``catch``. + +Here is an example (adapted from test case ``monaderror-resume``, featuring a +simple non-threaded lexer): + +.. code-block:: none + + %monad { ParseM } { (>>=) } { return } + %error { abort } { report } + + %token ... + ... + + %% + + Stmts :: { [String] } + Stmts : {- empty -} { [] } + | Exp { [$1] } + | Stmts ';' Exp { $1 ++ [$3] } + + Exp :: { String } + Exp : '1' { "1" } + | catch { "catch" } + | Exp '+' Exp { $1 ++ " + " ++ $3 } + | '(' Exp ')' { "(" ++ $2 ++ ")" } + + %% + + type ParseM = ... + report :: [LToken] -> ([LToken] -> ParseM a) -> ParseM a + report tks resume = do { ...; resume tks } + + abort :: [LToken] -> ParseM a + abort = ... -- throw exception or call `error` + + ... + +Note the use of ``catch`` in the second ``Exp`` rule and +the use of the binary form of the ``%error`` directive. +The directive specifies a pair of functions ``abort`` and ``report`` +which are necessary to handle multiple parse errors. + +The generated parser parses errorneous input such as ``1+;+1;(1+;1`` as +``["1 + catch", "catch + 1", "catch", "1"]``, with one list element per parsed +statement. +To a first approximation, one can think of ``catch`` as standing in for the +smallest syntax tree containing the error site. +A different analogy is that of a ``catch`` handler in exceptional control flow +in, e.g., Java, where the innermost catch frame handles the exception. +For ``happy``, the "exception handlers" are parser states "in the past" that can +shift the ``catch`` token, but it is not *always* the innermost handler that +resumes. + +Precisely, upon encountering a syntax error, function ``report`` is called for +the user to print or collect the error message. +As its last argument, ``report`` takes a resumption action, which when called +enters **error resumption mode**. This mode proceeds as follows: + + 1. Collect prefixes of the state stack that can shifts the ``catch`` token and + shift it. The resulting stacks are called **catch frames**. + 2. To resume parsing, discard input tokens until one of the catch frames + ultimately shifts the input token. + * When there are multiple catch frames that can resume at the current token, + pick the innermost catch frame. + * When the end of input is reached before any catch frame resumes, call + the ``abort`` function. + +A couple of notes: + + * When parsing the expression ``1+``, both ``"1 + catch"`` and ``"catch"`` would + be valid resumptive parses, expecting to shift the end-of-input token. + However, the first parse is preferable because it provides the "smaller + cover" of the error site. + This is ensured by "pick the innermost catch frame". + + * Why bother with multiple catch frames? Why not deterministically pick the + innermost one? After all, that is how ``bison`` does it. + + Answer: Consider the input ``(1+;1``, which errors when it sees ``;`` + because it expects to find an ``Exp``. + Now, ``Exp -> . catch`` is an item of the topmost state, and shifting the + ``catch`` token corresponds to the prefix of a parse ``(1+catch``. + This prefix can only resume when seeing ``+`` or ``)``, so the parser + will discard both ``;`` and ``1``, hitting the end of input. + Thus, trying to resume with the innermost frame will ultimately call + ``abort`` and thus failing to produce any syntax tree *at all*. + By contrast, picking the start state (which shifted ``(``) for resumption + means to stop discarding when we encounter the next ``;``. + This leads to the preferred parse ``["catch","1"]``. + + * After ``report`` has noted the parse error, its type leaves it no choice but + to call ``resume`` (or to throw an exception). + Similarly, ``abort`` must always throw an exception and cannot return a + syntax tree at all. It should *not* report a parse error as well. + + To illustrate how the new binary ``%error`` decomposition corresponds to + the regular unary one, consider the definition + ``myError tks = report tks abort``. + This definition could be used in ``%error { myError }``; in this case, the + parser would always abort after the first error. + + * Whether or not the ``abort`` and ``report`` functions get passed the + list of tokens is subject to the :ref:`same decision logic as for ``parseError`` `. + When using :ref:`the ``%error.expected`` directive `, + the list of expected tokens is passed to ``report`` only, between ``tks`` + and ``resume``. + +Note that defining a good AST representation for syntax errors is entirely up +to the user of happy; the example above simply emitted the string ``catch`` +whenever it stands-in an for an errorneous AST node. +A more reasonable implementation would be similar to typed holes in GHC. + +.. _sec-expected-list: + +Reporting expected tokens +------------------------- + +.. index:: expected tokens + +Often, it is useful to present users with suggestions as to which kind of tokens +where expected at the site of a syntax error. +To this end, when ``%error.expected`` directive is specified, happy assumes that +the error handling function (resp. ``report`` function when using the binary +form of the ``%error`` directive) takes a ``[String]`` argument (the argument +*after* the token stream, in case of a non-threaded lexer) listing all the +stringified tokens that were expected at the site of the syntax error. +The strings in this list are derived from the ``%token`` directive. + +Here is an example, inspired by test case ``monaderror-explist``: + +.. code-block:: none + + %tokentype { Token } + %error { handleErrorExpList } + %error.expected + + %monad { ParseM } { (>>=) } { return } + + %token + 'S' { TokenSucc } + 'Z' { TokenZero } + 'T' { TokenTest } + + %% + + Exp : 'Z' { 0 } + | 'T' 'Z' Exp { $3 + 1 } + | 'S' Exp { $2 + 1 } + + %% + + type ParseM = ... + + handleErrorExpList :: [Token] -> [String] -> ParseM a + handleErrorExpList ts explist = throwError $ ParseError $ explist + + ... .. _sec-multiple-parsers: diff --git a/lib/backend-glr/src/Happy/Backend/GLR/ProduceCode.lhs b/lib/backend-glr/src/Happy/Backend/GLR/ProduceCode.lhs index c9794f8f..282f26a9 100644 --- a/lib/backend-glr/src/Happy/Backend/GLR/ProduceCode.lhs +++ b/lib/backend-glr/src/Happy/Backend/GLR/ProduceCode.lhs @@ -307,6 +307,8 @@ It also shares identical reduction values as CAFs > mkLine state (symInt,action) > | symInt == errorTok -- skip error productions > = "" -- NB see ProduceCode's handling of these +> | symInt == catchTok -- skip error productions +> = "" -- NB see ProduceCode's handling of these > | otherwise > = case action of > LR'Fail -> "" diff --git a/lib/backend-lalr/src/Happy/Backend/LALR.hs b/lib/backend-lalr/src/Happy/Backend/LALR.hs index 78bf47d7..82142b84 100644 --- a/lib/backend-lalr/src/Happy/Backend/LALR.hs +++ b/lib/backend-lalr/src/Happy/Backend/LALR.hs @@ -19,14 +19,16 @@ magicFilter magicName = case magicName of in filter_output importsToInject :: Bool -> String -importsToInject debug = concat ["\n", import_array, import_bits, import_glaexts, debug_imports, applicative_imports] +importsToInject debug = concat ["\n", import_array, import_list, import_bits, import_glaexts, debug_imports, applicative_imports] where debug_imports | debug = import_debug | otherwise = "" applicative_imports = import_applicative import_glaexts = "import qualified GHC.Exts as Happy_GHC_Exts\n" + _import_ghcstack = "import qualified GHC.Stack as Happy_GHC_Stack\n" import_array = "import qualified Data.Array as Happy_Data_Array\n" + import_list = "import qualified Data.List as Happy_Data_List\n" import_bits = "import qualified Data.Bits as Bits\n" import_debug = "import qualified System.IO as Happy_System_IO\n" ++ "import qualified System.IO.Unsafe as Happy_System_IO_Unsafe\n" ++ @@ -35,7 +37,7 @@ importsToInject debug = concat ["\n", import_array, import_bits, import_glaexts, "import Control.Monad (ap)\n" langExtsToInject :: [String] -langExtsToInject = ["MagicHash", "BangPatterns", "TypeSynonymInstances", "FlexibleInstances", "PatternGuards", "NoStrictData"] +langExtsToInject = ["MagicHash", "BangPatterns", "TypeSynonymInstances", "FlexibleInstances", "PatternGuards", "NoStrictData", "UnboxedTuples", "PartialTypeSignatures"] defines :: Bool -> Bool -> String defines debug coerce = unlines [ "#define " ++ d ++ " 1" | d <- vars_to_define ] diff --git a/lib/backend-lalr/src/Happy/Backend/LALR/ProduceCode.lhs b/lib/backend-lalr/src/Happy/Backend/LALR/ProduceCode.lhs index f002a1de..de728d96 100644 --- a/lib/backend-lalr/src/Happy/Backend/LALR/ProduceCode.lhs +++ b/lib/backend-lalr/src/Happy/Backend/LALR/ProduceCode.lhs @@ -14,9 +14,8 @@ The code generator. > import Data.Maybe ( isNothing, fromMaybe ) > import Data.Char ( ord, chr ) -> import Data.List ( sortBy ) +> import Data.List ( sortBy, nub ) -> import Control.Monad ( forM_ ) > import Control.Monad.ST ( ST, runST ) > import Data.Word > import Data.Int @@ -60,7 +59,7 @@ Produce the complete output file. > , monad = (use_monad,monad_context,monad_tycon,monad_then,monad_return) > , token_type = token_type' > , error_handler = error_handler' -> , error_sig = error_sig' +> , error_expected = error_expected' > }) > action goto lang_exts module_header module_trailer > coerce strict @@ -70,7 +69,7 @@ Produce the complete output file. > -- comment goes *after* the module header, so that we > -- don't screw up any OPTIONS pragmas in the header. > . produceAbsSynDecl . nl -> . produceExpListPerState +> . produceTokToStringList > . produceActionTable > . produceReductions > . produceTokenConverter . nl @@ -103,8 +102,9 @@ We used to emit tabs for indentation, but since 2.0.0.1 we use 8 spaces for back > intMaybeHash = str "Happy_GHC_Exts.Int#" > -- Parsing monad and its constraints -> pty = str monad_tycon -> pcont = str monad_context +> pty = str monad_tycon -- str "P" +> ptyAt a = brack' (pty . str " " . a) -- \(str "a") -> str "(P a)" +> pcont = str monad_context -- str "Read a", some constraint for "P" to be a monad > > -- If GHC is enabled, wrap the content in a CPP ifdef that includes the > -- content and tests whether the GHC version is >= 7.10.3 @@ -368,52 +368,57 @@ The token conversion function. > = case lexer' of { > > Nothing -> -> str "happyNewToken action sts stk [] =\n" . indent -> . eofAction "notHappyAtAll" -> . str " []\n\n" -> . str "happyNewToken action sts stk (tk:tks) =\n" . indent -> . str "let cont i = " . doAction . str " sts stk tks in\n" . indent -> . str "case tk of {\n" . indent +> str "happyTerminalToTok term = case term of {\n" . indent > . interleave (";\n" ++ indentStr) (map doToken token_rep) -> . str "_ -> happyError' ((tk:tks), [])\n" . indent -> . str "}\n\n" -> . str "happyError_ explist " . eofTok . str " tk tks = happyError' (tks, explist)\n" -> . str "happyError_ explist _ tk tks = happyError' ((tk:tks), explist)\n"; +> . str "_ -> -1#;\n" . indent . str "}\n" -- -1# signals an invalid token +> . str "{-# NOINLINE happyTerminalToTok #-}\n" +> . str "\n" +> . str "happyLex kend _kmore [] = kend notHappyAtAll []\n" +> . str "happyLex _kend kmore (tk:tks)\n" +> . str " | Happy_GHC_Exts.tagToEnum# (i Happy_GHC_Exts.==# -1#) = happyReport' (tk:tks) [] happyAbort\n" -- invalid token (-1#); lexer error. +> . str " | otherwise = kmore i tk tks\n" +> . str " where i = happyTerminalToTok tk\n" +> . str "{-# INLINE happyLex #-}\n" +> . str "\n" +> . str "happyNewToken action sts stk = happyLex (\\tk -> " . eofAction "notHappyAtAll" . str ") (" +> . str "\\i tk -> " . doAction . str " sts stk)\n" +> . str "\n" +> . str "happyReport " . eofTok . str " tk explist resume tks = happyReport' tks explist resume\n" +> . str "happyReport _ tk explist resume tks = happyReport' (tk:tks) explist (\\tks -> resume (tail tks))\n" > -- when the token is EOF, tk == _|_ (notHappyAtAll) -> -- so we must not pass it to happyError' +> -- so we must not pass it to happyReport' +> . str "\n"; > Just (lexer'',eof') -> -> str "happyNewToken action sts stk\n" . indent . str "= " -> . str lexer'' -> . str "(\\tk -> " -> . str "\n\tlet cont i = " -> . doAction -> . str " sts stk in\n" . indent -> . str "case tk of {\n" . indent -> . str (eof' ++ " -> ") -> . eofAction "tk" . str ";\n" . indent +> str "happyTerminalToTok term = case term of {\n" . indent +> . str eof' . str " -> " . eofTok . str ";\n" . indent > . interleave (";\n" ++ indentStr) (map doToken token_rep) -> . str "_ -> happyError' (tk, [])\n" . indent -> . str "})\n\n" -> . str "happyError_ explist " . eofTok . str " tk = happyError' (tk, explist)\n" -> . str "happyError_ explist _ tk = happyError' (tk, explist)\n"; -> -- superfluous pattern match needed to force happyError_ to +> . str "_ -> error \"Encountered a token that was not declared to happy\"\n" . indent . str "}\n" +> . str "{-# NOINLINE happyTerminalToTok #-}\n" +> . str "\n" +> . str "happyLex kend kmore = " . str lexer'' . str " (\\tk -> case tk of {\n" . indent +> . str eof' . str " -> kend tk;\n" . indent +> . str "_ -> kmore (happyTerminalToTok tk) tk })\n" +> . str "{-# INLINE happyLex #-}\n" +> . str "\n" +> . str "happyNewToken action sts stk = happyLex (\\tk -> " . eofAction "tk" . str ") (" +> . str "\\i tk -> " . doAction . str " sts stk)\n" +> . str "\n" +> . str "happyReport " . eofTok . str " = happyReport'\n" +> . str "happyReport _ = happyReport'\n" +> -- superfluous pattern match needed to force happyReport to > -- have the correct type. +> . str "\n"; > } > where > eofAction tk = str "happyDoAction " > . eofTok . strspace . str tk -> . str " action" . str " sts stk" +> . str " action sts stk" > eofTok = showInt (tokIndex eof) - > doAction = str "happyDoAction i tk action" - -> doToken (i,tok) -> = str (removeDollarDollar tok) -> . str " -> cont " -> . showInt (tokIndex i) +> doToken (i,tok) = str (removeDollarDollar tok) . str " -> " . showInt (tokIndex i) Use a variable rather than '_' to replace '$$', so we can use it on the left hand side of '@'. @@ -430,9 +435,7 @@ the left hand side of '@'. > Just (TokenWithValue e) -> brack $ substExpressionWithHole e $ pat [] > where > pat = mkHappyVar i - -> tokIndex i = getName i - n_nonterminals - n_starts - 2 -> -- tokens adjusted to start at zero, see ARRAY_NOTES +> tokIndex i = getName i - getName fst_term + 2 -- +2: errorTok, catchTok %----------------------------------------------------------------------------- Action Tables. @@ -440,10 +443,17 @@ Action Tables. Here we do a bit of trickery and replace the normal default action (failure) for each state with at least one reduction action. For each such state, we pick one reduction action to be the default action. -This should make the code smaller without affecting the speed. It -changes the sematics for errors, however; errors could be detected in -a different state now (but they'll still be detected at the same point -in the token stream). +This should make the code smaller without affecting the speed. +It changes the sematics for errors, however; errors could be detected in a +different state now (but they'll still be detected at the same point in the +token stream). + +SG: For a data point, in issue93 the happyTable triples in size when we always +pick failure as the default reduction. +Presumably that is because there are quite a few reduction states, in which the +only non-default transition is a reduction. +Our scheme above ensures that these states don't occupy space in the main +happyTable at all; they just get an entry in the happyDefActions. Further notes on default cases: @@ -485,27 +495,17 @@ machinery to discard states in the parser... > produceActionTable > = produceActionArray > . produceReduceArray +> . produceRuleArray +> . produceCatchStates > . str "happy_n_terms = " . shows n_terminals . str " :: Prelude.Int\n" > . str "happy_n_nonterms = " . shows n_nonterminals . str " :: Prelude.Int\n\n" - -> produceExpListPerState -> = produceExpListArray -> . str "{-# NOINLINE happyExpListPerState #-}\n" -> . str "happyExpListPerState st =\n" -> . str " token_strs_expected\n" -> . str " where token_strs = " . str (show $ elems token_names') . str "\n" -> . str " bit_start = st Prelude.* " . str (show nr_tokens) . str "\n" -> . str " bit_end = (st Prelude.+ 1) Prelude.* " . str (show nr_tokens) . str "\n" -> . str " read_bit = readArrayBit happyExpList\n" -> . str " bits = Prelude.map read_bit [bit_start..bit_end Prelude.- 1]\n" -> . str " bits_indexed = Prelude.zip bits [0.." -> . str (show (nr_tokens - 1)) . str "]\n" -> . str " token_strs_expected = Prelude.concatMap f bits_indexed\n" -> . str " f (Prelude.False, _) = []\n" -> . str " f (Prelude.True, nr) = [token_strs Prelude.!! nr]\n" +> . str "happy_n_starts = " . shows n_starts . str " :: Prelude.Int\n\n" +> +> produceTokToStringList +> = str "{-# NOINLINE happyTokenStrings #-}\n" +> . str "happyTokenStrings = " . shows (drop (getName fst_term - 1) (elems token_names')) . str "\n" +> -- fst_term - 1: fst_term includes eofToken, but that is last in the list. > . str "\n" -> where (first_token, last_token) = bounds token_names' -> nr_tokens = getName last_token - getName first_token + 1 action array indexed by (terminal * last_state) + state @@ -520,15 +520,6 @@ action array indexed by (terminal * last_state) + state > . hexChars goto_offs > . str "\"#\n\n" --" > -> . str "happyAdjustOffset :: Happy_GHC_Exts.Int# -> Happy_GHC_Exts.Int#\n" -> . str "happyAdjustOffset off = " -> . (if length table < 32768 -> then str "off" -> else str "if happyLt off (" . shows min_off . str "# :: Happy_GHC_Exts.Int#)" -> . str " then off Happy_GHC_Exts.+# 65536#" -> . str " else off") -> . str "\n\n" --" -> > . str "happyDefActions :: HappyAddr\n" > . str "happyDefActions = HappyA# \"" --" > . hexChars defaults @@ -544,31 +535,35 @@ action array indexed by (terminal * last_state) + state > . hexChars table > . str "\"#\n\n" --" - -> produceExpListArray -> = str "happyExpList :: HappyAddr\n" -> . str "happyExpList = HappyA# \"" --" -> . hexCharsForBits explist -> . str "\"#\n\n" --" - > n_terminals = length terms > n_nonterminals = length nonterms - n_starts -- lose %starts > -> (act_offs,goto_offs,table,defaults,check,explist,min_off) +> (act_offs,goto_offs,table,defaults,check,catch_states) > = mkTables action goto first_nonterm' fst_term -> n_terminals n_nonterminals n_starts (bounds token_names') +> n_terminals n_nonterminals n_starts > > produceReduceArray -> = {- str "happyReduceArr :: Array Int a\n" -} -> str "happyReduceArr = Happy_Data_Array.array (" +> = str "happyReduceArr = Happy_Data_Array.array (" > . shows (n_starts :: Int) -- omit the %start reductions > . str ", " > . shows n_rules > . str ") [\n" > . interleave' ",\n" (map reduceArrElem [n_starts..n_rules]) > . str "\n" . indent . str "]\n\n" - +> +> produceRuleArray -- rule number to (non-terminal number, rule length) +> = str "happyRuleArr :: HappyAddr\n" +> . str "happyRuleArr = HappyA# \"" -- " +> . hexChars (concatMap (\(nt,len) -> [nt,len]) ruleArrElems) +> . str "\"#\n\n" --" +> +> ruleArrElems = map (\(Production nt toks _code _prio) -> (getName nt - getName first_nonterm',length toks)) (drop n_starts prods) +> > n_rules = length prods - 1 :: Int +> +> produceCatchStates +> = str "happyCatchStates :: [Int]\n" +> . str "happyCatchStates = " . shows catch_states . str "\n\n" > showInt i = shows i . showChar '#' @@ -629,6 +624,7 @@ MonadStuff: happyThen :: () => HappyIdentity a -> (a -> HappyIdentity b) -> HappyIdentity b happyReturn :: () => a -> HappyIdentity a happyThen1 m k tks = happyThen m (\a -> k a tks) + happyFmap1 f m tks = happyThen (m tks) (\a -> happyReturn (f a)) happyReturn1 = \a tks -> happyReturn a - with %monad: @@ -636,6 +632,7 @@ MonadStuff: happyThen :: CONTEXT => P a -> (a -> P b) -> P b happyReturn :: CONTEXT => a -> P a happyThen1 m k tks = happyThen m (\a -> k a tks) + happyFmap1 f m tks = happyThen (m tks) (\a -> happyReturn (f a)) happyReturn1 = \a tks -> happyReturn a - with %monad & %lexer: @@ -644,30 +641,39 @@ MonadStuff: happyReturn :: CONTEXT => a -> P a happyThen1 = happyThen happyReturn1 = happyReturn + happyFmap1 f m = happyThen m (\a -> happyReturn (f a)) > produceMonadStuff = -> str "happyThen :: " . pcont . str " => " . pty -> . str " a -> (a -> " . pty -> . str " b) -> " . pty . str " b\n" +> str "happyThen :: " . pcont . str " => " . ptyAt (str "a") +> . str " -> (a -> " . ptyAt (str "b") +> . str ") -> " . ptyAt (str "b") . str "\n" > . str "happyThen = " . brack monad_then . nl -> . str "happyReturn :: " . pcont . str " => a -> " . pty . str " a\n" +> . str "happyReturn :: " . pcont . str " => a -> " . ptyAt (str "a") . str "\n" > . str "happyReturn = " . brack monad_return . nl > . case lexer' of > Nothing -> > str "happyThen1 m k tks = (" . str monad_then > . str ") m (\\a -> k a tks)\n" -> . str "happyReturn1 :: " . pcont . str " => a -> b -> " . pty . str " a\n" +> . str "happyFmap1 f m tks = happyThen (m tks) (\\a -> happyReturn (f a))\n" +> . str "happyReturn1 :: " . pcont . str " => a -> b -> " . ptyAt (str "a") . str "\n" > . str "happyReturn1 = \\a tks -> " . brack monad_return > . str " a\n" -> . str "happyError' :: " . str monad_context . str " => ([" -> . token -> . str "], [Prelude.String]) -> " -> . str monad_tycon -> . str " a\n" -> . str "happyError' = " -> . str (if use_monad then "" else "HappyIdentity Prelude.. ") -> . errorHandler . str "\n" +> . str "happyReport' :: " . pcont . str " => " +> . str "[" . token . str "] -> " +> . str "[Prelude.String] -> (" +> . str "[" . token . str "] -> " +> . ptyAt (str "a") . str ") -> " +> . ptyAt (str "a") +> . str "\n" +> . str "happyReport' = " . callReportError . str "\n" +> . str "\n" +> . str "happyAbort :: " . pcont . str " => " +> . str "[" . token . str "] -> " +> . ptyAt (str "a") +> . str "\n" +> . str "happyAbort = " . str abort_handler . str "\n" +> . str "\n" > _ -> > let > happyParseSig = @@ -677,49 +683,72 @@ MonadStuff: > newTokenSig = > str "happyNewToken :: " . pcont . str " => " . intMaybeHash > . str " -> Happy_IntList -> HappyStk " . happyAbsSyn -> . str " -> " . pty . str " " . happyAbsSyn . str"\n" +> . str " -> " . ptyAt happyAbsSyn . str"\n" > . str "\n" > doActionSig = > str "happyDoAction :: " . pcont . str " => " . intMaybeHash > . str " -> " . str token_type' . str " -> " . intMaybeHash > . str " -> Happy_IntList -> HappyStk " . happyAbsSyn -> . str " -> " . pty . str " " . happyAbsSyn . str "\n" +> . str " -> " . ptyAt happyAbsSyn . str "\n" > . str "\n" > reduceArrSig = > str "happyReduceArr :: " . pcont > . str " => Happy_Data_Array.Array Prelude.Int (" . intMaybeHash > . str " -> " . str token_type' . str " -> " . intMaybeHash > . str " -> Happy_IntList -> HappyStk " . happyAbsSyn -> . str " -> " . pty . str " " . happyAbsSyn . str ")\n" +> . str " -> " . ptyAt happyAbsSyn . str ")\n" > . str "\n" > in filterTypeSig (happyParseSig . newTokenSig . doActionSig . reduceArrSig) > . str "happyThen1 :: " . pcont . str " => " . pty > . str " a -> (a -> " . pty > . str " b) -> " . pty . str " b\n" > . str "happyThen1 = happyThen\n" -> . str "happyReturn1 :: " . pcont . str " => a -> " . pty . str " a\n" +> . str "happyFmap1 f m = happyThen m (\\a -> happyReturn (f a))\n" +> . str "happyReturn1 :: " . pcont . str " => a -> " . ptyAt (str "a") . str "\n" > . str "happyReturn1 = happyReturn\n" -> . str "happyError' :: " . str monad_context . str " => (" -> . token . str ", [Prelude.String]) -> " -> . str monad_tycon -> . str " a\n" -> . str "happyError' tk = " -> . str (if use_monad then "" else "HappyIdentity ") -> . errorHandler . str " tk\n" - +> . str "happyReport' :: " . pcont . str " => " +> . token . str " -> " +> . str "[Prelude.String] -> " +> . ptyAt (str "a") . str " -> " +> . ptyAt (str "a") +> . str "\n" +> . str "happyReport' = " . callReportError . str "\n" +> . str "\n" +> . str "happyAbort :: " . pcont . str " => " +> . ptyAt (str "a") +> . str "\n" +> . str "happyAbort = " . str abort_handler . str "\n" +> . str "\n" + +The error handler takes up to three arguments. An error handler specified with %error is passed the current token -when used with %lexer, but happyError (the old way but kept for -compatibility) is not passed the current token. Also, the %errorhandlertype -directive determines the API of the provided function. - -> errorHandler = -> case error_handler' of -> Just h -> case error_sig' of -> ErrorHandlerTypeExpList -> str h -> ErrorHandlerTypeDefault -> str "(\\(tokens, _) -> " . str h . str " tokens)" -> Nothing -> case lexer' of -> Nothing -> str "(\\(tokens, _) -> happyError tokens)" -> Just _ -> str "(\\(tokens, explist) -> happyError)" +when used with %lexer as the first argument, but happyError (the old way but kept for +compatibility) is not passed the current token. +Furthermore, the second argument is the list of expected tokens +in the presence of the %error.expected directive. +The last argument is the "resumption", a continuation that tries to find +an item on the stack taking a @catch@ terminal where parsing may resume, +in the presence of the two-argument form of the %error directive. + +> callReportError = -- this one wraps around report_error_handler to expose a unified interface +> str "(\\tokens expected resume -> " . +> (if use_monad then str "" +> else str "HappyIdentity Prelude.$ ") . +> report_error_handler . +> (case (error_handler', lexer') of (DefaultErrorHandler, Just _) -> id +> _ -> str " tokens") . +> (if error_expected' then str " expected" +> else id) . +> (case error_handler' of ResumptiveErrorHandler{} -> str " resume" +> _ -> id) . +> str ")" +> report_error_handler = case error_handler' of +> DefaultErrorHandler -> str "happyError" +> CustomErrorHandler h -> brack h +> ResumptiveErrorHandler _abort report -> brack report +> abort_handler = case error_handler' of +> ResumptiveErrorHandler abort _report -> abort +> _ -> "error \"Called abort handler in non-resumptive parser\"" > reduceArrElem n > = str "" . indent . str "(" . shows n . str " , " @@ -835,24 +864,42 @@ vars used in this piece of code. See notes under "Action Tables" above for some subtleties in this function. > getDefault :: [(Name, LRAction)] -> LRAction -> getDefault actions = +> getDefault actions > -- pick out the action for the error token, if any -> case [ act | (e, act) <- actions, e == errorTok ] of +> | (act : _) <- error_acts, act /= LR'Fail +> = case act of > > -- use error reduction as the default action, if there is one. -> act@(LR'Reduce _ _) : _ -> act -> act@(LR'Multiple _ (LR'Reduce _ _)) : _ -> act +> LR'Reduce _ _ -> act +> LR'Multiple _ (LR'Reduce _ _) -> act > > -- if the error token is shifted or otherwise, don't generate -> -- a default action. This is *important*! -> (act : _) | act /= LR'Fail -> LR'Fail +> -- a default reduction action. This is *important*! +> _ -> LR'Fail +> +> -- do not reduce by default in a state that could shift the catch token. +> -- otherwise upon an error, we discard viable resumption points from the +> -- parsing stack. +> -- This makes a difference on GHC's parser for input such as +> -- f = foo data; x = + blah +> -- where we must detect `data` as a parse error early enough to parse +> -- `foo data` as an application +> | (LR'Shift{} : _) <- catch_acts +> = LR'Fail +> | (LR'Multiple _ LR'Shift{} : _) <- catch_acts +> = LR'Fail > -> -- no error actions, pick a reduce to be the default. -> _ -> case reduces of -> [] -> LR'Fail -> (act:_) -> act -- pick the first one we see for now +> | otherwise +> -- no error or catch actions, pick a reduce to be the default. +> = case reduces of +> _ -> case reduces of +> [] -> LR'Fail +> (act:_) -> act -- pick the first one we see for now > -> where reduces +> where +> error_acts = [ act | (e, act) <- actions, e == errorTok ] +> catch_acts = [ act | (e, act) <- actions, e == catchTok ] +> reduces > = [ act | (_, act@(LR'Reduce _ _)) <- actions ] > ++ [ act | (_, LR'Multiple _ act@(LR'Reduce _ _)) <- actions ] @@ -874,7 +921,6 @@ See notes under "Action Tables" above for some subtleties in this function. -- happyCheck -- Indicates whether we should use the default action for state - -- the table is laid out such that the action for a given state & token -- can be found by: -- @@ -901,36 +947,37 @@ See notes under "Action Tables" above for some subtleties in this function. -- try to fit the actions into the check table, using the ordering -- from above. +SG: If you want to know more about similar compression schemes, consult + Storing a Sparse Table (https://dl.acm.org/doi/10.1145/359168.359175) +One can think of the mapping @\(state,token) -> (offs ! state)+token@ as a hash +and @check@ as the way to detect "collisions" (i.e., default entries). > mkTables -> :: ActionTable -> GotoTable -> Name -> Name -> Int -> Int -> Int -> (Name, Name) -> +> :: ActionTable -> GotoTable -> Name -> Name -> Int -> Int -> Int -> > ( [Int] -- happyActOffsets > , [Int] -- happyGotoOffsets > , [Int] -- happyTable > , [Int] -- happyDefAction > , [Int] -- happyCheck -> , [Int] -- happyExpList -> , Int -- happyMinOffset +> , [Int] -- happyCatchStates > ) > > mkTables action goto first_nonterm' fst_term > n_terminals n_nonterminals n_starts -> token_names_bound > > = ( elems act_offs > , elems goto_offs > , take max_off (elems table) > , def_actions > , take max_off (elems check) -> , elems explist -> , min_off +> , shifted_catch_states > ) > where > -> (table,check,act_offs,goto_offs,explist,min_off,max_off) +> (table,check,act_offs,goto_offs,max_off) > = runST (genTables (length actions) -> max_token token_names_bound -> sorted_actions explist_actions) +> max_token +> sorted_actions) > > -- the maximum token number used in the parser > max_token = max n_terminals (n_starts+n_nonterminals) - 1 @@ -947,25 +994,25 @@ See notes under "Action Tables" above for some subtleties in this function. > length acts'', > acts'') > | (state, acts) <- assocs action, -> let (err:_dummy:vec) = assocs acts +> let (err:catch:_dummy:vec) = assocs acts > vec' = drop (n_starts+n_nonterminals) vec -> acts' = filter notFail (err:vec') +> acts' = filter notFail (err:catch:vec') > default_act = getDefault acts' > acts'' = mkActVals acts' default_act > ] > -> explist_actions :: [(Int, [Int])] -> explist_actions = [ (state, concatMap f $ assocs acts) -> | (state, acts) <- assocs action ] -> where -> f (t, LR'Shift _ _ ) = [getName t - getName (fst token_names_bound)] -> f (_, _) = [] +> shifted_catch_states :: [Int] +> shifted_catch_states = -- collect the states in which we have just shifted a catchTok +> nub [ to_state | (_from_state, acts) <- assocs action +> , let (_err:catch:_) = assocs acts +> , (_tok, LR'Shift to_state _) <- return catch ] > -> -- adjust terminals by -(fst_term+1), so they start at 1 (error is 0). +> -- adjust terminals by -(fst_term+2), so they start at 2 (error is 0, catch is 1). > -- (see ARRAY_NOTES) > adjust :: Name -> Int > adjust token | token == errorTok = 0 -> | otherwise = getName token - getName fst_term + 1 +> | token == catchTok = 1 +> | otherwise = getName token - getName fst_term + 2 > > mkActVals :: [(Name, LRAction)] -> LRAction -> [(Int, Int)] > mkActVals assocs' default_act = @@ -1008,42 +1055,34 @@ See notes under "Action Tables" above for some subtleties in this function. > genTables > :: Int -- number of actions > -> Int -- maximum token no. -> -> (Name, Name) -- token names bounds > -> [TableEntry] -- entries for the table -> -> [(Int, [Int])] -- expected tokens lists > -> ST s ( UArray Int Int -- table > , UArray Int Int -- check > , UArray Int Int -- action offsets > , UArray Int Int -- goto offsets -> , UArray Int Int -- expected tokens list -> , Int -- lowest offset in table > , Int -- highest offset in table > ) > -> genTables n_actions max_token token_names_bound entries explist = do +> genTables n_actions max_token entries = do > > table <- newArray (0, mAX_TABLE_SIZE) 0 > check <- newArray (0, mAX_TABLE_SIZE) (-1) > act_offs <- newArray (0, n_actions) 0 > goto_offs <- newArray (0, n_actions) 0 > off_arr <- newArray (-max_token, mAX_TABLE_SIZE) 0 -> exp_array <- newArray (0, (n_actions * n_token_names + 31) `div` 32) 0 -- 32 bits per entry > -> (min_off,max_off) <- genTables' table check act_offs goto_offs off_arr exp_array entries -> explist max_token n_token_names +> max_off <- genTables' table check act_offs goto_offs off_arr entries +> max_token > > table' <- freeze table > check' <- freeze check > act_offs' <- freeze act_offs > goto_offs' <- freeze goto_offs -> exp_array' <- freeze exp_array -> return (table',check',act_offs',goto_offs',exp_array',min_off,max_off+1) +> return (table',check',act_offs',goto_offs',max_off+1) > where > n_states = n_actions - 1 > mAX_TABLE_SIZE = n_states * (max_token + 1) -> (first_token, last') = token_names_bound -> n_token_names = getName last' - getName first_token + 1 > genTables' @@ -1052,33 +1091,21 @@ See notes under "Action Tables" above for some subtleties in this function. > -> STUArray s Int Int -- action offsets > -> STUArray s Int Int -- goto offsets > -> STUArray s Int Int -- offset array -> -> STUArray s Int Int -- expected token list > -> [TableEntry] -- entries for the table -> -> [(Int, [Int])] -- expected tokens lists > -> Int -- maximum token no. -> -> Int -- number of token names -> -> ST s (Int,Int) -- lowest and highest offsets in table +> -> ST s Int -- highest offsets in table > -> genTables' table check act_offs goto_offs off_arr exp_array entries -> explist max_token n_token_names -> = fill_exp_array >> fit_all entries 0 0 1 +> genTables' table check act_offs goto_offs off_arr entries +> max_token +> = fit_all entries 0 1 > where > -> fit_all [] min_off max_off _ = return (min_off, max_off) -> fit_all (s:ss) min_off max_off fst_zero = do -> (off, new_min_off, new_max_off, new_fst_zero) <- fit s min_off max_off fst_zero +> fit_all [] max_off _ = return max_off +> fit_all (s:ss) max_off fst_zero = do +> (off, new_max_off, new_fst_zero) <- fit s max_off fst_zero > ss' <- same_states s ss off > writeArray off_arr off 1 -> fit_all ss' new_min_off new_max_off new_fst_zero -> -> fill_exp_array = -> forM_ explist $ \(state, tokens) -> -> forM_ tokens $ \token -> do -> let bit_nr = state * n_token_names + token -> let word_nr = bit_nr `div` 32 -> let word_offset = bit_nr `mod` 32 -> x <- readArray exp_array word_nr -> writeArray exp_array word_nr (setBit x word_offset) +> fit_all ss' new_max_off new_fst_zero > > -- try to merge identical states. We only try the next state(s) > -- in the list, but the list is kind-of sorted so we shouldn't @@ -1095,19 +1122,16 @@ See notes under "Action Tables" above for some subtleties in this function. > -- fit a vector into the table. Return the offset of the vector, > -- the maximum offset used in the table, and the offset of the first > -- entry in the table (used to speed up the lookups a bit). -> fit (_,_,_,_,_,[]) min_off max_off fst_zero = return (0,min_off,max_off,fst_zero) +> fit (_,_,_,_,_,[]) max_off fst_zero = return (0,max_off,fst_zero) > > fit (act_or_goto, state_no, _deflt, _, _, state@((t,_):_)) -> min_off max_off fst_zero = do +> max_off fst_zero = do > -- start at offset 1 in the table: all the empty states > -- (states with just a default reduction) are mapped to > -- offset zero. > off <- findFreeOffset (-t+fst_zero) check off_arr state -> let new_min_off | furthest_left < min_off = furthest_left -> | otherwise = min_off -> new_max_off | furthest_right > max_off = furthest_right +> let new_max_off | furthest_right > max_off = furthest_right > | otherwise = max_off -> furthest_left = off > furthest_right = off + max_token > > -- trace ("fit: state " ++ show state_no ++ ", off " ++ show off ++ ", elems " ++ show state) $ do @@ -1115,7 +1139,7 @@ See notes under "Action Tables" above for some subtleties in this function. > writeArray (which_off act_or_goto) state_no off > addState off table check state > new_fst_zero <- findFstFreeSlot check fst_zero -> return (off, new_min_off, new_max_off, new_fst_zero) +> return (off, new_max_off, new_fst_zero) When looking for a free offset in the table, we use the 'check' table rather than the main table. The check table starts off with (-1) in @@ -1239,13 +1263,6 @@ slot is free or not. > hexChars :: [Int] -> String -> String > hexChars is s = foldr (hexChar . toInt32) s is -The following function is used for generating happyExpList, which is an array of -bits encoded as [Int] for legacy reasons; we don't want to check for overflow -here. - -> hexCharsForBits :: [Int] -> String -> String -> hexCharsForBits is s = foldr (hexChar . fromIntegral) s is - The following definition of @hexChar@ chooses a little endian encoding for `Int32` . Ergo, the compiled parser must use the same endianness when decoding array entries. On big endian architectures, this means users will have to compile with `WORDS_BIGENDIAN`, diff --git a/lib/data/HappyTemplate.hs b/lib/data/HappyTemplate.hs index 2d20f21f..7e7837c2 100644 --- a/lib/data/HappyTemplate.hs +++ b/lib/data/HappyTemplate.hs @@ -8,15 +8,9 @@ #include "MachDeps.h" -- Do not remove this comment. Required to fix CPP parsing when using GCC and a clang-compiled alex. -#if __GLASGOW_HASKELL__ > 706 -# define LT(n,m) ((Happy_GHC_Exts.tagToEnum# (n Happy_GHC_Exts.<# m)) :: Prelude.Bool) -# define GTE(n,m) ((Happy_GHC_Exts.tagToEnum# (n Happy_GHC_Exts.>=# m)) :: Prelude.Bool) -# define EQ(n,m) ((Happy_GHC_Exts.tagToEnum# (n Happy_GHC_Exts.==# m)) :: Prelude.Bool) -#else -# define LT(n,m) (n Happy_GHC_Exts.<# m) -# define GTE(n,m) (n Happy_GHC_Exts.>=# m) -# define EQ(n,m) (n Happy_GHC_Exts.==# m) -#endif +#define LT(n,m) ((Happy_GHC_Exts.tagToEnum# (n Happy_GHC_Exts.<# m)) :: Prelude.Bool) +#define GTE(n,m) ((Happy_GHC_Exts.tagToEnum# (n Happy_GHC_Exts.>=# m)) :: Prelude.Bool) +#define EQ(n,m) ((Happy_GHC_Exts.tagToEnum# (n Happy_GHC_Exts.==# m)) :: Prelude.Bool) #define PLUS(n,m) (n Happy_GHC_Exts.+# m) #define MINUS(n,m) (n Happy_GHC_Exts.-# m) #define TIMES(n,m) (n Happy_GHC_Exts.*# m) @@ -26,6 +20,7 @@ type Happy_Int = Happy_GHC_Exts.Int# data Happy_IntList = HappyCons Happy_Int Happy_IntList #define ERROR_TOK 0# +#define CATCH_TOK 1# #if defined(HAPPY_COERCE) # define GET_ERROR_TOKEN(x) (case Happy_GHC_Exts.unsafeCoerce# x of { (Happy_GHC_Exts.I# i) -> i }) @@ -74,7 +69,7 @@ happyDoAction i tk st = ",\taction: ") case happyDecodeAction (happyNextAction i st) of HappyFail -> DEBUG_TRACE("failing.\n") - happyFail (happyExpListPerState (Happy_GHC_Exts.I# st)) i tk st + happyFail i tk st HappyAccept -> DEBUG_TRACE("accept.\n") happyAccept i tk st HappyReduce rule -> DEBUG_TRACE("reduce (rule " ++ show (Happy_GHC_Exts.I# rule) ++ ")") @@ -89,7 +84,10 @@ happyNextAction i st = case happyIndexActionTable i st of {-# INLINE happyIndexActionTable #-} happyIndexActionTable i st - | GTE(off, 0#), EQ(happyIndexOffAddr happyCheck off, i) + | GTE(i, 0#), GTE(off, 0#), EQ(happyIndexOffAddr happyCheck off, i) + -- i >= 0: Guard against INVALID_TOK (do the default action, which ultimately errors) + -- off >= 0: Otherwise it's a default action + -- equality check: Ensure that the entry in the compressed array is owned by st = Prelude.Just (Happy_GHC_Exts.I# (happyIndexOffAddr happyTable off)) | otherwise = Prelude.Nothing @@ -101,6 +99,7 @@ data HappyAction | HappyAccept | HappyReduce Happy_Int -- rule number | HappyShift Happy_Int -- new state + deriving Show {-# INLINE happyDecodeAction #-} happyDecodeAction :: Happy_Int -> HappyAction @@ -129,12 +128,13 @@ happyIndexOffAddr (HappyA# arr) off = ))))) #endif -{-# INLINE happyLt #-} -happyLt x y = LT(x,y) - -readArrayBit arr bit = - Bits.testBit (Happy_GHC_Exts.I# (happyIndexOffAddr arr ((unbox_int bit) `Happy_GHC_Exts.iShiftRA#` 5#))) (bit `Prelude.mod` 32) - where unbox_int (Happy_GHC_Exts.I# x) = x +happyIndexRuleArr :: Happy_Int -> (# Happy_Int, Happy_Int #) +happyIndexRuleArr r = (# nt, len #) + where + !(Happy_GHC_Exts.I# n_starts) = happy_n_starts + offs = TIMES(MINUS(r,n_starts),2#) + nt = happyIndexOffAddr happyRuleArr offs + len = happyIndexOffAddr happyRuleArr PLUS(offs,1#) data HappyAddr = HappyA# Happy_GHC_Exts.Addr# @@ -142,8 +142,9 @@ data HappyAddr = HappyA# Happy_GHC_Exts.Addr# -- Shifting a token happyShift new_state ERROR_TOK tk st sts stk@(x `HappyStk` _) = + -- See "Error Fixup" below let i = GET_ERROR_TOKEN(x) in --- trace "shifting the error token" $ + DEBUG_TRACE("shifting the error token") happyDoAction i tk new_state (HappyCons st sts) stk happyShift new_state i tk st sts stk = @@ -151,62 +152,48 @@ happyShift new_state i tk st sts stk = -- happyReduce is specialised for the common cases. -happySpecReduce_0 i fn ERROR_TOK tk st sts stk - = happyFail [] ERROR_TOK tk st sts stk happySpecReduce_0 nt fn j tk st sts stk - = happyGoto nt j tk st (HappyCons st sts) (fn `HappyStk` stk) + = happySeq fn (happyGoto nt j tk st (HappyCons st sts) (fn `HappyStk` stk)) -happySpecReduce_1 i fn ERROR_TOK tk st sts stk - = happyFail [] ERROR_TOK tk st sts stk -happySpecReduce_1 nt fn j tk _ sts@(HappyCons st _) (v1 `HappyStk` stk') +happySpecReduce_1 nt fn j tk old_st sts@(HappyCons st _) (v1 `HappyStk` stk') = let r = fn v1 in - happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk')) + happyTcHack old_st (happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk'))) -happySpecReduce_2 i fn ERROR_TOK tk st sts stk - = happyFail [] ERROR_TOK tk st sts stk -happySpecReduce_2 nt fn j tk _ +happySpecReduce_2 nt fn j tk old_st (HappyCons _ sts@(HappyCons st _)) (v1 `HappyStk` v2 `HappyStk` stk') = let r = fn v1 v2 in - happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk')) + happyTcHack old_st (happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk'))) -happySpecReduce_3 i fn ERROR_TOK tk st sts stk - = happyFail [] ERROR_TOK tk st sts stk -happySpecReduce_3 nt fn j tk _ +happySpecReduce_3 nt fn j tk old_st (HappyCons _ (HappyCons _ sts@(HappyCons st _))) (v1 `HappyStk` v2 `HappyStk` v3 `HappyStk` stk') = let r = fn v1 v2 v3 in - happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk')) + happyTcHack old_st (happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk'))) -happyReduce k i fn ERROR_TOK tk st sts stk - = happyFail [] ERROR_TOK tk st sts stk happyReduce k nt fn j tk st sts stk = case happyDrop MINUS(k,(1# :: Happy_Int)) sts of sts1@(HappyCons st1 _) -> let r = fn stk in -- it doesn't hurt to always seq here... - happyDoSeq r (happyGoto nt j tk st1 sts1 r) + st `happyTcHack` happyDoSeq r (happyGoto nt j tk st1 sts1 r) -happyMonadReduce k nt fn ERROR_TOK tk st sts stk - = happyFail [] ERROR_TOK tk st sts stk happyMonadReduce k nt fn j tk st sts stk = case happyDrop k (HappyCons st sts) of sts1@(HappyCons st1 _) -> let drop_stk = happyDropStk k stk in - happyThen1 (fn stk tk) - (\r -> happyGoto nt j tk st1 sts1 (r `HappyStk` drop_stk)) + j `happyTcHack` happyThen1 (fn stk tk) + (\r -> happyGoto nt j tk st1 sts1 (r `HappyStk` drop_stk)) -happyMonad2Reduce k nt fn ERROR_TOK tk st sts stk - = happyFail [] ERROR_TOK tk st sts stk happyMonad2Reduce k nt fn j tk st sts stk = case happyDrop k (HappyCons st sts) of sts1@(HappyCons st1 _) -> let drop_stk = happyDropStk k stk - off = happyAdjustOffset (happyIndexOffAddr happyGotoOffsets st1) + off = happyIndexOffAddr happyGotoOffsets st1 off_i = PLUS(off, nt) new_state = happyIndexOffAddr happyTable off_i in - happyThen1 (fn stk tk) - (\r -> happyNewToken new_state sts1 (r `HappyStk` drop_stk)) + j `happyTcHack` happyThen1 (fn stk tk) + (\r -> happyNewToken new_state sts1 (r `HappyStk` drop_stk)) happyDrop 0# l = l happyDrop n (HappyCons _ t) = happyDrop MINUS(n,(1# :: Happy_Int)) t @@ -222,31 +209,263 @@ happyGoto nt j tk st = happyDoAction j tk new_state where new_state = happyIndexGotoTable nt st ------------------------------------------------------------------------------ --- Error recovery (ERROR_TOK is the error token) - --- parse error if we are in recovery and we fail again -happyFail explist ERROR_TOK tk old_st _ stk@(x `HappyStk` _) = - let i = GET_ERROR_TOKEN(x) in --- trace "failing" $ - happyError_ explist i tk - -{- We don't need state discarding for our restricted implementation of - "error". In fact, it can cause some bogus parses, so I've disabled it - for now --SDM - --- discard a state -happyFail ERROR_TOK tk old_st (HappyCons action sts) - (saved_tok `HappyStk` _ `HappyStk` stk) = --- trace ("discarding state, depth " ++ show (length stk)) $ - happyDoAction ERROR_TOK tk action sts (saved_tok`HappyStk`stk) +{- Note [Error recovery] +~~~~~~~~~~~~~~~~~~~~~~~~ +When there is no applicable action for the current lookahead token `tk`, +happy enters error recovery mode. Depending on whether the grammar file +declares the two action form `%error { abort } { report }` for + Resumptive Error Handling, +it works in one (not resumptive) or two phases (resumptive): + + 1. Fixup mode: + Try to see if there is an action for the error token ERROR_TOK. If there + is, do *not* emit an error and pretend instead that an `error` token was + inserted. + When there is no ERROR_TOK action, report an error. + + In non-resumptive error handling, calling the single error handler + (e.g. `happyError`) will throw an exception and abort the parser. + However, in resumptive error handling we enter *error resumption mode*. + + 2. Error resumption mode: + After reporting the error (with `report`), happy will attempt to find + a good state stack to resume parsing in. + For each candidate stack, it discards input until one of the candidates + resumes (i.e. shifts the current input). + If no candidate resumes before the end of input, resumption failed and + calls the `abort` function, to much the same effect as in non-resumptive + error handling. + + Candidate stacks are declared by the grammar author using the special + `catch` terminal and called "catch frames". + This mechanism is described in detail in Note [happyResume]. + +The `catch` resumption mechanism (2) is what usually is associated with +`error` in `bison` or `menhir`. Since `error` is used for the Fixup mechanism +(1) above, we call the corresponding token `catch`. +Furthermore, in constrast to `bison`, our implementation of `catch` +non-deterministically considers multiple catch frames on the stack for +resumption (See Note [Multiple catch frames]). + +Note [happyResume] +~~~~~~~~~~~~~~~~~~ +`happyResume` implements the resumption mechanism from Note [Error recovery]. +It is best understood by example. Consider + +Exp :: { String } +Exp : '1' { "1" } + | catch { "catch" } + | Exp '+' Exp %shift { $1 ++ " + " ++ $3 } -- %shift: associate 1 + 1 + 1 to the right + | '(' Exp ')' { "(" ++ $2 ++ ")" } + +The idea of the use of `catch` here is that upon encountering a parse error +during expression parsing, we can gracefully degrade using the `catch` rule, +still producing a partial syntax tree and keep on parsing to find further +syntax errors. + +Let's trace the parser state for input 11+1, which will error out after shifting 1. +After shifting, we have the following item stack (growing downwards and omitting +transitive closure items): + + State 0: %start_parseExp -> . Exp + State 5: Exp -> '1' . + +(Stack as a list of state numbers: [5,0].) +As Note [Error recovery] describes, we will first try Fixup mode. +That fails because no production can shift the `error` token. +Next we try Error resumption mode. This works as follows: + + 1. Pop off the item stack until we find an item that can shift the `catch` + token. (Implemented in `pop_items`.) + * State 5 cannot shift catch. Pop. + * State 0 can shift catch, which would transition into + State 4: Exp -> catch . + So record the *stack* `[4,0]` after doing the shift transition. + We call this a *catch frame*, where the top is a *catch state*, + corresponding to an item in which we just shifted a `catch` token. + There can be multiple such catch stacks, see Note [Multiple catch frames]. + + 2. Discard tokens from the input until the lookahead can be shifted in one + of the catch stacks. (Implemented in `discard_input_until_exp` and + `some_catch_state_shifts`.) + * We cannot shift the current lookahead '1' in state 4, so we discard + * We *can* shift the next lookahead '+' in state 4, but only after + reducing, which pops State 4 and goes to State 3: + State 3: %start_parseExp -> Exp . + Exp -> Exp . '+' Exp + Here we can shift '+'. + As you can see, to implement this machinery we need to simulate + the operation of the LALR automaton, especially reduction + (`happySimulateReduce`). + +Note [Multiple catch frames] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +For fewer spurious error messages, it can be beneficial to trace multiple catch +items. Consider + +Exp : '1' + | catch + | Exp '+' Exp %shift + | '(' Exp ')' + +Let's trace the parser state for input (;+1, which will error out after shifting (. +After shifting, we have the following item stack (growing downwards): + + State 0: %start_parseExp -> . Exp + State 6: Exp -> '(' . Exp ')' + +Upon error, we want to find items in the stack which can shift a catch token. +Note that both State 0 and State 6 can shift a catch token, transitioning into + State 4: Exp -> catch . +Hence we record the catch frames `[4,6,0]` and `[4,0]` for possible resumption. + +Which catch frame do we pick for resumption? +Note that resuming catch frame `[4,0]` will parse as "catch+1", whereas +resuming the innermost frame `[4,6,0]` corresponds to parsing "(catch+1". +The latter would keep discarding input until the closing ')' is found. +So we will discard + and 1, leading to a spurious syntax error at the end of +input, aborting the parse and never producing a partial syntax tree. Bad! + +It is far preferable to resume with catch frame `[4,0]`, where we can resume +successfully on input +, so that is what we do. + +In general, we pick the catch frame for resumption that discards the least +amount of input for a successful shift, preferring the topmost such catch frame. -} --- Enter error recovery: generate an error token, --- save the old token and carry on. -happyFail explist i tk action sts stk = --- trace "entering error recovery" $ - happyDoAction ERROR_TOK tk action sts (MK_ERROR_TOKEN(i) `HappyStk` stk) +-- happyFail :: Happy_Int -> _ -> Happy_Int -> _ +-- This function triggers Note [Error recovery]. +-- If the current token is ERROR_TOK, phase (1) has failed and we might try +-- phase (2). +happyFail ERROR_TOK = happyFixupFailed +happyFail i = happyTryFixup i + +-- Enter Error Fixup (see Note [Error recovery]): +-- generate an error token, save the old token and carry on. +-- When a `happyShift` accepts the error token, we will pop off the error token +-- to resume parsing with the current lookahead `i`. +happyTryFixup i tk action sts stk = + DEBUG_TRACE("entering `error` fixup.\n") + happyDoAction ERROR_TOK tk action sts (MK_ERROR_TOKEN(i) `HappyStk` stk) + -- NB: `happyShift` will simply pop the error token and carry on with + -- `tk`. Hence we don't change `tk` in the call here + +-- See Note [Error recovery], phase (2). +-- Enter resumption mode after reporting the error by calling `happyResume`. +happyFixupFailed tk st sts (x `HappyStk` stk) = + let i = GET_ERROR_TOKEN(x) in + DEBUG_TRACE("`error` fixup failed.\n") + let resume = happyResume i tk st sts stk + expected = happyExpectedTokens st sts in + happyReport i tk expected resume + +-- happyResume :: Happy_Int -> _ -> Happy_Int -> _ +-- See Note [happyResume] +happyResume i tk st sts stk = pop_items [] st sts stk + where + !(Happy_GHC_Exts.I# n_starts) = happy_n_starts -- this is to test whether we have a start token + !(Happy_GHC_Exts.I# eof_i) = happy_n_terms - 1 -- this is the token number of the EOF token + happy_list_to_list :: Happy_IntList -> [Int] + happy_list_to_list (HappyCons st sts) + | LT(st, n_starts) + = [(Happy_GHC_Exts.I# st)] + | otherwise + = (Happy_GHC_Exts.I# st) : happy_list_to_list sts + + -- See (1) of Note [happyResume] + pop_items catch_frames st sts stk + | LT(st, n_starts) + = DEBUG_TRACE("reached start state " ++ show (Happy_GHC_Exts.I# st) ++ ", ") + if null catch_frames_new + then DEBUG_TRACE("no resumption.\n") + happyAbort + else DEBUG_TRACE("now discard input, trying to anchor in states (reverse " ++ show (map (happy_list_to_list . fst) catch_frames_new) ++ ").\n") + discard_input_until_exp i tk (reverse catch_frames_new) + | (HappyCons st1 sts1) <- sts, _ `HappyStk` stk1 <- stk + = pop_items catch_frames_new st1 sts1 stk1 + where + !catch_frames_new + | HappyShift new_state <- happyDecodeAction (happyNextAction CATCH_TOK st) + , DEBUG_TRACE("can shift catch token in state " ++ show (Happy_GHC_Exts.I# st) ++ ", into state " ++ show (Happy_GHC_Exts.I# new_state) ++ "\n") + null (filter (\(HappyCons _ (HappyCons h _),_) -> EQ(st,h)) catch_frames) + = (HappyCons new_state (HappyCons st sts), MK_ERROR_TOKEN(i) `HappyStk` stk):catch_frames -- MK_ERROR_TOKEN(i) is just some dummy that should not be accessed by user code + | otherwise + = DEBUG_TRACE("already shifted or can't shift catch in " ++ show (Happy_GHC_Exts.I# st) ++ "\n") + catch_frames + + -- See (2) of Note [happyResume] + discard_input_until_exp i tk catch_frames + | Just (HappyCons st (HappyCons catch_st sts), catch_frame) <- some_catch_state_shifts i catch_frames + = DEBUG_TRACE("found expected token in state " ++ show (Happy_GHC_Exts.I# st) ++ " after shifting from " ++ show (Happy_GHC_Exts.I# catch_st) ++ ": " ++ show (Happy_GHC_Exts.I# i) ++ "\n") + happyDoAction i tk st (HappyCons catch_st sts) catch_frame + | EQ(i,eof_i) -- is i EOF? + = DEBUG_TRACE("reached EOF, cannot resume. abort parse :(\n") + happyAbort + | otherwise + = DEBUG_TRACE("discard token " ++ show (Happy_GHC_Exts.I# i) ++ "\n") + happyLex (\eof_tk -> discard_input_until_exp eof_i eof_tk catch_frames) -- eof + (\i tk -> discard_input_until_exp i tk catch_frames) -- not eof + + some_catch_state_shifts _ [] = DEBUG_TRACE("no catch state could shift.\n") Nothing + some_catch_state_shifts i catch_frames@(((HappyCons st sts),_):_) = try_head i st sts catch_frames + where + try_head i st sts catch_frames = -- PRECONDITION: head catch_frames = (HappyCons st sts) + DEBUG_TRACE("trying token " ++ show (Happy_GHC_Exts.I# i) ++ " in state " ++ show (Happy_GHC_Exts.I# st) ++ ": ") + case happyDecodeAction (happyNextAction i st) of + HappyFail -> DEBUG_TRACE("fail.\n") some_catch_state_shifts i (tail catch_frames) + HappyAccept -> DEBUG_TRACE("accept.\n") Just (head catch_frames) + HappyShift _ -> DEBUG_TRACE("shift.\n") Just (head catch_frames) + HappyReduce r -> case happySimulateReduce r st sts of + (HappyCons st1 sts1) -> try_head i st1 sts1 catch_frames + +happySimulateReduce r st sts = + DEBUG_TRACE("simulate reduction of rule " ++ show (Happy_GHC_Exts.I# r) ++ ", ") + let (# nt, len #) = happyIndexRuleArr r in + DEBUG_TRACE("nt " ++ show (Happy_GHC_Exts.I# nt) ++ ", len: " ++ show (Happy_GHC_Exts.I# len) ++ ", new_st ") + let !(sts1@(HappyCons st1 _)) = happyDrop len (HappyCons st sts) + new_st = happyIndexGotoTable nt st1 in + DEBUG_TRACE(show (Happy_GHC_Exts.I# new_st) ++ ".\n") + (HappyCons new_st sts1) + +happyTokenToString :: Prelude.Int -> Prelude.String +happyTokenToString i = happyTokenStrings Prelude.!! (i Prelude.- 2) -- 2: errorTok, catchTok + +happyExpectedTokens :: Happy_Int -> Happy_IntList -> [Prelude.String] +-- Upon a parse error, we want to suggest tokens that are expected in that +-- situation. This function computes such tokens. +-- It works by examining the top of the state stack. +-- For every token number that does a shift transition, record that token number. +-- For every token number that does a reduce transition, simulate that reduction +-- on the state state stack and repeat. +-- The recorded token numbers are then formatted with 'happyTokenToString' and +-- returned. +happyExpectedTokens st sts = + DEBUG_TRACE("constructing expected tokens.\n") + map happyTokenToString $ search_shifts st sts [] + where + search_shifts st sts shifts = foldr (add_action st sts) shifts (distinct_actions st) + add_action st sts (Happy_GHC_Exts.I# i, Happy_GHC_Exts.I# act) shifts = + DEBUG_TRACE("found action in state " ++ show (Happy_GHC_Exts.I# st) ++ ", input " ++ show (Happy_GHC_Exts.I# i) ++ ", " ++ show (happyDecodeAction act) ++ "\n") + case happyDecodeAction act of + HappyFail -> shifts + HappyAccept -> shifts -- This would always be %eof or error... Not helpful + HappyShift _ -> Happy_Data_List.insert (Happy_GHC_Exts.I# i) shifts + HappyReduce r -> case happySimulateReduce r st sts of + (HappyCons st1 sts1) -> search_shifts st1 sts1 shifts + distinct_actions st + -- The (token number, action) pairs of all actions in the given state + = ((-1), (Happy_GHC_Exts.I# (happyIndexOffAddr happyDefActions st))) + : [ (i, act) | i <- [begin_i..happy_n_terms], act <- get_act row_off i ] + where + row_off = happyIndexOffAddr happyActOffsets st + begin_i = 2 -- +2: errorTok,catchTok + get_act off (Happy_GHC_Exts.I# i) -- happyIndexActionTable with cached row offset + | let off_i = PLUS(off,i) + , GTE(off_i,0#) + , EQ(happyIndexOffAddr happyCheck off_i,i) + = [(Happy_GHC_Exts.I# (happyIndexOffAddr happyTable off_i))] + | otherwise + = [] -- Internal happy errors: diff --git a/lib/frontend/boot-src/Parser.ly b/lib/frontend/boot-src/Parser.ly index b193ae52..69880a9e 100644 --- a/lib/frontend/boot-src/Parser.ly +++ b/lib/frontend/boot-src/Parser.ly @@ -33,7 +33,7 @@ The parser. > spec_shift { TokenKW TokSpecId_Shift } > spec_expect { TokenKW TokSpecId_Expect } > spec_error { TokenKW TokSpecId_Error } -> spec_errorhandlertype { TokenKW TokSpecId_ErrorHandlerType } +> spec_errorexpected { TokenKW TokSpecId_ErrorExpected } > spec_attribute { TokenKW TokSpecId_Attribute } > spec_attributetype { TokenKW TokSpecId_Attributetype } > code { TokenInfo $$ TokCodeQuote } @@ -104,11 +104,11 @@ The parser. > | spec_shift { PrecShift } > | { PrecNone } -> tokInfos :: { [Directive String] } +> tokInfos :: { [Directive String] } > : tokInfos tokInfo { $2 : $1 } > | tokInfo { [$1] } -> tokInfo :: { Directive String } +> tokInfo :: { Directive String } > : spec_tokentype code { TokenType $2 } > | spec_token tokenSpecs { TokenSpec $2 } > | spec_name id optStart { TokenName $2 $3 False } @@ -123,8 +123,8 @@ The parser. > | spec_right ids { TokenRight $2 } > | spec_left ids { TokenLeft $2 } > | spec_expect int { TokenExpect $2 } -> | spec_error code { TokenError $2 } -> | spec_errorhandlertype id { TokenErrorHandlerType $2 } +> | spec_error code optCode { TokenError $2 $3 } +> | spec_errorexpected { TokenErrorExpected } > | spec_attributetype code { TokenAttributetype $2 } > | spec_attribute id code { TokenAttribute $2 $3 } diff --git a/lib/frontend/src/Happy/Frontend/AbsSyn.lhs b/lib/frontend/src/Happy/Frontend/AbsSyn.lhs index a730ac48..f842a83e 100644 --- a/lib/frontend/src/Happy/Frontend/AbsSyn.lhs +++ b/lib/frontend/src/Happy/Frontend/AbsSyn.lhs @@ -10,8 +10,8 @@ Here is the abstract syntax of the language we parse. > BookendedAbsSyn(..), > AbsSyn(..), Directive(..), > getTokenType, getTokenSpec, getParserNames, getLexer, -> getImportedIdentity, getMonad, getError, -> getPrios, getPrioNames, getExpect, getErrorHandlerType, +> getImportedIdentity, getMonad, ErrorHandlerInfo(..), getError, +> getPrios, getPrioNames, getExpect, getErrorHandlerExpectedList, > getAttributes, getAttributetype, getAttributeGrammarExtras, > parseTokenSpec, > Rule(..), Prod(..), Term(..), Prec(..), @@ -20,7 +20,7 @@ Here is the abstract syntax of the language we parse. > import Data.Char (isAlphaNum) > import Happy.Grammar -> ( ErrorHandlerType(..) +> ( ErrorHandlerInfo(..) > , TokenSpec(..) > , AttributeGrammarExtras(..) > ) @@ -74,17 +74,17 @@ generate some error messages. > | TokenSpec [(a, TokenSpec)] -- %token > | TokenName String (Maybe String) Bool -- %name/%partial (True <=> %partial) > | TokenLexer String String -- %lexer -> | TokenErrorHandlerType String -- %errorhandlertype > | TokenImportedIdentity -- %importedidentity > | TokenMonad String String String String -- %monad > | TokenNonassoc [String] -- %nonassoc > | TokenRight [String] -- %right > | TokenLeft [String] -- %left > | TokenExpect Int -- %expect -> | TokenError String -- %error +> | TokenError String (Maybe String) -- %error +> | TokenErrorExpected -- %error.expected > | TokenAttributetype String -- %attributetype > | TokenAttribute String String -- %attribute -> deriving Show +> deriving (Eq, Show) > getTokenType :: [Directive t] -> String > getTokenType ds @@ -142,22 +142,17 @@ generate some error messages. > [] -> Nothing > _ -> error "multiple expect directives" -> getError :: [Directive t] -> Maybe String +> getError :: [Directive t] -> ErrorHandlerInfo > getError ds -> = case [ a | (TokenError a) <- ds ] of -> [t] -> Just t -> [] -> Nothing +> = case [ (a, mb_b) | (TokenError a mb_b) <- ds ] of +> [] -> DefaultErrorHandler +> [(a,Nothing)] -> CustomErrorHandler a +> [(abort,Just addMessage)] -> ResumptiveErrorHandler abort addMessage > _ -> error "multiple error directives" -> getErrorHandlerType :: [Directive t] -> ErrorHandlerType -> getErrorHandlerType ds -> = case [ a | (TokenErrorHandlerType a) <- ds ] of -> [t] -> case t of -> "explist" -> ErrorHandlerTypeExpList -> "default" -> ErrorHandlerTypeDefault -> _ -> error "unsupported %errorhandlertype value" -> [] -> ErrorHandlerTypeDefault -> _ -> error "multiple errorhandlertype directives" +> getErrorHandlerExpectedList :: Eq t => [Directive t] -> Bool +> getErrorHandlerExpectedList ds +> = TokenErrorExpected `elem` ds > getAttributes :: [Directive t] -> [(String, String)] > getAttributes ds diff --git a/lib/frontend/src/Happy/Frontend/AttrGrammar/Parser.hs b/lib/frontend/src/Happy/Frontend/AttrGrammar/Parser.hs index 437fd960..b1ec1d74 100644 --- a/lib/frontend/src/Happy/Frontend/AttrGrammar/Parser.hs +++ b/lib/frontend/src/Happy/Frontend/AttrGrammar/Parser.hs @@ -1,7 +1,15 @@ {-# OPTIONS_GHC -w #-} -{-# OPTIONS -XMagicHash -XBangPatterns -XTypeSynonymInstances -XFlexibleInstances -cpp #-} +{-# LANGUAGE CPP #-} +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE BangPatterns #-} +{-# LANGUAGE TypeSynonymInstances #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE PatternGuards #-} +{-# LANGUAGE NoStrictData #-} +{-# LANGUAGE UnboxedTuples #-} +{-# LANGUAGE PartialTypeSignatures #-} #if __GLASGOW_HASKELL__ >= 710 -{-# OPTIONS_GHC -XPartialTypeSignatures #-} +{-# LANGUAGE PartialTypeSignatures #-} #endif {-# OPTIONS_GHC -w #-} module Happy.Frontend.AttrGrammar.Parser (agParser) where @@ -9,12 +17,13 @@ import Happy.Frontend.ParseMonad.Class import Happy.Frontend.ParseMonad import Happy.Frontend.AttrGrammar import qualified Data.Array as Happy_Data_Array +import qualified Data.List as Happy_Data_List import qualified Data.Bits as Bits import qualified GHC.Exts as Happy_GHC_Exts import Control.Applicative(Applicative(..)) import Control.Monad (ap) --- parser produced by Happy Version 1.20.1.1 +-- parser produced by Happy Version 2.0.2 newtype HappyAbsSyn = HappyAbsSyn HappyAny #if __GLASGOW_HASKELL__ >= 607 @@ -22,13 +31,6 @@ type HappyAny = Happy_GHC_Exts.Any #else type HappyAny = forall a . a #endif -newtype HappyWrap4 = HappyWrap4 ([AgRule]) -happyIn4 :: ([AgRule]) -> (HappyAbsSyn ) -happyIn4 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap4 x) -{-# INLINE happyIn4 #-} -happyOut4 :: (HappyAbsSyn ) -> HappyWrap4 -happyOut4 x = Happy_GHC_Exts.unsafeCoerce# x -{-# INLINE happyOut4 #-} newtype HappyWrap5 = HappyWrap5 ([AgRule]) happyIn5 :: ([AgRule]) -> (HappyAbsSyn ) happyIn5 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap5 x) @@ -36,15 +38,15 @@ happyIn5 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap5 x) happyOut5 :: (HappyAbsSyn ) -> HappyWrap5 happyOut5 x = Happy_GHC_Exts.unsafeCoerce# x {-# INLINE happyOut5 #-} -newtype HappyWrap6 = HappyWrap6 (AgRule) -happyIn6 :: (AgRule) -> (HappyAbsSyn ) +newtype HappyWrap6 = HappyWrap6 ([AgRule]) +happyIn6 :: ([AgRule]) -> (HappyAbsSyn ) happyIn6 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap6 x) {-# INLINE happyIn6 #-} happyOut6 :: (HappyAbsSyn ) -> HappyWrap6 happyOut6 x = Happy_GHC_Exts.unsafeCoerce# x {-# INLINE happyOut6 #-} -newtype HappyWrap7 = HappyWrap7 ([AgToken]) -happyIn7 :: ([AgToken]) -> (HappyAbsSyn ) +newtype HappyWrap7 = HappyWrap7 (AgRule) +happyIn7 :: (AgRule) -> (HappyAbsSyn ) happyIn7 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap7 x) {-# INLINE happyIn7 #-} happyOut7 :: (HappyAbsSyn ) -> HappyWrap7 @@ -57,6 +59,13 @@ happyIn8 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap8 x) happyOut8 :: (HappyAbsSyn ) -> HappyWrap8 happyOut8 x = Happy_GHC_Exts.unsafeCoerce# x {-# INLINE happyOut8 #-} +newtype HappyWrap9 = HappyWrap9 ([AgToken]) +happyIn9 :: ([AgToken]) -> (HappyAbsSyn ) +happyIn9 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap9 x) +{-# INLINE happyIn9 #-} +happyOut9 :: (HappyAbsSyn ) -> HappyWrap9 +happyOut9 x = Happy_GHC_Exts.unsafeCoerce# x +{-# INLINE happyOut9 #-} happyInTok :: (AgToken) -> (HappyAbsSyn ) happyInTok x = Happy_GHC_Exts.unsafeCoerce# x {-# INLINE happyInTok #-} @@ -65,426 +74,388 @@ happyOutTok x = Happy_GHC_Exts.unsafeCoerce# x {-# INLINE happyOutTok #-} -happyExpList :: HappyAddr -happyExpList = HappyA# "\x00\xf0\x00\xc0\x03\x00\x00\x00\x01\x00\xe9\x01\x20\x00\x80\x00\x00\x02\x00\x00\x00\xa4\x07\x90\x1e\x40\x7a\x00\x00\x00\xb4\x07\x90\x1e\x40\x7a\x00\xe9\x01\xa4\x07\x90\x1e\x00\x3c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x40\x7b\x00\xed\x01\xb4\x07\xd0\x1e\x40\x7b\x00\xe9\x01\xb4\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\xe9\x01\x00\x00\xd0\x1e\x00\x00\x00\x00"# - -{-# NOINLINE happyExpListPerState #-} -happyExpListPerState st = - token_strs_expected - where token_strs = ["error","%dummy","%start_agParser","agParser","rules","rule","code","code0","\"{\"","\"}\"","\";\"","\"=\"","where","selfRef","subRef","rightRef","unknown","%eof"] - bit_start = st Prelude.* 18 - bit_end = (st Prelude.+ 1) Prelude.* 18 - read_bit = readArrayBit happyExpList - bits = Prelude.map read_bit [bit_start..bit_end Prelude.- 1] - bits_indexed = Prelude.zip bits [0..17] - token_strs_expected = Prelude.concatMap f bits_indexed - f (Prelude.False, _) = [] - f (Prelude.True, nr) = [token_strs Prelude.!! nr] +{-# NOINLINE happyTokenStrings #-} +happyTokenStrings = ["\"{\"","\"}\"","\";\"","\"=\"","where","selfRef","subRef","rightRef","unknown","%eof"] happyActOffsets :: HappyAddr -happyActOffsets = HappyA# "\x0f\x00\x0f\x00\x00\x00\xfe\xff\x0a\x00\xff\xff\x02\x00\x19\x00\x05\x00\x0a\x00\x0a\x00\x0a\x00\x00\x00\x01\x00\x0a\x00\x0a\x00\x0a\x00\x0a\x00\x0a\x00\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1c\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x0a\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1d\x00\x0a\x00\x00\x00\x01\x00\x00\x00\x00\x00"# +happyActOffsets = HappyA# "\x0d\x00\x00\x00\x0d\x00\x00\x00\x00\x00\x00\x00\xfe\xff\xff\xff\x08\x00\x00\x00\x09\x00\x00\x00\x18\x00\x00\x00\x1a\x00\x00\x00\xfa\xff\xff\xff\x08\x00\x00\x00\x08\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x08\x00\x00\x00\x08\x00\x00\x00\x08\x00\x00\x00\x08\x00\x00\x00\x08\x00\x00\x00\x0d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1b\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x08\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1d\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00"# happyGotoOffsets :: HappyAddr -happyGotoOffsets = HappyA# "\x18\x00\x0b\x00\x00\x00\x00\x00\x1e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\x00\x20\x00\x21\x00\x00\x00\x22\x00\x24\x00\x25\x00\x26\x00\x27\x00\x28\x00\x1a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x29\x00\x2a\x00\x2b\x00\x2c\x00\x2d\x00\x2f\x00\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x32\x00\x00\x00\x33\x00\x00\x00\x00\x00"# - -happyAdjustOffset :: Happy_GHC_Exts.Int# -> Happy_GHC_Exts.Int# -happyAdjustOffset off = off +happyGotoOffsets = HappyA# "\x17\x00\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\x00\x00\x00\x20\x00\x00\x00\x21\x00\x00\x00\x00\x00\x00\x00\x22\x00\x00\x00\x24\x00\x00\x00\x25\x00\x00\x00\x26\x00\x00\x00\x27\x00\x00\x00\x28\x00\x00\x00\x19\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x29\x00\x00\x00\x2a\x00\x00\x00\x2b\x00\x00\x00\x2c\x00\x00\x00\x2d\x00\x00\x00\x2f\x00\x00\x00\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x32\x00\x00\x00\x00\x00\x00\x00\x33\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"# happyDefActions :: HappyAddr -happyDefActions = HappyA# "\xfb\xff\x00\x00\xfe\xff\xfc\xff\xf0\xff\x00\x00\x00\x00\x00\x00\x00\x00\xf0\xff\xf0\xff\xf0\xff\xf7\xff\xe8\xff\xf0\xff\xf0\xff\xf0\xff\xf0\xff\xf0\xff\xfb\xff\xfd\xff\xf1\xff\xf2\xff\xf3\xff\xf4\xff\xf5\xff\x00\x00\xe8\xff\xe8\xff\xe8\xff\xe8\xff\xe8\xff\xf0\xff\xe8\xff\xfa\xff\xf9\xff\xf8\xff\xe9\xff\xea\xff\xeb\xff\xec\xff\xee\xff\xed\xff\x00\x00\xf0\xff\xf6\xff\xe8\xff\xef\xff"# +happyDefActions = HappyA# "\xfb\xff\xff\xff\x00\x00\x00\x00\xfe\xff\xff\xff\xfc\xff\xff\xff\xf0\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0\xff\xff\xff\xf0\xff\xff\xff\xf0\xff\xff\xff\xf7\xff\xff\xff\xe8\xff\xff\xff\xf0\xff\xff\xff\xf0\xff\xff\xff\xf0\xff\xff\xff\xf0\xff\xff\xff\xf0\xff\xff\xff\xfb\xff\xff\xff\xfd\xff\xff\xff\xf1\xff\xff\xff\xf2\xff\xff\xff\xf3\xff\xff\xff\xf4\xff\xff\xff\xf5\xff\xff\xff\x00\x00\x00\x00\xe8\xff\xff\xff\xe8\xff\xff\xff\xe8\xff\xff\xff\xe8\xff\xff\xff\xe8\xff\xff\xff\xf0\xff\xff\xff\xe8\xff\xff\xff\xfa\xff\xff\xff\xf9\xff\xff\xff\xf8\xff\xff\xff\xe9\xff\xff\xff\xea\xff\xff\xff\xeb\xff\xff\xff\xec\xff\xff\xff\xee\xff\xff\xff\xed\xff\xff\xff\x00\x00\x00\x00\xf0\xff\xff\xff\xf6\xff\xff\xff\xe8\xff\xff\xff\xef\xff\xff\xff"# happyCheck :: HappyAddr -happyCheck = HappyA# "\xff\xff\x03\x00\x01\x00\x04\x00\x03\x00\x04\x00\x04\x00\x06\x00\x07\x00\x08\x00\x09\x00\x01\x00\x01\x00\x02\x00\x04\x00\x0a\x00\x06\x00\x07\x00\x08\x00\x09\x00\x05\x00\x06\x00\x07\x00\x08\x00\x00\x00\x01\x00\x02\x00\x01\x00\x02\x00\x04\x00\x02\x00\x02\x00\xff\xff\x03\x00\x03\x00\x03\x00\x03\x00\xff\xff\x04\x00\x03\x00\x03\x00\x03\x00\x03\x00\x03\x00\xff\xff\x04\x00\x04\x00\x04\x00\x04\x00\x04\x00\x03\x00\xff\xff\x04\x00\x03\x00\xff\xff\x04\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"# +happyCheck = HappyA# "\xff\xff\xff\xff\x02\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x05\x00\x00\x00\x0b\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\x09\x00\x00\x00\x0a\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x05\x00\x00\x00\x05\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\x09\x00\x00\x00\x0a\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\x09\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\xff\xff\xff\xff\x05\x00\x00\x00\x03\x00\x00\x00\x05\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\xff\xff\xff\xff\x04\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\xff\xff\xff\xff\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x03\x00\x00\x00\xff\xff\xff\xff\x04\x00\x00\x00\x03\x00\x00\x00\xff\xff\xff\xff\x04\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"# happyTable :: HappyAddr -happyTable = HappyA# "\x00\x00\x14\x00\x1c\x00\x0c\x00\x1d\x00\x1e\x00\x0b\x00\x1f\x00\x20\x00\x21\x00\x22\x00\x0e\x00\x02\x00\x03\x00\x0f\x00\xff\xff\x10\x00\x11\x00\x12\x00\x13\x00\x05\x00\x06\x00\x07\x00\x08\x00\x08\x00\x02\x00\x03\x00\x14\x00\x03\x00\x0a\x00\x2d\x00\x2f\x00\x00\x00\x0c\x00\x24\x00\x23\x00\x22\x00\x00\x00\x1a\x00\x19\x00\x18\x00\x17\x00\x16\x00\x15\x00\x00\x00\x2b\x00\x2a\x00\x29\x00\x28\x00\x27\x00\x26\x00\x00\x00\x25\x00\x2d\x00\x00\x00\x2f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"# +happyTable = HappyA# "\x00\x00\x00\x00\x1c\x00\x00\x00\x14\x00\x00\x00\x1d\x00\x00\x00\x1e\x00\x00\x00\xff\xff\xff\xff\x1f\x00\x00\x00\x20\x00\x00\x00\x21\x00\x00\x00\x22\x00\x00\x00\x0e\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x0f\x00\x00\x00\x0c\x00\x00\x00\x10\x00\x00\x00\x11\x00\x00\x00\x12\x00\x00\x00\x13\x00\x00\x00\x05\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\x08\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x14\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x0b\x00\x00\x00\x2d\x00\x00\x00\x0a\x00\x00\x00\x2f\x00\x00\x00\x0c\x00\x00\x00\x24\x00\x00\x00\x23\x00\x00\x00\x22\x00\x00\x00\x00\x00\x00\x00\x1a\x00\x00\x00\x19\x00\x00\x00\x18\x00\x00\x00\x17\x00\x00\x00\x16\x00\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x2b\x00\x00\x00\x2a\x00\x00\x00\x29\x00\x00\x00\x28\x00\x00\x00\x27\x00\x00\x00\x26\x00\x00\x00\x00\x00\x00\x00\x25\x00\x00\x00\x2d\x00\x00\x00\x00\x00\x00\x00\x2f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"# happyReduceArr = Happy_Data_Array.array (1, 23) [ - (1 , happyReduce_1), - (2 , happyReduce_2), - (3 , happyReduce_3), - (4 , happyReduce_4), - (5 , happyReduce_5), - (6 , happyReduce_6), - (7 , happyReduce_7), - (8 , happyReduce_8), - (9 , happyReduce_9), - (10 , happyReduce_10), - (11 , happyReduce_11), - (12 , happyReduce_12), - (13 , happyReduce_13), - (14 , happyReduce_14), - (15 , happyReduce_15), - (16 , happyReduce_16), - (17 , happyReduce_17), - (18 , happyReduce_18), - (19 , happyReduce_19), - (20 , happyReduce_20), - (21 , happyReduce_21), - (22 , happyReduce_22), - (23 , happyReduce_23) - ] - -happy_n_terms = 11 :: Prelude.Int + (1 , happyReduce_1), + (2 , happyReduce_2), + (3 , happyReduce_3), + (4 , happyReduce_4), + (5 , happyReduce_5), + (6 , happyReduce_6), + (7 , happyReduce_7), + (8 , happyReduce_8), + (9 , happyReduce_9), + (10 , happyReduce_10), + (11 , happyReduce_11), + (12 , happyReduce_12), + (13 , happyReduce_13), + (14 , happyReduce_14), + (15 , happyReduce_15), + (16 , happyReduce_16), + (17 , happyReduce_17), + (18 , happyReduce_18), + (19 , happyReduce_19), + (20 , happyReduce_20), + (21 , happyReduce_21), + (22 , happyReduce_22), + (23 , happyReduce_23) + ] + +happyRuleArr :: HappyAddr +happyRuleArr = HappyA# "\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x03\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x02\x00\x00\x00\x04\x00\x00\x00\x02\x00\x00\x00\x04\x00\x00\x00\x02\x00\x00\x00\x04\x00\x00\x00\x02\x00\x00\x00\x04\x00\x00\x00\x02\x00\x00\x00\x04\x00\x00\x00\x02\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00"# + +happyCatchStates :: [Int] +happyCatchStates = [] + +happy_n_terms = 12 :: Prelude.Int happy_n_nonterms = 5 :: Prelude.Int +happy_n_starts = 1 :: Prelude.Int + happyReduce_1 :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_1 = happySpecReduce_1 0# happyReduction_1 happyReduction_1 happy_x_1 - = case happyOut5 happy_x_1 of { (HappyWrap5 happy_var_1) -> - happyIn4 - (happy_var_1 - )} + = case happyOut6 happy_x_1 of { (HappyWrap6 happy_var_1) -> + happyIn5 + (happy_var_1 + )} happyReduce_2 :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_2 = happySpecReduce_3 1# happyReduction_2 happyReduction_2 happy_x_3 - happy_x_2 - happy_x_1 - = case happyOut6 happy_x_1 of { (HappyWrap6 happy_var_1) -> - case happyOut5 happy_x_3 of { (HappyWrap5 happy_var_3) -> - happyIn5 - (happy_var_1 : happy_var_3 - )}} + happy_x_2 + happy_x_1 + = case happyOut7 happy_x_1 of { (HappyWrap7 happy_var_1) -> + case happyOut6 happy_x_3 of { (HappyWrap6 happy_var_3) -> + happyIn6 + (happy_var_1 : happy_var_3 + )}} happyReduce_3 :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_3 = happySpecReduce_1 1# happyReduction_3 happyReduction_3 happy_x_1 - = case happyOut6 happy_x_1 of { (HappyWrap6 happy_var_1) -> - happyIn5 - (happy_var_1 : [] - )} + = case happyOut7 happy_x_1 of { (HappyWrap7 happy_var_1) -> + happyIn6 + (happy_var_1 : [] + )} happyReduce_4 :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_4 = happySpecReduce_0 1# happyReduction_4 -happyReduction_4 = happyIn5 - ([] - ) +happyReduction_4 = happyIn6 + ([] + ) happyReduce_5 :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_5 = happySpecReduce_3 2# happyReduction_5 happyReduction_5 happy_x_3 - happy_x_2 - happy_x_1 - = case happyOutTok happy_x_1 of { happy_var_1 -> - case happyOut7 happy_x_3 of { (HappyWrap7 happy_var_3) -> - happyIn6 - (SelfAssign $ MkAgSelfAssign (selfRefVal happy_var_1) happy_var_3 - )}} + happy_x_2 + happy_x_1 + = case happyOutTok happy_x_1 of { happy_var_1 -> + case happyOut8 happy_x_3 of { (HappyWrap8 happy_var_3) -> + happyIn7 + (SelfAssign $ MkAgSelfAssign (selfRefVal happy_var_1) happy_var_3 + )}} happyReduce_6 :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_6 = happySpecReduce_3 2# happyReduction_6 happyReduction_6 happy_x_3 - happy_x_2 - happy_x_1 - = case happyOutTok happy_x_1 of { happy_var_1 -> - case happyOut7 happy_x_3 of { (HappyWrap7 happy_var_3) -> - happyIn6 - (SubAssign $ MkAgSubAssign (subRefVal happy_var_1) happy_var_3 - )}} + happy_x_2 + happy_x_1 + = case happyOutTok happy_x_1 of { happy_var_1 -> + case happyOut8 happy_x_3 of { (HappyWrap8 happy_var_3) -> + happyIn7 + (SubAssign $ MkAgSubAssign (subRefVal happy_var_1) happy_var_3 + )}} happyReduce_7 :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_7 = happySpecReduce_3 2# happyReduction_7 happyReduction_7 happy_x_3 - happy_x_2 - happy_x_1 - = case happyOutTok happy_x_1 of { happy_var_1 -> - case happyOut7 happy_x_3 of { (HappyWrap7 happy_var_3) -> - happyIn6 - (RightmostAssign (rightRefVal happy_var_1) happy_var_3 - )}} + happy_x_2 + happy_x_1 + = case happyOutTok happy_x_1 of { happy_var_1 -> + case happyOut8 happy_x_3 of { (HappyWrap8 happy_var_3) -> + happyIn7 + (RightmostAssign (rightRefVal happy_var_1) happy_var_3 + )}} happyReduce_8 :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_8 = happySpecReduce_2 2# happyReduction_8 happyReduction_8 happy_x_2 - happy_x_1 - = case happyOut7 happy_x_2 of { (HappyWrap7 happy_var_2) -> - happyIn6 - (Conditional $ MkAgConditional happy_var_2 - )} + happy_x_1 + = case happyOut8 happy_x_2 of { (HappyWrap8 happy_var_2) -> + happyIn7 + (Conditional $ MkAgConditional happy_var_2 + )} happyReduce_9 :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_9 = happyReduce 4# 3# happyReduction_9 happyReduction_9 (happy_x_4 `HappyStk` - happy_x_3 `HappyStk` - happy_x_2 `HappyStk` - happy_x_1 `HappyStk` - happyRest) - = case happyOutTok happy_x_1 of { happy_var_1 -> - case happyOut8 happy_x_2 of { (HappyWrap8 happy_var_2) -> - case happyOutTok happy_x_3 of { happy_var_3 -> - case happyOut7 happy_x_4 of { (HappyWrap7 happy_var_4) -> - happyIn7 - ([happy_var_1] ++ happy_var_2 ++ [happy_var_3] ++ happy_var_4 - ) `HappyStk` happyRest}}}} + happy_x_3 `HappyStk` + happy_x_2 `HappyStk` + happy_x_1 `HappyStk` + happyRest) + = case happyOutTok happy_x_1 of { happy_var_1 -> + case happyOut9 happy_x_2 of { (HappyWrap9 happy_var_2) -> + case happyOutTok happy_x_3 of { happy_var_3 -> + case happyOut8 happy_x_4 of { (HappyWrap8 happy_var_4) -> + happyIn8 + ([happy_var_1] ++ happy_var_2 ++ [happy_var_3] ++ happy_var_4 + ) `HappyStk` happyRest}}}} happyReduce_10 :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_10 = happySpecReduce_2 3# happyReduction_10 happyReduction_10 happy_x_2 - happy_x_1 - = case happyOutTok happy_x_1 of { happy_var_1 -> - case happyOut7 happy_x_2 of { (HappyWrap7 happy_var_2) -> - happyIn7 - (happy_var_1 : happy_var_2 - )}} + happy_x_1 + = case happyOutTok happy_x_1 of { happy_var_1 -> + case happyOut8 happy_x_2 of { (HappyWrap8 happy_var_2) -> + happyIn8 + (happy_var_1 : happy_var_2 + )}} happyReduce_11 :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_11 = happySpecReduce_2 3# happyReduction_11 happyReduction_11 happy_x_2 - happy_x_1 - = case happyOutTok happy_x_1 of { happy_var_1 -> - case happyOut7 happy_x_2 of { (HappyWrap7 happy_var_2) -> - happyIn7 - (happy_var_1 : happy_var_2 - )}} + happy_x_1 + = case happyOutTok happy_x_1 of { happy_var_1 -> + case happyOut8 happy_x_2 of { (HappyWrap8 happy_var_2) -> + happyIn8 + (happy_var_1 : happy_var_2 + )}} happyReduce_12 :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_12 = happySpecReduce_2 3# happyReduction_12 happyReduction_12 happy_x_2 - happy_x_1 - = case happyOutTok happy_x_1 of { happy_var_1 -> - case happyOut7 happy_x_2 of { (HappyWrap7 happy_var_2) -> - happyIn7 - (happy_var_1 : happy_var_2 - )}} + happy_x_1 + = case happyOutTok happy_x_1 of { happy_var_1 -> + case happyOut8 happy_x_2 of { (HappyWrap8 happy_var_2) -> + happyIn8 + (happy_var_1 : happy_var_2 + )}} happyReduce_13 :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_13 = happySpecReduce_2 3# happyReduction_13 happyReduction_13 happy_x_2 - happy_x_1 - = case happyOutTok happy_x_1 of { happy_var_1 -> - case happyOut7 happy_x_2 of { (HappyWrap7 happy_var_2) -> - happyIn7 - (happy_var_1 : happy_var_2 - )}} + happy_x_1 + = case happyOutTok happy_x_1 of { happy_var_1 -> + case happyOut8 happy_x_2 of { (HappyWrap8 happy_var_2) -> + happyIn8 + (happy_var_1 : happy_var_2 + )}} happyReduce_14 :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_14 = happySpecReduce_2 3# happyReduction_14 happyReduction_14 happy_x_2 - happy_x_1 - = case happyOutTok happy_x_1 of { happy_var_1 -> - case happyOut7 happy_x_2 of { (HappyWrap7 happy_var_2) -> - happyIn7 - (happy_var_1 : happy_var_2 - )}} + happy_x_1 + = case happyOutTok happy_x_1 of { happy_var_1 -> + case happyOut8 happy_x_2 of { (HappyWrap8 happy_var_2) -> + happyIn8 + (happy_var_1 : happy_var_2 + )}} happyReduce_15 :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_15 = happySpecReduce_0 3# happyReduction_15 -happyReduction_15 = happyIn7 - ([] - ) +happyReduction_15 = happyIn8 + ([] + ) happyReduce_16 :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_16 = happyReduce 4# 4# happyReduction_16 happyReduction_16 (happy_x_4 `HappyStk` - happy_x_3 `HappyStk` - happy_x_2 `HappyStk` - happy_x_1 `HappyStk` - happyRest) - = case happyOutTok happy_x_1 of { happy_var_1 -> - case happyOut8 happy_x_2 of { (HappyWrap8 happy_var_2) -> - case happyOutTok happy_x_3 of { happy_var_3 -> - case happyOut8 happy_x_4 of { (HappyWrap8 happy_var_4) -> - happyIn8 - ([happy_var_1] ++ happy_var_2 ++ [happy_var_3] ++ happy_var_4 - ) `HappyStk` happyRest}}}} + happy_x_3 `HappyStk` + happy_x_2 `HappyStk` + happy_x_1 `HappyStk` + happyRest) + = case happyOutTok happy_x_1 of { happy_var_1 -> + case happyOut9 happy_x_2 of { (HappyWrap9 happy_var_2) -> + case happyOutTok happy_x_3 of { happy_var_3 -> + case happyOut9 happy_x_4 of { (HappyWrap9 happy_var_4) -> + happyIn9 + ([happy_var_1] ++ happy_var_2 ++ [happy_var_3] ++ happy_var_4 + ) `HappyStk` happyRest}}}} happyReduce_17 :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_17 = happySpecReduce_2 4# happyReduction_17 happyReduction_17 happy_x_2 - happy_x_1 - = case happyOutTok happy_x_1 of { happy_var_1 -> - case happyOut8 happy_x_2 of { (HappyWrap8 happy_var_2) -> - happyIn8 - (happy_var_1 : happy_var_2 - )}} + happy_x_1 + = case happyOutTok happy_x_1 of { happy_var_1 -> + case happyOut9 happy_x_2 of { (HappyWrap9 happy_var_2) -> + happyIn9 + (happy_var_1 : happy_var_2 + )}} happyReduce_18 :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_18 = happySpecReduce_2 4# happyReduction_18 happyReduction_18 happy_x_2 - happy_x_1 - = case happyOutTok happy_x_1 of { happy_var_1 -> - case happyOut8 happy_x_2 of { (HappyWrap8 happy_var_2) -> - happyIn8 - (happy_var_1 : happy_var_2 - )}} + happy_x_1 + = case happyOutTok happy_x_1 of { happy_var_1 -> + case happyOut9 happy_x_2 of { (HappyWrap9 happy_var_2) -> + happyIn9 + (happy_var_1 : happy_var_2 + )}} happyReduce_19 :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_19 = happySpecReduce_2 4# happyReduction_19 happyReduction_19 happy_x_2 - happy_x_1 - = case happyOutTok happy_x_1 of { happy_var_1 -> - case happyOut8 happy_x_2 of { (HappyWrap8 happy_var_2) -> - happyIn8 - (happy_var_1 : happy_var_2 - )}} + happy_x_1 + = case happyOutTok happy_x_1 of { happy_var_1 -> + case happyOut9 happy_x_2 of { (HappyWrap9 happy_var_2) -> + happyIn9 + (happy_var_1 : happy_var_2 + )}} happyReduce_20 :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_20 = happySpecReduce_2 4# happyReduction_20 happyReduction_20 happy_x_2 - happy_x_1 - = case happyOutTok happy_x_1 of { happy_var_1 -> - case happyOut8 happy_x_2 of { (HappyWrap8 happy_var_2) -> - happyIn8 - (happy_var_1 : happy_var_2 - )}} + happy_x_1 + = case happyOutTok happy_x_1 of { happy_var_1 -> + case happyOut9 happy_x_2 of { (HappyWrap9 happy_var_2) -> + happyIn9 + (happy_var_1 : happy_var_2 + )}} happyReduce_21 :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_21 = happySpecReduce_2 4# happyReduction_21 happyReduction_21 happy_x_2 - happy_x_1 - = case happyOutTok happy_x_1 of { happy_var_1 -> - case happyOut7 happy_x_2 of { (HappyWrap7 happy_var_2) -> - happyIn8 - (happy_var_1 : happy_var_2 - )}} + happy_x_1 + = case happyOutTok happy_x_1 of { happy_var_1 -> + case happyOut8 happy_x_2 of { (HappyWrap8 happy_var_2) -> + happyIn9 + (happy_var_1 : happy_var_2 + )}} happyReduce_22 :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_22 = happySpecReduce_2 4# happyReduction_22 happyReduction_22 happy_x_2 - happy_x_1 - = case happyOutTok happy_x_1 of { happy_var_1 -> - case happyOut8 happy_x_2 of { (HappyWrap8 happy_var_2) -> - happyIn8 - (happy_var_1 : happy_var_2 - )}} + happy_x_1 + = case happyOutTok happy_x_1 of { happy_var_1 -> + case happyOut9 happy_x_2 of { (HappyWrap9 happy_var_2) -> + happyIn9 + (happy_var_1 : happy_var_2 + )}} happyReduce_23 :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_23 = happySpecReduce_0 4# happyReduction_23 -happyReduction_23 = happyIn8 - ([] - ) - -happyNewToken action sts stk - = lexTokenP(\tk -> - let cont i = happyDoAction i tk action sts stk in - case tk of { - AgTok_EOF -> happyDoAction 10# tk action sts stk; - AgTok_LBrace -> cont 1#; - AgTok_RBrace -> cont 2#; - AgTok_Semicolon -> cont 3#; - AgTok_Eq -> cont 4#; - AgTok_Where -> cont 5#; - AgTok_SelfRef _ -> cont 6#; - AgTok_SubRef _ -> cont 7#; - AgTok_RightmostRef _ -> cont 8#; - AgTok_Unknown _ -> cont 9#; - _ -> happyError' (tk, []) - }) - -happyError_ explist 10# tk = happyError' (tk, explist) -happyError_ explist _ tk = happyError' (tk, explist) - -happyThen :: () => P a -> (a -> P b) -> P b +happyReduction_23 = happyIn9 + ([] + ) + +happyTerminalToTok term = case term of { + AgTok_EOF -> 11#; + AgTok_LBrace -> 2#; + AgTok_RBrace -> 3#; + AgTok_Semicolon -> 4#; + AgTok_Eq -> 5#; + AgTok_Where -> 6#; + AgTok_SelfRef _ -> 7#; + AgTok_SubRef _ -> 8#; + AgTok_RightmostRef _ -> 9#; + AgTok_Unknown _ -> 10#; + _ -> error "Encountered a token that was not declared to happy" + } +{-# NOINLINE happyTerminalToTok #-} + +happyLex kend kmore = lexTokenP (\tk -> case tk of { + AgTok_EOF -> kend tk; + _ -> kmore (happyTerminalToTok tk) tk }) +{-# INLINE happyLex #-} + +happyNewToken action sts stk = happyLex (\tk -> happyDoAction 11# tk action sts stk) (\i tk -> happyDoAction i tk action sts stk) + +happyReport 11# = happyReport' +happyReport _ = happyReport' + + +happyThen :: () => (P a) -> (a -> (P b)) -> (P b) happyThen = (Prelude.>>=) -happyReturn :: () => a -> P a +happyReturn :: () => a -> (P a) happyReturn = (Prelude.return) happyParse :: () => Happy_GHC_Exts.Int# -> P (HappyAbsSyn ) -happyNewToken :: () => Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) +happyNewToken :: () => Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> (P (HappyAbsSyn )) -happyDoAction :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) +happyDoAction :: () => Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> (P (HappyAbsSyn )) -happyReduceArr :: () => Happy_Data_Array.Array Prelude.Int (Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn )) +happyReduceArr :: () => Happy_Data_Array.Array Prelude.Int (Happy_GHC_Exts.Int# -> AgToken -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> (P (HappyAbsSyn ))) happyThen1 :: () => P a -> (a -> P b) -> P b happyThen1 = happyThen -happyReturn1 :: () => a -> P a +happyFmap1 f m = happyThen m (\a -> happyReturn (f a)) +happyReturn1 :: () => a -> (P a) happyReturn1 = happyReturn -happyError' :: () => ((AgToken), [Prelude.String]) -> P a -happyError' tk = (\(tokens, explist) -> happyError) tk +happyReport' :: () => (AgToken) -> [Prelude.String] -> (P a) -> (P a) +happyReport' = (\tokens expected resume -> happyError) + +happyAbort :: () => (P a) +happyAbort = error "Called abort handler in non-resumptive parser" + agParser = happySomeParser where - happySomeParser = happyThen (happyParse 0#) (\x -> happyReturn (let {(HappyWrap4 x') = happyOut4 x} in x')) + happySomeParser = happyThen (happyParse 0#) (\x -> happyReturn (let {(HappyWrap5 x') = happyOut5 x} in x')) happySeq = happyDontSeq happyError :: P a happyError = failP (\l -> show l ++ ": Parse error\n") -{-# LINE 1 "templates/GenericTemplate.hs" #-} +#define HAPPY_COERCE 1 -- $Id: GenericTemplate.hs,v 1.26 2005/01/14 14:47:22 simonmar Exp $ +#if !defined(__GLASGOW_HASKELL__) +# error This code isn't being built with GHC. +#endif - - - - - - - - - - +-- Get WORDS_BIGENDIAN (if defined) +#include "MachDeps.h" -- Do not remove this comment. Required to fix CPP parsing when using GCC and a clang-compiled alex. -#if __GLASGOW_HASKELL__ > 706 #define LT(n,m) ((Happy_GHC_Exts.tagToEnum# (n Happy_GHC_Exts.<# m)) :: Prelude.Bool) #define GTE(n,m) ((Happy_GHC_Exts.tagToEnum# (n Happy_GHC_Exts.>=# m)) :: Prelude.Bool) #define EQ(n,m) ((Happy_GHC_Exts.tagToEnum# (n Happy_GHC_Exts.==# m)) :: Prelude.Bool) -#else -#define LT(n,m) (n Happy_GHC_Exts.<# m) -#define GTE(n,m) (n Happy_GHC_Exts.>=# m) -#define EQ(n,m) (n Happy_GHC_Exts.==# m) -#endif - - - - - - - - - - - - - - - - - - - -data Happy_IntList = HappyCons Happy_GHC_Exts.Int# Happy_IntList - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +#define PLUS(n,m) (n Happy_GHC_Exts.+# m) +#define MINUS(n,m) (n Happy_GHC_Exts.-# m) +#define TIMES(n,m) (n Happy_GHC_Exts.*# m) +#define NEGATE(n) (Happy_GHC_Exts.negateInt# (n)) +type Happy_Int = Happy_GHC_Exts.Int# +data Happy_IntList = HappyCons Happy_Int Happy_IntList +#define ERROR_TOK 0# +#define CATCH_TOK 1# +#if defined(HAPPY_COERCE) +# define GET_ERROR_TOKEN(x) (case Happy_GHC_Exts.unsafeCoerce# x of { (Happy_GHC_Exts.I# i) -> i }) +# define MK_ERROR_TOKEN(i) (Happy_GHC_Exts.unsafeCoerce# (Happy_GHC_Exts.I# i)) +# define MK_TOKEN(x) (happyInTok (x)) +#else +# define GET_ERROR_TOKEN(x) (case x of { HappyErrorToken (Happy_GHC_Exts.I# i) -> i }) +# define MK_ERROR_TOKEN(i) (HappyErrorToken (Happy_GHC_Exts.I# i)) +# define MK_TOKEN(x) (HappyTerminal (x)) +#endif +#if defined(HAPPY_DEBUG) +# define DEBUG_TRACE(s) (happyTrace (s)) $ +happyTrace string expr = Happy_System_IO_Unsafe.unsafePerformIO $ do + Happy_System_IO.hPutStr Happy_System_IO.stderr string + return expr +#else +# define DEBUG_TRACE(s) {- nothing -} +#endif infixr 9 `HappyStk` data HappyStk a = HappyStk a (HappyStk a) @@ -500,214 +471,432 @@ happyParse start_state = happyNewToken start_state notHappyAtAll notHappyAtAll -- If the current token is ERROR_TOK, it means we've just accepted a partial -- parse (a %partial parser). We must ignore the saved token on the top of -- the stack in this case. -happyAccept 0# tk st sts (_ `HappyStk` ans `HappyStk` _) = +happyAccept ERROR_TOK tk st sts (_ `HappyStk` ans `HappyStk` _) = happyReturn1 ans -happyAccept j tk st sts (HappyStk ans _) = +happyAccept j tk st sts (HappyStk ans _) = (happyTcHack j (happyTcHack st)) (happyReturn1 ans) ----------------------------------------------------------------------------- -- Arrays only: do the next action - - -happyDoAction i tk st - = {- nothing -} - case action of - 0# -> {- nothing -} - happyFail (happyExpListPerState ((Happy_GHC_Exts.I# (st)) :: Prelude.Int)) i tk st - -1# -> {- nothing -} - happyAccept i tk st - n | LT(n,(0# :: Happy_GHC_Exts.Int#)) -> {- nothing -} - (happyReduceArr Happy_Data_Array.! rule) i tk st - where rule = (Happy_GHC_Exts.I# ((Happy_GHC_Exts.negateInt# ((n Happy_GHC_Exts.+# (1# :: Happy_GHC_Exts.Int#)))))) - n -> {- nothing -} - happyShift new_state i tk st - where new_state = (n Happy_GHC_Exts.-# (1# :: Happy_GHC_Exts.Int#)) - where off = happyAdjustOffset (indexShortOffAddr happyActOffsets st) - off_i = (off Happy_GHC_Exts.+# i) - check = if GTE(off_i,(0# :: Happy_GHC_Exts.Int#)) - then EQ(indexShortOffAddr happyCheck off_i, i) - else Prelude.False - action - | check = indexShortOffAddr happyTable off_i - | Prelude.otherwise = indexShortOffAddr happyDefActions st - - - - -indexShortOffAddr (HappyA# arr) off = - Happy_GHC_Exts.narrow16Int# i +happyDoAction i tk st = + DEBUG_TRACE("state: " ++ show (Happy_GHC_Exts.I# st) ++ + ",\ttoken: " ++ show (Happy_GHC_Exts.I# i) ++ + ",\taction: ") + case happyDecodeAction (happyNextAction i st) of + HappyFail -> DEBUG_TRACE("failing.\n") + happyFail i tk st + HappyAccept -> DEBUG_TRACE("accept.\n") + happyAccept i tk st + HappyReduce rule -> DEBUG_TRACE("reduce (rule " ++ show (Happy_GHC_Exts.I# rule) ++ ")") + (happyReduceArr Happy_Data_Array.! (Happy_GHC_Exts.I# rule)) i tk st + HappyShift new_state -> DEBUG_TRACE("shift, enter state " ++ show (Happy_GHC_Exts.I# new_state) ++ "\n") + happyShift new_state i tk st + +{-# INLINE happyNextAction #-} +happyNextAction i st = case happyIndexActionTable i st of + Just (Happy_GHC_Exts.I# act) -> act + Nothing -> happyIndexOffAddr happyDefActions st + +{-# INLINE happyIndexActionTable #-} +happyIndexActionTable i st + | GTE(i, 0#), GTE(off, 0#), EQ(happyIndexOffAddr happyCheck off, i) + -- i >= 0: Guard against INVALID_TOK (do the default action, which ultimately errors) + -- off >= 0: Otherwise it's a default action + -- equality check: Ensure that the entry in the compressed array is owned by st + = Prelude.Just (Happy_GHC_Exts.I# (happyIndexOffAddr happyTable off)) + | otherwise + = Prelude.Nothing where - i = Happy_GHC_Exts.word2Int# (Happy_GHC_Exts.or# (Happy_GHC_Exts.uncheckedShiftL# high 8#) low) - high = Happy_GHC_Exts.int2Word# (Happy_GHC_Exts.ord# (Happy_GHC_Exts.indexCharOffAddr# arr (off' Happy_GHC_Exts.+# 1#))) - low = Happy_GHC_Exts.int2Word# (Happy_GHC_Exts.ord# (Happy_GHC_Exts.indexCharOffAddr# arr off')) - off' = off Happy_GHC_Exts.*# 2# - - - - -{-# INLINE happyLt #-} -happyLt x y = LT(x,y) - - -readArrayBit arr bit = - Bits.testBit (Happy_GHC_Exts.I# (indexShortOffAddr arr ((unbox_int bit) `Happy_GHC_Exts.iShiftRA#` 4#))) (bit `Prelude.mod` 16) - where unbox_int (Happy_GHC_Exts.I# x) = x - - - + off = PLUS(happyIndexOffAddr happyActOffsets st, i) + +data HappyAction + = HappyFail + | HappyAccept + | HappyReduce Happy_Int -- rule number + | HappyShift Happy_Int -- new state + deriving Show + +{-# INLINE happyDecodeAction #-} +happyDecodeAction :: Happy_Int -> HappyAction +happyDecodeAction 0# = HappyFail +happyDecodeAction -1# = HappyAccept +happyDecodeAction action | LT(action, 0#) = HappyReduce NEGATE(PLUS(action, 1#)) + | otherwise = HappyShift MINUS(action, 1#) + +{-# INLINE happyIndexGotoTable #-} +happyIndexGotoTable nt st = happyIndexOffAddr happyTable off + where + off = PLUS(happyIndexOffAddr happyGotoOffsets st, nt) +{-# INLINE happyIndexOffAddr #-} +happyIndexOffAddr :: HappyAddr -> Happy_Int -> Happy_Int +happyIndexOffAddr (HappyA# arr) off = +#if __GLASGOW_HASKELL__ >= 901 + Happy_GHC_Exts.int32ToInt# -- qualified import because it doesn't exist on older GHC's +#endif +#ifdef WORDS_BIGENDIAN + -- The CI of `alex` tests this code path + (Happy_GHC_Exts.word32ToInt32# (Happy_GHC_Exts.wordToWord32# (Happy_GHC_Exts.byteSwap32# (Happy_GHC_Exts.word32ToWord# (Happy_GHC_Exts.int32ToWord32# +#endif + (Happy_GHC_Exts.indexInt32OffAddr# arr off) +#ifdef WORDS_BIGENDIAN + ))))) +#endif +happyIndexRuleArr :: Happy_Int -> (# Happy_Int, Happy_Int #) +happyIndexRuleArr r = (# nt, len #) + where + !(Happy_GHC_Exts.I# n_starts) = happy_n_starts + offs = TIMES(MINUS(r,n_starts),2#) + nt = happyIndexOffAddr happyRuleArr offs + len = happyIndexOffAddr happyRuleArr PLUS(offs,1#) data HappyAddr = HappyA# Happy_GHC_Exts.Addr# - ------------------------------------------------------------------------------ --- HappyState data type (not arrays) - - - - - - - - - - - - - ----------------------------------------------------------------------------- -- Shifting a token -happyShift new_state 0# tk st sts stk@(x `HappyStk` _) = - let i = (case Happy_GHC_Exts.unsafeCoerce# x of { (Happy_GHC_Exts.I# (i)) -> i }) in --- trace "shifting the error token" $ - happyDoAction i tk new_state (HappyCons (st) (sts)) (stk) +happyShift new_state ERROR_TOK tk st sts stk@(x `HappyStk` _) = + -- See "Error Fixup" below + let i = GET_ERROR_TOKEN(x) in + DEBUG_TRACE("shifting the error token") + happyDoAction i tk new_state (HappyCons st sts) stk happyShift new_state i tk st sts stk = - happyNewToken new_state (HappyCons (st) (sts)) ((happyInTok (tk))`HappyStk`stk) + happyNewToken new_state (HappyCons st sts) (MK_TOKEN(tk) `HappyStk` stk) -- happyReduce is specialised for the common cases. -happySpecReduce_0 i fn 0# tk st sts stk - = happyFail [] 0# tk st sts stk -happySpecReduce_0 nt fn j tk st@((action)) sts stk - = happyGoto nt j tk st (HappyCons (st) (sts)) (fn `HappyStk` stk) +happySpecReduce_0 nt fn j tk st sts stk + = happySeq fn (happyGoto nt j tk st (HappyCons st sts) (fn `HappyStk` stk)) -happySpecReduce_1 i fn 0# tk st sts stk - = happyFail [] 0# tk st sts stk -happySpecReduce_1 nt fn j tk _ sts@((HappyCons (st@(action)) (_))) (v1`HappyStk`stk') +happySpecReduce_1 nt fn j tk old_st sts@(HappyCons st _) (v1 `HappyStk` stk') = let r = fn v1 in - happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk')) + happyTcHack old_st (happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk'))) -happySpecReduce_2 i fn 0# tk st sts stk - = happyFail [] 0# tk st sts stk -happySpecReduce_2 nt fn j tk _ (HappyCons (_) (sts@((HappyCons (st@(action)) (_))))) (v1`HappyStk`v2`HappyStk`stk') +happySpecReduce_2 nt fn j tk old_st + (HappyCons _ sts@(HappyCons st _)) + (v1 `HappyStk` v2 `HappyStk` stk') = let r = fn v1 v2 in - happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk')) + happyTcHack old_st (happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk'))) -happySpecReduce_3 i fn 0# tk st sts stk - = happyFail [] 0# tk st sts stk -happySpecReduce_3 nt fn j tk _ (HappyCons (_) ((HappyCons (_) (sts@((HappyCons (st@(action)) (_))))))) (v1`HappyStk`v2`HappyStk`v3`HappyStk`stk') +happySpecReduce_3 nt fn j tk old_st + (HappyCons _ (HappyCons _ sts@(HappyCons st _))) + (v1 `HappyStk` v2 `HappyStk` v3 `HappyStk` stk') = let r = fn v1 v2 v3 in - happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk')) + happyTcHack old_st (happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk'))) -happyReduce k i fn 0# tk st sts stk - = happyFail [] 0# tk st sts stk happyReduce k nt fn j tk st sts stk - = case happyDrop (k Happy_GHC_Exts.-# (1# :: Happy_GHC_Exts.Int#)) sts of - sts1@((HappyCons (st1@(action)) (_))) -> - let r = fn stk in -- it doesn't hurt to always seq here... - happyDoSeq r (happyGoto nt j tk st1 sts1 r) + = case happyDrop MINUS(k,(1# :: Happy_Int)) sts of + sts1@(HappyCons st1 _) -> + let r = fn stk in -- it doesn't hurt to always seq here... + st `happyTcHack` happyDoSeq r (happyGoto nt j tk st1 sts1 r) -happyMonadReduce k nt fn 0# tk st sts stk - = happyFail [] 0# tk st sts stk happyMonadReduce k nt fn j tk st sts stk = - case happyDrop k (HappyCons (st) (sts)) of - sts1@((HappyCons (st1@(action)) (_))) -> + case happyDrop k (HappyCons st sts) of + sts1@(HappyCons st1 _) -> let drop_stk = happyDropStk k stk in - happyThen1 (fn stk tk) (\r -> happyGoto nt j tk st1 sts1 (r `HappyStk` drop_stk)) + j `happyTcHack` happyThen1 (fn stk tk) + (\r -> happyGoto nt j tk st1 sts1 (r `HappyStk` drop_stk)) -happyMonad2Reduce k nt fn 0# tk st sts stk - = happyFail [] 0# tk st sts stk happyMonad2Reduce k nt fn j tk st sts stk = - case happyDrop k (HappyCons (st) (sts)) of - sts1@((HappyCons (st1@(action)) (_))) -> - let drop_stk = happyDropStk k stk - - off = happyAdjustOffset (indexShortOffAddr happyGotoOffsets st1) - off_i = (off Happy_GHC_Exts.+# nt) - new_state = indexShortOffAddr happyTable off_i - - - - + case happyDrop k (HappyCons st sts) of + sts1@(HappyCons st1 _) -> + let drop_stk = happyDropStk k stk + off = happyIndexOffAddr happyGotoOffsets st1 + off_i = PLUS(off, nt) + new_state = happyIndexOffAddr happyTable off_i in - happyThen1 (fn stk tk) (\r -> happyNewToken new_state sts1 (r `HappyStk` drop_stk)) + j `happyTcHack` happyThen1 (fn stk tk) + (\r -> happyNewToken new_state sts1 (r `HappyStk` drop_stk)) -happyDrop 0# l = l -happyDrop n (HappyCons (_) (t)) = happyDrop (n Happy_GHC_Exts.-# (1# :: Happy_GHC_Exts.Int#)) t +happyDrop 0# l = l +happyDrop n (HappyCons _ t) = happyDrop MINUS(n,(1# :: Happy_Int)) t -happyDropStk 0# l = l -happyDropStk n (x `HappyStk` xs) = happyDropStk (n Happy_GHC_Exts.-# (1#::Happy_GHC_Exts.Int#)) xs +happyDropStk 0# l = l +happyDropStk n (x `HappyStk` xs) = happyDropStk MINUS(n,(1#::Happy_Int)) xs ----------------------------------------------------------------------------- -- Moving to a new state after a reduction - -happyGoto nt j tk st = - {- nothing -} +happyGoto nt j tk st = + DEBUG_TRACE(", goto state " ++ show (Happy_GHC_Exts.I# new_state) ++ "\n") happyDoAction j tk new_state - where off = happyAdjustOffset (indexShortOffAddr happyGotoOffsets st) - off_i = (off Happy_GHC_Exts.+# nt) - new_state = indexShortOffAddr happyTable off_i - - - - ------------------------------------------------------------------------------ --- Error recovery (ERROR_TOK is the error token) - --- parse error if we are in recovery and we fail again -happyFail explist 0# tk old_st _ stk@(x `HappyStk` _) = - let i = (case Happy_GHC_Exts.unsafeCoerce# x of { (Happy_GHC_Exts.I# (i)) -> i }) in --- trace "failing" $ - happyError_ explist i tk - -{- We don't need state discarding for our restricted implementation of - "error". In fact, it can cause some bogus parses, so I've disabled it - for now --SDM - --- discard a state -happyFail ERROR_TOK tk old_st CONS(HAPPYSTATE(action),sts) - (saved_tok `HappyStk` _ `HappyStk` stk) = --- trace ("discarding state, depth " ++ show (length stk)) $ - DO_ACTION(action,ERROR_TOK,tk,sts,(saved_tok`HappyStk`stk)) + where new_state = happyIndexGotoTable nt st + +{- Note [Error recovery] +~~~~~~~~~~~~~~~~~~~~~~~~ +When there is no applicable action for the current lookahead token `tk`, +happy enters error recovery mode. Depending on whether the grammar file +declares the two action form `%error { abort } { report }` for + Resumptive Error Handling, +it works in one (not resumptive) or two phases (resumptive): + + 1. Fixup mode: + Try to see if there is an action for the error token ERROR_TOK. If there + is, do *not* emit an error and pretend instead that an `error` token was + inserted. + When there is no ERROR_TOK action, report an error. + + In non-resumptive error handling, calling the single error handler + (e.g. `happyError`) will throw an exception and abort the parser. + However, in resumptive error handling we enter *error resumption mode*. + + 2. Error resumption mode: + After reporting the error (with `report`), happy will attempt to find + a good state stack to resume parsing in. + For each candidate stack, it discards input until one of the candidates + resumes (i.e. shifts the current input). + If no candidate resumes before the end of input, resumption failed and + calls the `abort` function, to much the same effect as in non-resumptive + error handling. + + Candidate stacks are declared by the grammar author using the special + `catch` terminal and called "catch frames". + This mechanism is described in detail in Note [happyResume]. + +The `catch` resumption mechanism (2) is what usually is associated with +`error` in `bison` or `menhir`. Since `error` is used for the Fixup mechanism +(1) above, we call the corresponding token `catch`. +Furthermore, in constrast to `bison`, our implementation of `catch` +non-deterministically considers multiple catch frames on the stack for +resumption (See Note [Multiple catch frames]). + +Note [happyResume] +~~~~~~~~~~~~~~~~~~ +`happyResume` implements the resumption mechanism from Note [Error recovery]. +It is best understood by example. Consider + +Exp :: { String } +Exp : '1' { "1" } + | catch { "catch" } + | Exp '+' Exp %shift { $1 ++ " + " ++ $3 } -- %shift: associate 1 + 1 + 1 to the right + | '(' Exp ')' { "(" ++ $2 ++ ")" } + +The idea of the use of `catch` here is that upon encountering a parse error +during expression parsing, we can gracefully degrade using the `catch` rule, +still producing a partial syntax tree and keep on parsing to find further +syntax errors. + +Let's trace the parser state for input 11+1, which will error out after shifting 1. +After shifting, we have the following item stack (growing downwards and omitting +transitive closure items): + + State 0: %start_parseExp -> . Exp + State 5: Exp -> '1' . + +(Stack as a list of state numbers: [5,0].) +As Note [Error recovery] describes, we will first try Fixup mode. +That fails because no production can shift the `error` token. +Next we try Error resumption mode. This works as follows: + + 1. Pop off the item stack until we find an item that can shift the `catch` + token. (Implemented in `pop_items`.) + * State 5 cannot shift catch. Pop. + * State 0 can shift catch, which would transition into + State 4: Exp -> catch . + So record the *stack* `[4,0]` after doing the shift transition. + We call this a *catch frame*, where the top is a *catch state*, + corresponding to an item in which we just shifted a `catch` token. + There can be multiple such catch stacks, see Note [Multiple catch frames]. + + 2. Discard tokens from the input until the lookahead can be shifted in one + of the catch stacks. (Implemented in `discard_input_until_exp` and + `some_catch_state_shifts`.) + * We cannot shift the current lookahead '1' in state 4, so we discard + * We *can* shift the next lookahead '+' in state 4, but only after + reducing, which pops State 4 and goes to State 3: + State 3: %start_parseExp -> Exp . + Exp -> Exp . '+' Exp + Here we can shift '+'. + As you can see, to implement this machinery we need to simulate + the operation of the LALR automaton, especially reduction + (`happySimulateReduce`). + +Note [Multiple catch frames] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +For fewer spurious error messages, it can be beneficial to trace multiple catch +items. Consider + +Exp : '1' + | catch + | Exp '+' Exp %shift + | '(' Exp ')' + +Let's trace the parser state for input (;+1, which will error out after shifting (. +After shifting, we have the following item stack (growing downwards): + + State 0: %start_parseExp -> . Exp + State 6: Exp -> '(' . Exp ')' + +Upon error, we want to find items in the stack which can shift a catch token. +Note that both State 0 and State 6 can shift a catch token, transitioning into + State 4: Exp -> catch . +Hence we record the catch frames `[4,6,0]` and `[4,0]` for possible resumption. + +Which catch frame do we pick for resumption? +Note that resuming catch frame `[4,0]` will parse as "catch+1", whereas +resuming the innermost frame `[4,6,0]` corresponds to parsing "(catch+1". +The latter would keep discarding input until the closing ')' is found. +So we will discard + and 1, leading to a spurious syntax error at the end of +input, aborting the parse and never producing a partial syntax tree. Bad! + +It is far preferable to resume with catch frame `[4,0]`, where we can resume +successfully on input +, so that is what we do. + +In general, we pick the catch frame for resumption that discards the least +amount of input for a successful shift, preferring the topmost such catch frame. -} --- Enter error recovery: generate an error token, --- save the old token and carry on. -happyFail explist i tk (action) sts stk = --- trace "entering error recovery" $ - happyDoAction 0# tk action sts ((Happy_GHC_Exts.unsafeCoerce# (Happy_GHC_Exts.I# (i))) `HappyStk` stk) +-- happyFail :: Happy_Int -> _ -> Happy_Int -> _ +-- This function triggers Note [Error recovery]. +-- If the current token is ERROR_TOK, phase (1) has failed and we might try +-- phase (2). +happyFail ERROR_TOK = happyFixupFailed +happyFail i = happyTryFixup i + +-- Enter Error Fixup (see Note [Error recovery]): +-- generate an error token, save the old token and carry on. +-- When a `happyShift` accepts the error token, we will pop off the error token +-- to resume parsing with the current lookahead `i`. +happyTryFixup i tk action sts stk = + DEBUG_TRACE("entering `error` fixup.\n") + happyDoAction ERROR_TOK tk action sts (MK_ERROR_TOKEN(i) `HappyStk` stk) + -- NB: `happyShift` will simply pop the error token and carry on with + -- `tk`. Hence we don't change `tk` in the call here + +-- See Note [Error recovery], phase (2). +-- Enter resumption mode after reporting the error by calling `happyResume`. +happyFixupFailed tk st sts (x `HappyStk` stk) = + let i = GET_ERROR_TOKEN(x) in + DEBUG_TRACE("`error` fixup failed.\n") + let resume = happyResume i tk st sts stk + expected = happyExpectedTokens st sts in + happyReport i tk expected resume + +-- happyResume :: Happy_Int -> _ -> Happy_Int -> _ +-- See Note [happyResume] +happyResume i tk st sts stk = pop_items [] st sts stk + where + !(Happy_GHC_Exts.I# n_starts) = happy_n_starts -- this is to test whether we have a start token + !(Happy_GHC_Exts.I# eof_i) = happy_n_terms - 1 -- this is the token number of the EOF token + happy_list_to_list :: Happy_IntList -> [Int] + happy_list_to_list (HappyCons st sts) + | LT(st, n_starts) + = [(Happy_GHC_Exts.I# st)] + | otherwise + = (Happy_GHC_Exts.I# st) : happy_list_to_list sts + + -- See (1) of Note [happyResume] + pop_items catch_frames st sts stk + | LT(st, n_starts) + = DEBUG_TRACE("reached start state " ++ show (Happy_GHC_Exts.I# st) ++ ", ") + if null catch_frames_new + then DEBUG_TRACE("no resumption.\n") + happyAbort + else DEBUG_TRACE("now discard input, trying to anchor in states (reverse " ++ show (map (happy_list_to_list . fst) catch_frames_new) ++ ").\n") + discard_input_until_exp i tk (reverse catch_frames_new) + | (HappyCons st1 sts1) <- sts, _ `HappyStk` stk1 <- stk + = pop_items catch_frames_new st1 sts1 stk1 + where + !catch_frames_new + | HappyShift new_state <- happyDecodeAction (happyNextAction CATCH_TOK st) + , DEBUG_TRACE("can shift catch token in state " ++ show (Happy_GHC_Exts.I# st) ++ ", into state " ++ show (Happy_GHC_Exts.I# new_state) ++ "\n") + null (filter (\(HappyCons _ (HappyCons h _),_) -> EQ(st,h)) catch_frames) + = (HappyCons new_state (HappyCons st sts), MK_ERROR_TOKEN(i) `HappyStk` stk):catch_frames -- MK_ERROR_TOKEN(i) is just some dummy that should not be accessed by user code + | otherwise + = DEBUG_TRACE("already shifted or can't shift catch in " ++ show (Happy_GHC_Exts.I# st) ++ "\n") + catch_frames + + -- See (2) of Note [happyResume] + discard_input_until_exp i tk catch_frames + | Just (HappyCons st (HappyCons catch_st sts), catch_frame) <- some_catch_state_shifts i catch_frames + = DEBUG_TRACE("found expected token in state " ++ show (Happy_GHC_Exts.I# st) ++ " after shifting from " ++ show (Happy_GHC_Exts.I# catch_st) ++ ": " ++ show (Happy_GHC_Exts.I# i) ++ "\n") + happyDoAction i tk st (HappyCons catch_st sts) catch_frame + | EQ(i,eof_i) -- is i EOF? + = DEBUG_TRACE("reached EOF, cannot resume. abort parse :(\n") + happyAbort + | otherwise + = DEBUG_TRACE("discard token " ++ show (Happy_GHC_Exts.I# i) ++ "\n") + happyLex (\eof_tk -> discard_input_until_exp eof_i eof_tk catch_frames) -- eof + (\i tk -> discard_input_until_exp i tk catch_frames) -- not eof + + some_catch_state_shifts _ [] = DEBUG_TRACE("no catch state could shift.\n") Nothing + some_catch_state_shifts i catch_frames@(((HappyCons st sts),_):_) = try_head i st sts catch_frames + where + try_head i st sts catch_frames = -- PRECONDITION: head catch_frames = (HappyCons st sts) + DEBUG_TRACE("trying token " ++ show (Happy_GHC_Exts.I# i) ++ " in state " ++ show (Happy_GHC_Exts.I# st) ++ ": ") + case happyDecodeAction (happyNextAction i st) of + HappyFail -> DEBUG_TRACE("fail.\n") some_catch_state_shifts i (tail catch_frames) + HappyAccept -> DEBUG_TRACE("accept.\n") Just (head catch_frames) + HappyShift _ -> DEBUG_TRACE("shift.\n") Just (head catch_frames) + HappyReduce r -> case happySimulateReduce r st sts of + (HappyCons st1 sts1) -> try_head i st1 sts1 catch_frames + +happySimulateReduce r st sts = + DEBUG_TRACE("simulate reduction of rule " ++ show (Happy_GHC_Exts.I# r) ++ ", ") + let (# nt, len #) = happyIndexRuleArr r in + DEBUG_TRACE("nt " ++ show (Happy_GHC_Exts.I# nt) ++ ", len: " ++ show (Happy_GHC_Exts.I# len) ++ ", new_st ") + let !(sts1@(HappyCons st1 _)) = happyDrop len (HappyCons st sts) + new_st = happyIndexGotoTable nt st1 in + DEBUG_TRACE(show (Happy_GHC_Exts.I# new_st) ++ ".\n") + (HappyCons new_st sts1) + +happyTokenToString :: Prelude.Int -> Prelude.String +happyTokenToString i = happyTokenStrings Prelude.!! (i Prelude.- 2) -- 2: errorTok, catchTok + +happyExpectedTokens :: Happy_Int -> Happy_IntList -> [Prelude.String] +-- Upon a parse error, we want to suggest tokens that are expected in that +-- situation. This function computes such tokens. +-- It works by examining the top of the state stack. +-- For every token number that does a shift transition, record that token number. +-- For every token number that does a reduce transition, simulate that reduction +-- on the state state stack and repeat. +-- The recorded token numbers are then formatted with 'happyTokenToString' and +-- returned. +happyExpectedTokens st sts = + DEBUG_TRACE("constructing expected tokens.\n") + map happyTokenToString $ search_shifts st sts [] + where + search_shifts st sts shifts = foldr (add_action st sts) shifts (distinct_actions st) + add_action st sts (Happy_GHC_Exts.I# i, Happy_GHC_Exts.I# act) shifts = + DEBUG_TRACE("found action in state " ++ show (Happy_GHC_Exts.I# st) ++ ", input " ++ show (Happy_GHC_Exts.I# i) ++ ", " ++ show (happyDecodeAction act) ++ "\n") + case happyDecodeAction act of + HappyFail -> shifts + HappyAccept -> shifts -- This would always be %eof or error... Not helpful + HappyShift _ -> Happy_Data_List.insert (Happy_GHC_Exts.I# i) shifts + HappyReduce r -> case happySimulateReduce r st sts of + (HappyCons st1 sts1) -> search_shifts st1 sts1 shifts + distinct_actions st + -- The (token number, action) pairs of all actions in the given state + = ((-1), (Happy_GHC_Exts.I# (happyIndexOffAddr happyDefActions st))) + : [ (i, act) | i <- [begin_i..happy_n_terms], act <- get_act row_off i ] + where + row_off = happyIndexOffAddr happyActOffsets st + begin_i = 2 -- +2: errorTok,catchTok + get_act off (Happy_GHC_Exts.I# i) -- happyIndexActionTable with cached row offset + | let off_i = PLUS(off,i) + , GTE(off_i,0#) + , EQ(happyIndexOffAddr happyCheck off_i,i) + = [(Happy_GHC_Exts.I# (happyIndexOffAddr happyTable off_i))] + | otherwise + = [] -- Internal happy errors: notHappyAtAll :: a -notHappyAtAll = Prelude.error "Internal Happy error\n" +notHappyAtAll = Prelude.error "Internal Happy parser panic. This is not supposed to happen! Please open a bug report at https://github.com/haskell/happy/issues.\n" ----------------------------------------------------------------------------- -- Hack to get the typechecker to accept our action functions - -happyTcHack :: Happy_GHC_Exts.Int# -> a -> a +happyTcHack :: Happy_Int -> a -> a happyTcHack x y = y {-# INLINE happyTcHack #-} - ----------------------------------------------------------------------------- --- Seq-ing. If the --strict flag is given, then Happy emits +-- Seq-ing. If the --strict flag is given, then Happy emits -- happySeq = happyDoSeq -- otherwise it emits -- happySeq = happyDontSeq @@ -721,7 +910,6 @@ happyDontSeq a b = b -- of deciding to inline happyGoto everywhere, which increases the size of -- the generated parser quite a bit. - {-# NOINLINE happyDoAction #-} {-# NOINLINE happyTable #-} {-# NOINLINE happyCheck #-} diff --git a/lib/frontend/src/Happy/Frontend/Lexer.lhs b/lib/frontend/src/Happy/Frontend/Lexer.lhs index 8bfe65bd..d51060db 100644 --- a/lib/frontend/src/Happy/Frontend/Lexer.lhs +++ b/lib/frontend/src/Happy/Frontend/Lexer.lhs @@ -37,7 +37,6 @@ The lexer. > | TokSpecId_Token -- %token > | TokSpecId_Name -- %name > | TokSpecId_Partial -- %partial -> | TokSpecId_ErrorHandlerType -- %errorhandlertype > | TokSpecId_Lexer -- %lexer > | TokSpecId_ImportedIdentity -- %importedidentity > | TokSpecId_Monad -- %monad @@ -48,6 +47,7 @@ The lexer. > | TokSpecId_Shift -- %shift > | TokSpecId_Expect -- %expect > | TokSpecId_Error -- %error +> | TokSpecId_ErrorExpected -- %error.expected > | TokSpecId_Attributetype -- %attributetype > | TokSpecId_Attribute -- %attribute > | TokCodeQuote -- stuff inside { .. } @@ -103,42 +103,45 @@ followed by a special identifier. > lexPercent :: (Token -> Pfunc a) -> [Char] -> Int -> ParseResult a > lexPercent cont s = case s of > '%':rest -> cont (TokenKW TokDoublePercent) rest -> 't':'o':'k':'e':'n':'t':'y':'p':'e':rest -> +> 't':'o':'k':'e':'n':'t':'y':'p':'e':rest | end_of_id rest -> > cont (TokenKW TokSpecId_TokenType) rest -> 't':'o':'k':'e':'n':rest -> +> 't':'o':'k':'e':'n':rest | end_of_id rest -> > cont (TokenKW TokSpecId_Token) rest -> 'n':'a':'m':'e':rest -> +> 'n':'a':'m':'e':rest | end_of_id rest -> > cont (TokenKW TokSpecId_Name) rest -> 'p':'a':'r':'t':'i':'a':'l':rest -> +> 'p':'a':'r':'t':'i':'a':'l':rest | end_of_id rest -> > cont (TokenKW TokSpecId_Partial) rest -> 'i':'m':'p':'o':'r':'t':'e':'d':'i':'d':'e':'n':'t':'i':'t':'y':rest -> +> 'i':'m':'p':'o':'r':'t':'e':'d':'i':'d':'e':'n':'t':'i':'t':'y':rest | end_of_id rest -> > cont (TokenKW TokSpecId_ImportedIdentity) rest -> 'm':'o':'n':'a':'d':rest -> +> 'm':'o':'n':'a':'d':rest | end_of_id rest -> > cont (TokenKW TokSpecId_Monad) rest -> 'l':'e':'x':'e':'r':rest -> +> 'l':'e':'x':'e':'r':rest | end_of_id rest -> > cont (TokenKW TokSpecId_Lexer) rest -> 'n':'o':'n':'a':'s':'s':'o':'c':rest -> +> 'n':'o':'n':'a':'s':'s':'o':'c':rest | end_of_id rest -> > cont (TokenKW TokSpecId_Nonassoc) rest -> 'l':'e':'f':'t':rest -> +> 'l':'e':'f':'t':rest | end_of_id rest -> > cont (TokenKW TokSpecId_Left) rest -> 'r':'i':'g':'h':'t':rest -> +> 'r':'i':'g':'h':'t':rest | end_of_id rest -> > cont (TokenKW TokSpecId_Right) rest -> 'p':'r':'e':'c':rest -> +> 'p':'r':'e':'c':rest | end_of_id rest -> > cont (TokenKW TokSpecId_Prec) rest -> 's':'h':'i':'f':'t':rest -> +> 's':'h':'i':'f':'t':rest | end_of_id rest -> > cont (TokenKW TokSpecId_Shift) rest -> 'e':'x':'p':'e':'c':'t':rest -> +> 'e':'x':'p':'e':'c':'t':rest | end_of_id rest -> > cont (TokenKW TokSpecId_Expect) rest -> 'e':'r':'r':'o':'r':'h':'a':'n':'d':'l':'e':'r':'t':'y':'p':'e':rest -> -> cont (TokenKW TokSpecId_ErrorHandlerType) rest -> 'e':'r':'r':'o':'r':rest -> +> 'e':'r':'r':'o':'r':'.':'e':'x':'p':'e':'c':'t':'e':'d':rest | end_of_id rest -> +> cont (TokenKW TokSpecId_ErrorExpected) rest +> 'e':'r':'r':'o':'r':rest | end_of_id rest -> > cont (TokenKW TokSpecId_Error) rest -> 'a':'t':'t':'r':'i':'b':'u':'t':'e':'t':'y':'p':'e':rest -> +> 'a':'t':'t':'r':'i':'b':'u':'t':'e':'t':'y':'p':'e':rest | end_of_id rest -> > cont (TokenKW TokSpecId_Attributetype) rest -> 'a':'t':'t':'r':'i':'b':'u':'t':'e':rest -> +> 'a':'t':'t':'r':'i':'b':'u':'t':'e':rest | end_of_id rest -> > cont (TokenKW TokSpecId_Attribute) rest > _ -> lexError ("unrecognised directive: %" ++ > takeWhile (not.isSpace) s) s +> where +> end_of_id (c:_) = not (isAlphaNum c) +> end_of_id [] = True > lexColon :: (Token -> Pfunc a) -> [Char] -> Int -> ParseResult a > lexColon cont (':':rest) = cont (TokenKW TokDoubleColon) rest diff --git a/lib/frontend/src/Happy/Frontend/Mangler.lhs b/lib/frontend/src/Happy/Frontend/Mangler.lhs index 622785e6..bbda6dbe 100644 --- a/lib/frontend/src/Happy/Frontend/Mangler.lhs +++ b/lib/frontend/src/Happy/Frontend/Mangler.lhs @@ -85,25 +85,31 @@ go do special processing. If not, pass on to the regular processing routine > starts' = case getParserNames dirs of > [] -> [TokenName "happyParse" Nothing False] > ns -> ns +> error_resumptive | ResumptiveErrorHandler{} <- getError dirs = True +> | otherwise = False > > start_strs = [ startName++'_':p | (TokenName p _ _) <- starts' ] Build up a mapping from name values to strings. > name_env = (errorTok, errorName) : +> (catchTok, catchName) : > (dummyTok, dummyName) : > zip start_names start_strs ++ > zip nonterm_names nonterm_strs ++ > zip terminal_names terminal_strs > lookupName :: String -> [Name] -> lookupName n = [ t | (t,r) <- name_env, r == n ] +> lookupName n = [ t | (t,r) <- name_env, r == n +> , t /= catchTok || error_resumptive ] +> -- hide catchName unless %errorresumptive is active +> -- issue93.y uses catch as a nonterminal, we should not steal it > mapToName str' = > case lookupName str' of > [a] -> return a > [] -> do addErr ("unknown identifier '" ++ str' ++ "'") -> return errorTok +> return errorTok -- SG: What a confusing use of errorTok.. Use dummyTok? > (a:_) -> do addErr ("multiple use of '" ++ str' ++ "'") > return a @@ -242,7 +248,7 @@ Get the token specs in terms of Names. > lookupProdNo = (prod_array !), > lookupProdsOfName = lookup_prods, > token_specs = tokspec, -> terminals = errorTok : terminal_names, +> terminals = errorTok : catchTok : terminal_names, > non_terminals = start_names ++ nonterm_names, > -- INCLUDES the %start tokens > starts = zip4 parser_names start_names start_toks @@ -259,7 +265,7 @@ Get the token specs in terms of Names. > monad = getMonad dirs, > lexer = getLexer dirs, > error_handler = getError dirs, -> error_sig = getErrorHandlerType dirs, +> error_expected = getErrorHandlerExpectedList dirs, > token_type = getTokenType dirs, > expect = getExpect dirs > }) diff --git a/lib/frontend/src/Happy/Frontend/Parser.hs b/lib/frontend/src/Happy/Frontend/Parser.hs index 6c19582d..cc2013bc 100644 --- a/lib/frontend/src/Happy/Frontend/Parser.hs +++ b/lib/frontend/src/Happy/Frontend/Parser.hs @@ -1,7 +1,15 @@ {-# OPTIONS_GHC -w #-} -{-# OPTIONS -XMagicHash -XBangPatterns -XTypeSynonymInstances -XFlexibleInstances -cpp #-} +{-# LANGUAGE CPP #-} +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE BangPatterns #-} +{-# LANGUAGE TypeSynonymInstances #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE PatternGuards #-} +{-# LANGUAGE NoStrictData #-} +{-# LANGUAGE UnboxedTuples #-} +{-# LANGUAGE PartialTypeSignatures #-} #if __GLASGOW_HASKELL__ >= 710 -{-# OPTIONS_GHC -XPartialTypeSignatures #-} +{-# LANGUAGE PartialTypeSignatures #-} #endif {-# OPTIONS_GHC -w #-} module Happy.Frontend.Parser (ourParser) where @@ -10,12 +18,13 @@ import Happy.Frontend.ParseMonad import Happy.Frontend.AbsSyn import Happy.Frontend.Lexer import qualified Data.Array as Happy_Data_Array +import qualified Data.List as Happy_Data_List import qualified Data.Bits as Bits import qualified GHC.Exts as Happy_GHC_Exts import Control.Applicative(Applicative(..)) import Control.Monad (ap) --- parser produced by Happy Version 1.20.1.1 +-- parser produced by Happy Version 2.0.2 newtype HappyAbsSyn = HappyAbsSyn HappyAny #if __GLASGOW_HASKELL__ >= 607 @@ -23,36 +32,29 @@ type HappyAny = Happy_GHC_Exts.Any #else type HappyAny = forall a . a #endif -newtype HappyWrap4 = HappyWrap4 (BookendedAbsSyn) -happyIn4 :: (BookendedAbsSyn) -> (HappyAbsSyn ) -happyIn4 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap4 x) -{-# INLINE happyIn4 #-} -happyOut4 :: (HappyAbsSyn ) -> HappyWrap4 -happyOut4 x = Happy_GHC_Exts.unsafeCoerce# x -{-# INLINE happyOut4 #-} -newtype HappyWrap5 = HappyWrap5 (AbsSyn String) -happyIn5 :: (AbsSyn String) -> (HappyAbsSyn ) +newtype HappyWrap5 = HappyWrap5 (BookendedAbsSyn) +happyIn5 :: (BookendedAbsSyn) -> (HappyAbsSyn ) happyIn5 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap5 x) {-# INLINE happyIn5 #-} happyOut5 :: (HappyAbsSyn ) -> HappyWrap5 happyOut5 x = Happy_GHC_Exts.unsafeCoerce# x {-# INLINE happyOut5 #-} -newtype HappyWrap6 = HappyWrap6 ([Rule String]) -happyIn6 :: ([Rule String]) -> (HappyAbsSyn ) +newtype HappyWrap6 = HappyWrap6 (AbsSyn String) +happyIn6 :: (AbsSyn String) -> (HappyAbsSyn ) happyIn6 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap6 x) {-# INLINE happyIn6 #-} happyOut6 :: (HappyAbsSyn ) -> HappyWrap6 happyOut6 x = Happy_GHC_Exts.unsafeCoerce# x {-# INLINE happyOut6 #-} -newtype HappyWrap7 = HappyWrap7 (Rule String) -happyIn7 :: (Rule String) -> (HappyAbsSyn ) +newtype HappyWrap7 = HappyWrap7 ([Rule String]) +happyIn7 :: ([Rule String]) -> (HappyAbsSyn ) happyIn7 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap7 x) {-# INLINE happyIn7 #-} happyOut7 :: (HappyAbsSyn ) -> HappyWrap7 happyOut7 x = Happy_GHC_Exts.unsafeCoerce# x {-# INLINE happyOut7 #-} -newtype HappyWrap8 = HappyWrap8 ([String]) -happyIn8 :: ([String]) -> (HappyAbsSyn ) +newtype HappyWrap8 = HappyWrap8 (Rule String) +happyIn8 :: (Rule String) -> (HappyAbsSyn ) happyIn8 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap8 x) {-# INLINE happyIn8 #-} happyOut8 :: (HappyAbsSyn ) -> HappyWrap8 @@ -65,29 +67,29 @@ happyIn9 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap9 x) happyOut9 :: (HappyAbsSyn ) -> HappyWrap9 happyOut9 x = Happy_GHC_Exts.unsafeCoerce# x {-# INLINE happyOut9 #-} -newtype HappyWrap10 = HappyWrap10 ([Prod String]) -happyIn10 :: ([Prod String]) -> (HappyAbsSyn ) +newtype HappyWrap10 = HappyWrap10 ([String]) +happyIn10 :: ([String]) -> (HappyAbsSyn ) happyIn10 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap10 x) {-# INLINE happyIn10 #-} happyOut10 :: (HappyAbsSyn ) -> HappyWrap10 happyOut10 x = Happy_GHC_Exts.unsafeCoerce# x {-# INLINE happyOut10 #-} -newtype HappyWrap11 = HappyWrap11 (Prod String) -happyIn11 :: (Prod String) -> (HappyAbsSyn ) +newtype HappyWrap11 = HappyWrap11 ([Prod String]) +happyIn11 :: ([Prod String]) -> (HappyAbsSyn ) happyIn11 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap11 x) {-# INLINE happyIn11 #-} happyOut11 :: (HappyAbsSyn ) -> HappyWrap11 happyOut11 x = Happy_GHC_Exts.unsafeCoerce# x {-# INLINE happyOut11 #-} -newtype HappyWrap12 = HappyWrap12 (Term) -happyIn12 :: (Term) -> (HappyAbsSyn ) +newtype HappyWrap12 = HappyWrap12 (Prod String) +happyIn12 :: (Prod String) -> (HappyAbsSyn ) happyIn12 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap12 x) {-# INLINE happyIn12 #-} happyOut12 :: (HappyAbsSyn ) -> HappyWrap12 happyOut12 x = Happy_GHC_Exts.unsafeCoerce# x {-# INLINE happyOut12 #-} -newtype HappyWrap13 = HappyWrap13 ([Term]) -happyIn13 :: ([Term]) -> (HappyAbsSyn ) +newtype HappyWrap13 = HappyWrap13 (Term) +happyIn13 :: (Term) -> (HappyAbsSyn ) happyIn13 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap13 x) {-# INLINE happyIn13 #-} happyOut13 :: (HappyAbsSyn ) -> HappyWrap13 @@ -107,62 +109,69 @@ happyIn15 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap15 x) happyOut15 :: (HappyAbsSyn ) -> HappyWrap15 happyOut15 x = Happy_GHC_Exts.unsafeCoerce# x {-# INLINE happyOut15 #-} -newtype HappyWrap16 = HappyWrap16 (Prec) -happyIn16 :: (Prec) -> (HappyAbsSyn ) +newtype HappyWrap16 = HappyWrap16 ([Term]) +happyIn16 :: ([Term]) -> (HappyAbsSyn ) happyIn16 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap16 x) {-# INLINE happyIn16 #-} happyOut16 :: (HappyAbsSyn ) -> HappyWrap16 happyOut16 x = Happy_GHC_Exts.unsafeCoerce# x {-# INLINE happyOut16 #-} -newtype HappyWrap17 = HappyWrap17 ([Directive String]) -happyIn17 :: ([Directive String]) -> (HappyAbsSyn ) +newtype HappyWrap17 = HappyWrap17 (Prec) +happyIn17 :: (Prec) -> (HappyAbsSyn ) happyIn17 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap17 x) {-# INLINE happyIn17 #-} happyOut17 :: (HappyAbsSyn ) -> HappyWrap17 happyOut17 x = Happy_GHC_Exts.unsafeCoerce# x {-# INLINE happyOut17 #-} -newtype HappyWrap18 = HappyWrap18 (Directive String) -happyIn18 :: (Directive String) -> (HappyAbsSyn ) +newtype HappyWrap18 = HappyWrap18 ([Directive String]) +happyIn18 :: ([Directive String]) -> (HappyAbsSyn ) happyIn18 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap18 x) {-# INLINE happyIn18 #-} happyOut18 :: (HappyAbsSyn ) -> HappyWrap18 happyOut18 x = Happy_GHC_Exts.unsafeCoerce# x {-# INLINE happyOut18 #-} -newtype HappyWrap19 = HappyWrap19 (Maybe String) -happyIn19 :: (Maybe String) -> (HappyAbsSyn ) +newtype HappyWrap19 = HappyWrap19 (Directive String) +happyIn19 :: (Directive String) -> (HappyAbsSyn ) happyIn19 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap19 x) {-# INLINE happyIn19 #-} happyOut19 :: (HappyAbsSyn ) -> HappyWrap19 happyOut19 x = Happy_GHC_Exts.unsafeCoerce# x {-# INLINE happyOut19 #-} -newtype HappyWrap20 = HappyWrap20 ([(String, TokenSpec)]) -happyIn20 :: ([(String, TokenSpec)]) -> (HappyAbsSyn ) +newtype HappyWrap20 = HappyWrap20 (Maybe String) +happyIn20 :: (Maybe String) -> (HappyAbsSyn ) happyIn20 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap20 x) {-# INLINE happyIn20 #-} happyOut20 :: (HappyAbsSyn ) -> HappyWrap20 happyOut20 x = Happy_GHC_Exts.unsafeCoerce# x {-# INLINE happyOut20 #-} -newtype HappyWrap21 = HappyWrap21 ((String, TokenSpec)) -happyIn21 :: ((String, TokenSpec)) -> (HappyAbsSyn ) +newtype HappyWrap21 = HappyWrap21 ([(String, TokenSpec)]) +happyIn21 :: ([(String, TokenSpec)]) -> (HappyAbsSyn ) happyIn21 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap21 x) {-# INLINE happyIn21 #-} happyOut21 :: (HappyAbsSyn ) -> HappyWrap21 happyOut21 x = Happy_GHC_Exts.unsafeCoerce# x {-# INLINE happyOut21 #-} -newtype HappyWrap22 = HappyWrap22 ([String]) -happyIn22 :: ([String]) -> (HappyAbsSyn ) +newtype HappyWrap22 = HappyWrap22 ((String, TokenSpec)) +happyIn22 :: ((String, TokenSpec)) -> (HappyAbsSyn ) happyIn22 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap22 x) {-# INLINE happyIn22 #-} happyOut22 :: (HappyAbsSyn ) -> HappyWrap22 happyOut22 x = Happy_GHC_Exts.unsafeCoerce# x {-# INLINE happyOut22 #-} -newtype HappyWrap23 = HappyWrap23 (Maybe String) -happyIn23 :: (Maybe String) -> (HappyAbsSyn ) +newtype HappyWrap23 = HappyWrap23 ([String]) +happyIn23 :: ([String]) -> (HappyAbsSyn ) happyIn23 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap23 x) {-# INLINE happyIn23 #-} happyOut23 :: (HappyAbsSyn ) -> HappyWrap23 happyOut23 x = Happy_GHC_Exts.unsafeCoerce# x {-# INLINE happyOut23 #-} +newtype HappyWrap24 = HappyWrap24 (Maybe String) +happyIn24 :: (Maybe String) -> (HappyAbsSyn ) +happyIn24 x = Happy_GHC_Exts.unsafeCoerce# (HappyWrap24 x) +{-# INLINE happyIn24 #-} +happyOut24 :: (HappyAbsSyn ) -> HappyWrap24 +happyOut24 x = Happy_GHC_Exts.unsafeCoerce# x +{-# INLINE happyOut24 #-} happyInTok :: (Token) -> (HappyAbsSyn ) happyInTok x = Happy_GHC_Exts.unsafeCoerce# x {-# INLINE happyInTok #-} @@ -171,785 +180,747 @@ happyOutTok x = Happy_GHC_Exts.unsafeCoerce# x {-# INLINE happyOutTok #-} -happyExpList :: HappyAddr -happyExpList = HappyA# "\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\xff\xf3\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\xff\xf3\x41\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x08\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x08\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x20\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x20\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x28\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"# - -{-# NOINLINE happyExpListPerState #-} -happyExpListPerState st = - token_strs_expected - where token_strs = ["error","%dummy","%start_ourParser","parser","core_parser","rules","rule","params","comma_ids","prods","prod","term","terms","terms_rev","comma_terms","prec","tokInfos","tokInfo","optStart","tokenSpecs","tokenSpec","ids","optCode","id","spec_tokentype","spec_token","spec_name","spec_partial","spec_lexer","spec_imported_identity","spec_monad","spec_nonassoc","spec_left","spec_right","spec_prec","spec_shift","spec_expect","spec_error","spec_errorhandlertype","spec_attribute","spec_attributetype","code","int","\":\"","\";\"","\"::\"","\"%%\"","\"|\"","\"(\"","\")\"","\",\"","%eof"] - bit_start = st Prelude.* 52 - bit_end = (st Prelude.+ 1) Prelude.* 52 - read_bit = readArrayBit happyExpList - bits = Prelude.map read_bit [bit_start..bit_end Prelude.- 1] - bits_indexed = Prelude.zip bits [0..51] - token_strs_expected = Prelude.concatMap f bits_indexed - f (Prelude.False, _) = [] - f (Prelude.True, nr) = [token_strs Prelude.!! nr] +{-# NOINLINE happyTokenStrings #-} +happyTokenStrings = ["id","spec_tokentype","spec_token","spec_name","spec_partial","spec_lexer","spec_imported_identity","spec_monad","spec_nonassoc","spec_left","spec_right","spec_prec","spec_shift","spec_expect","spec_error","spec_errorexpected","spec_attribute","spec_attributetype","code","int","\":\"","\";\"","\"::\"","\"%%\"","\"|\"","\"(\"","\")\"","\",\"","%eof"] happyActOffsets :: HappyAddr -happyActOffsets = HappyA# "\x01\x00\x01\x00\x24\x00\x00\x00\xf9\xff\x32\x00\xff\xff\x00\x00\x37\x00\x4e\x00\x4f\x00\x50\x00\x3f\x00\x00\x00\x40\x00\x53\x00\x53\x00\x53\x00\x41\x00\x43\x00\x56\x00\x57\x00\x46\x00\x00\x00\x47\x00\x00\x00\x00\x00\x00\x00\x00\x00\x5a\x00\x00\x00\x00\x00\x49\x00\x4a\x00\x5d\x00\x5d\x00\x00\x00\x5e\x00\x4d\x00\x00\x00\x00\x00\x60\x00\x00\x00\x60\x00\x00\x00\x48\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x51\x00\x00\x00\x00\x00\x52\x00\xfe\xff\x62\x00\x00\x00\x15\x00\x00\x00\x65\x00\x54\x00\x00\x00\x0a\x00\x00\x00\x55\x00\x00\x00\x3a\x00\x67\x00\x58\x00\x00\x00\x68\x00\x00\x00\x69\x00\x00\x00\x59\x00\x6a\x00\x00\x00\x6c\x00\x5b\x00\x6e\x00\x00\x00\x6e\x00\x00\x00\x00\x00\x5f\x00\x00\x00\x27\x00\x00\x00\x70\x00\x00\x00\x00\x00\x00\x00\x00\x00"# +happyActOffsets = HappyA# "\x02\x00\x00\x00\x02\x00\x00\x00\x23\x00\x00\x00\x00\x00\x00\x00\xf6\xff\xff\xff\x35\x00\x00\x00\xfe\xff\xff\xff\x00\x00\x00\x00\x3b\x00\x00\x00\x4c\x00\x00\x00\x4e\x00\x00\x00\x4f\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x3f\x00\x00\x00\x52\x00\x00\x00\x52\x00\x00\x00\x52\x00\x00\x00\x40\x00\x00\x00\x42\x00\x00\x00\x00\x00\x00\x00\x55\x00\x00\x00\x44\x00\x00\x00\x00\x00\x00\x00\x45\x00\x00\x00\x46\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x59\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x48\x00\x00\x00\x49\x00\x00\x00\x5c\x00\x00\x00\x5c\x00\x00\x00\x00\x00\x00\x00\x5d\x00\x00\x00\x4d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x5e\x00\x00\x00\x00\x00\x00\x00\x5e\x00\x00\x00\x00\x00\x00\x00\x47\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x50\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x51\x00\x00\x00\xfd\xff\xff\xff\x61\x00\x00\x00\x00\x00\x00\x00\x26\x00\x00\x00\x00\x00\x00\x00\x64\x00\x00\x00\x53\x00\x00\x00\x00\x00\x00\x00\x09\x00\x00\x00\x00\x00\x00\x00\x54\x00\x00\x00\x00\x00\x00\x00\x38\x00\x00\x00\x66\x00\x00\x00\x56\x00\x00\x00\x00\x00\x00\x00\x67\x00\x00\x00\x00\x00\x00\x00\x68\x00\x00\x00\x00\x00\x00\x00\x57\x00\x00\x00\x6a\x00\x00\x00\x00\x00\x00\x00\x6b\x00\x00\x00\x5a\x00\x00\x00\x6d\x00\x00\x00\x00\x00\x00\x00\x6d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x5b\x00\x00\x00\x00\x00\x00\x00\x2b\x00\x00\x00\x00\x00\x00\x00\x71\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"# happyGotoOffsets :: HappyAddr -happyGotoOffsets = HappyA# "\x12\x00\x61\x00\x0b\x00\x00\x00\x00\x00\x63\x00\x6b\x00\x00\x00\x00\x00\x38\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x66\x00\x6d\x00\x6f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x71\x00\x00\x00\x00\x00\x00\x00\x00\x00\x64\x00\x73\x00\x00\x00\x3b\x00\x00\x00\x00\x00\x00\x00\x4b\x00\x00\x00\x74\x00\x00\x00\x76\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x77\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x72\x00\x75\x00\x00\x00\x00\x00\x00\x00\x00\x00\x39\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1a\x00\x00\x00\x31\x00\x00\x00\x36\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x78\x00\x00\x00\x00\x00\x00\x00\x00\x00"# - -happyAdjustOffset :: Happy_GHC_Exts.Int# -> Happy_GHC_Exts.Int# -happyAdjustOffset off = off +happyGotoOffsets = HappyA# "\x12\x00\x00\x00\x62\x00\x00\x00\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x63\x00\x00\x00\x69\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x6c\x00\x00\x00\x6e\x00\x00\x00\x6f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x65\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x74\x00\x00\x00\x75\x00\x00\x00\x00\x00\x00\x00\x3a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x4a\x00\x00\x00\x00\x00\x00\x00\x76\x00\x00\x00\x00\x00\x00\x00\x77\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x78\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x73\x00\x00\x00\x72\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x39\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1a\x00\x00\x00\x00\x00\x00\x00\x31\x00\x00\x00\x00\x00\x00\x00\x36\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x7d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"# happyDefActions :: HappyAddr -happyDefActions = HappyA# "\xc8\xff\x00\x00\x00\x00\xc9\xff\x00\x00\xc8\xff\x00\x00\xe3\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xff\x00\x00\xca\xff\xca\xff\xca\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xd2\xff\x00\x00\xd3\xff\xd4\xff\xd5\xff\xd7\xff\xca\xff\xd6\xff\xd8\xff\xdc\xff\x00\x00\xcf\xff\xcf\xff\xe1\xff\xcd\xff\x00\x00\xe2\xff\xe4\xff\x00\x00\xfe\xff\xfd\xff\xfb\xff\xf6\xff\xcc\xff\xce\xff\xe0\xff\xd0\xff\xdf\xff\xdd\xff\xdb\xff\xcb\xff\xd1\xff\xda\xff\x00\x00\x00\x00\xfc\xff\x00\x00\xf5\xff\xec\xff\x00\x00\xd9\xff\x00\x00\xf8\xff\xf2\xff\xeb\xff\xe5\xff\xed\xff\xef\xff\xf7\xff\x00\x00\xf4\xff\x00\x00\xea\xff\x00\x00\x00\x00\xe6\xff\xec\xff\x00\x00\xec\xff\xfa\xff\xec\xff\xf3\xff\xe7\xff\xf0\xff\xe9\xff\x00\x00\xee\xff\x00\x00\xf1\xff\xf9\xff\xe8\xff"# +happyDefActions = HappyA# "\xc8\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\xc9\xff\xff\xff\x00\x00\x00\x00\xc8\xff\xff\xff\x00\x00\x00\x00\xe3\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xff\xff\xff\x00\x00\x00\x00\xca\xff\xff\xff\xca\xff\xff\xff\xca\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\xd3\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\xd2\xff\xff\xff\x00\x00\x00\x00\xc8\xff\xff\xff\xd5\xff\xff\xff\xd7\xff\xff\xff\xca\xff\xff\xff\xd6\xff\xff\xff\xd8\xff\xff\xff\xdc\xff\xff\xff\x00\x00\x00\x00\xcf\xff\xff\xff\xcf\xff\xff\xff\xe1\xff\xff\xff\xcd\xff\xff\xff\x00\x00\x00\x00\xe2\xff\xff\xff\xe4\xff\xff\xff\x00\x00\x00\x00\xfe\xff\xff\xff\xfd\xff\xff\xff\xfb\xff\xff\xff\xf6\xff\xff\xff\xcc\xff\xff\xff\xce\xff\xff\xff\xe0\xff\xff\xff\xd0\xff\xff\xff\xdf\xff\xff\xff\xdd\xff\xff\xff\xdb\xff\xff\xff\xcb\xff\xff\xff\xd4\xff\xff\xff\xd1\xff\xff\xff\xda\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\xfc\xff\xff\xff\x00\x00\x00\x00\xf5\xff\xff\xff\xec\xff\xff\xff\x00\x00\x00\x00\xd9\xff\xff\xff\x00\x00\x00\x00\xf8\xff\xff\xff\xf2\xff\xff\xff\xeb\xff\xff\xff\xe5\xff\xff\xff\xed\xff\xff\xff\xef\xff\xff\xff\xf7\xff\xff\xff\x00\x00\x00\x00\xf4\xff\xff\xff\x00\x00\x00\x00\xea\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\xe6\xff\xff\xff\xec\xff\xff\xff\x00\x00\x00\x00\xec\xff\xff\xff\xfa\xff\xff\xff\xec\xff\xff\xff\xf3\xff\xff\xff\xe7\xff\xff\xff\xf0\xff\xff\xff\xe9\xff\xff\xff\x00\x00\x00\x00\xee\xff\xff\xff\x00\x00\x00\x00\xf1\xff\xff\xff\xf9\xff\xff\xff\xe8\xff\xff\xff"# happyCheck :: HappyAddr -happyCheck = HappyA# "\xff\xff\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\x0b\x00\x01\x00\x01\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x00\x00\x15\x00\x13\x00\x17\x00\x1d\x00\x18\x00\x0d\x00\x0e\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\x15\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\x13\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\x0b\x00\x1b\x00\x1c\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\x06\x00\x07\x00\x08\x00\x09\x00\x0a\x00\x08\x00\x1b\x00\x1c\x00\x0b\x00\x13\x00\x0c\x00\x0d\x00\x10\x00\x11\x00\x13\x00\x10\x00\x11\x00\x02\x00\x03\x00\x01\x00\x01\x00\x01\x00\x13\x00\x13\x00\x01\x00\x14\x00\x13\x00\x01\x00\x01\x00\x13\x00\x13\x00\x01\x00\x13\x00\x13\x00\x01\x00\x01\x00\x13\x00\x01\x00\x1a\x00\x01\x00\x13\x00\x13\x00\x01\x00\x13\x00\x01\x00\x01\x00\x01\x00\x01\x00\x13\x00\x01\x00\x19\x00\x01\x00\x15\x00\x01\x00\x1a\x00\x0f\x00\x13\x00\x16\x00\x13\x00\x03\x00\x12\x00\x0e\x00\x04\x00\xff\xff\x05\x00\x08\x00\x0c\x00\x12\x00\x08\x00\x12\x00\x0f\x00\x12\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"# +happyCheck = HappyA# "\xff\xff\xff\xff\x03\x00\x00\x00\x04\x00\x00\x00\x05\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\x09\x00\x00\x00\x0a\x00\x00\x00\x0b\x00\x00\x00\x0c\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x0f\x00\x00\x00\x10\x00\x00\x00\x11\x00\x00\x00\x12\x00\x00\x00\x13\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00\x00\x1e\x00\x00\x00\x18\x00\x00\x00\x14\x00\x00\x00\x19\x00\x00\x00\x0d\x00\x00\x00\x0e\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\x09\x00\x00\x00\x0a\x00\x00\x00\x16\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\x09\x00\x00\x00\x0a\x00\x00\x00\x13\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x05\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\x09\x00\x00\x00\x0a\x00\x00\x00\x0b\x00\x00\x00\x0c\x00\x00\x00\x10\x00\x00\x00\x11\x00\x00\x00\x0f\x00\x00\x00\x10\x00\x00\x00\x11\x00\x00\x00\x12\x00\x00\x00\x13\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\x09\x00\x00\x00\x0a\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\x09\x00\x00\x00\x0a\x00\x00\x00\x08\x00\x00\x00\x1c\x00\x00\x00\x1d\x00\x00\x00\x0b\x00\x00\x00\x0d\x00\x00\x00\x0e\x00\x00\x00\x1c\x00\x00\x00\x1d\x00\x00\x00\x14\x00\x00\x00\x10\x00\x00\x00\x11\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x02\x00\x00\x00\x14\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x14\x00\x00\x00\x14\x00\x00\x00\x02\x00\x00\x00\x15\x00\x00\x00\x14\x00\x00\x00\x02\x00\x00\x00\x14\x00\x00\x00\x14\x00\x00\x00\x14\x00\x00\x00\x02\x00\x00\x00\x14\x00\x00\x00\x14\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x14\x00\x00\x00\x1b\x00\x00\x00\x02\x00\x00\x00\x14\x00\x00\x00\x14\x00\x00\x00\x02\x00\x00\x00\x14\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x14\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x1a\x00\x00\x00\x02\x00\x00\x00\x16\x00\x00\x00\x1b\x00\x00\x00\x17\x00\x00\x00\x02\x00\x00\x00\xff\xff\xff\xff\x13\x00\x00\x00\x13\x00\x00\x00\x0e\x00\x00\x00\x13\x00\x00\x00\x03\x00\x00\x00\x08\x00\x00\x00\x04\x00\x00\x00\xff\xff\xff\xff\x05\x00\x00\x00\x12\x00\x00\x00\x0c\x00\x00\x00\x12\x00\x00\x00\x12\x00\x00\x00\x12\x00\x00\x00\x0f\x00\x00\x00\x0f\x00\x00\x00\x08\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"# happyTable :: HappyAddr -happyTable = HappyA# "\x00\x00\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x51\x00\x05\x00\x13\x00\x14\x00\x15\x00\x16\x00\x17\x00\x04\x00\x3e\x00\x04\x00\x3f\x00\xff\xff\x2a\x00\x06\x00\x07\x00\x41\x00\x42\x00\x43\x00\x44\x00\x45\x00\x52\x00\x54\x00\x42\x00\x43\x00\x44\x00\x45\x00\x02\x00\x09\x00\x0a\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x0f\x00\x10\x00\x11\x00\x12\x00\x48\x00\x49\x00\x13\x00\x14\x00\x15\x00\x16\x00\x17\x00\x52\x00\x42\x00\x43\x00\x44\x00\x45\x00\x5c\x00\x42\x00\x43\x00\x44\x00\x45\x00\x57\x00\x5a\x00\x5b\x00\x58\x00\x04\x00\x4e\x00\x4f\x00\x24\x00\x25\x00\x28\x00\x2f\x00\x25\x00\x2b\x00\x2c\x00\x27\x00\x24\x00\x23\x00\x22\x00\x21\x00\x1e\x00\x1c\x00\x1b\x00\x1a\x00\x19\x00\x18\x00\x37\x00\x1e\x00\x35\x00\x34\x00\x32\x00\x27\x00\x2f\x00\x2e\x00\x3a\x00\x3d\x00\x38\x00\x40\x00\x47\x00\x41\x00\x47\x00\x4a\x00\x47\x00\x56\x00\x57\x00\x47\x00\x50\x00\x47\x00\x54\x00\x47\x00\x4b\x00\x32\x00\x02\x00\x5c\x00\x2a\x00\x3a\x00\x1f\x00\x28\x00\x38\x00\x00\x00\x3b\x00\x4b\x00\x4c\x00\x1e\x00\x5d\x00\x1c\x00\x30\x00\x35\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"# +happyTable = HappyA# "\x00\x00\x00\x00\x09\x00\x00\x00\x0a\x00\x00\x00\x0b\x00\x00\x00\x0c\x00\x00\x00\x0d\x00\x00\x00\x0e\x00\x00\x00\x0f\x00\x00\x00\x10\x00\x00\x00\x11\x00\x00\x00\x12\x00\x00\x00\x51\x00\x00\x00\x05\x00\x00\x00\x13\x00\x00\x00\x14\x00\x00\x00\x15\x00\x00\x00\x16\x00\x00\x00\x17\x00\x00\x00\x04\x00\x00\x00\x3e\x00\x00\x00\xff\xff\xff\xff\x3f\x00\x00\x00\x04\x00\x00\x00\x29\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x41\x00\x00\x00\x42\x00\x00\x00\x43\x00\x00\x00\x44\x00\x00\x00\x45\x00\x00\x00\x52\x00\x00\x00\x54\x00\x00\x00\x42\x00\x00\x00\x43\x00\x00\x00\x44\x00\x00\x00\x45\x00\x00\x00\x02\x00\x00\x00\x09\x00\x00\x00\x0a\x00\x00\x00\x0b\x00\x00\x00\x0c\x00\x00\x00\x0d\x00\x00\x00\x0e\x00\x00\x00\x0f\x00\x00\x00\x10\x00\x00\x00\x11\x00\x00\x00\x12\x00\x00\x00\x23\x00\x00\x00\x24\x00\x00\x00\x13\x00\x00\x00\x14\x00\x00\x00\x15\x00\x00\x00\x16\x00\x00\x00\x17\x00\x00\x00\x52\x00\x00\x00\x42\x00\x00\x00\x43\x00\x00\x00\x44\x00\x00\x00\x45\x00\x00\x00\x5c\x00\x00\x00\x42\x00\x00\x00\x43\x00\x00\x00\x44\x00\x00\x00\x45\x00\x00\x00\x57\x00\x00\x00\x48\x00\x00\x00\x49\x00\x00\x00\x58\x00\x00\x00\x4e\x00\x00\x00\x4f\x00\x00\x00\x5a\x00\x00\x00\x5b\x00\x00\x00\x04\x00\x00\x00\x2e\x00\x00\x00\x24\x00\x00\x00\x2a\x00\x00\x00\x2b\x00\x00\x00\x26\x00\x00\x00\x27\x00\x00\x00\x23\x00\x00\x00\x22\x00\x00\x00\x21\x00\x00\x00\x20\x00\x00\x00\x1d\x00\x00\x00\x1b\x00\x00\x00\x1a\x00\x00\x00\x19\x00\x00\x00\x18\x00\x00\x00\x37\x00\x00\x00\x04\x00\x00\x00\x1d\x00\x00\x00\x34\x00\x00\x00\x33\x00\x00\x00\x31\x00\x00\x00\x26\x00\x00\x00\x2d\x00\x00\x00\x2e\x00\x00\x00\x3a\x00\x00\x00\x3d\x00\x00\x00\x38\x00\x00\x00\x40\x00\x00\x00\x47\x00\x00\x00\x41\x00\x00\x00\x47\x00\x00\x00\x4a\x00\x00\x00\x47\x00\x00\x00\x57\x00\x00\x00\x56\x00\x00\x00\x47\x00\x00\x00\x50\x00\x00\x00\x47\x00\x00\x00\x54\x00\x00\x00\x4b\x00\x00\x00\x5c\x00\x00\x00\x47\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x29\x00\x00\x00\x27\x00\x00\x00\x35\x00\x00\x00\x3a\x00\x00\x00\x4b\x00\x00\x00\x38\x00\x00\x00\x00\x00\x00\x00\x3b\x00\x00\x00\x1e\x00\x00\x00\x4c\x00\x00\x00\x1d\x00\x00\x00\x1b\x00\x00\x00\x34\x00\x00\x00\x31\x00\x00\x00\x2f\x00\x00\x00\x5d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"# happyReduceArr = Happy_Data_Array.array (1, 55) [ - (1 , happyReduce_1), - (2 , happyReduce_2), - (3 , happyReduce_3), - (4 , happyReduce_4), - (5 , happyReduce_5), - (6 , happyReduce_6), - (7 , happyReduce_7), - (8 , happyReduce_8), - (9 , happyReduce_9), - (10 , happyReduce_10), - (11 , happyReduce_11), - (12 , happyReduce_12), - (13 , happyReduce_13), - (14 , happyReduce_14), - (15 , happyReduce_15), - (16 , happyReduce_16), - (17 , happyReduce_17), - (18 , happyReduce_18), - (19 , happyReduce_19), - (20 , happyReduce_20), - (21 , happyReduce_21), - (22 , happyReduce_22), - (23 , happyReduce_23), - (24 , happyReduce_24), - (25 , happyReduce_25), - (26 , happyReduce_26), - (27 , happyReduce_27), - (28 , happyReduce_28), - (29 , happyReduce_29), - (30 , happyReduce_30), - (31 , happyReduce_31), - (32 , happyReduce_32), - (33 , happyReduce_33), - (34 , happyReduce_34), - (35 , happyReduce_35), - (36 , happyReduce_36), - (37 , happyReduce_37), - (38 , happyReduce_38), - (39 , happyReduce_39), - (40 , happyReduce_40), - (41 , happyReduce_41), - (42 , happyReduce_42), - (43 , happyReduce_43), - (44 , happyReduce_44), - (45 , happyReduce_45), - (46 , happyReduce_46), - (47 , happyReduce_47), - (48 , happyReduce_48), - (49 , happyReduce_49), - (50 , happyReduce_50), - (51 , happyReduce_51), - (52 , happyReduce_52), - (53 , happyReduce_53), - (54 , happyReduce_54), - (55 , happyReduce_55) - ] - -happy_n_terms = 30 :: Prelude.Int + (1 , happyReduce_1), + (2 , happyReduce_2), + (3 , happyReduce_3), + (4 , happyReduce_4), + (5 , happyReduce_5), + (6 , happyReduce_6), + (7 , happyReduce_7), + (8 , happyReduce_8), + (9 , happyReduce_9), + (10 , happyReduce_10), + (11 , happyReduce_11), + (12 , happyReduce_12), + (13 , happyReduce_13), + (14 , happyReduce_14), + (15 , happyReduce_15), + (16 , happyReduce_16), + (17 , happyReduce_17), + (18 , happyReduce_18), + (19 , happyReduce_19), + (20 , happyReduce_20), + (21 , happyReduce_21), + (22 , happyReduce_22), + (23 , happyReduce_23), + (24 , happyReduce_24), + (25 , happyReduce_25), + (26 , happyReduce_26), + (27 , happyReduce_27), + (28 , happyReduce_28), + (29 , happyReduce_29), + (30 , happyReduce_30), + (31 , happyReduce_31), + (32 , happyReduce_32), + (33 , happyReduce_33), + (34 , happyReduce_34), + (35 , happyReduce_35), + (36 , happyReduce_36), + (37 , happyReduce_37), + (38 , happyReduce_38), + (39 , happyReduce_39), + (40 , happyReduce_40), + (41 , happyReduce_41), + (42 , happyReduce_42), + (43 , happyReduce_43), + (44 , happyReduce_44), + (45 , happyReduce_45), + (46 , happyReduce_46), + (47 , happyReduce_47), + (48 , happyReduce_48), + (49 , happyReduce_49), + (50 , happyReduce_50), + (51 , happyReduce_51), + (52 , happyReduce_52), + (53 , happyReduce_53), + (54 , happyReduce_54), + (55 , happyReduce_55) + ] + +happyRuleArr :: HappyAddr +happyRuleArr = HappyA# "\x00\x00\x00\x00\x03\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00\x06\x00\x00\x00\x03\x00\x00\x00\x07\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x01\x00\x00\x00\x05\x00\x00\x00\x03\x00\x00\x00\x06\x00\x00\x00\x03\x00\x00\x00\x06\x00\x00\x00\x01\x00\x00\x00\x07\x00\x00\x00\x04\x00\x00\x00\x07\x00\x00\x00\x03\x00\x00\x00\x08\x00\x00\x00\x01\x00\x00\x00\x08\x00\x00\x00\x04\x00\x00\x00\x09\x00\x00\x00\x01\x00\x00\x00\x09\x00\x00\x00\x00\x00\x00\x00\x0a\x00\x00\x00\x01\x00\x00\x00\x0a\x00\x00\x00\x02\x00\x00\x00\x0b\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x03\x00\x00\x00\x0c\x00\x00\x00\x02\x00\x00\x00\x0c\x00\x00\x00\x01\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x0d\x00\x00\x00\x02\x00\x00\x00\x0d\x00\x00\x00\x01\x00\x00\x00\x0e\x00\x00\x00\x02\x00\x00\x00\x0e\x00\x00\x00\x02\x00\x00\x00\x0e\x00\x00\x00\x03\x00\x00\x00\x0e\x00\x00\x00\x03\x00\x00\x00\x0e\x00\x00\x00\x01\x00\x00\x00\x0e\x00\x00\x00\x03\x00\x00\x00\x0e\x00\x00\x00\x02\x00\x00\x00\x0e\x00\x00\x00\x03\x00\x00\x00\x0e\x00\x00\x00\x04\x00\x00\x00\x0e\x00\x00\x00\x05\x00\x00\x00\x0e\x00\x00\x00\x02\x00\x00\x00\x0e\x00\x00\x00\x02\x00\x00\x00\x0e\x00\x00\x00\x02\x00\x00\x00\x0e\x00\x00\x00\x02\x00\x00\x00\x0e\x00\x00\x00\x03\x00\x00\x00\x0e\x00\x00\x00\x01\x00\x00\x00\x0e\x00\x00\x00\x02\x00\x00\x00\x0e\x00\x00\x00\x03\x00\x00\x00\x0f\x00\x00\x00\x01\x00\x00\x00\x0f\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x02\x00\x00\x00\x10\x00\x00\x00\x01\x00\x00\x00\x11\x00\x00\x00\x02\x00\x00\x00\x12\x00\x00\x00\x02\x00\x00\x00\x12\x00\x00\x00\x00\x00\x00\x00\x13\x00\x00\x00\x01\x00\x00\x00\x13\x00\x00\x00\x00\x00\x00\x00"# + +happyCatchStates :: [Int] +happyCatchStates = [] + +happy_n_terms = 31 :: Prelude.Int happy_n_nonterms = 20 :: Prelude.Int +happy_n_starts = 1 :: Prelude.Int + happyReduce_1 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_1 = happySpecReduce_3 0# happyReduction_1 happyReduction_1 happy_x_3 - happy_x_2 - happy_x_1 - = case happyOut23 happy_x_1 of { (HappyWrap23 happy_var_1) -> - case happyOut5 happy_x_2 of { (HappyWrap5 happy_var_2) -> - case happyOut23 happy_x_3 of { (HappyWrap23 happy_var_3) -> - happyIn4 - (BookendedAbsSyn happy_var_1 happy_var_2 happy_var_3 - )}}} + happy_x_2 + happy_x_1 + = case happyOut24 happy_x_1 of { (HappyWrap24 happy_var_1) -> + case happyOut6 happy_x_2 of { (HappyWrap6 happy_var_2) -> + case happyOut24 happy_x_3 of { (HappyWrap24 happy_var_3) -> + happyIn5 + (BookendedAbsSyn happy_var_1 happy_var_2 happy_var_3 + )}}} happyReduce_2 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_2 = happySpecReduce_3 1# happyReduction_2 happyReduction_2 happy_x_3 - happy_x_2 - happy_x_1 - = case happyOut17 happy_x_1 of { (HappyWrap17 happy_var_1) -> - case happyOut6 happy_x_3 of { (HappyWrap6 happy_var_3) -> - happyIn5 - (AbsSyn (reverse happy_var_1) (reverse happy_var_3) - )}} + happy_x_2 + happy_x_1 + = case happyOut18 happy_x_1 of { (HappyWrap18 happy_var_1) -> + case happyOut7 happy_x_3 of { (HappyWrap7 happy_var_3) -> + happyIn6 + (AbsSyn (reverse happy_var_1) (reverse happy_var_3) + )}} happyReduce_3 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_3 = happySpecReduce_2 2# happyReduction_3 happyReduction_3 happy_x_2 - happy_x_1 - = case happyOut6 happy_x_1 of { (HappyWrap6 happy_var_1) -> - case happyOut7 happy_x_2 of { (HappyWrap7 happy_var_2) -> - happyIn6 - (happy_var_2 : happy_var_1 - )}} + happy_x_1 + = case happyOut7 happy_x_1 of { (HappyWrap7 happy_var_1) -> + case happyOut8 happy_x_2 of { (HappyWrap8 happy_var_2) -> + happyIn7 + (happy_var_2 : happy_var_1 + )}} happyReduce_4 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_4 = happySpecReduce_1 2# happyReduction_4 happyReduction_4 happy_x_1 - = case happyOut7 happy_x_1 of { (HappyWrap7 happy_var_1) -> - happyIn6 - ([happy_var_1] - )} + = case happyOut8 happy_x_1 of { (HappyWrap8 happy_var_1) -> + happyIn7 + ([happy_var_1] + )} happyReduce_5 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_5 = happyReduce 6# 3# happyReduction_5 happyReduction_5 (happy_x_6 `HappyStk` - happy_x_5 `HappyStk` - happy_x_4 `HappyStk` - happy_x_3 `HappyStk` - happy_x_2 `HappyStk` - happy_x_1 `HappyStk` - happyRest) - = case happyOutTok happy_x_1 of { (TokenInfo happy_var_1 TokId) -> - case happyOut8 happy_x_2 of { (HappyWrap8 happy_var_2) -> - case happyOutTok happy_x_4 of { (TokenInfo happy_var_4 TokCodeQuote) -> - case happyOut10 happy_x_6 of { (HappyWrap10 happy_var_6) -> - happyIn7 - (Rule happy_var_1 happy_var_2 happy_var_6 (Just happy_var_4) - ) `HappyStk` happyRest}}}} + happy_x_5 `HappyStk` + happy_x_4 `HappyStk` + happy_x_3 `HappyStk` + happy_x_2 `HappyStk` + happy_x_1 `HappyStk` + happyRest) + = case happyOutTok happy_x_1 of { (TokenInfo happy_var_1 TokId) -> + case happyOut9 happy_x_2 of { (HappyWrap9 happy_var_2) -> + case happyOutTok happy_x_4 of { (TokenInfo happy_var_4 TokCodeQuote) -> + case happyOut11 happy_x_6 of { (HappyWrap11 happy_var_6) -> + happyIn8 + (Rule happy_var_1 happy_var_2 happy_var_6 (Just happy_var_4) + ) `HappyStk` happyRest}}}} happyReduce_6 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_6 = happyReduce 7# 3# happyReduction_6 happyReduction_6 (happy_x_7 `HappyStk` - happy_x_6 `HappyStk` - happy_x_5 `HappyStk` - happy_x_4 `HappyStk` - happy_x_3 `HappyStk` - happy_x_2 `HappyStk` - happy_x_1 `HappyStk` - happyRest) - = case happyOutTok happy_x_1 of { (TokenInfo happy_var_1 TokId) -> - case happyOut8 happy_x_2 of { (HappyWrap8 happy_var_2) -> - case happyOutTok happy_x_4 of { (TokenInfo happy_var_4 TokCodeQuote) -> - case happyOut10 happy_x_7 of { (HappyWrap10 happy_var_7) -> - happyIn7 - (Rule happy_var_1 happy_var_2 happy_var_7 (Just happy_var_4) - ) `HappyStk` happyRest}}}} + happy_x_6 `HappyStk` + happy_x_5 `HappyStk` + happy_x_4 `HappyStk` + happy_x_3 `HappyStk` + happy_x_2 `HappyStk` + happy_x_1 `HappyStk` + happyRest) + = case happyOutTok happy_x_1 of { (TokenInfo happy_var_1 TokId) -> + case happyOut9 happy_x_2 of { (HappyWrap9 happy_var_2) -> + case happyOutTok happy_x_4 of { (TokenInfo happy_var_4 TokCodeQuote) -> + case happyOut11 happy_x_7 of { (HappyWrap11 happy_var_7) -> + happyIn8 + (Rule happy_var_1 happy_var_2 happy_var_7 (Just happy_var_4) + ) `HappyStk` happyRest}}}} happyReduce_7 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_7 = happyReduce 4# 3# happyReduction_7 happyReduction_7 (happy_x_4 `HappyStk` - happy_x_3 `HappyStk` - happy_x_2 `HappyStk` - happy_x_1 `HappyStk` - happyRest) - = case happyOutTok happy_x_1 of { (TokenInfo happy_var_1 TokId) -> - case happyOut8 happy_x_2 of { (HappyWrap8 happy_var_2) -> - case happyOut10 happy_x_4 of { (HappyWrap10 happy_var_4) -> - happyIn7 - (Rule happy_var_1 happy_var_2 happy_var_4 Nothing - ) `HappyStk` happyRest}}} + happy_x_3 `HappyStk` + happy_x_2 `HappyStk` + happy_x_1 `HappyStk` + happyRest) + = case happyOutTok happy_x_1 of { (TokenInfo happy_var_1 TokId) -> + case happyOut9 happy_x_2 of { (HappyWrap9 happy_var_2) -> + case happyOut11 happy_x_4 of { (HappyWrap11 happy_var_4) -> + happyIn8 + (Rule happy_var_1 happy_var_2 happy_var_4 Nothing + ) `HappyStk` happyRest}}} happyReduce_8 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_8 = happySpecReduce_3 4# happyReduction_8 happyReduction_8 happy_x_3 - happy_x_2 - happy_x_1 - = case happyOut9 happy_x_2 of { (HappyWrap9 happy_var_2) -> - happyIn8 - (reverse happy_var_2 - )} + happy_x_2 + happy_x_1 + = case happyOut10 happy_x_2 of { (HappyWrap10 happy_var_2) -> + happyIn9 + (reverse happy_var_2 + )} happyReduce_9 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_9 = happySpecReduce_0 4# happyReduction_9 -happyReduction_9 = happyIn8 - ([] - ) +happyReduction_9 = happyIn9 + ([] + ) happyReduce_10 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_10 = happySpecReduce_1 5# happyReduction_10 happyReduction_10 happy_x_1 - = case happyOutTok happy_x_1 of { (TokenInfo happy_var_1 TokId) -> - happyIn9 - ([happy_var_1] - )} + = case happyOutTok happy_x_1 of { (TokenInfo happy_var_1 TokId) -> + happyIn10 + ([happy_var_1] + )} happyReduce_11 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_11 = happySpecReduce_3 5# happyReduction_11 happyReduction_11 happy_x_3 - happy_x_2 - happy_x_1 - = case happyOut9 happy_x_1 of { (HappyWrap9 happy_var_1) -> - case happyOutTok happy_x_3 of { (TokenInfo happy_var_3 TokId) -> - happyIn9 - (happy_var_3 : happy_var_1 - )}} + happy_x_2 + happy_x_1 + = case happyOut10 happy_x_1 of { (HappyWrap10 happy_var_1) -> + case happyOutTok happy_x_3 of { (TokenInfo happy_var_3 TokId) -> + happyIn10 + (happy_var_3 : happy_var_1 + )}} happyReduce_12 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_12 = happySpecReduce_3 6# happyReduction_12 happyReduction_12 happy_x_3 - happy_x_2 - happy_x_1 - = case happyOut11 happy_x_1 of { (HappyWrap11 happy_var_1) -> - case happyOut10 happy_x_3 of { (HappyWrap10 happy_var_3) -> - happyIn10 - (happy_var_1 : happy_var_3 - )}} + happy_x_2 + happy_x_1 + = case happyOut12 happy_x_1 of { (HappyWrap12 happy_var_1) -> + case happyOut11 happy_x_3 of { (HappyWrap11 happy_var_3) -> + happyIn11 + (happy_var_1 : happy_var_3 + )}} happyReduce_13 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_13 = happySpecReduce_1 6# happyReduction_13 happyReduction_13 happy_x_1 - = case happyOut11 happy_x_1 of { (HappyWrap11 happy_var_1) -> - happyIn10 - ([happy_var_1] - )} + = case happyOut12 happy_x_1 of { (HappyWrap12 happy_var_1) -> + happyIn11 + ([happy_var_1] + )} happyReduce_14 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_14 = happyMonadReduce 4# 7# happyReduction_14 happyReduction_14 (happy_x_4 `HappyStk` - happy_x_3 `HappyStk` - happy_x_2 `HappyStk` - happy_x_1 `HappyStk` - happyRest) tk - = happyThen ((case happyOut13 happy_x_1 of { (HappyWrap13 happy_var_1) -> - case happyOut16 happy_x_2 of { (HappyWrap16 happy_var_2) -> - case happyOutTok happy_x_3 of { (TokenInfo happy_var_3 TokCodeQuote) -> - ( lineP >>= \l -> return (Prod happy_var_1 happy_var_3 l happy_var_2))}}}) - ) (\r -> happyReturn (happyIn11 r)) + happy_x_3 `HappyStk` + happy_x_2 `HappyStk` + happy_x_1 `HappyStk` + happyRest) tk + = happyThen ((case happyOut14 happy_x_1 of { (HappyWrap14 happy_var_1) -> + case happyOut17 happy_x_2 of { (HappyWrap17 happy_var_2) -> + case happyOutTok happy_x_3 of { (TokenInfo happy_var_3 TokCodeQuote) -> + ( lineP >>= \l -> return (Prod happy_var_1 happy_var_3 l happy_var_2))}}}) + ) (\r -> happyReturn (happyIn12 r)) happyReduce_15 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_15 = happyMonadReduce 3# 7# happyReduction_15 happyReduction_15 (happy_x_3 `HappyStk` - happy_x_2 `HappyStk` - happy_x_1 `HappyStk` - happyRest) tk - = happyThen ((case happyOut13 happy_x_1 of { (HappyWrap13 happy_var_1) -> - case happyOut16 happy_x_2 of { (HappyWrap16 happy_var_2) -> - case happyOutTok happy_x_3 of { (TokenInfo happy_var_3 TokCodeQuote) -> - ( lineP >>= \l -> return (Prod happy_var_1 happy_var_3 l happy_var_2))}}}) - ) (\r -> happyReturn (happyIn11 r)) + happy_x_2 `HappyStk` + happy_x_1 `HappyStk` + happyRest) tk + = happyThen ((case happyOut14 happy_x_1 of { (HappyWrap14 happy_var_1) -> + case happyOut17 happy_x_2 of { (HappyWrap17 happy_var_2) -> + case happyOutTok happy_x_3 of { (TokenInfo happy_var_3 TokCodeQuote) -> + ( lineP >>= \l -> return (Prod happy_var_1 happy_var_3 l happy_var_2))}}}) + ) (\r -> happyReturn (happyIn12 r)) happyReduce_16 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_16 = happySpecReduce_1 8# happyReduction_16 happyReduction_16 happy_x_1 - = case happyOutTok happy_x_1 of { (TokenInfo happy_var_1 TokId) -> - happyIn12 - (App happy_var_1 [] - )} + = case happyOutTok happy_x_1 of { (TokenInfo happy_var_1 TokId) -> + happyIn13 + (App happy_var_1 [] + )} happyReduce_17 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_17 = happyReduce 4# 8# happyReduction_17 happyReduction_17 (happy_x_4 `HappyStk` - happy_x_3 `HappyStk` - happy_x_2 `HappyStk` - happy_x_1 `HappyStk` - happyRest) - = case happyOutTok happy_x_1 of { (TokenInfo happy_var_1 TokId) -> - case happyOut15 happy_x_3 of { (HappyWrap15 happy_var_3) -> - happyIn12 - (App happy_var_1 (reverse happy_var_3) - ) `HappyStk` happyRest}} + happy_x_3 `HappyStk` + happy_x_2 `HappyStk` + happy_x_1 `HappyStk` + happyRest) + = case happyOutTok happy_x_1 of { (TokenInfo happy_var_1 TokId) -> + case happyOut16 happy_x_3 of { (HappyWrap16 happy_var_3) -> + happyIn13 + (App happy_var_1 (reverse happy_var_3) + ) `HappyStk` happyRest}} happyReduce_18 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_18 = happySpecReduce_1 9# happyReduction_18 happyReduction_18 happy_x_1 - = case happyOut14 happy_x_1 of { (HappyWrap14 happy_var_1) -> - happyIn13 - (reverse happy_var_1 - )} + = case happyOut15 happy_x_1 of { (HappyWrap15 happy_var_1) -> + happyIn14 + (reverse happy_var_1 + )} happyReduce_19 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_19 = happySpecReduce_0 9# happyReduction_19 -happyReduction_19 = happyIn13 - ([] - ) +happyReduction_19 = happyIn14 + ([] + ) happyReduce_20 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_20 = happySpecReduce_1 10# happyReduction_20 happyReduction_20 happy_x_1 - = case happyOut12 happy_x_1 of { (HappyWrap12 happy_var_1) -> - happyIn14 - ([happy_var_1] - )} + = case happyOut13 happy_x_1 of { (HappyWrap13 happy_var_1) -> + happyIn15 + ([happy_var_1] + )} happyReduce_21 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_21 = happySpecReduce_2 10# happyReduction_21 happyReduction_21 happy_x_2 - happy_x_1 - = case happyOut14 happy_x_1 of { (HappyWrap14 happy_var_1) -> - case happyOut12 happy_x_2 of { (HappyWrap12 happy_var_2) -> - happyIn14 - (happy_var_2 : happy_var_1 - )}} + happy_x_1 + = case happyOut15 happy_x_1 of { (HappyWrap15 happy_var_1) -> + case happyOut13 happy_x_2 of { (HappyWrap13 happy_var_2) -> + happyIn15 + (happy_var_2 : happy_var_1 + )}} happyReduce_22 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_22 = happySpecReduce_1 11# happyReduction_22 happyReduction_22 happy_x_1 - = case happyOut12 happy_x_1 of { (HappyWrap12 happy_var_1) -> - happyIn15 - ([happy_var_1] - )} + = case happyOut13 happy_x_1 of { (HappyWrap13 happy_var_1) -> + happyIn16 + ([happy_var_1] + )} happyReduce_23 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_23 = happySpecReduce_3 11# happyReduction_23 happyReduction_23 happy_x_3 - happy_x_2 - happy_x_1 - = case happyOut15 happy_x_1 of { (HappyWrap15 happy_var_1) -> - case happyOut12 happy_x_3 of { (HappyWrap12 happy_var_3) -> - happyIn15 - (happy_var_3 : happy_var_1 - )}} + happy_x_2 + happy_x_1 + = case happyOut16 happy_x_1 of { (HappyWrap16 happy_var_1) -> + case happyOut13 happy_x_3 of { (HappyWrap13 happy_var_3) -> + happyIn16 + (happy_var_3 : happy_var_1 + )}} happyReduce_24 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_24 = happySpecReduce_2 12# happyReduction_24 happyReduction_24 happy_x_2 - happy_x_1 - = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokId) -> - happyIn16 - (PrecId happy_var_2 - )} + happy_x_1 + = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokId) -> + happyIn17 + (PrecId happy_var_2 + )} happyReduce_25 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_25 = happySpecReduce_1 12# happyReduction_25 happyReduction_25 happy_x_1 - = happyIn16 - (PrecShift - ) + = happyIn17 + (PrecShift + ) happyReduce_26 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_26 = happySpecReduce_0 12# happyReduction_26 -happyReduction_26 = happyIn16 - (PrecNone - ) +happyReduction_26 = happyIn17 + (PrecNone + ) happyReduce_27 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_27 = happySpecReduce_2 13# happyReduction_27 happyReduction_27 happy_x_2 - happy_x_1 - = case happyOut17 happy_x_1 of { (HappyWrap17 happy_var_1) -> - case happyOut18 happy_x_2 of { (HappyWrap18 happy_var_2) -> - happyIn17 - (happy_var_2 : happy_var_1 - )}} + happy_x_1 + = case happyOut18 happy_x_1 of { (HappyWrap18 happy_var_1) -> + case happyOut19 happy_x_2 of { (HappyWrap19 happy_var_2) -> + happyIn18 + (happy_var_2 : happy_var_1 + )}} happyReduce_28 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_28 = happySpecReduce_1 13# happyReduction_28 happyReduction_28 happy_x_1 - = case happyOut18 happy_x_1 of { (HappyWrap18 happy_var_1) -> - happyIn17 - ([happy_var_1] - )} + = case happyOut19 happy_x_1 of { (HappyWrap19 happy_var_1) -> + happyIn18 + ([happy_var_1] + )} happyReduce_29 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_29 = happySpecReduce_2 14# happyReduction_29 happyReduction_29 happy_x_2 - happy_x_1 - = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokCodeQuote) -> - happyIn18 - (TokenType happy_var_2 - )} + happy_x_1 + = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokCodeQuote) -> + happyIn19 + (TokenType happy_var_2 + )} happyReduce_30 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_30 = happySpecReduce_2 14# happyReduction_30 happyReduction_30 happy_x_2 - happy_x_1 - = case happyOut20 happy_x_2 of { (HappyWrap20 happy_var_2) -> - happyIn18 - (TokenSpec happy_var_2 - )} + happy_x_1 + = case happyOut21 happy_x_2 of { (HappyWrap21 happy_var_2) -> + happyIn19 + (TokenSpec happy_var_2 + )} happyReduce_31 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_31 = happySpecReduce_3 14# happyReduction_31 happyReduction_31 happy_x_3 - happy_x_2 - happy_x_1 - = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokId) -> - case happyOut19 happy_x_3 of { (HappyWrap19 happy_var_3) -> - happyIn18 - (TokenName happy_var_2 happy_var_3 False - )}} + happy_x_2 + happy_x_1 + = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokId) -> + case happyOut20 happy_x_3 of { (HappyWrap20 happy_var_3) -> + happyIn19 + (TokenName happy_var_2 happy_var_3 False + )}} happyReduce_32 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_32 = happySpecReduce_3 14# happyReduction_32 happyReduction_32 happy_x_3 - happy_x_2 - happy_x_1 - = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokId) -> - case happyOut19 happy_x_3 of { (HappyWrap19 happy_var_3) -> - happyIn18 - (TokenName happy_var_2 happy_var_3 True - )}} + happy_x_2 + happy_x_1 + = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokId) -> + case happyOut20 happy_x_3 of { (HappyWrap20 happy_var_3) -> + happyIn19 + (TokenName happy_var_2 happy_var_3 True + )}} happyReduce_33 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_33 = happySpecReduce_1 14# happyReduction_33 happyReduction_33 happy_x_1 - = happyIn18 - (TokenImportedIdentity - ) + = happyIn19 + (TokenImportedIdentity + ) happyReduce_34 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_34 = happySpecReduce_3 14# happyReduction_34 happyReduction_34 happy_x_3 - happy_x_2 - happy_x_1 - = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokCodeQuote) -> - case happyOutTok happy_x_3 of { (TokenInfo happy_var_3 TokCodeQuote) -> - happyIn18 - (TokenLexer happy_var_2 happy_var_3 - )}} + happy_x_2 + happy_x_1 + = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokCodeQuote) -> + case happyOutTok happy_x_3 of { (TokenInfo happy_var_3 TokCodeQuote) -> + happyIn19 + (TokenLexer happy_var_2 happy_var_3 + )}} happyReduce_35 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_35 = happySpecReduce_2 14# happyReduction_35 happyReduction_35 happy_x_2 - happy_x_1 - = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokCodeQuote) -> - happyIn18 - (TokenMonad "()" happy_var_2 "Prelude.>>=" "Prelude.return" - )} + happy_x_1 + = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokCodeQuote) -> + happyIn19 + (TokenMonad "()" happy_var_2 "Prelude.>>=" "Prelude.return" + )} happyReduce_36 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_36 = happySpecReduce_3 14# happyReduction_36 happyReduction_36 happy_x_3 - happy_x_2 - happy_x_1 - = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokCodeQuote) -> - case happyOutTok happy_x_3 of { (TokenInfo happy_var_3 TokCodeQuote) -> - happyIn18 - (TokenMonad happy_var_2 happy_var_3 "Prelude.>>=" "Prelude.return" - )}} + happy_x_2 + happy_x_1 + = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokCodeQuote) -> + case happyOutTok happy_x_3 of { (TokenInfo happy_var_3 TokCodeQuote) -> + happyIn19 + (TokenMonad happy_var_2 happy_var_3 "Prelude.>>=" "Prelude.return" + )}} happyReduce_37 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_37 = happyReduce 4# 14# happyReduction_37 happyReduction_37 (happy_x_4 `HappyStk` - happy_x_3 `HappyStk` - happy_x_2 `HappyStk` - happy_x_1 `HappyStk` - happyRest) - = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokCodeQuote) -> - case happyOutTok happy_x_3 of { (TokenInfo happy_var_3 TokCodeQuote) -> - case happyOutTok happy_x_4 of { (TokenInfo happy_var_4 TokCodeQuote) -> - happyIn18 - (TokenMonad "()" happy_var_2 happy_var_3 happy_var_4 - ) `HappyStk` happyRest}}} + happy_x_3 `HappyStk` + happy_x_2 `HappyStk` + happy_x_1 `HappyStk` + happyRest) + = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokCodeQuote) -> + case happyOutTok happy_x_3 of { (TokenInfo happy_var_3 TokCodeQuote) -> + case happyOutTok happy_x_4 of { (TokenInfo happy_var_4 TokCodeQuote) -> + happyIn19 + (TokenMonad "()" happy_var_2 happy_var_3 happy_var_4 + ) `HappyStk` happyRest}}} happyReduce_38 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_38 = happyReduce 5# 14# happyReduction_38 happyReduction_38 (happy_x_5 `HappyStk` - happy_x_4 `HappyStk` - happy_x_3 `HappyStk` - happy_x_2 `HappyStk` - happy_x_1 `HappyStk` - happyRest) - = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokCodeQuote) -> - case happyOutTok happy_x_3 of { (TokenInfo happy_var_3 TokCodeQuote) -> - case happyOutTok happy_x_4 of { (TokenInfo happy_var_4 TokCodeQuote) -> - case happyOutTok happy_x_5 of { (TokenInfo happy_var_5 TokCodeQuote) -> - happyIn18 - (TokenMonad happy_var_2 happy_var_3 happy_var_4 happy_var_5 - ) `HappyStk` happyRest}}}} + happy_x_4 `HappyStk` + happy_x_3 `HappyStk` + happy_x_2 `HappyStk` + happy_x_1 `HappyStk` + happyRest) + = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokCodeQuote) -> + case happyOutTok happy_x_3 of { (TokenInfo happy_var_3 TokCodeQuote) -> + case happyOutTok happy_x_4 of { (TokenInfo happy_var_4 TokCodeQuote) -> + case happyOutTok happy_x_5 of { (TokenInfo happy_var_5 TokCodeQuote) -> + happyIn19 + (TokenMonad happy_var_2 happy_var_3 happy_var_4 happy_var_5 + ) `HappyStk` happyRest}}}} happyReduce_39 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_39 = happySpecReduce_2 14# happyReduction_39 happyReduction_39 happy_x_2 - happy_x_1 - = case happyOut22 happy_x_2 of { (HappyWrap22 happy_var_2) -> - happyIn18 - (TokenNonassoc happy_var_2 - )} + happy_x_1 + = case happyOut23 happy_x_2 of { (HappyWrap23 happy_var_2) -> + happyIn19 + (TokenNonassoc happy_var_2 + )} happyReduce_40 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_40 = happySpecReduce_2 14# happyReduction_40 happyReduction_40 happy_x_2 - happy_x_1 - = case happyOut22 happy_x_2 of { (HappyWrap22 happy_var_2) -> - happyIn18 - (TokenRight happy_var_2 - )} + happy_x_1 + = case happyOut23 happy_x_2 of { (HappyWrap23 happy_var_2) -> + happyIn19 + (TokenRight happy_var_2 + )} happyReduce_41 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_41 = happySpecReduce_2 14# happyReduction_41 happyReduction_41 happy_x_2 - happy_x_1 - = case happyOut22 happy_x_2 of { (HappyWrap22 happy_var_2) -> - happyIn18 - (TokenLeft happy_var_2 - )} + happy_x_1 + = case happyOut23 happy_x_2 of { (HappyWrap23 happy_var_2) -> + happyIn19 + (TokenLeft happy_var_2 + )} happyReduce_42 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_42 = happySpecReduce_2 14# happyReduction_42 happyReduction_42 happy_x_2 - happy_x_1 - = case happyOutTok happy_x_2 of { (TokenNum happy_var_2 TokNum) -> - happyIn18 - (TokenExpect happy_var_2 - )} + happy_x_1 + = case happyOutTok happy_x_2 of { (TokenNum happy_var_2 TokNum) -> + happyIn19 + (TokenExpect happy_var_2 + )} happyReduce_43 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) -happyReduce_43 = happySpecReduce_2 14# happyReduction_43 -happyReduction_43 happy_x_2 - happy_x_1 - = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokCodeQuote) -> - happyIn18 - (TokenError happy_var_2 - )} +happyReduce_43 = happySpecReduce_3 14# happyReduction_43 +happyReduction_43 happy_x_3 + happy_x_2 + happy_x_1 + = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokCodeQuote) -> + case happyOut24 happy_x_3 of { (HappyWrap24 happy_var_3) -> + happyIn19 + (TokenError happy_var_2 happy_var_3 + )}} happyReduce_44 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) -happyReduce_44 = happySpecReduce_2 14# happyReduction_44 -happyReduction_44 happy_x_2 - happy_x_1 - = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokId) -> - happyIn18 - (TokenErrorHandlerType happy_var_2 - )} +happyReduce_44 = happySpecReduce_1 14# happyReduction_44 +happyReduction_44 happy_x_1 + = happyIn19 + (TokenErrorExpected + ) happyReduce_45 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_45 = happySpecReduce_2 14# happyReduction_45 happyReduction_45 happy_x_2 - happy_x_1 - = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokCodeQuote) -> - happyIn18 - (TokenAttributetype happy_var_2 - )} + happy_x_1 + = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokCodeQuote) -> + happyIn19 + (TokenAttributetype happy_var_2 + )} happyReduce_46 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_46 = happySpecReduce_3 14# happyReduction_46 happyReduction_46 happy_x_3 - happy_x_2 - happy_x_1 - = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokId) -> - case happyOutTok happy_x_3 of { (TokenInfo happy_var_3 TokCodeQuote) -> - happyIn18 - (TokenAttribute happy_var_2 happy_var_3 - )}} + happy_x_2 + happy_x_1 + = case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokId) -> + case happyOutTok happy_x_3 of { (TokenInfo happy_var_3 TokCodeQuote) -> + happyIn19 + (TokenAttribute happy_var_2 happy_var_3 + )}} happyReduce_47 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_47 = happySpecReduce_1 15# happyReduction_47 happyReduction_47 happy_x_1 - = case happyOutTok happy_x_1 of { (TokenInfo happy_var_1 TokId) -> - happyIn19 - (Just happy_var_1 - )} + = case happyOutTok happy_x_1 of { (TokenInfo happy_var_1 TokId) -> + happyIn20 + (Just happy_var_1 + )} happyReduce_48 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_48 = happySpecReduce_0 15# happyReduction_48 -happyReduction_48 = happyIn19 - (Nothing - ) +happyReduction_48 = happyIn20 + (Nothing + ) happyReduce_49 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_49 = happySpecReduce_2 16# happyReduction_49 happyReduction_49 happy_x_2 - happy_x_1 - = case happyOut21 happy_x_1 of { (HappyWrap21 happy_var_1) -> - case happyOut20 happy_x_2 of { (HappyWrap20 happy_var_2) -> - happyIn20 - (happy_var_1:happy_var_2 - )}} + happy_x_1 + = case happyOut22 happy_x_1 of { (HappyWrap22 happy_var_1) -> + case happyOut21 happy_x_2 of { (HappyWrap21 happy_var_2) -> + happyIn21 + (happy_var_1:happy_var_2 + )}} happyReduce_50 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_50 = happySpecReduce_1 16# happyReduction_50 happyReduction_50 happy_x_1 - = case happyOut21 happy_x_1 of { (HappyWrap21 happy_var_1) -> - happyIn20 - ([happy_var_1] - )} + = case happyOut22 happy_x_1 of { (HappyWrap22 happy_var_1) -> + happyIn21 + ([happy_var_1] + )} happyReduce_51 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_51 = happySpecReduce_2 17# happyReduction_51 happyReduction_51 happy_x_2 - happy_x_1 - = case happyOutTok happy_x_1 of { (TokenInfo happy_var_1 TokId) -> - case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokCodeQuote) -> - happyIn21 - ((happy_var_1, parseTokenSpec happy_var_2) - )}} + happy_x_1 + = case happyOutTok happy_x_1 of { (TokenInfo happy_var_1 TokId) -> + case happyOutTok happy_x_2 of { (TokenInfo happy_var_2 TokCodeQuote) -> + happyIn22 + ((happy_var_1, parseTokenSpec happy_var_2) + )}} happyReduce_52 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_52 = happySpecReduce_2 18# happyReduction_52 happyReduction_52 happy_x_2 - happy_x_1 - = case happyOutTok happy_x_1 of { (TokenInfo happy_var_1 TokId) -> - case happyOut22 happy_x_2 of { (HappyWrap22 happy_var_2) -> - happyIn22 - (happy_var_1 : happy_var_2 - )}} + happy_x_1 + = case happyOutTok happy_x_1 of { (TokenInfo happy_var_1 TokId) -> + case happyOut23 happy_x_2 of { (HappyWrap23 happy_var_2) -> + happyIn23 + (happy_var_1 : happy_var_2 + )}} happyReduce_53 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_53 = happySpecReduce_0 18# happyReduction_53 -happyReduction_53 = happyIn22 - ([] - ) +happyReduction_53 = happyIn23 + ([] + ) happyReduce_54 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_54 = happySpecReduce_1 19# happyReduction_54 happyReduction_54 happy_x_1 - = case happyOutTok happy_x_1 of { (TokenInfo happy_var_1 TokCodeQuote) -> - happyIn23 - (Just happy_var_1 - )} + = case happyOutTok happy_x_1 of { (TokenInfo happy_var_1 TokCodeQuote) -> + happyIn24 + (Just happy_var_1 + )} happyReduce_55 :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) happyReduce_55 = happySpecReduce_0 19# happyReduction_55 -happyReduction_55 = happyIn23 - (Nothing - ) - -happyNewToken action sts stk - = lexTokenP(\tk -> - let cont i = happyDoAction i tk action sts stk in - case tk of { - TokenEOF -> happyDoAction 29# tk action sts stk; - TokenInfo happy_dollar_dollar TokId -> cont 1#; - TokenKW TokSpecId_TokenType -> cont 2#; - TokenKW TokSpecId_Token -> cont 3#; - TokenKW TokSpecId_Name -> cont 4#; - TokenKW TokSpecId_Partial -> cont 5#; - TokenKW TokSpecId_Lexer -> cont 6#; - TokenKW TokSpecId_ImportedIdentity -> cont 7#; - TokenKW TokSpecId_Monad -> cont 8#; - TokenKW TokSpecId_Nonassoc -> cont 9#; - TokenKW TokSpecId_Left -> cont 10#; - TokenKW TokSpecId_Right -> cont 11#; - TokenKW TokSpecId_Prec -> cont 12#; - TokenKW TokSpecId_Shift -> cont 13#; - TokenKW TokSpecId_Expect -> cont 14#; - TokenKW TokSpecId_Error -> cont 15#; - TokenKW TokSpecId_ErrorHandlerType -> cont 16#; - TokenKW TokSpecId_Attribute -> cont 17#; - TokenKW TokSpecId_Attributetype -> cont 18#; - TokenInfo happy_dollar_dollar TokCodeQuote -> cont 19#; - TokenNum happy_dollar_dollar TokNum -> cont 20#; - TokenKW TokColon -> cont 21#; - TokenKW TokSemiColon -> cont 22#; - TokenKW TokDoubleColon -> cont 23#; - TokenKW TokDoublePercent -> cont 24#; - TokenKW TokBar -> cont 25#; - TokenKW TokParenL -> cont 26#; - TokenKW TokParenR -> cont 27#; - TokenKW TokComma -> cont 28#; - _ -> happyError' (tk, []) - }) - -happyError_ explist 29# tk = happyError' (tk, explist) -happyError_ explist _ tk = happyError' (tk, explist) - -happyThen :: () => P a -> (a -> P b) -> P b +happyReduction_55 = happyIn24 + (Nothing + ) + +happyTerminalToTok term = case term of { + TokenEOF -> 30#; + TokenInfo happy_dollar_dollar TokId -> 2#; + TokenKW TokSpecId_TokenType -> 3#; + TokenKW TokSpecId_Token -> 4#; + TokenKW TokSpecId_Name -> 5#; + TokenKW TokSpecId_Partial -> 6#; + TokenKW TokSpecId_Lexer -> 7#; + TokenKW TokSpecId_ImportedIdentity -> 8#; + TokenKW TokSpecId_Monad -> 9#; + TokenKW TokSpecId_Nonassoc -> 10#; + TokenKW TokSpecId_Left -> 11#; + TokenKW TokSpecId_Right -> 12#; + TokenKW TokSpecId_Prec -> 13#; + TokenKW TokSpecId_Shift -> 14#; + TokenKW TokSpecId_Expect -> 15#; + TokenKW TokSpecId_Error -> 16#; + TokenKW TokSpecId_ErrorExpected -> 17#; + TokenKW TokSpecId_Attribute -> 18#; + TokenKW TokSpecId_Attributetype -> 19#; + TokenInfo happy_dollar_dollar TokCodeQuote -> 20#; + TokenNum happy_dollar_dollar TokNum -> 21#; + TokenKW TokColon -> 22#; + TokenKW TokSemiColon -> 23#; + TokenKW TokDoubleColon -> 24#; + TokenKW TokDoublePercent -> 25#; + TokenKW TokBar -> 26#; + TokenKW TokParenL -> 27#; + TokenKW TokParenR -> 28#; + TokenKW TokComma -> 29#; + _ -> error "Encountered a token that was not declared to happy" + } +{-# NOINLINE happyTerminalToTok #-} + +happyLex kend kmore = lexTokenP (\tk -> case tk of { + TokenEOF -> kend tk; + _ -> kmore (happyTerminalToTok tk) tk }) +{-# INLINE happyLex #-} + +happyNewToken action sts stk = happyLex (\tk -> happyDoAction 30# tk action sts stk) (\i tk -> happyDoAction i tk action sts stk) + +happyReport 30# = happyReport' +happyReport _ = happyReport' + + +happyThen :: () => (P a) -> (a -> (P b)) -> (P b) happyThen = (Prelude.>>=) -happyReturn :: () => a -> P a +happyReturn :: () => a -> (P a) happyReturn = (Prelude.return) happyParse :: () => Happy_GHC_Exts.Int# -> P (HappyAbsSyn ) -happyNewToken :: () => Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) +happyNewToken :: () => Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> (P (HappyAbsSyn )) -happyDoAction :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn ) +happyDoAction :: () => Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> (P (HappyAbsSyn )) -happyReduceArr :: () => Happy_Data_Array.Array Prelude.Int (Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> P (HappyAbsSyn )) +happyReduceArr :: () => Happy_Data_Array.Array Prelude.Int (Happy_GHC_Exts.Int# -> Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn ) -> (P (HappyAbsSyn ))) happyThen1 :: () => P a -> (a -> P b) -> P b happyThen1 = happyThen -happyReturn1 :: () => a -> P a +happyFmap1 f m = happyThen m (\a -> happyReturn (f a)) +happyReturn1 :: () => a -> (P a) happyReturn1 = happyReturn -happyError' :: () => ((Token), [Prelude.String]) -> P a -happyError' tk = (\(tokens, explist) -> happyError) tk +happyReport' :: () => (Token) -> [Prelude.String] -> (P a) -> (P a) +happyReport' = (\tokens expected resume -> happyError) + +happyAbort :: () => (P a) +happyAbort = error "Called abort handler in non-resumptive parser" + ourParser = happySomeParser where - happySomeParser = happyThen (happyParse 0#) (\x -> happyReturn (let {(HappyWrap4 x') = happyOut4 x} in x')) + happySomeParser = happyThen (happyParse 0#) (\x -> happyReturn (let {(HappyWrap5 x') = happyOut5 x} in x')) happySeq = happyDontSeq happyError :: P a happyError = failP (\l -> show l ++ ": Parse error\n") -{-# LINE 1 "templates/GenericTemplate.hs" #-} +#define HAPPY_COERCE 1 -- $Id: GenericTemplate.hs,v 1.26 2005/01/14 14:47:22 simonmar Exp $ +#if !defined(__GLASGOW_HASKELL__) +# error This code isn't being built with GHC. +#endif - - - - - - - - - - +-- Get WORDS_BIGENDIAN (if defined) +#include "MachDeps.h" -- Do not remove this comment. Required to fix CPP parsing when using GCC and a clang-compiled alex. -#if __GLASGOW_HASKELL__ > 706 #define LT(n,m) ((Happy_GHC_Exts.tagToEnum# (n Happy_GHC_Exts.<# m)) :: Prelude.Bool) #define GTE(n,m) ((Happy_GHC_Exts.tagToEnum# (n Happy_GHC_Exts.>=# m)) :: Prelude.Bool) #define EQ(n,m) ((Happy_GHC_Exts.tagToEnum# (n Happy_GHC_Exts.==# m)) :: Prelude.Bool) -#else -#define LT(n,m) (n Happy_GHC_Exts.<# m) -#define GTE(n,m) (n Happy_GHC_Exts.>=# m) -#define EQ(n,m) (n Happy_GHC_Exts.==# m) -#endif - - - - - - - - - - - - - - - - - - - -data Happy_IntList = HappyCons Happy_GHC_Exts.Int# Happy_IntList - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +#define PLUS(n,m) (n Happy_GHC_Exts.+# m) +#define MINUS(n,m) (n Happy_GHC_Exts.-# m) +#define TIMES(n,m) (n Happy_GHC_Exts.*# m) +#define NEGATE(n) (Happy_GHC_Exts.negateInt# (n)) +type Happy_Int = Happy_GHC_Exts.Int# +data Happy_IntList = HappyCons Happy_Int Happy_IntList +#define ERROR_TOK 0# +#define CATCH_TOK 1# +#if defined(HAPPY_COERCE) +# define GET_ERROR_TOKEN(x) (case Happy_GHC_Exts.unsafeCoerce# x of { (Happy_GHC_Exts.I# i) -> i }) +# define MK_ERROR_TOKEN(i) (Happy_GHC_Exts.unsafeCoerce# (Happy_GHC_Exts.I# i)) +# define MK_TOKEN(x) (happyInTok (x)) +#else +# define GET_ERROR_TOKEN(x) (case x of { HappyErrorToken (Happy_GHC_Exts.I# i) -> i }) +# define MK_ERROR_TOKEN(i) (HappyErrorToken (Happy_GHC_Exts.I# i)) +# define MK_TOKEN(x) (HappyTerminal (x)) +#endif +#if defined(HAPPY_DEBUG) +# define DEBUG_TRACE(s) (happyTrace (s)) $ +happyTrace string expr = Happy_System_IO_Unsafe.unsafePerformIO $ do + Happy_System_IO.hPutStr Happy_System_IO.stderr string + return expr +#else +# define DEBUG_TRACE(s) {- nothing -} +#endif infixr 9 `HappyStk` data HappyStk a = HappyStk a (HappyStk a) @@ -965,214 +936,432 @@ happyParse start_state = happyNewToken start_state notHappyAtAll notHappyAtAll -- If the current token is ERROR_TOK, it means we've just accepted a partial -- parse (a %partial parser). We must ignore the saved token on the top of -- the stack in this case. -happyAccept 0# tk st sts (_ `HappyStk` ans `HappyStk` _) = +happyAccept ERROR_TOK tk st sts (_ `HappyStk` ans `HappyStk` _) = happyReturn1 ans -happyAccept j tk st sts (HappyStk ans _) = +happyAccept j tk st sts (HappyStk ans _) = (happyTcHack j (happyTcHack st)) (happyReturn1 ans) ----------------------------------------------------------------------------- -- Arrays only: do the next action - - -happyDoAction i tk st - = {- nothing -} - case action of - 0# -> {- nothing -} - happyFail (happyExpListPerState ((Happy_GHC_Exts.I# (st)) :: Prelude.Int)) i tk st - -1# -> {- nothing -} - happyAccept i tk st - n | LT(n,(0# :: Happy_GHC_Exts.Int#)) -> {- nothing -} - (happyReduceArr Happy_Data_Array.! rule) i tk st - where rule = (Happy_GHC_Exts.I# ((Happy_GHC_Exts.negateInt# ((n Happy_GHC_Exts.+# (1# :: Happy_GHC_Exts.Int#)))))) - n -> {- nothing -} - happyShift new_state i tk st - where new_state = (n Happy_GHC_Exts.-# (1# :: Happy_GHC_Exts.Int#)) - where off = happyAdjustOffset (indexShortOffAddr happyActOffsets st) - off_i = (off Happy_GHC_Exts.+# i) - check = if GTE(off_i,(0# :: Happy_GHC_Exts.Int#)) - then EQ(indexShortOffAddr happyCheck off_i, i) - else Prelude.False - action - | check = indexShortOffAddr happyTable off_i - | Prelude.otherwise = indexShortOffAddr happyDefActions st - - - - -indexShortOffAddr (HappyA# arr) off = - Happy_GHC_Exts.narrow16Int# i +happyDoAction i tk st = + DEBUG_TRACE("state: " ++ show (Happy_GHC_Exts.I# st) ++ + ",\ttoken: " ++ show (Happy_GHC_Exts.I# i) ++ + ",\taction: ") + case happyDecodeAction (happyNextAction i st) of + HappyFail -> DEBUG_TRACE("failing.\n") + happyFail i tk st + HappyAccept -> DEBUG_TRACE("accept.\n") + happyAccept i tk st + HappyReduce rule -> DEBUG_TRACE("reduce (rule " ++ show (Happy_GHC_Exts.I# rule) ++ ")") + (happyReduceArr Happy_Data_Array.! (Happy_GHC_Exts.I# rule)) i tk st + HappyShift new_state -> DEBUG_TRACE("shift, enter state " ++ show (Happy_GHC_Exts.I# new_state) ++ "\n") + happyShift new_state i tk st + +{-# INLINE happyNextAction #-} +happyNextAction i st = case happyIndexActionTable i st of + Just (Happy_GHC_Exts.I# act) -> act + Nothing -> happyIndexOffAddr happyDefActions st + +{-# INLINE happyIndexActionTable #-} +happyIndexActionTable i st + | GTE(i, 0#), GTE(off, 0#), EQ(happyIndexOffAddr happyCheck off, i) + -- i >= 0: Guard against INVALID_TOK (do the default action, which ultimately errors) + -- off >= 0: Otherwise it's a default action + -- equality check: Ensure that the entry in the compressed array is owned by st + = Prelude.Just (Happy_GHC_Exts.I# (happyIndexOffAddr happyTable off)) + | otherwise + = Prelude.Nothing where - i = Happy_GHC_Exts.word2Int# (Happy_GHC_Exts.or# (Happy_GHC_Exts.uncheckedShiftL# high 8#) low) - high = Happy_GHC_Exts.int2Word# (Happy_GHC_Exts.ord# (Happy_GHC_Exts.indexCharOffAddr# arr (off' Happy_GHC_Exts.+# 1#))) - low = Happy_GHC_Exts.int2Word# (Happy_GHC_Exts.ord# (Happy_GHC_Exts.indexCharOffAddr# arr off')) - off' = off Happy_GHC_Exts.*# 2# - - - - -{-# INLINE happyLt #-} -happyLt x y = LT(x,y) - - -readArrayBit arr bit = - Bits.testBit (Happy_GHC_Exts.I# (indexShortOffAddr arr ((unbox_int bit) `Happy_GHC_Exts.iShiftRA#` 4#))) (bit `Prelude.mod` 16) - where unbox_int (Happy_GHC_Exts.I# x) = x - - - + off = PLUS(happyIndexOffAddr happyActOffsets st, i) + +data HappyAction + = HappyFail + | HappyAccept + | HappyReduce Happy_Int -- rule number + | HappyShift Happy_Int -- new state + deriving Show + +{-# INLINE happyDecodeAction #-} +happyDecodeAction :: Happy_Int -> HappyAction +happyDecodeAction 0# = HappyFail +happyDecodeAction -1# = HappyAccept +happyDecodeAction action | LT(action, 0#) = HappyReduce NEGATE(PLUS(action, 1#)) + | otherwise = HappyShift MINUS(action, 1#) + +{-# INLINE happyIndexGotoTable #-} +happyIndexGotoTable nt st = happyIndexOffAddr happyTable off + where + off = PLUS(happyIndexOffAddr happyGotoOffsets st, nt) +{-# INLINE happyIndexOffAddr #-} +happyIndexOffAddr :: HappyAddr -> Happy_Int -> Happy_Int +happyIndexOffAddr (HappyA# arr) off = +#if __GLASGOW_HASKELL__ >= 901 + Happy_GHC_Exts.int32ToInt# -- qualified import because it doesn't exist on older GHC's +#endif +#ifdef WORDS_BIGENDIAN + -- The CI of `alex` tests this code path + (Happy_GHC_Exts.word32ToInt32# (Happy_GHC_Exts.wordToWord32# (Happy_GHC_Exts.byteSwap32# (Happy_GHC_Exts.word32ToWord# (Happy_GHC_Exts.int32ToWord32# +#endif + (Happy_GHC_Exts.indexInt32OffAddr# arr off) +#ifdef WORDS_BIGENDIAN + ))))) +#endif +happyIndexRuleArr :: Happy_Int -> (# Happy_Int, Happy_Int #) +happyIndexRuleArr r = (# nt, len #) + where + !(Happy_GHC_Exts.I# n_starts) = happy_n_starts + offs = TIMES(MINUS(r,n_starts),2#) + nt = happyIndexOffAddr happyRuleArr offs + len = happyIndexOffAddr happyRuleArr PLUS(offs,1#) data HappyAddr = HappyA# Happy_GHC_Exts.Addr# - ------------------------------------------------------------------------------ --- HappyState data type (not arrays) - - - - - - - - - - - - - ----------------------------------------------------------------------------- -- Shifting a token -happyShift new_state 0# tk st sts stk@(x `HappyStk` _) = - let i = (case Happy_GHC_Exts.unsafeCoerce# x of { (Happy_GHC_Exts.I# (i)) -> i }) in --- trace "shifting the error token" $ - happyDoAction i tk new_state (HappyCons (st) (sts)) (stk) +happyShift new_state ERROR_TOK tk st sts stk@(x `HappyStk` _) = + -- See "Error Fixup" below + let i = GET_ERROR_TOKEN(x) in + DEBUG_TRACE("shifting the error token") + happyDoAction i tk new_state (HappyCons st sts) stk happyShift new_state i tk st sts stk = - happyNewToken new_state (HappyCons (st) (sts)) ((happyInTok (tk))`HappyStk`stk) + happyNewToken new_state (HappyCons st sts) (MK_TOKEN(tk) `HappyStk` stk) -- happyReduce is specialised for the common cases. -happySpecReduce_0 i fn 0# tk st sts stk - = happyFail [] 0# tk st sts stk -happySpecReduce_0 nt fn j tk st@((action)) sts stk - = happyGoto nt j tk st (HappyCons (st) (sts)) (fn `HappyStk` stk) +happySpecReduce_0 nt fn j tk st sts stk + = happySeq fn (happyGoto nt j tk st (HappyCons st sts) (fn `HappyStk` stk)) -happySpecReduce_1 i fn 0# tk st sts stk - = happyFail [] 0# tk st sts stk -happySpecReduce_1 nt fn j tk _ sts@((HappyCons (st@(action)) (_))) (v1`HappyStk`stk') +happySpecReduce_1 nt fn j tk old_st sts@(HappyCons st _) (v1 `HappyStk` stk') = let r = fn v1 in - happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk')) + happyTcHack old_st (happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk'))) -happySpecReduce_2 i fn 0# tk st sts stk - = happyFail [] 0# tk st sts stk -happySpecReduce_2 nt fn j tk _ (HappyCons (_) (sts@((HappyCons (st@(action)) (_))))) (v1`HappyStk`v2`HappyStk`stk') +happySpecReduce_2 nt fn j tk old_st + (HappyCons _ sts@(HappyCons st _)) + (v1 `HappyStk` v2 `HappyStk` stk') = let r = fn v1 v2 in - happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk')) + happyTcHack old_st (happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk'))) -happySpecReduce_3 i fn 0# tk st sts stk - = happyFail [] 0# tk st sts stk -happySpecReduce_3 nt fn j tk _ (HappyCons (_) ((HappyCons (_) (sts@((HappyCons (st@(action)) (_))))))) (v1`HappyStk`v2`HappyStk`v3`HappyStk`stk') +happySpecReduce_3 nt fn j tk old_st + (HappyCons _ (HappyCons _ sts@(HappyCons st _))) + (v1 `HappyStk` v2 `HappyStk` v3 `HappyStk` stk') = let r = fn v1 v2 v3 in - happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk')) + happyTcHack old_st (happySeq r (happyGoto nt j tk st sts (r `HappyStk` stk'))) -happyReduce k i fn 0# tk st sts stk - = happyFail [] 0# tk st sts stk happyReduce k nt fn j tk st sts stk - = case happyDrop (k Happy_GHC_Exts.-# (1# :: Happy_GHC_Exts.Int#)) sts of - sts1@((HappyCons (st1@(action)) (_))) -> - let r = fn stk in -- it doesn't hurt to always seq here... - happyDoSeq r (happyGoto nt j tk st1 sts1 r) + = case happyDrop MINUS(k,(1# :: Happy_Int)) sts of + sts1@(HappyCons st1 _) -> + let r = fn stk in -- it doesn't hurt to always seq here... + st `happyTcHack` happyDoSeq r (happyGoto nt j tk st1 sts1 r) -happyMonadReduce k nt fn 0# tk st sts stk - = happyFail [] 0# tk st sts stk happyMonadReduce k nt fn j tk st sts stk = - case happyDrop k (HappyCons (st) (sts)) of - sts1@((HappyCons (st1@(action)) (_))) -> + case happyDrop k (HappyCons st sts) of + sts1@(HappyCons st1 _) -> let drop_stk = happyDropStk k stk in - happyThen1 (fn stk tk) (\r -> happyGoto nt j tk st1 sts1 (r `HappyStk` drop_stk)) + j `happyTcHack` happyThen1 (fn stk tk) + (\r -> happyGoto nt j tk st1 sts1 (r `HappyStk` drop_stk)) -happyMonad2Reduce k nt fn 0# tk st sts stk - = happyFail [] 0# tk st sts stk happyMonad2Reduce k nt fn j tk st sts stk = - case happyDrop k (HappyCons (st) (sts)) of - sts1@((HappyCons (st1@(action)) (_))) -> - let drop_stk = happyDropStk k stk - - off = happyAdjustOffset (indexShortOffAddr happyGotoOffsets st1) - off_i = (off Happy_GHC_Exts.+# nt) - new_state = indexShortOffAddr happyTable off_i - - - - + case happyDrop k (HappyCons st sts) of + sts1@(HappyCons st1 _) -> + let drop_stk = happyDropStk k stk + off = happyIndexOffAddr happyGotoOffsets st1 + off_i = PLUS(off, nt) + new_state = happyIndexOffAddr happyTable off_i in - happyThen1 (fn stk tk) (\r -> happyNewToken new_state sts1 (r `HappyStk` drop_stk)) + j `happyTcHack` happyThen1 (fn stk tk) + (\r -> happyNewToken new_state sts1 (r `HappyStk` drop_stk)) -happyDrop 0# l = l -happyDrop n (HappyCons (_) (t)) = happyDrop (n Happy_GHC_Exts.-# (1# :: Happy_GHC_Exts.Int#)) t +happyDrop 0# l = l +happyDrop n (HappyCons _ t) = happyDrop MINUS(n,(1# :: Happy_Int)) t -happyDropStk 0# l = l -happyDropStk n (x `HappyStk` xs) = happyDropStk (n Happy_GHC_Exts.-# (1#::Happy_GHC_Exts.Int#)) xs +happyDropStk 0# l = l +happyDropStk n (x `HappyStk` xs) = happyDropStk MINUS(n,(1#::Happy_Int)) xs ----------------------------------------------------------------------------- -- Moving to a new state after a reduction - -happyGoto nt j tk st = - {- nothing -} +happyGoto nt j tk st = + DEBUG_TRACE(", goto state " ++ show (Happy_GHC_Exts.I# new_state) ++ "\n") happyDoAction j tk new_state - where off = happyAdjustOffset (indexShortOffAddr happyGotoOffsets st) - off_i = (off Happy_GHC_Exts.+# nt) - new_state = indexShortOffAddr happyTable off_i - - - - ------------------------------------------------------------------------------ --- Error recovery (ERROR_TOK is the error token) - --- parse error if we are in recovery and we fail again -happyFail explist 0# tk old_st _ stk@(x `HappyStk` _) = - let i = (case Happy_GHC_Exts.unsafeCoerce# x of { (Happy_GHC_Exts.I# (i)) -> i }) in --- trace "failing" $ - happyError_ explist i tk - -{- We don't need state discarding for our restricted implementation of - "error". In fact, it can cause some bogus parses, so I've disabled it - for now --SDM - --- discard a state -happyFail ERROR_TOK tk old_st CONS(HAPPYSTATE(action),sts) - (saved_tok `HappyStk` _ `HappyStk` stk) = --- trace ("discarding state, depth " ++ show (length stk)) $ - DO_ACTION(action,ERROR_TOK,tk,sts,(saved_tok`HappyStk`stk)) + where new_state = happyIndexGotoTable nt st + +{- Note [Error recovery] +~~~~~~~~~~~~~~~~~~~~~~~~ +When there is no applicable action for the current lookahead token `tk`, +happy enters error recovery mode. Depending on whether the grammar file +declares the two action form `%error { abort } { report }` for + Resumptive Error Handling, +it works in one (not resumptive) or two phases (resumptive): + + 1. Fixup mode: + Try to see if there is an action for the error token ERROR_TOK. If there + is, do *not* emit an error and pretend instead that an `error` token was + inserted. + When there is no ERROR_TOK action, report an error. + + In non-resumptive error handling, calling the single error handler + (e.g. `happyError`) will throw an exception and abort the parser. + However, in resumptive error handling we enter *error resumption mode*. + + 2. Error resumption mode: + After reporting the error (with `report`), happy will attempt to find + a good state stack to resume parsing in. + For each candidate stack, it discards input until one of the candidates + resumes (i.e. shifts the current input). + If no candidate resumes before the end of input, resumption failed and + calls the `abort` function, to much the same effect as in non-resumptive + error handling. + + Candidate stacks are declared by the grammar author using the special + `catch` terminal and called "catch frames". + This mechanism is described in detail in Note [happyResume]. + +The `catch` resumption mechanism (2) is what usually is associated with +`error` in `bison` or `menhir`. Since `error` is used for the Fixup mechanism +(1) above, we call the corresponding token `catch`. +Furthermore, in constrast to `bison`, our implementation of `catch` +non-deterministically considers multiple catch frames on the stack for +resumption (See Note [Multiple catch frames]). + +Note [happyResume] +~~~~~~~~~~~~~~~~~~ +`happyResume` implements the resumption mechanism from Note [Error recovery]. +It is best understood by example. Consider + +Exp :: { String } +Exp : '1' { "1" } + | catch { "catch" } + | Exp '+' Exp %shift { $1 ++ " + " ++ $3 } -- %shift: associate 1 + 1 + 1 to the right + | '(' Exp ')' { "(" ++ $2 ++ ")" } + +The idea of the use of `catch` here is that upon encountering a parse error +during expression parsing, we can gracefully degrade using the `catch` rule, +still producing a partial syntax tree and keep on parsing to find further +syntax errors. + +Let's trace the parser state for input 11+1, which will error out after shifting 1. +After shifting, we have the following item stack (growing downwards and omitting +transitive closure items): + + State 0: %start_parseExp -> . Exp + State 5: Exp -> '1' . + +(Stack as a list of state numbers: [5,0].) +As Note [Error recovery] describes, we will first try Fixup mode. +That fails because no production can shift the `error` token. +Next we try Error resumption mode. This works as follows: + + 1. Pop off the item stack until we find an item that can shift the `catch` + token. (Implemented in `pop_items`.) + * State 5 cannot shift catch. Pop. + * State 0 can shift catch, which would transition into + State 4: Exp -> catch . + So record the *stack* `[4,0]` after doing the shift transition. + We call this a *catch frame*, where the top is a *catch state*, + corresponding to an item in which we just shifted a `catch` token. + There can be multiple such catch stacks, see Note [Multiple catch frames]. + + 2. Discard tokens from the input until the lookahead can be shifted in one + of the catch stacks. (Implemented in `discard_input_until_exp` and + `some_catch_state_shifts`.) + * We cannot shift the current lookahead '1' in state 4, so we discard + * We *can* shift the next lookahead '+' in state 4, but only after + reducing, which pops State 4 and goes to State 3: + State 3: %start_parseExp -> Exp . + Exp -> Exp . '+' Exp + Here we can shift '+'. + As you can see, to implement this machinery we need to simulate + the operation of the LALR automaton, especially reduction + (`happySimulateReduce`). + +Note [Multiple catch frames] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +For fewer spurious error messages, it can be beneficial to trace multiple catch +items. Consider + +Exp : '1' + | catch + | Exp '+' Exp %shift + | '(' Exp ')' + +Let's trace the parser state for input (;+1, which will error out after shifting (. +After shifting, we have the following item stack (growing downwards): + + State 0: %start_parseExp -> . Exp + State 6: Exp -> '(' . Exp ')' + +Upon error, we want to find items in the stack which can shift a catch token. +Note that both State 0 and State 6 can shift a catch token, transitioning into + State 4: Exp -> catch . +Hence we record the catch frames `[4,6,0]` and `[4,0]` for possible resumption. + +Which catch frame do we pick for resumption? +Note that resuming catch frame `[4,0]` will parse as "catch+1", whereas +resuming the innermost frame `[4,6,0]` corresponds to parsing "(catch+1". +The latter would keep discarding input until the closing ')' is found. +So we will discard + and 1, leading to a spurious syntax error at the end of +input, aborting the parse and never producing a partial syntax tree. Bad! + +It is far preferable to resume with catch frame `[4,0]`, where we can resume +successfully on input +, so that is what we do. + +In general, we pick the catch frame for resumption that discards the least +amount of input for a successful shift, preferring the topmost such catch frame. -} --- Enter error recovery: generate an error token, --- save the old token and carry on. -happyFail explist i tk (action) sts stk = --- trace "entering error recovery" $ - happyDoAction 0# tk action sts ((Happy_GHC_Exts.unsafeCoerce# (Happy_GHC_Exts.I# (i))) `HappyStk` stk) +-- happyFail :: Happy_Int -> _ -> Happy_Int -> _ +-- This function triggers Note [Error recovery]. +-- If the current token is ERROR_TOK, phase (1) has failed and we might try +-- phase (2). +happyFail ERROR_TOK = happyFixupFailed +happyFail i = happyTryFixup i + +-- Enter Error Fixup (see Note [Error recovery]): +-- generate an error token, save the old token and carry on. +-- When a `happyShift` accepts the error token, we will pop off the error token +-- to resume parsing with the current lookahead `i`. +happyTryFixup i tk action sts stk = + DEBUG_TRACE("entering `error` fixup.\n") + happyDoAction ERROR_TOK tk action sts (MK_ERROR_TOKEN(i) `HappyStk` stk) + -- NB: `happyShift` will simply pop the error token and carry on with + -- `tk`. Hence we don't change `tk` in the call here + +-- See Note [Error recovery], phase (2). +-- Enter resumption mode after reporting the error by calling `happyResume`. +happyFixupFailed tk st sts (x `HappyStk` stk) = + let i = GET_ERROR_TOKEN(x) in + DEBUG_TRACE("`error` fixup failed.\n") + let resume = happyResume i tk st sts stk + expected = happyExpectedTokens st sts in + happyReport i tk expected resume + +-- happyResume :: Happy_Int -> _ -> Happy_Int -> _ +-- See Note [happyResume] +happyResume i tk st sts stk = pop_items [] st sts stk + where + !(Happy_GHC_Exts.I# n_starts) = happy_n_starts -- this is to test whether we have a start token + !(Happy_GHC_Exts.I# eof_i) = happy_n_terms - 1 -- this is the token number of the EOF token + happy_list_to_list :: Happy_IntList -> [Int] + happy_list_to_list (HappyCons st sts) + | LT(st, n_starts) + = [(Happy_GHC_Exts.I# st)] + | otherwise + = (Happy_GHC_Exts.I# st) : happy_list_to_list sts + + -- See (1) of Note [happyResume] + pop_items catch_frames st sts stk + | LT(st, n_starts) + = DEBUG_TRACE("reached start state " ++ show (Happy_GHC_Exts.I# st) ++ ", ") + if null catch_frames_new + then DEBUG_TRACE("no resumption.\n") + happyAbort + else DEBUG_TRACE("now discard input, trying to anchor in states (reverse " ++ show (map (happy_list_to_list . fst) catch_frames_new) ++ ").\n") + discard_input_until_exp i tk (reverse catch_frames_new) + | (HappyCons st1 sts1) <- sts, _ `HappyStk` stk1 <- stk + = pop_items catch_frames_new st1 sts1 stk1 + where + !catch_frames_new + | HappyShift new_state <- happyDecodeAction (happyNextAction CATCH_TOK st) + , DEBUG_TRACE("can shift catch token in state " ++ show (Happy_GHC_Exts.I# st) ++ ", into state " ++ show (Happy_GHC_Exts.I# new_state) ++ "\n") + null (filter (\(HappyCons _ (HappyCons h _),_) -> EQ(st,h)) catch_frames) + = (HappyCons new_state (HappyCons st sts), MK_ERROR_TOKEN(i) `HappyStk` stk):catch_frames -- MK_ERROR_TOKEN(i) is just some dummy that should not be accessed by user code + | otherwise + = DEBUG_TRACE("already shifted or can't shift catch in " ++ show (Happy_GHC_Exts.I# st) ++ "\n") + catch_frames + + -- See (2) of Note [happyResume] + discard_input_until_exp i tk catch_frames + | Just (HappyCons st (HappyCons catch_st sts), catch_frame) <- some_catch_state_shifts i catch_frames + = DEBUG_TRACE("found expected token in state " ++ show (Happy_GHC_Exts.I# st) ++ " after shifting from " ++ show (Happy_GHC_Exts.I# catch_st) ++ ": " ++ show (Happy_GHC_Exts.I# i) ++ "\n") + happyDoAction i tk st (HappyCons catch_st sts) catch_frame + | EQ(i,eof_i) -- is i EOF? + = DEBUG_TRACE("reached EOF, cannot resume. abort parse :(\n") + happyAbort + | otherwise + = DEBUG_TRACE("discard token " ++ show (Happy_GHC_Exts.I# i) ++ "\n") + happyLex (\eof_tk -> discard_input_until_exp eof_i eof_tk catch_frames) -- eof + (\i tk -> discard_input_until_exp i tk catch_frames) -- not eof + + some_catch_state_shifts _ [] = DEBUG_TRACE("no catch state could shift.\n") Nothing + some_catch_state_shifts i catch_frames@(((HappyCons st sts),_):_) = try_head i st sts catch_frames + where + try_head i st sts catch_frames = -- PRECONDITION: head catch_frames = (HappyCons st sts) + DEBUG_TRACE("trying token " ++ show (Happy_GHC_Exts.I# i) ++ " in state " ++ show (Happy_GHC_Exts.I# st) ++ ": ") + case happyDecodeAction (happyNextAction i st) of + HappyFail -> DEBUG_TRACE("fail.\n") some_catch_state_shifts i (tail catch_frames) + HappyAccept -> DEBUG_TRACE("accept.\n") Just (head catch_frames) + HappyShift _ -> DEBUG_TRACE("shift.\n") Just (head catch_frames) + HappyReduce r -> case happySimulateReduce r st sts of + (HappyCons st1 sts1) -> try_head i st1 sts1 catch_frames + +happySimulateReduce r st sts = + DEBUG_TRACE("simulate reduction of rule " ++ show (Happy_GHC_Exts.I# r) ++ ", ") + let (# nt, len #) = happyIndexRuleArr r in + DEBUG_TRACE("nt " ++ show (Happy_GHC_Exts.I# nt) ++ ", len: " ++ show (Happy_GHC_Exts.I# len) ++ ", new_st ") + let !(sts1@(HappyCons st1 _)) = happyDrop len (HappyCons st sts) + new_st = happyIndexGotoTable nt st1 in + DEBUG_TRACE(show (Happy_GHC_Exts.I# new_st) ++ ".\n") + (HappyCons new_st sts1) + +happyTokenToString :: Prelude.Int -> Prelude.String +happyTokenToString i = happyTokenStrings Prelude.!! (i Prelude.- 2) -- 2: errorTok, catchTok + +happyExpectedTokens :: Happy_Int -> Happy_IntList -> [Prelude.String] +-- Upon a parse error, we want to suggest tokens that are expected in that +-- situation. This function computes such tokens. +-- It works by examining the top of the state stack. +-- For every token number that does a shift transition, record that token number. +-- For every token number that does a reduce transition, simulate that reduction +-- on the state state stack and repeat. +-- The recorded token numbers are then formatted with 'happyTokenToString' and +-- returned. +happyExpectedTokens st sts = + DEBUG_TRACE("constructing expected tokens.\n") + map happyTokenToString $ search_shifts st sts [] + where + search_shifts st sts shifts = foldr (add_action st sts) shifts (distinct_actions st) + add_action st sts (Happy_GHC_Exts.I# i, Happy_GHC_Exts.I# act) shifts = + DEBUG_TRACE("found action in state " ++ show (Happy_GHC_Exts.I# st) ++ ", input " ++ show (Happy_GHC_Exts.I# i) ++ ", " ++ show (happyDecodeAction act) ++ "\n") + case happyDecodeAction act of + HappyFail -> shifts + HappyAccept -> shifts -- This would always be %eof or error... Not helpful + HappyShift _ -> Happy_Data_List.insert (Happy_GHC_Exts.I# i) shifts + HappyReduce r -> case happySimulateReduce r st sts of + (HappyCons st1 sts1) -> search_shifts st1 sts1 shifts + distinct_actions st + -- The (token number, action) pairs of all actions in the given state + = ((-1), (Happy_GHC_Exts.I# (happyIndexOffAddr happyDefActions st))) + : [ (i, act) | i <- [begin_i..happy_n_terms], act <- get_act row_off i ] + where + row_off = happyIndexOffAddr happyActOffsets st + begin_i = 2 -- +2: errorTok,catchTok + get_act off (Happy_GHC_Exts.I# i) -- happyIndexActionTable with cached row offset + | let off_i = PLUS(off,i) + , GTE(off_i,0#) + , EQ(happyIndexOffAddr happyCheck off_i,i) + = [(Happy_GHC_Exts.I# (happyIndexOffAddr happyTable off_i))] + | otherwise + = [] -- Internal happy errors: notHappyAtAll :: a -notHappyAtAll = Prelude.error "Internal Happy error\n" +notHappyAtAll = Prelude.error "Internal Happy parser panic. This is not supposed to happen! Please open a bug report at https://github.com/haskell/happy/issues.\n" ----------------------------------------------------------------------------- -- Hack to get the typechecker to accept our action functions - -happyTcHack :: Happy_GHC_Exts.Int# -> a -> a +happyTcHack :: Happy_Int -> a -> a happyTcHack x y = y {-# INLINE happyTcHack #-} - ----------------------------------------------------------------------------- --- Seq-ing. If the --strict flag is given, then Happy emits +-- Seq-ing. If the --strict flag is given, then Happy emits -- happySeq = happyDoSeq -- otherwise it emits -- happySeq = happyDontSeq @@ -1186,7 +1375,6 @@ happyDontSeq a b = b -- of deciding to inline happyGoto everywhere, which increases the size of -- the generated parser quite a bit. - {-# NOINLINE happyDoAction #-} {-# NOINLINE happyTable #-} {-# NOINLINE happyCheck #-} diff --git a/lib/grammar/src/Happy/Grammar.lhs b/lib/grammar/src/Happy/Grammar.lhs index 960b7c1a..bb7ea2a5 100644 --- a/lib/grammar/src/Happy/Grammar.lhs +++ b/lib/grammar/src/Happy/Grammar.lhs @@ -16,9 +16,11 @@ The Grammar data type. > AttributeGrammarExtras(..), > Priority(..), > Assoc(..), -> Pragmas(..), ErrorHandlerType(..), +> ErrorHandlerInfo(..), +> Pragmas(..), > -> errorName, errorTok, startName, dummyName, firstStartTok, dummyTok, +> errorName, errorTok, catchName, catchTok, +> startName, dummyName, firstStartTok, dummyTok, > eofName, epsilonTok, > ) where @@ -98,9 +100,16 @@ The Grammar data type. > Prio _ i == Prio _ j = i == j > _ == _ = False -> data ErrorHandlerType -> = ErrorHandlerTypeDefault -> | ErrorHandlerTypeExpList +> data ErrorHandlerInfo +> = DefaultErrorHandler +> -- ^ Default handler `happyError` +> | CustomErrorHandler String +> -- ^ Call this handler on error. +> | ResumptiveErrorHandler String String +> -- ^ `ResumptiveErrorHandler abort report`: +> -- Upon encountering a parse error, call non-fatal function `report`. +> -- Then try to resume parsing by finding a catch production. +> -- If that ultimately fails, call `abort`. > -- | Stuff like `\%monad`, `\%expect` > data Pragmas @@ -110,8 +119,10 @@ The Grammar data type. > monad :: (Bool,String,String,String,String), > expect :: Maybe Int, > lexer :: Maybe (String,String), -> error_handler :: Maybe String, -> error_sig :: ErrorHandlerType +> error_handler :: ErrorHandlerInfo, +> error_expected :: Bool +> -- ^ Error handler specified in `error_handler` takes +> -- a `[String]` carrying the pretty-printed expected tokens > } ----------------------------------------------------------------------------- @@ -150,14 +161,16 @@ In normal and GHC-based parsers, these numbers are also used in the generated grammar itself, except that the error token is mapped to -1. For array-based parsers, see the note in Tabular/LALR.lhs. -> startName, eofName, errorName, dummyName :: String +> startName, eofName, errorName, catchName, dummyName :: String > startName = "%start" -- with a suffix, like %start_1, %start_2 etc. > eofName = "%eof" > errorName = "error" +> catchName = "catch" > dummyName = "%dummy" -- shouldn't occur in the grammar anywhere -> firstStartTok, dummyTok, errorTok, epsilonTok :: Name -> firstStartTok = MkName 3 -> dummyTok = MkName 2 +> firstStartTok, dummyTok, errorTok, catchTok, epsilonTok :: Name +> firstStartTok = MkName 4 +> dummyTok = MkName 3 +> catchTok = MkName 2 > errorTok = MkName 1 > epsilonTok = MkName 0 diff --git a/lib/happy-lib.cabal b/lib/happy-lib.cabal index b3866ac3..18426914 100644 --- a/lib/happy-lib.cabal +++ b/lib/happy-lib.cabal @@ -69,7 +69,7 @@ source-repository head common common-stanza default-language: Haskell98 - default-extensions: CPP, MagicHash, FlexibleContexts, NamedFieldPuns + default-extensions: CPP, MagicHash, FlexibleContexts, NamedFieldPuns, PatternGuards ghc-options: -Wall -Wno-incomplete-uni-patterns library grammar diff --git a/lib/tabular/src/Happy/Tabular.lhs b/lib/tabular/src/Happy/Tabular.lhs index ea7b980a..1ece5497 100644 --- a/lib/tabular/src/Happy/Tabular.lhs +++ b/lib/tabular/src/Happy/Tabular.lhs @@ -64,7 +64,7 @@ Find unused rules and tokens > start_rules = [ 0 .. (length starts' - 1) ] > used_rules = start_rules ++ > nub [ r | (_,a) <- actions, r <- extract_reductions a ] -> used_tokens = errorTok : eof : +> used_tokens = errorTok : catchTok : eof : > nub [ t | (t,a) <- actions, is_shift a ] > n_prods = length productions' > unused_terminals = filter (`notElem` used_tokens) terms diff --git a/lib/tabular/src/Happy/Tabular/First.lhs b/lib/tabular/src/Happy/Tabular/First.lhs index 3a2fbce9..b281a959 100644 --- a/lib/tabular/src/Happy/Tabular/First.lhs +++ b/lib/tabular/src/Happy/Tabular/First.lhs @@ -9,6 +9,7 @@ Implementation of FIRST > import Happy.Tabular.NameSet ( NameSet ) > import qualified Happy.Tabular.NameSet as Set > import Happy.Grammar +> import Data.Maybe (fromMaybe) \subsection{Utilities} @@ -20,15 +21,13 @@ Implementation of FIRST > | otherwise = h @mkClosure@ makes a closure, when given a comparison and iteration loop. +It's a fixed point computation, we keep applying the function over the +input until it does not change. Be careful, because if the functional always makes the object different, This will never terminate. > mkClosure :: (a -> a -> Bool) -> (a -> a) -> a -> a -> mkClosure eq f = match . iterate f -> where -> match (a:b:_) | a `eq` b = a -> match (_:c) = match c -> match [] = error "Can't happen: match []" +> mkClosure eq f = until (\x -> eq x (f x)) f \subsection{Implementation of FIRST} @@ -38,23 +37,25 @@ This will never terminate. > , lookupProdsOfName = prodsOfName > , non_terminals = nts > }) -> = joinSymSets (\ h -> maybe (Set.singleton h) id (lookup h env) ) +> = joinSymSets (\h -> fromMaybe (Set.singleton h) (lookup h env)) > where -> env = mkClosure (==) (getNext fst_term prodNo prodsOfName) -> [ (name,Set.empty) | name <- nts ] +> env = mkClosure (==) (updateFirstSets fst_term prodNo prodsOfName) [(name,Set.empty) | name <- nts] -> getNext :: Name -> (a -> Production e) -> (Name -> [a]) -> -> [(Name, NameSet)] -> [(Name, NameSet)] -> getNext fst_term prodNo prodsOfName env = -> [ (nm, next nm) | (nm,_) <- env ] +> updateFirstSets :: Name -> (a -> Production e) -> (Name -> [a]) -> [(Name, NameSet)] +> -> [(Name, NameSet)] +> updateFirstSets fst_term prodNo prodsOfName env = [ (nm, nextFstSet nm) +> | (nm,_) <- env ] > where -> fn t | t == errorTok || t >= fst_term = Set.singleton t -> fn x = maybe (error "attempted FIRST(e) :-(") id (lookup x env) - -> next :: Name -> NameSet -> next t | t >= fst_term = Set.singleton t -> next n = Set.unions -> [ joinSymSets fn lhs -> | rl <- prodsOfName n -> , let Production _ lhs _ _ = prodNo rl ] - +> terminalP :: Name -> Bool +> terminalP s = s >= fst_term + +> currFstSet :: Name -> NameSet +> currFstSet s | s == errorTok || s == catchTok || terminalP s = Set.singleton s +> | otherwise = maybe (error "attempted FIRST(e) :-(") +> id (lookup s env) + +> nextFstSet :: Name -> NameSet +> nextFstSet s | terminalP s = Set.singleton s +> | otherwise = Set.unions [ joinSymSets currFstSet rhs +> | rl <- prodsOfName s +> , let Production _ rhs _ _ = prodNo rl ] diff --git a/lib/tabular/src/Happy/Tabular/LALR.lhs b/lib/tabular/src/Happy/Tabular/LALR.lhs index 8e1a09a7..6cf8194d 100644 --- a/lib/tabular/src/Happy/Tabular/LALR.lhs +++ b/lib/tabular/src/Happy/Tabular/LALR.lhs @@ -523,7 +523,7 @@ Generate the action table > possAction goto _set (Lr1 rule pos la) = > case findRule g rule pos of -> Just t | t >= fst_term || t == errorTok -> +> Just t | t >= fst_term || t == errorTok || t == catchTok -> > let f j = (t,LR'Shift j p) > p = maybe No id (lookup t prios) > in map f $ maybeToList (lookup t goto) diff --git a/tests/issue265.y b/tests/issue265.y new file mode 100644 index 00000000..9cbfcc21 --- /dev/null +++ b/tests/issue265.y @@ -0,0 +1,80 @@ +{ +{-# LANGUAGE FunctionalDependencies #-} +{-# LANGUAGE FlexibleInstances #-} +-- For ancient GHC 7.0.4 +{-# LANGUAGE MultiParamTypeClasses #-} +module Main where + +import Control.Monad (when) +import Data.Char +import System.Exit +} + +%name parseStmts +%tokentype { Token } +%errorhandlertype explist +%error { handleError } + +%monad { ParseM } { (>>=) } { return } + +%token + '1' { TOne } + '+' { TPlus } + ';' { TSemi } + +%% + +Stmts : {- empty -} { [] } + | Stmt { [$1] } + | Stmts ';' Stmt { $1 ++ [$3] } + +Stmt : Exp { ExpStmt $1 } + +Exp : '1' { One } + | Exp '+' Exp %shift { Plus $1 $3 } + +{ +data Token = TOne | TPlus | TSemi + deriving (Eq,Show) + +type Stmts = [Stmt] +data Stmt = ExpStmt Exp + deriving (Eq, Show) +data Exp = One | Plus Exp Exp + deriving (Eq, Show) + +type ParseM = Either ParseError + +data ParseError + = ParseError [String] + deriving Eq +instance Show ParseError where + show (ParseError exp) = "Parse error. Expected: " ++ show exp + +recordParseError :: [String] -> ParseM a +recordParseError expected = Left (ParseError expected) + +handleError :: ([Token], [String]) -> ParseM a +handleError (ts, expected) = recordParseError expected + +lexer :: String -> [Token] +lexer [] = [] +lexer (c:cs) + | isSpace c = lexer cs + | c == '1' = TOne:(lexer cs) + | c == '+' = TPlus:(lexer cs) + | c == ';' = TSemi:(lexer cs) + | otherwise = error "lexer error" + +main :: IO () +main = do + test "11;1" $ \res -> res == Left (ParseError ["';'","'+'"]) + where + test inp p = do + putStrLn $ "testing " ++ inp + let tokens = lexer inp + let res = parseStmts tokens + when (not (p res)) $ do + print res + exitWith (ExitFailure 1) +} diff --git a/tests/monaderror-explist.y b/tests/monaderror-explist.y index 558f28ee..dd84d23c 100644 --- a/tests/monaderror-explist.y +++ b/tests/monaderror-explist.y @@ -14,8 +14,8 @@ import Data.List (isPrefixOf) %name parseFoo %tokentype { Token } -%errorhandlertype explist %error { handleErrorExpList } +%error.expected %monad { ParseM } { (>>=) } { return } @@ -46,9 +46,9 @@ data Token | TokenTest deriving (Eq,Show) -handleErrorExpList :: ([Token], [String]) -> ParseM a -handleErrorExpList ([], _) = throwError $ ParseError Nothing -handleErrorExpList (ts, explist) = throwError $ ParseError $ Just $ (head ts, explist) +handleErrorExpList :: [Token] -> [String] -> ParseM a +handleErrorExpList [] _ = throwError $ ParseError Nothing +handleErrorExpList ts explist = throwError $ ParseError $ Just $ (head ts, explist) lexer :: String -> [Token] lexer [] = [] diff --git a/tests/monaderror-resume.y b/tests/monaderror-resume.y new file mode 100644 index 00000000..631c2b5e --- /dev/null +++ b/tests/monaderror-resume.y @@ -0,0 +1,150 @@ +{ +{-# LANGUAGE FunctionalDependencies #-} +{-# LANGUAGE FlexibleInstances #-} +-- For ancient GHC 7.0.4 +{-# LANGUAGE MultiParamTypeClasses #-} +module Main where + +import Control.Monad (when) +import Data.IORef +import Data.Char +import System.Exit +} + +%name parseStmts Stmts +%name parseExp Exp +%tokentype { LToken } +%error { abort } { reportError } -- the entire point of this test +%error.expected -- as in monaderror-explist.y + +%monad { ParseM } { (>>=) } { return } + +%token + '1' { (_, TOne) } + '+' { (_, TPlus) } + ';' { (_, TSemi) } + '(' { (_, TOpen) } + ')' { (_, TClose) } + +%right '+' + +%% + +Stmts :: { [String] } +Stmts : {- empty -} { [] } + | Exp { [$1] } + | Stmts ';' Exp { $1 ++ [$3] } + +Exp :: { String } +Exp : '1' { "1" } + | catch { "catch" } + | Exp '+' Exp { $1 ++ " + " ++ $3 } + | '(' Exp ')' { "(" ++ $2 ++ ")" } + +{ +data Token = TOne | TPlus | TSemi | TOpen | TClose + deriving (Eq,Show) + +----------- Validation monad +data Validate e a = V e (Maybe a) + deriving Functor +instance Monoid e => Applicative (Validate e) where + pure a = V mempty (Just a) + V e1 f <*> V e2 a = V (e1 <> e2) (f <*> a) +instance Monoid e => Monad (Validate e) where + V e Nothing >>= _ = V e Nothing -- fatal + V e1 (Just a) >>= k | V e2 b <- k a = V (e1 <> e2) b -- non-fatal + +abort :: Monoid e => [LToken] -> Validate e a -- this would be mzero from MonadPlus +abort _ = V mempty Nothing + +recordError :: e -> Validate e () -- this would be tell from MonadWriter +recordError e = V e (Just ()) + +runValidate (V e mb_a) = (e, mb_a) +----------- + +type ParseM = Validate [ParseError] + +data ParseError + = ParseError Int [String] + deriving Eq +instance Show ParseError where + show (ParseError loc exp) = "Parse error at " ++ locS ++ ". Expected: " ++ commaSep exp ++ "." + where + locS | loc < 0 = "EOF" + | otherwise = "column " ++ show loc + commaSep [] = "" + commaSep [s] = s + commaSep (s:ss) = s ++ "," ++ commaSep ss + +recordParseError :: Int -> [String] -> ParseM () +recordParseError loc expected = recordError [ParseError loc expected] + +eofLoc :: Int +eofLoc = -1 +reportError :: [LToken] -> [String] -> ([LToken] -> ParseM a) -> ParseM a +reportError ts expected resume = do + let loc | (l,_):_ <- ts = l + | otherwise = eofLoc + recordParseError loc expected + resume ts + +type LToken = (Int, Token) -- Token with location + +lexer :: Int -> String -> [LToken] +lexer _ [] = [] +lexer n (c:cs) + | isSpace c = lexer (n+1) cs + | c == '1' = (n,TOne):(lexer (n+1) cs) + | c == '+' = (n,TPlus):(lexer (n+1) cs) + | c == ';' = (n,TSemi):(lexer (n+1) cs) + | c == '(' = (n,TOpen):(lexer (n+1) cs) + | c == ')' = (n,TClose):(lexer (n+1) cs) + | otherwise = error "lexer error" + +main :: IO () +main = do + exit_code_ref <- newIORef ExitSuccess + let exp_err loc = ParseError loc ["'1'","'('"] + testStmts exit_code_ref "1+1;1" $ \(_,mb_ast) -> mb_ast == Just ["1 + 1", "1"] + testStmts exit_code_ref "1++1;1" $ \(errs,_) -> errs == [exp_err 2] + testStmts exit_code_ref "1++1;1;+" $ \(errs,_) -> errs == [exp_err 2, exp_err 7, exp_err eofLoc] + testStmts exit_code_ref "11;1" $ \(errs,_) -> errs == [ParseError 1 ["';'"]] + testStmts exit_code_ref "11;1;++" $ \(errs,_) -> errs == [ParseError 1 ["';'"], exp_err 5, exp_err 6, exp_err eofLoc] + testStmts exit_code_ref "11;1;1++" $ \(errs,_) -> errs == [ParseError 1 ["';'"], exp_err 7, exp_err eofLoc] + testExp exit_code_ref "11" $ \(errs,_) -> errs == [ParseError 1 ["'+'"]] + + testStmts exit_code_ref "(;1)" $ \(errs,mb_ast) -> errs == [exp_err 1, ParseError 3 ["';'"]] + testStmts exit_code_ref "1+;" $ \(errs,mb_ast) -> errs == [exp_err 2, exp_err eofLoc] + + -- The main point of the following 2 tests: rather than discarding tokens until + -- the EOF is reached upon the first error because of a missing ')', resume + -- after ';'. In the first case, we error again at EOF, in the second case we error again on '+' + testStmts exit_code_ref "(;" $ \(errs,mb_ast) -> + errs == [exp_err 1, exp_err eofLoc] && + mb_ast == Just ["catch","catch"] + testStmts exit_code_ref "(;+1" $ \(errs,mb_ast) -> + errs == [exp_err 1, exp_err 2] && + mb_ast == Just ["catch","catch + 1"] + + -- Example from the user's guide: + testStmts exit_code_ref "1+;+1;(+1;1" $ \(_,mb_ast) -> mb_ast == Just ["1 + catch","catch + 1","catch","1"] + + readIORef exit_code_ref >>= exitWith + where + testStmts ref inp p = do + putStrLn $ "testing Stmts " ++ inp + let tokens = lexer 0 inp + let res@(_,mb_ast) = runValidate $ parseStmts tokens + when (not (p res) || mb_ast == Nothing) $ do -- mb_ast == Nothing: Ensure that we *never* fail to resume! + print res + writeIORef ref (ExitFailure 1) + testExp ref inp p = do + putStrLn $ "testing Exp " ++ inp + let tokens = lexer 0 inp + let res = runValidate $ parseExp tokens + when (not (p res)) $ do + print res + writeIORef ref (ExitFailure 1) +}