Skip to content

Commit

Permalink
Merge pull request #8921 from haskell/mergify/bp/3.10/pr-8896
Browse files Browse the repository at this point in the history
Regenerate Lexer.hs with latest Alex (fix #8892) (backport #8896)
  • Loading branch information
mergify[bot] authored Apr 26, 2023
2 parents 44c5604 + 3103b87 commit 4bfd6a0
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 132 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/quick-jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Update Hackage index
run: cabal v2-update
- name: Install alex
run: cabal v2-install alex --constraint='alex ==3.2.6'
run: cabal v2-install alex --constraint='alex ==3.2.7.3'
- uses: actions/checkout@v3
- name: Regenerate files
run: |
Expand Down
321 changes: 207 additions & 114 deletions Cabal-syntax/src/Distribution/Fields/Lexer.hs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Cabal-syntax/src/Distribution/Fields/LexerMonad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module Distribution.Fields.LexerMonad (
LexWarning(..),
LexWarningType(..),
addWarning,
addWarningAt,
toPWarnings,

) where
Expand Down Expand Up @@ -153,3 +154,8 @@ setStartCode c = Lex $ \s -> LexResult s{ curCode = c } ()
addWarning :: LexWarningType -> Lex ()
addWarning wt = Lex $ \s@LexState{ curPos = pos, warnings = ws } ->
LexResult s{ warnings = LexWarning wt pos : ws } ()

-- | Add warning at specific position
addWarningAt :: Position -> LexWarningType -> Lex ()
addWarningAt pos wt = Lex $ \s@LexState{ warnings = ws } ->
LexResult s{ warnings = LexWarning wt pos : ws } ()
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Octree-0.5.cabal:39:3: Non breaking spaces at 39:3, 41:3, 43:3
Octree-0.5.cabal:39:1: Non breaking spaces at 39:1, 41:1, 43:1
cabal-version: >=1.8
name: Octree
version: 0.5
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
monad-param.cabal:19:3: Tabs used as indentation at 19:3, 20:3
monad-param.cabal:19:1: Tabs used as indentation at 19:1, 20:1
name: monad-param
version: 0.0.1
license: BSD3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
th-lift-instances.cabal:15:9: Tabs used as indentation at 15:9
th-lift-instances.cabal:15:1: Tabs used as indentation at 15:1
cabal-version: >=1.10
name: th-lift-instances
version: 0.1.4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cabal check
Warning: These warnings may cause trouble when distributing the package:
Warning: pkg.cabal:1:2: Byte-order mark found at the beginning of the file
Warning: pkg.cabal:1:1: Byte-order mark found at the beginning of the file
Warning: The following errors will cause portability problems on other environments:
Warning: ./pkg.cabal starts with an Unicode byte order mark (BOM). This may cause problems with older cabal versions.
Warning: Hackage would reject this package.
11 changes: 11 additions & 0 deletions changelog.d/issue-8892
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
synopsis: Regenerate Lexer.hs to avoid out-of-bound array access due to a bug in Alex
packages: Cabal-syntax
prs: #8896
issues: #8892

description: {

- Regenerate Cabal-syntax's Lexer.hs with Alex 3.2.7.3 which includes a fix for
an out-of-bound array access (only noticeable with GHC's JavaScript backend).

}
26 changes: 13 additions & 13 deletions templates/Lexer.x
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,22 @@ $instresc = $printable
tokens :-

<0> {
@bom? { \_ len _ -> do
when (len /= 0) $ addWarning LexWarningBOM
@bom? { \pos len _ -> do
when (len /= 0) $ addWarningAt pos LexWarningBOM
setStartCode bol_section
lexToken
}
}

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

<bol_section> {
@nbspspacetab* { \pos len inp -> checkLeadingWhitespace len inp >>
@nbspspacetab* { \pos len inp -> checkLeadingWhitespace pos len inp >>
if B.length inp == len
then return (L pos EOF)
else setStartCode in_section
Expand All @@ -123,7 +123,7 @@ tokens :-
}

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

checkLeadingWhitespace :: Int -> ByteString -> Lex Int
checkLeadingWhitespace len bs
checkLeadingWhitespace :: Position -> Int -> ByteString -> Lex Int
checkLeadingWhitespace pos len bs
| B.any (== 9) (B.take len bs) = do
addWarning LexWarningTab
checkWhitespace len bs
| otherwise = checkWhitespace len bs
addWarningAt pos LexWarningTab
checkWhitespace pos len bs
| otherwise = checkWhitespace pos len bs

checkWhitespace :: Int -> ByteString -> Lex Int
checkWhitespace len bs
checkWhitespace :: Position -> Int -> ByteString -> Lex Int
checkWhitespace pos len bs
| B.any (== 194) (B.take len bs) = do
addWarning LexWarningNBSP
addWarningAt pos LexWarningNBSP
return $ len - B.count 194 (B.take len bs)
| otherwise = return len

Expand Down

0 comments on commit 4bfd6a0

Please sign in to comment.