Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Happy catchtok #283

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions packages/backend-glr/src/Happy/Backend/GLR/ProduceCode.lhs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ the driver and data strs (large template).
> -> CommonOptions -- Happy.CodeGen.Common.Options
> -> (String -- data
> ,String) -- parser
>

> produceGLRParser (base, lib) basename tables start header trailer (debug,options) g common_options
> = ( content base $ ""
> , lib_content lib
Expand All @@ -103,7 +103,7 @@ the driver and data strs (large template).
> (imps, lang_exts) = case ghcExts_opt of
> UseGhcExts is os -> (is, os)
> _ -> ("", [])
>

> defines = concat
> [ [ "HAPPY_DEBUG" | debug ]
> , [ "HAPPY_GHC" | UseGhcExts _ _ <- return ghcExts_opt ]
Expand Down Expand Up @@ -251,7 +251,7 @@ Formats the tables as code.
> -> GhcExts -- Use unboxed values?
> -> Grammar -- Happy Grammar
> -> ShowS
>

> mkTbls (action,goto) sem_info exts g
> = let gsMap = mkGSymMap g
> semfn_map = mk_semfn_map sem_info
Expand Down Expand Up @@ -303,10 +303,12 @@ It also shares identical reduction values as CAFs
> errorLine = name ++ " _ _ = Error"
> mkState (i,arr)
> = filter (/="") $ map (mkLine i) (assocs arr)
>

> 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 -> ""
Expand Down Expand Up @@ -356,10 +358,10 @@ Do the same with the Happy goto table.
> name = "goto"
> errorLine = "goto _ _ = " ++ show_st exts (negate 1)
> mkLines = map mkState (assocs goTbl)
>

> mkState (i,arr)
> = unlines $ filter (/="") $ map (mkLine i) (assocs arr)
>

> mkLine state (ntInt,goto)
> = case goto of
> NoGoto -> ""
Expand Down
320 changes: 229 additions & 91 deletions packages/backend-lalr/data/HappyTemplate.hs

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion packages/backend-lalr/src/Happy/Backend/LALR.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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" ++
Expand Down
Loading
Loading