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

Generate 8 spaces instead 2 spaces (#303) #304

Merged
merged 1 commit into from
Sep 20, 2024
Merged
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
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Revision history for Happy

## 2.0.1

The 2.0 changed the indentation character from tabs to two spaces, triggering an
unforced breaking change in GHC (#303).
This release provides the fix by using eight spaces for indentation.

## 2.0

There are two main breaking changes in this release:
Expand Down
4 changes: 2 additions & 2 deletions happy.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: happy
version: 2.0
version: 2.0.1
license: BSD2
license-file: LICENSE
copyright: (c) Andy Gill, Simon Marlow
Expand Down Expand Up @@ -139,7 +139,7 @@ executable happy
array,
containers >= 0.4.2,
mtl >= 2.2.1,
happy-lib == 2.0
happy-lib == 2.0.1

default-language: Haskell98
default-extensions: CPP, MagicHash, FlexibleContexts, NamedFieldPuns
Expand Down
61 changes: 33 additions & 28 deletions lib/backend-lalr/src/Happy/Backend/LALR/ProduceCode.lhs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ Produce the complete output file.
>
> partTySigs_opts = ifGeGhc710 (str "{-# LANGUAGE PartialTypeSignatures #-}" . nl)

We used to emit tabs for indentation, but since 2.0.0.1 we use 8 spaces for back-compat (#303):

> indentStr = " "
> indent = str indentStr

> intMaybeHash = str "Happy_GHC_Exts.Int#"

> -- Parsing monad and its constraints
Expand Down Expand Up @@ -208,10 +213,10 @@ example where this matters.

> | otherwise
> = str "data HappyAbsSyn " . str_tyvars
> . str "\n = HappyTerminal " . token
> . str "\n | HappyErrorToken Prelude.Int\n"
> . str "\n" . indent . str "= HappyTerminal " . token
> . str "\n" . indent . str "| HappyErrorToken Prelude.Int\n"
> . interleave "\n"
> [ str " | " . makeAbsSynCon n . strspace . typeParam n ty
> [ str "" . indent . str "| " . makeAbsSynCon n . strspace . typeParam n ty
> | (n, ty) <- assocs nt_types,
> (nt_types_index ! n) == n]

Expand Down Expand Up @@ -254,21 +259,21 @@ happyMonadReduce to get polymorphic recursion. Sigh.

> | is_monad_prod && (use_monad || imported_identity')
> = mkReductionHdr (showInt lt) monad_reduce
> . char '(' . interleave " `HappyStk`\n " tokPatterns
> . str "happyRest) tk\n = happyThen ("
> . char '(' . interleave (" `HappyStk`\n" ++ indentStr) tokPatterns
> . str "happyRest) tk\n" . indent . str " = happyThen ("
> . str "("
> . tokLets (char '(' . str code' . char ')')
> . str ")"
> . (if monad_pass_token then str " tk" else id)
> . str "\n ) (\\r -> happyReturn (" . this_absSynCon . str " r))"
> . str "\n" . indent . str ") (\\r -> happyReturn (" . this_absSynCon . str " r))"

> | specReduceFun lt
> = mkReductionHdr id ("happySpecReduce_" ++ show lt)
> . interleave "\n " tokPatterns
> . interleave ("\n" ++ indentStr) tokPatterns
> . str " = "
> . tokLets (
> this_absSynCon . str "\n "
> . char '(' . str code' . str "\n )"
> this_absSynCon . str "\n" . indent . indent . str " "
> . char '(' . str code' . str "\n" . indent . str ")"
> )
> . (if coerce || null toks || null vars_used then
> id
Expand All @@ -279,11 +284,11 @@ happyMonadReduce to get polymorphic recursion. Sigh.

> | otherwise
> = mkReductionHdr (showInt lt) "happyReduce"
> . char '(' . interleave " `HappyStk`\n " tokPatterns
> . str "happyRest)\n = "
> . char '(' . interleave (" `HappyStk`\n" ++ indentStr) tokPatterns
> . str "happyRest)\n" . indent . str " = "
> . tokLets
> ( this_absSynCon . str "\n "
> . char '(' . str code'. str "\n ) `HappyStk` happyRest"
> ( this_absSynCon . str "\n" . indent . indent . str " "
> . char '(' . str code'. str "\n" . indent . str ") `HappyStk` happyRest"
> )

> where
Expand Down Expand Up @@ -335,7 +340,7 @@ happyMonadReduce to get polymorphic recursion. Sigh.
>
> tokLets code''
> | coerce && not (null cases)
> = interleave "\n " cases
> = interleave ("\n"++indentStr) cases
> . code'' . str (replicate (length cases) '}')
> | otherwise = code''
>
Expand All @@ -359,32 +364,32 @@ The token conversion function.
> = case lexer' of {
>
> Nothing ->
> str "happyNewToken action sts stk [] =\n "
> str "happyNewToken action sts stk [] =\n" . indent
> . eofAction "notHappyAtAll"
> . str " []\n\n"
> . str "happyNewToken action sts stk (tk:tks) =\n "
> . str "let cont i = " . doAction . str " sts stk tks in\n "
> . str "case tk of {\n "
> . interleave ";\n " (map doToken token_rep)
> . str "_ -> happyError' ((tk:tks), [])\n "
> . str "happyNewToken action sts stk (tk:tks) =\n" . indent
> . str "let cont i = " . doAction . str " sts stk tks in\n" . indent
> . str "case tk of {\n" . indent
> . interleave (";\n" ++ indentStr) (map doToken token_rep)
> . str "_ -> happyError' ((tk:tks), [])\n" . indent
> . str "}\n\n"
> . str "happyError_ explist " . eofTok . str " tk tks = happyError' (tks, explist)\n"
> . str "happyError_ explist _ tk tks = happyError' ((tk:tks), explist)\n";
> -- when the token is EOF, tk == _|_ (notHappyAtAll)
> -- so we must not pass it to happyError'

> Just (lexer'',eof') ->
> str "happyNewToken action sts stk\n = "
> str "happyNewToken action sts stk\n" . indent . str "= "
> . str lexer''
> . str "(\\tk -> "
> . str "\n\tlet cont i = "
> . doAction
> . str " sts stk in\n "
> . str "case tk of {\n "
> . str " sts stk in\n" . indent
> . str "case tk of {\n" . indent
> . str (eof' ++ " -> ")
> . eofAction "tk" . str ";\n "
> . interleave ";\n " (map doToken token_rep)
> . str "_ -> happyError' (tk, [])\n "
> . eofAction "tk" . str ";\n" . indent
> . interleave (";\n" ++ indentStr) (map doToken token_rep)
> . str "_ -> happyError' (tk, [])\n" . indent
> . str "})\n\n"
> . str "happyError_ explist " . eofTok . str " tk = happyError' (tk, explist)\n"
> . str "happyError_ explist _ tk = happyError' (tk, explist)\n";
Expand Down Expand Up @@ -559,7 +564,7 @@ action array indexed by (terminal * last_state) + state
> . shows n_rules
> . str ") [\n"
> . interleave' ",\n" (map reduceArrElem [n_starts..n_rules])
> . str "\n ]\n\n"
> . str "\n" . indent . str "]\n\n"

> n_rules = length prods - 1 :: Int

Expand Down Expand Up @@ -715,7 +720,7 @@ directive determines the API of the provided function.
> Just _ -> str "(\\(tokens, explist) -> happyError)"

> reduceArrElem n
> = str " (" . shows n . str " , "
> = str "" . indent . str "(" . shows n . str " , "
> . str "happyReduce_" . shows n . char ')'

-----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion lib/happy-lib.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: happy-lib
version: 2.0
version: 2.0.1
license: BSD-2-Clause
copyright: (c) Andy Gill, Simon Marlow
author: Andy Gill and Simon Marlow
Expand Down