Skip to content

Commit 4bfd6a0

Browse files
authored
Merge pull request #8921 from haskell/mergify/bp/3.10/pr-8896
Regenerate Lexer.hs with latest Alex (fix #8892) (backport #8896)
2 parents 44c5604 + 3103b87 commit 4bfd6a0

File tree

9 files changed

+242
-132
lines changed

9 files changed

+242
-132
lines changed

.github/workflows/quick-jobs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
- name: Update Hackage index
4848
run: cabal v2-update
4949
- name: Install alex
50-
run: cabal v2-install alex --constraint='alex ==3.2.6'
50+
run: cabal v2-install alex --constraint='alex ==3.2.7.3'
5151
- uses: actions/checkout@v3
5252
- name: Regenerate files
5353
run: |

Cabal-syntax/src/Distribution/Fields/Lexer.hs

Lines changed: 207 additions & 114 deletions
Large diffs are not rendered by default.

Cabal-syntax/src/Distribution/Fields/LexerMonad.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module Distribution.Fields.LexerMonad (
2727
LexWarning(..),
2828
LexWarningType(..),
2929
addWarning,
30+
addWarningAt,
3031
toPWarnings,
3132

3233
) where
@@ -153,3 +154,8 @@ setStartCode c = Lex $ \s -> LexResult s{ curCode = c } ()
153154
addWarning :: LexWarningType -> Lex ()
154155
addWarning wt = Lex $ \s@LexState{ curPos = pos, warnings = ws } ->
155156
LexResult s{ warnings = LexWarning wt pos : ws } ()
157+
158+
-- | Add warning at specific position
159+
addWarningAt :: Position -> LexWarningType -> Lex ()
160+
addWarningAt pos wt = Lex $ \s@LexState{ warnings = ws } ->
161+
LexResult s{ warnings = LexWarning wt pos : ws } ()

Cabal-tests/tests/ParserTests/regressions/Octree-0.5.format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Octree-0.5.cabal:39:3: Non breaking spaces at 39:3, 41:3, 43:3
1+
Octree-0.5.cabal:39:1: Non breaking spaces at 39:1, 41:1, 43:1
22
cabal-version: >=1.8
33
name: Octree
44
version: 0.5

Cabal-tests/tests/ParserTests/regressions/monad-param.format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
monad-param.cabal:19:3: Tabs used as indentation at 19:3, 20:3
1+
monad-param.cabal:19:1: Tabs used as indentation at 19:1, 20:1
22
name: monad-param
33
version: 0.0.1
44
license: BSD3

Cabal-tests/tests/ParserTests/regressions/th-lift-instances.format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
th-lift-instances.cabal:15:9: Tabs used as indentation at 15:9
1+
th-lift-instances.cabal:15:1: Tabs used as indentation at 15:1
22
cabal-version: >=1.10
33
name: th-lift-instances
44
version: 0.1.4
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# cabal check
22
Warning: These warnings may cause trouble when distributing the package:
3-
Warning: pkg.cabal:1:2: Byte-order mark found at the beginning of the file
3+
Warning: pkg.cabal:1:1: Byte-order mark found at the beginning of the file
44
Warning: The following errors will cause portability problems on other environments:
55
Warning: ./pkg.cabal starts with an Unicode byte order mark (BOM). This may cause problems with older cabal versions.
66
Warning: Hackage would reject this package.

changelog.d/issue-8892

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
synopsis: Regenerate Lexer.hs to avoid out-of-bound array access due to a bug in Alex
2+
packages: Cabal-syntax
3+
prs: #8896
4+
issues: #8892
5+
6+
description: {
7+
8+
- Regenerate Cabal-syntax's Lexer.hs with Alex 3.2.7.3 which includes a fix for
9+
an out-of-bound array access (only noticeable with GHC's JavaScript backend).
10+
11+
}

templates/Lexer.x

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,22 @@ $instresc = $printable
8383
tokens :-
8484

8585
<0> {
86-
@bom? { \_ len _ -> do
87-
when (len /= 0) $ addWarning LexWarningBOM
86+
@bom? { \pos len _ -> do
87+
when (len /= 0) $ addWarningAt pos LexWarningBOM
8888
setStartCode bol_section
8989
lexToken
9090
}
9191
}
9292

9393
<bol_section, bol_field_layout, bol_field_braces> {
94-
@nbspspacetab* @nl { \_pos len inp -> checkWhitespace len inp >> adjustPos retPos >> lexToken }
94+
@nbspspacetab* @nl { \pos len inp -> checkWhitespace pos len inp >> adjustPos retPos >> lexToken }
9595
-- no @nl here to allow for comments on last line of the file with no trailing \n
9696
$spacetab* "--" $comment* ; -- TODO: check the lack of @nl works here
9797
-- including counting line numbers
9898
}
9999

100100
<bol_section> {
101-
@nbspspacetab* { \pos len inp -> checkLeadingWhitespace len inp >>
101+
@nbspspacetab* { \pos len inp -> checkLeadingWhitespace pos len inp >>
102102
if B.length inp == len
103103
then return (L pos EOF)
104104
else setStartCode in_section
@@ -123,7 +123,7 @@ tokens :-
123123
}
124124

125125
<bol_field_layout> {
126-
@nbspspacetab* { \pos len inp -> checkLeadingWhitespace len inp >>= \len' ->
126+
@nbspspacetab* { \pos len inp -> checkLeadingWhitespace pos len inp >>= \len' ->
127127
if B.length inp == len
128128
then return (L pos EOF)
129129
else setStartCode in_field_layout
@@ -172,17 +172,17 @@ toki t pos len input = return $! L pos (t (B.take len input))
172172
tok :: Token -> Position -> Int -> ByteString -> Lex LToken
173173
tok t pos _len _input = return $! L pos t
174174

175-
checkLeadingWhitespace :: Int -> ByteString -> Lex Int
176-
checkLeadingWhitespace len bs
175+
checkLeadingWhitespace :: Position -> Int -> ByteString -> Lex Int
176+
checkLeadingWhitespace pos len bs
177177
| B.any (== 9) (B.take len bs) = do
178-
addWarning LexWarningTab
179-
checkWhitespace len bs
180-
| otherwise = checkWhitespace len bs
178+
addWarningAt pos LexWarningTab
179+
checkWhitespace pos len bs
180+
| otherwise = checkWhitespace pos len bs
181181

182-
checkWhitespace :: Int -> ByteString -> Lex Int
183-
checkWhitespace len bs
182+
checkWhitespace :: Position -> Int -> ByteString -> Lex Int
183+
checkWhitespace pos len bs
184184
| B.any (== 194) (B.take len bs) = do
185-
addWarning LexWarningNBSP
185+
addWarningAt pos LexWarningNBSP
186186
return $ len - B.count 194 (B.take len bs)
187187
| otherwise = return len
188188

0 commit comments

Comments
 (0)