Commit 37d64a51 authored by rodlogic's avatar rodlogic Committed by Austin Seipp

small parser/lexer cleanup

Summary:
The last three '#define ...' macros were removed from Parser.y.pp and this file was renamed to Parser.y.
This basically got rid of a CPP step in the build.

Also converted two modules in compiler/parser/ from .lhs to .hs.

Test Plan: Does it build? Yes, I performed a full build here and things are looking good.

Reviewers: austin

Reviewed By: austin

Subscribers: adamse, thomie, carter, simonmar

Differential Revision: https://phabricator.haskell.org/D411
parent 24e05f48
Character classification
\begin{code}
-- Character classification
{-# LANGUAGE CPP #-}
module Ctype
( is_ident -- Char# -> Bool
......@@ -22,11 +20,9 @@ import Data.Int ( Int32 )
import Data.Bits ( Bits((.&.)) )
import Data.Char ( ord, chr )
import Panic
\end{code}
Bit masks
-- Bit masks
\begin{code}
cIdent, cSymbol, cAny, cSpace, cLower, cUpper, cDigit :: Int
cIdent = 1
cSymbol = 2
......@@ -35,12 +31,10 @@ cSpace = 8
cLower = 16
cUpper = 32
cDigit = 64
\end{code}
The predicates below look costly, but aren't, GHC+GCC do a great job
at the big case below.
-- | The predicates below look costly, but aren't, GHC+GCC do a great job
-- at the big case below.
\begin{code}
{-# INLINE is_ctype #-}
is_ctype :: Int -> Char -> Bool
is_ctype mask c = (fromIntegral (charType c) .&. fromIntegral mask) /= (0::Int32)
......@@ -55,11 +49,9 @@ is_lower = is_ctype cLower
is_upper = is_ctype cUpper
is_digit = is_ctype cDigit
is_alphanum = is_ctype (cLower+cUpper+cDigit)
\end{code}
Utils
-- Utils
\begin{code}
hexDigit :: Char -> Int
hexDigit c | is_decdigit c = ord c - ord '0'
| otherwise = ord (to_lower c) - ord 'a' + 10
......@@ -87,12 +79,10 @@ to_lower :: Char -> Char
to_lower c
| c >= 'A' && c <= 'Z' = chr (ord c - (ord 'A' - ord 'a'))
| otherwise = c
\end{code}
We really mean .|. instead of + below, but GHC currently doesn't do
any constant folding with bitops. *sigh*
-- | We really mean .|. instead of + below, but GHC currently doesn't do
-- any constant folding with bitops. *sigh*
\begin{code}
charType :: Char -> Int
charType c = case c of
'\0' -> 0 -- \000
......@@ -224,4 +214,3 @@ charType c = case c of
'\126' -> cAny + cSymbol -- ~
'\127' -> 0 -- \177
_ -> panic ("charType: " ++ show c)
\end{code}
......@@ -74,33 +74,44 @@ module Lexer (
lexTokenStream
) where
-- base
import Control.Applicative
import Control.Monad
import Data.Bits
import Data.Char
import Data.List
import Data.Maybe
import Data.Ratio
import Data.Word
-- bytestring
import Data.ByteString (ByteString)
-- containers
import Data.Map (Map)
import qualified Data.Map as Map
-- compiler/utils
import Bag
import ErrUtils
import Outputable
import StringBuffer
import FastString
import SrcLoc
import UniqFM
import Util ( readRational )
-- compiler/main
import ErrUtils
import DynFlags
-- compiler/basicTypes
import SrcLoc
import Module
import Ctype
import BasicTypes ( InlineSpec(..), RuleMatchInfo(..), FractionalLit(..) )
import Util ( readRational )
import Control.Applicative
import Control.Monad
import Data.Bits
import Data.ByteString (ByteString)
import Data.Char
import Data.List
import Data.Maybe
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Ratio
import Data.Word
-- compiler/parser
import Ctype
}
-- -----------------------------------------------------------------------------
-- Alex "Character set macros"
......
......@@ -359,7 +359,7 @@ endif
# Packages to build
# The lists of packages that we *actually* going to build in each stage:
#
# $(PACKAGES_STAGE0)
# $(PACKAGES_STAGE0)
# $(PACKAGES_STAGE1)
# $(PACKAGES_STAGE2)
#
......@@ -630,7 +630,7 @@ BUILD_DIRS += includes
BUILD_DIRS += rts
ifneq "$(BINDIST)" "YES"
BUILD_DIRS += bindisttest
BUILD_DIRS += bindisttest
BUILD_DIRS += utils/genapply
endif
......@@ -696,10 +696,10 @@ stage1_libs : $(ALL_STAGE1_LIBS)
# ----------------------------------------------
# Per-package compiler flags
#
# If you want to add per-package compiler flags, this
#
# If you want to add per-package compiler flags, this
# is the place to do it. Do it like this for package <pkg>
#
#
# libraries/<pkg>_dist-boot_HC_OPTS += -Wwarn
# libraries/<pkg>_dist-install_HC_OPTS += -Wwarn
......@@ -1140,7 +1140,7 @@ sdist-ghc-prep :
$(call sdist_ghc_file,compiler,stage2,cmm,,CmmLex,x)
$(call sdist_ghc_file,compiler,stage2,cmm,,CmmParse,y)
$(call sdist_ghc_file,compiler,stage2,parser,,Lexer,x)
$(call sdist_ghc_file,compiler,stage2,parser,,Parser,y.pp)
$(call sdist_ghc_file,compiler,stage2,parser,,Parser,y)
$(call sdist_ghc_file,utils/hpc,dist-install,,,HpcParser,y)
$(call sdist_ghc_file,utils/genprimopcode,dist,,,Lexer,x)
$(call sdist_ghc_file,utils/genprimopcode,dist,,,Parser,y)
......@@ -1225,7 +1225,6 @@ CLEAN_FILES += includes/ghcautoconf.h
CLEAN_FILES += includes/ghcplatform.h
CLEAN_FILES += includes/ghcversion.h
CLEAN_FILES += utils/ghc-pkg/Version.hs
CLEAN_FILES += compiler/parser/Parser.y
CLEAN_FILES += compiler/prelude/primops.txt
CLEAN_FILES += $(wildcard compiler/primop*incl)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment