Skip to content

Commit 5bbb6fb

Browse files
authored
Merge pull request #153 from andreasabel/prettify-output
Prettify output (alex_action_n); enable CI for ghc 7.0.4; bump to 3.2.6; update README
2 parents 5eb985f + 01466f0 commit 5bbb6fb

File tree

8 files changed

+86
-60
lines changed

8 files changed

+86
-60
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
# Keep the list of tested GHC versions in sync with `tested-with` in `alex.cabal`.
44
env:
5-
- GHCVER=8.8.2
6-
- GHCVER=8.6.5
7-
# - GHCVER=7.0.4
5+
- GHCVER=7.0.4
86
- GHCVER=7.4.2
97
- GHCVER=7.6.3
108
- GHCVER=7.8.4
119
- GHCVER=7.10.3
1210
- GHCVER=8.0.2
1311
- GHCVER=8.2.2
1412
- GHCVER=8.4.4
13+
- GHCVER=8.6.5
14+
- GHCVER=8.8.2
1515

1616
before_install:
1717
- sudo add-apt-repository -y ppa:hvr/ghc

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## Changes in 3.2.6:
2+
13
## Changes in 3.2.5:
24

35
* Build fixes for GHC 8.8.x

README.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,14 @@ documentation, see the doc directory.
99

1010
- <https://hackage.haskell.org/package/alex>
1111

12-
Alex version 2.0 has changed fairly considerably since version 1.x,
13-
and the syntax is almost completely different. For a detailed list of
14-
changes, see the release notes in the documentation.
12+
Alex is covered by a BSD-Style licence; see the licence file in
13+
the `doc` directory for details.
1514

16-
Alex is now covered by a BSD-Style licence; see the licence file in
17-
the 'doc' directory for details.
15+
The sources are in the `src` directory and the documentation in the `doc`
16+
directory; various examples are in the `examples` subdirectory.
1817

19-
The sources are in the 'src' directory and the documentation in the 'doc'
20-
directory; various examples are in the 'examples' subdirectory.
21-
22-
The source code in the 'src' and 'examples' directories is intended
23-
for a Haskell 98 compiler with hierarchical modules. It should work
24-
with GHC >= 5.04.
18+
The source code in the `src` and `examples` directories is intended to work
19+
with GHC >= 7.0.
2520

2621
## Build Instructions
2722

@@ -51,7 +46,7 @@ Haskell Platform, or e.g. via (run this outside the Git repository!):
5146
$ cabal install alex happy
5247

5348
which installs them into `${HOME}/.cabal/bin` by default (make sure
54-
they're in your `$PATH` for the next steps!).
49+
they are in your `$PATH` for the next steps!).
5550

5651
### Variant A
5752

@@ -65,7 +60,7 @@ First you need to generate the pre-processed templates via
6560
And then you can install `alex` simply by invoking
6661

6762
$ cabal install
68-
63+
6964
from inside the Git folder.
7065

7166
### Variant B
@@ -78,7 +73,7 @@ new-run gen-alex-sdist` pre-preprocessing step):
7873
$ make sdist
7974
$ cabal install dist/alex-*.tar.gz
8075

81-
For convenience, there's also a `make sdist-test` target which builds the
76+
For convenience, there is also a `make sdist-test` target which builds the
8277
source source tarball and runs the test-suite from within the source dist.
8378

8479
## Contributing & Reporting Issues
@@ -92,3 +87,5 @@ Chris Dornan: [email protected]
9287
Isaac Jones: [email protected]
9388

9489
Simon Marlow: [email protected]
90+
91+
and [recent contributors](https://github.com/simonmar/alex/graphs/contributors).

alex.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: >= 1.8
22
name: alex
3-
version: 3.2.5
3+
version: 3.2.6
44
-- don't forget updating changelog.md!
55
license: BSD3
66
license-file: LICENSE
@@ -23,6 +23,7 @@ build-type: Simple
2323

2424
-- Keep the contents of `tested-with` in sync with `env` in `.travis.yml`.
2525
tested-with:
26+
GHC == 7.0.4
2627
GHC == 7.4.2
2728
GHC == 7.6.3
2829
GHC == 7.8.4

src/AbsSyn.hs

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ encodeStartCodes scan = (scan', 0 : map snd name_code_pairs, sc_hdr)
320320
-- generated file.
321321

322322
extractActions :: Scheme -> Scanner -> (Scanner,ShowS)
323-
extractActions scheme scanner = (scanner{scannerTokens = new_tokens}, decl_str)
323+
extractActions scheme scanner = (scanner{scannerTokens = new_tokens}, decl_str . nl)
324324
where
325325
(new_tokens, decls) = unzip (zipWith f (scannerTokens scanner) act_names)
326326

@@ -333,61 +333,57 @@ extractActions scheme scanner = (scanner{scannerTokens = new_tokens}, decl_str)
333333
str "AlexPosn -> Char -> String -> Int -> ((Int, state) -> "
334334
. str res . str ") -> (Int, state) -> " . str res
335335

336-
mkDecl fun code = case scheme of
337-
Default { defaultTypeInfo = Just (Nothing, actionty) } ->
338-
str fun . str " :: " . str actionty . str "\n"
339-
. str fun . str " = " . str code . nl
340-
Default { defaultTypeInfo = Just (Just tyclasses, actionty) } ->
336+
mkDecl fun code = mkTySig fun
337+
. mkDef fun code
338+
339+
mkDef fun code = str fun . str " = " . str code . nl
340+
341+
mkTySig fun = case scheme of
342+
Default { defaultTypeInfo = Just (Nothing, actionty) } -> nl .
343+
str fun . str " :: " . str actionty . nl
344+
Default { defaultTypeInfo = Just (Just tyclasses, actionty) } -> nl .
341345
str fun . str " :: (" . str tyclasses . str ") => " .
342-
str actionty . str "\n" .
343-
str fun . str " = " . str code . nl
344-
GScan { gscanTypeInfo = Just (Nothing, tokenty) } ->
345-
str fun . str " :: " . gscanActionType tokenty . str "\n"
346-
. str fun . str " = " . str code . nl
347-
GScan { gscanTypeInfo = Just (Just tyclasses, tokenty) } ->
346+
str actionty . nl
347+
GScan { gscanTypeInfo = Just (Nothing, tokenty) } -> nl .
348+
str fun . str " :: " . gscanActionType tokenty . nl
349+
GScan { gscanTypeInfo = Just (Just tyclasses, tokenty) } -> nl .
348350
str fun . str " :: (" . str tyclasses . str ") => " .
349-
gscanActionType tokenty . str "\n" .
350-
str fun . str " = " . str code . nl
351-
Basic { basicStrType = strty, basicTypeInfo = Just (Nothing, tokenty) } ->
351+
gscanActionType tokenty . nl
352+
Basic { basicStrType = strty, basicTypeInfo = Just (Nothing, tokenty) } -> nl .
352353
str fun . str " :: " . str (show strty) . str " -> "
353-
. str tokenty . str "\n"
354-
. str fun . str " = " . str code . nl
354+
. str tokenty . nl
355355
Basic { basicStrType = strty,
356-
basicTypeInfo = Just (Just tyclasses, tokenty) } ->
356+
basicTypeInfo = Just (Just tyclasses, tokenty) } -> nl .
357357
str fun . str " :: (" . str tyclasses . str ") => " .
358-
str (show strty) . str " -> " . str tokenty . str "\n" .
359-
str fun . str " = " . str code . nl
358+
str (show strty) . str " -> " . str tokenty . nl
360359
Posn { posnByteString = isByteString,
361-
posnTypeInfo = Just (Nothing, tokenty) } ->
360+
posnTypeInfo = Just (Nothing, tokenty) } -> nl .
362361
str fun . str " :: AlexPosn -> " . str (strtype isByteString) . str " -> "
363-
. str tokenty . str "\n"
364-
. str fun . str " = " . str code . nl
362+
. str tokenty . nl
365363
Posn { posnByteString = isByteString,
366-
posnTypeInfo = Just (Just tyclasses, tokenty) } ->
364+
posnTypeInfo = Just (Just tyclasses, tokenty) } -> nl .
367365
str fun . str " :: (" . str tyclasses . str ") => AlexPosn -> " .
368-
str (strtype isByteString) . str " -> " . str tokenty . str "\n" .
369-
str fun . str " = " . str code . nl
366+
str (strtype isByteString) . str " -> " . str tokenty . nl
370367
Monad { monadByteString = isByteString,
371-
monadTypeInfo = Just (Nothing, tokenty) } ->
368+
monadTypeInfo = Just (Nothing, tokenty) } -> nl .
372369
let
373370
actintty = if isByteString then "Int64" else "Int"
374371
in
375372
str fun . str " :: AlexInput -> " . str actintty . str " -> Alex ("
376-
. str tokenty . str ")\n"
377-
. str fun . str " = " . str code . nl
373+
. str tokenty . str ")" . nl
378374
Monad { monadByteString = isByteString,
379-
monadTypeInfo = Just (Just tyclasses, tokenty) } ->
375+
monadTypeInfo = Just (Just tyclasses, tokenty) } -> nl .
380376
let
381377
actintty = if isByteString then "Int64" else "Int"
382378
in
383-
str fun . str " :: (" . str tyclasses . str ") => "
379+
str fun . str " :: (" . str tyclasses . str ") =>"
384380
. str " AlexInput -> " . str actintty
385-
. str " -> Alex (" . str tokenty . str ")\n"
386-
. str fun . str " = " . str code . nl
387-
_ -> str fun . str " = " . str code . nl
381+
. str " -> Alex (" . str tokenty . str ")" . nl
382+
_ -> id
388383

389384
act_names = map (\n -> "alex_action_" ++ show (n::Int)) [0..]
390385

386+
decl_str :: ShowS
391387
decl_str = foldr (.) id [ decl | Just decl <- decls ]
392388

393389
-- -----------------------------------------------------------------------------

src/Main.hs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ parseScript file prg =
115115

116116
Right script -> return script
117117

118-
alex :: [CLIFlags] -> FilePath -> FilePath
118+
alex :: [CLIFlags]
119+
-> FilePath
120+
-> FilePath
119121
-> (Maybe (AlexPosn, Code), [Directive], Scanner, Maybe (AlexPosn, Code))
120122
-> IO ()
121123
alex cli file basename script = do
@@ -148,7 +150,10 @@ alex cli file basename script = do
148150

149151
template_dir <- templateDir getDataDir cli
150152

151-
let (maybe_header, directives, scanner1, maybe_footer) = script
153+
let maybe_header, maybe_footer :: Maybe (AlexPosn, Code)
154+
directives :: [Directive]
155+
scanner1 :: Scanner
156+
(maybe_header, directives, scanner1, maybe_footer) = script
152157

153158
scheme <- getScheme directives
154159

@@ -158,7 +163,12 @@ alex cli file basename script = do
158163
(\h -> do hClose h; removeFile o_file)
159164
$ \out_h -> do
160165

161-
let
166+
let wrapper_name :: Maybe FilePath
167+
scanner2, scanner_final :: Scanner
168+
scs :: [StartCode]
169+
sc_hdr, actions :: ShowS
170+
encodingsScript :: [Encoding]
171+
162172
wrapper_name = wrapperFile template_dir scheme
163173
(scanner2, scs, sc_hdr) = encodeStartCodes scanner1
164174
(scanner_final, actions) = extractActions scheme scanner2

src/Scan.x

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ code (p,_,_inp) _ = do
175175
go :: AlexInput -> Int -> String -> P Token
176176
go inp 0 cs = do
177177
setInput inp
178-
return (T p (CodeT (reverse (tail cs))))
178+
return $ T p $ CodeT $ triml $ reverse $ triml $ tail cs
179179
go inp n cs = do
180180
case alexGetChar inp of
181181
Nothing -> err inp
@@ -210,6 +210,8 @@ code (p,_,_inp) _ = do
210210

211211
err inp = do setInput inp; lexError "lexical error in code fragment"
212212

213+
triml = dropWhile isSpace
214+
213215
lexError :: String -> P a
214216
lexError s = do
215217
(_,_,_,input) <- getInput

tests/Makefile

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# NOTE: `cabal test` will take care to build the local `alex`
2-
# executable and place it into $PATH for us to pick up.
3-
#
2+
# executable and place it into $PATH for us to pick up.
3+
#
44
# If it doesn't look like the alex binary in $PATH comes from the
55
# build tree, then we'll fall back to pointing to
66
# ../dist/build/alex/alex to support running tests via "runghc
@@ -13,7 +13,19 @@ endif
1313

1414
# NOTE: This assumes that a working `ghc` is on $PATH; this may not necessarily be the same GHC used by `cabal` for building `alex`.
1515
HC=ghc
16-
HC_OPTS=-Wall -fwarn-incomplete-uni-patterns -fno-warn-missing-signatures -fno-warn-unused-imports -fno-warn-tabs -Werror
16+
17+
# Some GHC warnings are only available from a certain version on
18+
# Get the GHC version
19+
GHC_VERSION:=$(shell ghc --numeric-version)
20+
GHC_VERSION_WORDS=$(subst ., ,$(GHC_VERSION))
21+
GHC_MAJOR_VERSION=$(word 1,$(GHC_VERSION_WORDS))
22+
GHC_MINOR_VERSION=$(word 2,$(GHC_VERSION_WORDS))
23+
# -fwarn-incomplete-uni-patterns only from 7.4
24+
WARNS_FOR_GHC_GTEQ_7_4=-fwarn-incomplete-uni-patterns
25+
WARNS_FOR_GHC_LT_7_4=-fno-warn-lazy-unlifted-bindings
26+
WARNS_DEP_GHC_GTEQ_7_4:=$(shell if [ $(GHC_MAJOR_VERSION) -gt 7 -o $(GHC_MAJOR_VERSION) -ge 7 -a $(GHC_MINOR_VERSION) -ge 4 ]; then echo "$(WARNS_FOR_GHC_GTEQ_7_4)"; else echo "$(WARNS_FOR_GHC_LT_7_4)"; fi)
27+
28+
HC_OPTS=-Wall $(WARNS_DEP_GHC_GTEQ_7_4) -fno-warn-missing-signatures -fno-warn-unused-imports -fno-warn-tabs -Werror
1729

1830
.PRECIOUS: %.n.hs %.g.hs %.o %.exe %.bin
1931

@@ -73,7 +85,8 @@ ALL_TESTS = $(patsubst %.hs, %.run, $(ALL_TEST_HS))
7385

7486
all :: $(ALL_TESTS)
7587

76-
.PHONY: clean
88+
.PHONY: clean debug
89+
7790
clean:
7891
rm -f $(CLEAN_FILES)
7992

@@ -82,3 +95,8 @@ interact:
8295
ghci -cpp -i../src -i../dist/build/autogen -i../dist/build/alex/alex-tmp Main -fbreak-on-exception
8396
# -args='--template=.. simple.x -o simple.n.hs'
8497
# :set args --template=.. simple.x -o simple.n.hs
98+
99+
debug :
100+
@echo HC_OPTS=$(HC_OPTS)
101+
102+
# EOF

0 commit comments

Comments
 (0)