Happy is a parser generator for Haskell 98 (and later).
Happy Parsing!
Documentation is hosted on Read the Docs:
For basic information of the sort typically found in a read-me, see the following sections of the docs:
The Happy parser generator for Haskell
License: Other
Happy is a parser generator for Haskell 98 (and later).
Happy Parsing!
Documentation is hosted on Read the Docs:
For basic information of the sort typically found in a read-me, see the following sections of the docs:
There could be a directive %shift
and %reduce
, for rules in which there are shift/reduce conflicts. Or maybe %conflict shift
and %conflict reduce
.
It would slightly ease the process of bootstrapping happy on new architectures if it shipped pregenerated files that are the result of running happy over happy's own .ly files. alex does this - could happy please follow suit?
The update to happy-1.19.6
in NixOS fails its test suite. I'm citing from https://hydra.nixos.org/build/60004784/nixlog/1:
make: *** No rule to make target 'issue91.n.run', needed by 'all'.
make: *** No rule to make target 'issue91.a.run', needed by 'all'.
make: *** No rule to make target 'issue91.g.run', needed by 'all'.
make: *** No rule to make target 'issue91.gc.run', needed by 'all'.
make: *** No rule to make target 'issue91.ag.run', needed by 'all'.
make: *** No rule to make target 'issue91.agc.run', needed by 'all'.
make: *** No rule to make target 'issue95.n.run', needed by 'all'.
make: *** No rule to make target 'issue95.a.run', needed by 'all'.
make: *** No rule to make target 'issue95.g.run', needed by 'all'.
make: *** No rule to make target 'issue95.gc.run', needed by 'all'.
make: *** No rule to make target 'issue95.ag.run', needed by 'all'.
make: *** No rule to make target 'issue95.agc.run', needed by 'all'.
One of my co-workers attempted to make a polymorphic token type
for generated parsers (handy to try various target types)
http://code.haskell.org/~slyfox/M.y
and even succeded in it with the following hack:
{-# OPTIONS -cpp #-}
...
#define HappyAbsSyn (HappyAbsSyn_ ta tb)
...
%tokentype { Token ta tb }
What do you think of adding direct support for polymorphic token types to happy?
Thanks!
GHC 8.4.1-alpha1 was announced. While testing Agda with this version of GHC, I got errors like this one:
$ cabal install
...
Building executable 'happy' for happy-1.19.8..
...
[15 of 19] Compiling PrettyGrammar ( src/PrettyGrammar.hs, dist/dist-sandbox-12f2e1a5/build/happy/happy-tmp/PrettyGrammar.o )
src/PrettyGrammar.hs:34:28: error:
Ambiguous occurrence ‘<>’
It could refer to either ‘Prelude.<>’,
imported from ‘Prelude’ at src/PrettyGrammar.hs:1:8-20
(and originally defined in ‘GHC.Base’)
or ‘PrettyGrammar.<>’, defined at src/PrettyGrammar.hs:68:9
|
34 | ppTerm (App x ts) = text x <> ppTuple (map ppTerm ts)
| ^^
Since the upstream version (master branch, commit 8e4dc43) compiles with GHC 8.4.1-alpha1, could you make a release, please?
Blocking agda/agda#2878.
The Cabal file places this code under BSD3 but the LICENSE file contains a BSD2 license.
I'll see about doing a PR to also make it warning clean on 8.0 builds and update the travis ci file
(seems a shame to have a happy release that doesn't have a de-bitrottted glr support :) )
The title pretty much speaks for itself—using tabs for layout is usually not the greatest idea, so Happy shouldn't be producing code that does so. The simplest way to do this is probably to replace \t
with eight literal spaces everywhere it appears in the code generator source. The clean way is probably to add a function tabIn = (" "++)
I noticed that when I have a monadic grammar with a threaded lexer, generated with (just) -a
enabled, and do not include a type signature on a production, I get type errors in the generated code. I don’t think this is the expected behaviour. Here is an example of such a grammar:
-- compileBug.y
%name parse prod
%tokentype { Token }
%monad { P } { bindP } { returnP }
%error { error "parse error" }
%lexer { lexer } { EOF }
%token
IDENT { Identifier $$ }
%%
-- Uncommenting the type signature below makes the generated code compile
prod -- :: { () }
: IDENT { () }
{
data Token = EOF | Identifier String
type P a = String -> (a, String)
bindP :: P a -> (a -> P b) -> P b
bindP p f s = let (x,s') = p s in f x s'
returnP :: a -> P a
returnP = (,)
lexer :: (Token -> P a) -> P a
lexer cont s = cont (case s of { "" -> EOF; _ -> Identifier s }) ""
main = return ()
}
Without the type signature:
$ happy -a -o compileBug.hs compileBug.y
$ ghc compileBug.hs
[1 of 1] Compiling Main ( compileBug.hs, compileBug.o )
compileBug.hs:61:17: error:
• Couldn't match type ‘t4’ with ‘()’
‘t4’ is a rigid type variable bound by
the type signature for:
happyReduce_1 :: forall t4.
Int
-> Token
-> Int
-> Happy_IntList
-> HappyStk (HappyAbsSyn t4)
-> P (HappyAbsSyn t4)
at compileBug.hs:60:18
Expected type: Int
-> Token
-> Int
-> Happy_IntList
-> HappyStk (HappyAbsSyn t4)
-> P (HappyAbsSyn t4)
Actual type: Int
-> Token
-> Int
-> Happy_IntList
-> HappyStk (HappyAbsSyn ())
-> P (HappyAbsSyn ())
• In the expression: happySpecReduce_1 0 happyReduction_1
In an equation for ‘happyReduce_1’:
happyReduce_1 = happySpecReduce_1 0 happyReduction_1
• Relevant bindings include
happyReduce_1 :: Int
-> Token
-> Int
-> Happy_IntList
-> HappyStk (HappyAbsSyn t4)
-> P (HappyAbsSyn t4)
(bound at compileBug.hs:61:1)
$
With the type signature uncommented:
$ happy -a -o compileBug.hs compileBug.y
$ ghc compileBug.hs
[1 of 1] Compiling Main ( compileBug.hs, compileBug.o )
Linking compileBug ...
$
Note that this is a regression (I have at least some older version of Happy on which the type signature is not required to generate compiling code). This bug seems present in at least 1.19.5 and HEAD.
You mention version number redundantly at lot of places so currently readme says 1.18, cabal 1.19 and spec 1.17.
It's confusing.
The GLR mode of Happy is likely to be slow. Fortunately, the problem of speeding it up has already been solved by Elkhound, which can generate parsers in C++ or OCaml.
attached is
Pure Functional Parsing
an advanced tutorial
Peter Ljunglof
Pure Functional Parsing an advanced tutorial Peter Ljunglof Ljunglof-2002a.pdf
not sure what papers / docs correspond to the other GLR units of work
Instead of producing errors depending on the values of matched terminals/non terminals, is it possible to constrain the rule so that it simply doesn't match ?
There is a caveat to using parameterised productions which is not mentioned in the online documentation, which is that it is possible to effectively define infinite grammars, causing non-termination. A simply example is some recursive production in which the argument always "grows". In this case, the Happy pre-processor would have to generate infinitely many nonterminals.
For example:
%tokentype { Char }
%token '1' { '1' }
%error { error }
%%
start : list('1') { $1 }
list(p) : p { 1 }
| p list(parens(p)) { $2 + 1 }
parens(p) : '(' p ')' { $2 }
This describes the language {"1" |-> 1, "1(1)" |-> 2, "1(1)((1)) |-> 3", ...}
.
When I run the happy tool on this grammar description (version 1.19.5), it fails to terminate.
I am reporting this because I thought it would be helpful to add this caveat to the online documentation.
Note that parser combinators may be able to handle such descriptions. This is the case when parsers terminate when all of the input is consumed. For example, the parser written with Parsec below:
import Text.ParserCombinators.Parsec hiding (Parser)
type Parser a = GenParser Char () a
pStart :: Parser Int
pStart = pList (char '1')
pList :: Parser Char -> Parser Int
pList p = try (1 <$ p <* eof)
<|> (1+) <$ p <*> pList (parens p)
where parens :: Parser a -> Parser a
parens x = char '(' *> x <* char ')'
I got that message when cabal install happy
Resolving dependencies...
[1 of 1] Compiling Main ( C:\Users\SQLSER~1\AppData\Local\Temp\happy-1.19.3-2820\happy-1.19.3\Setup.lhs, C:\Users\SQLSER~1\AppData\Local\Temp\happy-1.19.3-2820\happy-1.19.3\dist\dist-sandbox-6655fc3f\setup\Main.o )
Linking C:\Users\SQLSER~1\AppData\Local\Temp\happy-1.19.3-2820\happy-1.19.3\dist/dist-sandbox-6655fc3f\setup\setup.exe ...
Configuring happy-1.19.3...
Building happy-1.19.3...
Preprocessing executable 'happy' for happy-1.19.3...
[ 1 of 18] Compiling NameSet ( src\NameSet.hs, dist\dist-sandbox-6655fc3f\build\happy\happy-tmp\NameSet.o )
[ 2 of 18] Compiling Target ( src\Target.lhs, dist\dist-sandbox-6655fc3f\build\happy\happy-tmp\Target.o )
[ 3 of 18] Compiling AbsSyn ( src\AbsSyn.lhs, dist\dist-sandbox-6655fc3f\build\happy\happy-tmp\AbsSyn.o )
[ 4 of 18] Compiling ParamRules ( src\ParamRules.hs, dist\dist-sandbox-6655fc3f\build\happy\happy-tmp\ParamRules.o )
[ 5 of 18] Compiling GenUtils ( src\GenUtils.lhs, dist\dist-sandbox-6655fc3f\build\happy\happy-tmp\GenUtils.o )
[ 6 of 18] Compiling ParseMonad ( src\ParseMonad.lhs, dist\dist-sandbox-6655fc3f\build\happy\happy-tmp\ParseMonad.o )
[ 7 of 18] Compiling Lexer ( src\Lexer.lhs, dist\dist-sandbox-6655fc3f\build\happy\happy-tmp\Lexer.o )
[ 8 of 18] Compiling Parser ( dist\dist-sandbox-6655fc3f\build\happy\happy-tmp\Parser.hs, dist\dist-sandbox-6655fc3f\build\happy\happy-tmp\Parser.o )
Failed to install happy-1.19.3
src\NameSet.hs:7:1: Warning:
The import of `Prelude' is redundant
except perhaps to import instances from `Prelude'
To import instances alone, use: import Prelude()
src\ParamRules.hs:6:1: Warning:
Module `Control.Monad.Instances' is deprecated:
This module now contains no instances and will be removed in the future
src\ParseMonad.lhs:17:12: Warning:
`P' is an instance of Monad but not Applicative - this will become an error
in GHC 7.10, under the Applicative-Monad Proposal.
templates\GenericTemplate.hs:104:22:
Couldn't match expected type `Bool'
with actual type `Happy_GHC_Exts.Int#'
In the expression:
(n Happy_GHC_Exts.<# (0# :: Happy_GHC_Exts.Int#))
In a stmt of a pattern guard for
a case alternative:
(n Happy_GHC_Exts.<# (0# :: Happy_GHC_Exts.Int#))
In a case alternative:
n | (n Happy_GHC_Exts.<# (0# :: Happy_GHC_Exts.Int#))
-> (happyReduceArr Happy_Data_Array.! rule) i tk st
where
rule
= (Happy_GHC_Exts.I#
((Happy_GHC_Exts.negateInt#
((n Happy_GHC_Exts.+# (1# :: Happy_GHC_Exts.Int#))))))
templates\GenericTemplate.hs:115:23:
Couldn't match expected type `Bool'
with actual type `Happy_GHC_Exts.Int#'
In the expression:
(off_i Happy_GHC_Exts.>=# (0# :: Happy_GHC_Exts.Int#))
In the expression:
if (off_i Happy_GHC_Exts.>=# (0# :: Happy_GHC_Exts.Int#)) then
(indexShortOffAddr happyCheck off_i Happy_GHC_Exts.==# i)
else
False
In an equation for `check':
check
= if (off_i Happy_GHC_Exts.>=# (0# :: Happy_GHC_Exts.Int#)) then
(indexShortOffAddr happyCheck off_i Happy_GHC_Exts.==# i)
else
False
templates\GenericTemplate.hs:117:30:
Couldn't match expected type `Happy_GHC_Exts.Int#'
with actual type `Bool'
In the expression: False
In the expression:
if (off_i Happy_GHC_Exts.>=# (0# :: Happy_GHC_Exts.Int#)) then
(indexShortOffAddr happyCheck off_i Happy_GHC_Exts.==# i)
else
False
templates\GenericTemplate.hs:119:13:
Couldn't match expected type `Bool'
with actual type `Happy_GHC_Exts.Int#'
In the expression: check
In a stmt of a pattern guard for
a pattern binding:
check
templates\GenericTemplate.hs:212:14:
Pattern bindings containing unlifted types should use an outermost bang patt
ern:
(sts1@((HappyCons (st1@(action)) (_))))
= happyDrop k (HappyCons (st) (sts))
In an equation for `happyMonadReduce':
happyMonadReduce k nt fn j tk st sts stk
= happyThen1
(fn stk tk)
(\ r -> happyGoto nt j tk st1 sts1 (r `HappyStk` drop_stk))
where
(sts1@((HappyCons (st1@(action)) (_))))
= happyDrop k (HappyCons (st) (sts))
drop_stk = happyDropStk k stk
templates\GenericTemplate.hs:219:14:
Pattern bindings containing unlifted types should use an outermost bang patt
ern:
(sts1@((HappyCons (st1@(action)) (_))))
= happyDrop k (HappyCons (st) (sts))
In an equation for `happyMonad2Reduce':
happyMonad2Reduce k nt fn j tk st sts stk
= happyThen1
(fn stk tk)
(\ r -> happyNewToken new_state sts1 (r `HappyStk` drop_stk))
where
(sts1@((HappyCons (st1@(action)) (_))))
= happyDrop k (HappyCons (st) (sts))
drop_stk = happyDropStk k stk
(off) = indexShortOffAddr happyGotoOffsets st1
(off_i) = (off Happy_GHC_Exts.+# nt)
....
cabal: Error: some packages failed to install:
happy-1.19.3 failed during the building phase. The exception was:
ExitFailure 1
Trying to build happy I encountered a problem during the cabal install
step.
This is on archlinux with ghc 8.0.2 and cabal from recent git HEAD.
Full log, so you can see what I'm doing. The interesting line is probably:
happy: /tmp/happy-1.19.5/.cabal-sandbox/share/x86_64-linux-ghc-8.0.2/happy-1.19.5/HappyTemplate-arrays-coerce: openFile: does not exist (No such file or directory)
- cabal get happy
Unpacking to happy-1.19.5/- cd happy-1.19.5
- cabal sandbox init
Writing a default package environment file to
/tmp/happy-1.19.5/cabal.sandbox.config
Creating a new sandbox at /tmp/happy-1.19.5/.cabal-sandbox- cabal install --dependencies-only
Resolving dependencies...
Notice: installing into a sandbox located at /tmp/happy-1.19.5/.cabal-sandbox
Configuring mtl-2.2.1...
Building mtl-2.2.1...
Installed mtl-2.2.1- cabal configure
Resolving dependencies...
[1 of 1] Compiling Main ( dist/setup/setup.hs, dist/setup/Main.o )dist/setup/setup.hs:21:1: warning: [-Wtabs]
Tab character found here, and in 39 further locations.
Please use spaces instead.
Linking ./dist/setup/setup ...
Configuring happy-1.19.5...
- cabal build
Building happy-1.19.5...
Preprocessing executable 'happy' for happy-1.19.5...
[ 1 of 18] Compiling Target ( src/Target.lhs, dist/build/happy/happy-tmp/Target.o )
[ 2 of 18] Compiling Paths_happy ( dist/build/autogen/Paths_happy.hs, dist/build/happy/happy-tmp/Paths_happy.o )
[ 3 of 18] Compiling ParseMonad ( src/ParseMonad.hs, dist/build/happy/happy-tmp/ParseMonad.o )
[ 4 of 18] Compiling NameSet ( src/NameSet.hs, dist/build/happy/happy-tmp/NameSet.o )
[ 5 of 18] Compiling Lexer ( src/Lexer.lhs, dist/build/happy/happy-tmp/Lexer.o )
[ 6 of 18] Compiling GenUtils ( src/GenUtils.lhs, dist/build/happy/happy-tmp/GenUtils.o )
[ 7 of 18] Compiling AttrGrammar ( src/AttrGrammar.lhs, dist/build/happy/happy-tmp/AttrGrammar.o )
[ 8 of 18] Compiling AttrGrammarParser ( dist/build/happy/happy-tmp/AttrGrammarParser.hs, dist/build/happy/happy-tmp/AttrGrammarParser.o )
[ 9 of 18] Compiling AbsSyn ( src/AbsSyn.lhs, dist/build/happy/happy-tmp/AbsSyn.o )
[10 of 18] Compiling ParamRules ( src/ParamRules.hs, dist/build/happy/happy-tmp/ParamRules.o )src/ParamRules.hs:5:1: warning: [-Wdeprecations]
Module ‘Control.Monad.Error’ is deprecated:
Use Control.Monad.Except insteadsrc/ParamRules.hs:6:1: warning: [-Wdeprecations]
Module ‘Control.Monad.Instances’ is deprecated:
This module now contains no instances and will be removed in the futuresrc/ParamRules.hs:31:17: warning: [-Wdeprecations]
In the use of type constructor or class ‘ErrorT’
(imported from Control.Monad.Error, but defined in transformers-0.5.2.0:Control.Monad.Trans.Error):
Deprecated: "Use Control.Monad.Trans.Except instead"src/ParamRules.hs:71:10: warning: [-Wdeprecations]
In the use of type constructor or class ‘ErrorT’
(imported from Control.Monad.Error, but defined in transformers-0.5.2.0:Control.Monad.Trans.Error):
Deprecated: "Use Control.Monad.Trans.Except instead"src/ParamRules.hs:72:27: warning: [-Wdeprecations]
In the use of ‘runErrorT’
(imported from Control.Monad.Error, but defined in transformers-0.5.2.0:Control.Monad.Trans.Error):
Deprecated: "Use Control.Monad.Trans.Except instead"
[11 of 18] Compiling Grammar ( src/Grammar.lhs, dist/build/happy/happy-tmp/Grammar.o )
[12 of 18] Compiling First ( src/First.lhs, dist/build/happy/happy-tmp/First.o )
[13 of 18] Compiling LALR ( src/LALR.lhs, dist/build/happy/happy-tmp/LALR.o )
[14 of 18] Compiling Info ( src/Info.lhs, dist/build/happy/happy-tmp/Info.o )
[15 of 18] Compiling ProduceCode ( src/ProduceCode.lhs, dist/build/happy/happy-tmp/ProduceCode.o )
[16 of 18] Compiling ProduceGLRCode ( src/ProduceGLRCode.lhs, dist/build/happy/happy-tmp/ProduceGLRCode.o )
[17 of 18] Compiling Parser ( dist/build/happy/happy-tmp/Parser.hs, dist/build/happy/happy-tmp/Parser.o )
[18 of 18] Compiling Main ( src/Main.lhs, dist/build/happy/happy-tmp/Main.o )
Linking dist/build/happy/happy ...
++ realpath dist/build/happy
- export PATH=/tmp/happy-1.19.5/dist/build/happy:/home/ongy/.bin/:/home/ongy/.cabal/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
- PATH=/tmp/happy-1.19.5/dist/build/happy:/home/ongy/.bin/:/home/ongy/.cabal/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
- cabal install
Resolving dependencies...
Notice: installing into a sandbox located at /tmp/happy-1.19.5/.cabal-sandbox
Configuring happy-1.19.5...
Building happy-1.19.5...
Failed to install happy-1.19.5
Build log ( /tmp/happy-1.19.5/.cabal-sandbox/logs/ghc-8.0.2/happy-1.19.5-GUPzpM8oSlA9ybE7TUr7pj.log ):
cabal: Entering directory '.'
[1 of 1] Compiling Main ( dist/dist-sandbox-661b7d0a/setup/setup.hs, dist/dist-sandbox-661b7d0a/setup/Main.o )
Linking ./dist/dist-sandbox-661b7d0a/setup/setup ...
Configuring happy-1.19.5...
Building happy-1.19.5...
Preprocessing executable 'happy' for happy-1.19.5...
happy: /tmp/happy-1.19.5/.cabal-sandbox/share/x86_64-linux-ghc-8.0.2/happy-1.19.5/HappyTemplate-arrays-coerce: openFile: does not exist (No such file or directory)
cabal: Leaving directory '.'
cabal: Error: some packages failed to install:
happy-1.19.5-GUPzpM8oSlA9ybE7TUr7pj failed during the building phase. The
exception was:
ExitFailure 1
The GLR feature in Happy is currently not usable for people using cabal (ie everyone) because the GLR feature requires the use of command line arguments, and Cabal provides no way to set happy command line arguments in the .cabal file.
Now you may say "well then, cabal should just let me specify command line arguments to happy". But actually this behaviour in Cabal is by design. The right place to say if your parser is GLR or not is in the .y file itself, not in the .cabal file. In practice each .y file is either going to be GLR or not, and this is something that is decided by the author, not the person building the package.
Exactly how you do this is up to you of course, but happy already has a syntax for directives, like %name, so you could just add something like
%grammar glr
and similarly for the functionality of the --decode and --filter options.
The general principle here, is to consider that there is a division of roles between the author of the program/package and the person building the package. The person building can decide things like optimisation levels, where input and output files live etc. The author decides the code and anything that is necessary for the meaning of that code. The preferable place to put the code (and related) is in the file itself, or sometimes in the .cabal file, but the less configuration the better. The preferable place for the builder to specify things is in the build environment (cabal command line, cabal config file, sandbox config file etc).
It seems the new primops are only used when bootstrapping GHC-7.7 from GHC-7.6, not when building happy with GHC-7.7. Here are the build errors that I get:
[ 8 of 18] Compiling Parser ( dist/build/happy/happy-tmp/Parser.hs, dist/build/happy/happy-tmp/Parser.o )
templates/GenericTemplate.hs:104:22:
Couldn't match expected type ‛Bool’
with actual type ‛Happy_GHC_Exts.Int#’
In the expression:
(n Happy_GHC_Exts.<# (0# :: Happy_GHC_Exts.Int#))
In a stmt of a pattern guard for
a case alternative:
(n Happy_GHC_Exts.<# (0# :: Happy_GHC_Exts.Int#))
In a case alternative:
n | (n Happy_GHC_Exts.<# (0# :: Happy_GHC_Exts.Int#))
-> (happyReduceArr Happy_Data_Array.! rule) i tk st
where
rule
= (Happy_GHC_Exts.I#
((Happy_GHC_Exts.negateInt#
((n Happy_GHC_Exts.+# (1# :: Happy_GHC_Exts.Int#))))))
templates/GenericTemplate.hs:115:23:
Couldn't match expected type ‛Bool’
with actual type ‛Happy_GHC_Exts.Int#’
In the expression:
(off_i Happy_GHC_Exts.>=# (0# :: Happy_GHC_Exts.Int#))
In the expression:
if (off_i Happy_GHC_Exts.>=# (0# :: Happy_GHC_Exts.Int#)) then
(indexShortOffAddr happyCheck off_i Happy_GHC_Exts.==# i)
else
False
In an equation for ‛check’:
check
= if (off_i Happy_GHC_Exts.>=# (0# :: Happy_GHC_Exts.Int#)) then
(indexShortOffAddr happyCheck off_i Happy_GHC_Exts.==# i)
else
False
templates/GenericTemplate.hs:117:30:
Couldn't match expected type ‛Happy_GHC_Exts.Int#’
with actual type ‛Bool’
In the expression: False
In the expression:
if (off_i Happy_GHC_Exts.>=# (0# :: Happy_GHC_Exts.Int#)) then
(indexShortOffAddr happyCheck off_i Happy_GHC_Exts.==# i)
else
False
templates/GenericTemplate.hs:119:13:
Couldn't match expected type ‛Bool’
with actual type ‛Happy_GHC_Exts.Int#’
In the expression: check
In a stmt of a pattern guard for
a pattern binding:
check
Happy currently gives pretty bad error messages. This is shown by GHC's error messages on invalid syntax, which usually aren't very good.
One solution is used by the Menhir parser generator. Menhir provides an incremental parser API, which allows for error handling based on what states an error can be detected in. Its manual provides more details.
Is there a reason why different tokens cannot be mapped into a single one using %token
directive? This is particularly useful for spelling of keywords when the lexer is not sophisticated and would eliminate the need to do it in grammar. Here's an example:
%token
centered { TIdentifier "centered" }
centered { TIdentifier "centred" }
I get the following error:
C:\TorXakisSandbox\2560_Sort\torxakis\sys\front\.stack-work\dist\1f7101f2\build\TxsHappy.hs:3025:86: error:
Ambiguous occurrence `foldr'
It could refer to either `List.foldr',
imported from `Prelude' at .stack-work\dist\1f7101f2\build\TxsHappy.hs:4:8-15
(and originally defined in `Data.Foldable')
or `Map.foldr',
imported from `SortParser' at .stack-work\dist\1f7101f2\build\TxsHappy.hs:24:1-17
(and originally defined in `containers-0.5.7.1:Data.Map.Base')
The generated code is:
txsParser toks = let { f = do_txsParser toks; (conds,attrs) = f happyEmptyAttrs; x = foldr seq attrs conds; } in (parseVal x)
which is generated by ProduceCode.lhs , in particular the function: produceAttrEntries.
See https://github.com/simonmar/happy/blob/04a71e273676052abf40bfd475bde0cdc4f334dc/src/ProduceCode.lhs
> regularAE name
> = str name . str " toks = "
> . str "let { "
> . str "f = do_" . str name . str " toks; "
> . str "(conds,attrs) = f happyEmptyAttrs; "
> . str "x = foldr seq attrs conds; "
> . str "} in (". str defaultAttr . str " x)"
I think it should be List.foldr....
Note that foldr occurs 4 times in ProduceCode.lhs without a name space in front of it!
My first attempt of running the glr/expr-eval example was using a (nearly) fresh install of the haskell-platform on Ubuntu 14.04.
This however resulted in an installation of happy-1.19.0, which caused imports to fail (modules Char and System).
Therefore I installed happy-1.19.5 and tried what can be found in the attachment.
I maintain a compiler that uses a reasonably sized parser written with Happy: https://github.com/diku-dk/futhark/blob/e3f5344ac74f80a7d74ee57cbff27597b86eb545/src/Language/Futhark/Parser/Parser.y
There is nothing fancy going on, and I believe that I have type signatures for all productions. I do use parameterized productions a little bit, though. Unfortunately, while the parser generated by Happy 1.19.5 compiles with GHC in a dozen seconds, the parser generated by Happy 1.19.8 takes upward of twenty minutes. I have identified these hole-y type signatures as the culprit:
#if __GLASGOW_HASKELL__ >= 710
happyReduce_6 :: () => Happy_GHC_Exts.Int# -> L Token -> Happy_GHC_Exts.Int# -> Happy_IntList -> HappyStk (HappyAbsSyn _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) -> ParserMonad (HappyAbsSyn _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _)
#endif
If I remove these type signatures, then compile times drop down to a dozen seconds again. Perhaps GHC has some quadratic behaviour in the implementation of typed holes, or perhaps Happy shouldn't be generating these - I'm not sure. But given the relative simplicity of my grammar, I don't think I'll be the only one encountering this. Is there perhaps a workaround, or am I doing something stupid?
(Happy 1.19.6 and 1.19.7 produce code that does not compile for this parser, likely due to #94.)
Happy does not accept the empty list after %token
.
CUP for instance, can live without terminals.
Is there a reason why an empty token list should not at least be parsed?
(I admit there are no sensible grammars if there are no tokens, but: garbage-in-garbage-out.)
Hi,
I was trying to generate a parser for Promela (the SPIN language) from this grammar: http://spinroot.com/spin/Man/grammar.html - I simply copy/pasted it into a file 'grammar.y' and then executed 'happy grammar.y'. Unfortunately, it just prints "happy: 1: Parse error". How can I find out what's wrong? Does this error message mean there was already a parsing error on line 1? If yes, which part of line 1 does happy not understand?
Thanks for your help,
Marius
greencard 3.0.4.1 builds fine with ghc 7.6.3, but fails on ghc HEAD.
I'm using Happy ffd7be430e and Alex 1c9617b110
Trying to install greencard 3.0.4.1 and ghc 7.7.20131121 gives me the following error message:
[16 of 21] Compiling Parse ( dist/build/greencard/greencard-tmp/Parse.hs, dist/build/greencard/greencard-tmp/Parse.o )
templates/GenericTemplate.hs:104:22:
Couldn't match expected type ‛Bool’
with actual type ‛Happy_GHC_Exts.Int#’
In the expression:
(n Happy_GHC_Exts.<# (0# :: Happy_GHC_Exts.Int#))
In a stmt of a pattern guard for
a case alternative:
(n Happy_GHC_Exts.<# (0# :: Happy_GHC_Exts.Int#))
In a case alternative:
n | (n Happy_GHC_Exts.<# (0# :: Happy_GHC_Exts.Int#))
-> (happyReduceArr Happy_Data_Array.! rule) i tk st
where
rule
= (Happy_GHC_Exts.I#
((Happy_GHC_Exts.negateInt#
((n Happy_GHC_Exts.+# (1# :: Happy_GHC_Exts.Int#))))))
templates/GenericTemplate.hs:115:23:
Couldn't match expected type ‛Bool’
with actual type ‛Happy_GHC_Exts.Int#’
In the expression:
(off_i Happy_GHC_Exts.>=# (0# :: Happy_GHC_Exts.Int#))
In the expression:
if (off_i Happy_GHC_Exts.>=# (0# :: Happy_GHC_Exts.Int#)) then
(indexShortOffAddr happyCheck off_i Happy_GHC_Exts.==# i)
else
False
In an equation for ‛check’:
check
= if (off_i Happy_GHC_Exts.>=# (0# :: Happy_GHC_Exts.Int#)) then
(indexShortOffAddr happyCheck off_i Happy_GHC_Exts.==# i)
else
False
templates/GenericTemplate.hs:117:30:
Couldn't match expected type ‛Happy_GHC_Exts.Int#’
with actual type ‛Bool’
In the expression: False
In the expression:
if (off_i Happy_GHC_Exts.>=# (0# :: Happy_GHC_Exts.Int#)) then
(indexShortOffAddr happyCheck off_i Happy_GHC_Exts.==# i)
else
False
templates/GenericTemplate.hs:119:13:
Couldn't match expected type ‛Bool’
with actual type ‛Happy_GHC_Exts.Int#’
In the expression: check
In a stmt of a pattern guard for
a pattern binding:
check
templates/GenericTemplate.hs:212:14:
Pattern bindings containing unlifted types should use an outermost bang pattern:
(sts1@((HappyCons (st1@(action)) (_))))
= happyDrop k (HappyCons (st) (sts))
In an equation for ‛happyMonadReduce’:
happyMonadReduce k nt fn j tk st sts stk
= happyThen1
(fn stk tk)
(\ r -> happyGoto nt j tk st1 sts1 (r `HappyStk` drop_stk))
where
(sts1@((HappyCons (st1@(action)) (_))))
= happyDrop k (HappyCons (st) (sts))
drop_stk = happyDropStk k stk
templates/GenericTemplate.hs:219:14:
Pattern bindings containing unlifted types should use an outermost bang pattern:
(sts1@((HappyCons (st1@(action)) (_))))
= happyDrop k (HappyCons (st) (sts))
In an equation for ‛happyMonad2Reduce’:
happyMonad2Reduce k nt fn j tk st sts stk
= happyThen1
(fn stk tk)
(\ r -> happyNewToken new_state sts1 (r `HappyStk` drop_stk))
where
(sts1@((HappyCons (st1@(action)) (_))))
= happyDrop k (HappyCons (st) (sts))
drop_stk = happyDropStk k stk
(off) = indexShortOffAddr happyGotoOffsets st1
(off_i) = (off Happy_GHC_Exts.+# nt)
....
Failed to install greencard-3.0.4.1
I'm sure I'm missing something obvious with the invocation of happy.
happy -gca MyGrammar.y
unused rules: 23
unused terminals: 3
shift/reduce conflicts: 9
reduce/reduce conflicts: 37
Great, it identified 23 unused rules and 3 unused terminals. How do I ask happy to list them?
https://www.haskell.org/happy/ still claims that Happy is using Darcs.
Due to missing export (haskell/mtl#10).
I am using Alex along with Happy, and I have a rule that looks something like:
gdecl : typedef type ident ';' {%^ mkTypDef $2 $3 }
The documentation says that this is the proper way to get a hold of the lookahead token when using a threaded lexer (%lexer). Running Happy on this produces a .hs file which GHC can't parse:
Parser.hs:301:47: parse error on input ‘tk’
Here is the function that contains the error:
happyReduce_6 = happyMonadReduce 4# 2# happyReduction_6
happyReduction_6 (happy_x_4 `HappyStk`
happy_x_3 `HappyStk`
happy_x_2 `HappyStk`
happy_x_1 `HappyStk`
happyRest) tk
= happyThen (case happyOut21 happy_x_2 of { happy_var_2 ->
case happyOutTok happy_x_3 of { (LocTok _ (TokIdent happy_var_3)) ->
( mkTypDef happy_var_2 happy_var_3)}} tk <-- Error Here
) (\r -> happyReturn (happyIn6 r))
Normal monadic productions, i.e. {% expn}, work fine. I am using Happy 1.19.4 and GHC 7.8.3. I can't post the entire Happy file, but if necessary I could probably put together a minimal working example.
When generating code for happyNewToken
, Happy does not use the token type given by %tokentype
, hardcoding instead to Token
. Here is the relevant code:
str "happyNewToken :: " . pcont . str " => "
. str "(Happy_GHC_Exts.Int#\n"
. str " -> Happy_GHC_Exts.Int#\n"
. str " -> Token\n"
. str " -> HappyState Token (t -> "
. pty . str " a)\n"
. str " -> [HappyState Token (t -> "
. pty . str " a)]\n"
. str " -> t\n"
. str " -> " . pty . str " a)\n"
. str " -> [HappyState Token (t -> "
. pty . str " a)]\n"
. str " -> t\n"
. str " -> " . pty . str " a\n"
I've already fixed this issue on a local branch of mine, so I'll open a PR soon.
$ cabal list happy
* happy
Synopsis: Happy is a parser generator for Haskell
Default available version: 1.19.5
Installed versions: [ Unknown ]
Homepage: http://www.haskell.org/happy/
License: BSD3
ghc version:
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.10.1
cabal version
$ cabal -V
cabal-install version 1.22.6.0
using version 1.22.2.0 of the Cabal library
somehow the install version becomes unknown. I updated to the latest package list and install happy today(2015/7/28).
We've tried to update our ghc-head snapshot in NixOS to a recent version, but unfortunately we cannot build happy with that compiler:
src/ParamRules.hs:63:9:
Non type-variable argument in the constraint: MonadError [Char] m
(Use FlexibleContexts to permit this)
In the context: (MonadError [Char] m)
While checking the inferred type for ‘err’
In an equation for ‘inst_rule’:
inst_rule (x, xs, ps, t) ts
= do { s <- build xs ts [];
ps1 <- lift $ mapM (inst_prod s) ps;
let y = ...;
.... }
where
build (x' : xs') (t' : ts') m = build xs' ts' ((x', t') : m)
build [] [] m = return m
build xs' [] _
= err ("Need " ++ show (length xs') ++ " more arguments")
build _ ts' _ = err (show (length ts') ++ " arguments too many.")
err m = throwError ("In " ++ inst_name (x, ts) ++ ": " ++ m)
A complete build log is at http://hydra.cryp.to/build/52135/nixlog/1/raw.
A lot of stuff in the documentation are out-of-date. Many links are no more valid (e.g. the first two links in Chapt 4). And some claims are still made 10 years ago, which may or may not still be true (e.g. BNFC support). I don't know of any better/more recent tutorials/docs on happy, which means this user guide is still the most complete, official and valuable doc. It's really a shame that it's not in a good shape.
Right now I'm rewriting the code generator and unfortunately, there are no tests for the "coerce" flag. What would be a minimal example that uses it?
A test that triggers the _ ->
branch of case lexer'
in produceMonadStuff
would be handy as well (I believe there's a bug in the definition of happyError'
there).
as of e941bd5 on GHC 8.0, i get the following warnings
src/ParamRules.hs:5:1: warning: [-Wdeprecations]
Module ‘Control.Monad.Error’ is deprecated:
Use Control.Monad.Except instead
src/ParamRules.hs:6:1: warning: [-Wdeprecations]
Module ‘Control.Monad.Instances’ is deprecated:
This module now contains no instances and will be removed in the future
src/ParamRules.hs:32:17: warning: [-Wdeprecations]
In the use of type constructor or class ‘ErrorT’
(imported from Control.Monad.Error, but defined in transformers-0.5.2.0:Control.Monad.Trans.Error):
Deprecated: "Use Control.Monad.Trans.Except instead"
src/ParamRules.hs:58:53: warning: [-Wname-shadowing]
This binding for ‘x’ shadows the existing binding
bound at src/ParamRules.hs:55:12
src/ParamRules.hs:72:10: warning: [-Wdeprecations]
In the use of type constructor or class ‘ErrorT’
(imported from Control.Monad.Error, but defined in transformers-0.5.2.0:Control.Monad.Trans.Error):
Deprecated: "Use Control.Monad.Trans.Except instead"
src/ParamRules.hs:73:27: warning: [-Wdeprecations]
In the use of ‘runErrorT’
(imported from Control.Monad.Error, but defined in transformers-0.5.2.0:Control.Monad.Trans.Error):
Deprecated: "Use Control.Monad.Trans.Except instead"
theses should probably be cleaned up or CPP'd over before a release with fixed up GLR support is done (cc @thomie )
happy: 12: No closing '}' in code segment
Test file:
%tokentype { Token }
%token
JUNK { Junk }
%%
junk : JUNK
{
happyFailsToParse = ('\'','{')
}
Something seems to have changed in happy between the version 1.19.4 on Hackage and current trunk (7b50000) causing this failure when building language-c:
rwbarton@morphism:/tmp/language-c-0.4.6$ cabal install
Resolving dependencies...
Configuring language-c-0.4.6...
Building language-c-0.4.6...
Preprocessing library language-c-0.4.6...
unused rules: 143
The grammar has 0 shift/reduce conflicts.
This is different from the number given in the expect directive
Failed to install language-c-0.4.6
cabal: Error: some packages failed to install:
language-c-0.4.6 failed during the building phase. The exception was:
ExitFailure 1
language-c's Language/C/Parser/Parser.y contains the directive %expect 1
.
Is this change, well, expected? What's the best way for a user of happy to deal with such a change?
One of the things I've loved about using Happy is its parametrized production rules (being able to abstract out things like optional
, some
, and many
is a godsend!). However, there isn't currently any way to add type signatures to parametrized production rules. Looking here at the bottom, it mentions that there are plans to support type signatures on these productions.
I'd like to be able to write something (completely inventing syntax) like
sepBy1 :: { a } { b } { NonEmpty a }
sepBy1(p, sep) : p { $1 :| [] }
| sepBy1(p, sep) sep p { cons $3 $1 }
If the fix for this is anticipated to be pretty simple, I'd be willing to have a go at it myself and put in a PR.
I currently have a pretty big grammar that relies a fair bit on parametrized productions. Compile times are getting to be pretty horrendous. I added type signatures to everything I could, and compile times got a lot better, but are still quite bad. I suspect Happy would be a lot happier if it could just check against types for my parametrized productions instead of having to create them.
As a side thought, I guess that my syntax above is probably insufficient - soon enough someone probably will want to add constraints in the type signatures for their parametrized productions...
The bug in question came from a parser hosted here. In short, if you write
| FunName Universals OptTermetric OptType OptExpression { PreF $1 (fst <$> $4) [] $2 [NoArgs] (snd <$> $4) $3 $5 }
instead of
| FunName Universals OptTermetric OptType OptExpression { PreF $1 (fmap fst $4) [] $2 [NoArgs] (fmap snd $4) $3 $5 }
it will fail during compilation with an arcane error message, viz.
/home/vanessa/programming/haskell/done/ats/dist-newstyle/build/x86_64-linux/ghc-8.2.2/language-ats-1.0.1.0/opt/build/Language/ATS/Parser.hs:4832:38: error:
• Couldn't match type ‘Maybe (String, Type AlexPosn)
-> (b0, b0) -> b0’
with ‘Maybe (Expression AlexPosn)’
Expected type: HappyStk
(HappyAbsSyn
(ATS AlexPosn)
[Declaration AlexPosn]
[Type AlexPosn]
[Type AlexPosn]
(Type AlexPosn)
[Arg AlexPosn]
[Arg AlexPosn]
(Arg AlexPosn)
(Arg AlexPosn)
(Expression AlexPosn)
[Pattern AlexPosn]
(Pattern AlexPosn)
[(Pattern AlexPosn, LambdaType AlexPosn, Expression AlexPosn)]
[(Expression AlexPosn, LambdaType AlexPosn, Expression AlexPosn)]
(Maybe [Expression AlexPosn], [Expression AlexPosn])
[Expression AlexPosn]
[Expression AlexPosn]
(LambdaType AlexPosn)
(LambdaType AlexPosn)
(Expression AlexPosn)
[Type AlexPosn]
(Expression AlexPosn)
[StaticExpression AlexPosn]
[Declaration AlexPosn]
(StaticExpression AlexPosn)
(Expression AlexPosn)
(AlexPosn, StaticExpression AlexPosn)
(Sort AlexPosn)
[String]
(Existential AlexPosn)
[StaticExpression AlexPosn]
(Universal AlexPosn)
[[Type AlexPosn]]
[[Type AlexPosn]]
(Either (StaticExpression AlexPosn) (Expression AlexPosn))
(Implementation AlexPosn)
(Implementation AlexPosn)
(Name AlexPosn)
(Name AlexPosn)
[(String, Expression AlexPosn)]
[(String, Type AlexPosn)]
[String]
(Maybe (Type AlexPosn))
[StaticExpression AlexPosn]
(Leaf AlexPosn)
[Leaf AlexPosn]
[Universal AlexPosn]
(Maybe (StaticExpression AlexPosn))
(UnOp AlexPosn)
(BinOp AlexPosn)
(Maybe (Expression AlexPosn))
(DataPropLeaf AlexPosn)
[DataPropLeaf AlexPosn]
String
(Maybe (String, Type AlexPosn))
(PreFunction AlexPosn)
(Declaration AlexPosn)
(Declaration AlexPosn)
(Declaration AlexPosn)
[Declaration AlexPosn]
String
(Maybe (Type AlexPosn))
[Arg AlexPosn]
[SortArg AlexPosn]
(Maybe [SortArg AlexPosn])
(Declaration AlexPosn)
(Fixity AlexPosn)
String
[String]
(StackFunction AlexPosn)
[Declaration AlexPosn]
(Declaration AlexPosn)
(DataSortLeaf AlexPosn)
[DataSortLeaf AlexPosn]
(Declaration AlexPosn)
(Declaration AlexPosn)
(Declaration AlexPosn))
-> HappyStk
(HappyAbsSyn
(ATS AlexPosn)
[Declaration AlexPosn]
[Type AlexPosn]
[Type AlexPosn]
(Type AlexPosn)
[Arg AlexPosn]
[Arg AlexPosn]
(Arg AlexPosn)
(Arg AlexPosn)
(Expression AlexPosn)
[Pattern AlexPosn]
(Pattern AlexPosn)
[(Pattern AlexPosn, LambdaType AlexPosn, Expression AlexPosn)]
[(Expression AlexPosn, LambdaType AlexPosn, Expression AlexPosn)]
(Maybe [Expression AlexPosn], [Expression AlexPosn])
[Expression AlexPosn]
[Expression AlexPosn]
(LambdaType AlexPosn)
(LambdaType AlexPosn)
(Expression AlexPosn)
[Type AlexPosn]
(Expression AlexPosn)
[StaticExpression AlexPosn]
[Declaration AlexPosn]
(StaticExpression AlexPosn)
(Expression AlexPosn)
(AlexPosn, StaticExpression AlexPosn)
(Sort AlexPosn)
[String]
(Existential AlexPosn)
[StaticExpression AlexPosn]
(Universal AlexPosn)
[[Type AlexPosn]]
[[Type AlexPosn]]
(Either (StaticExpression AlexPosn) (Expression AlexPosn))
(Implementation AlexPosn)
(Implementation AlexPosn)
(Name AlexPosn)
(Name AlexPosn)
[(String, Expression AlexPosn)]
[(String, Type AlexPosn)]
[String]
(Maybe (Type AlexPosn))
[StaticExpression AlexPosn]
(Leaf AlexPosn)
[Leaf AlexPosn]
[Universal AlexPosn]
(Maybe (StaticExpression AlexPosn))
(UnOp AlexPosn)
(BinOp AlexPosn)
(Maybe (Expression AlexPosn))
(DataPropLeaf AlexPosn)
[DataPropLeaf AlexPosn]
String
(Maybe (String, Type AlexPosn))
(PreFunction AlexPosn)
(Declaration AlexPosn)
(Declaration AlexPosn)
(Declaration AlexPosn)
[Declaration AlexPosn]
String
(Maybe (Type AlexPosn))
[Arg AlexPosn]
[SortArg AlexPosn]
(Maybe [SortArg AlexPosn])
(Declaration AlexPosn)
(Fixity AlexPosn)
String
[String]
(StackFunction AlexPosn)
[Declaration AlexPosn]
(Declaration AlexPosn)
(DataSortLeaf AlexPosn)
[DataSortLeaf AlexPosn]
(Declaration AlexPosn)
(Declaration AlexPosn)
(Declaration AlexPosn))
Actual type: HappyStk
(HappyAbsSyn
(ATS AlexPosn)
[Declaration AlexPosn]
[Type AlexPosn]
[Type AlexPosn]
(Type AlexPosn)
[Arg AlexPosn]
[Arg AlexPosn]
(Arg AlexPosn)
(Arg AlexPosn)
(Expression AlexPosn)
[Pattern AlexPosn]
(Pattern AlexPosn)
[(Pattern AlexPosn, LambdaType AlexPosn, Expression AlexPosn)]
[(Expression AlexPosn, LambdaType AlexPosn, Expression AlexPosn)]
(Maybe [Expression AlexPosn], [Expression AlexPosn])
[Expression AlexPosn]
[Expression AlexPosn]
(LambdaType AlexPosn)
(LambdaType AlexPosn)
(Expression AlexPosn)
[Type AlexPosn]
(Expression AlexPosn)
[StaticExpression AlexPosn]
[Declaration AlexPosn]
(StaticExpression AlexPosn)
(Expression AlexPosn)
(AlexPosn, StaticExpression AlexPosn)
(Sort AlexPosn)
[String]
(Existential AlexPosn)
[StaticExpression AlexPosn]
(Universal AlexPosn)
[[Type AlexPosn]]
[[Type AlexPosn]]
(Either (StaticExpression AlexPosn) (Expression AlexPosn))
(Implementation AlexPosn)
(Implementation AlexPosn)
(Name AlexPosn)
(Name AlexPosn)
[(String, Expression AlexPosn)]
[(String, Type AlexPosn)]
[String]
(Maybe (Type AlexPosn))
[StaticExpression AlexPosn]
(Leaf AlexPosn)
[Leaf AlexPosn]
[Universal AlexPosn]
(Maybe (StaticExpression AlexPosn))
(UnOp AlexPosn)
(BinOp AlexPosn)
(Maybe (String, Type AlexPosn) -> (b0, b0) -> b0)
(DataPropLeaf AlexPosn)
[DataPropLeaf AlexPosn]
String
(Maybe (String, Type AlexPosn))
(PreFunction AlexPosn)
(Declaration AlexPosn)
(Declaration AlexPosn)
(Declaration AlexPosn)
[Declaration AlexPosn]
String
(Maybe (Type AlexPosn))
[Arg AlexPosn]
[SortArg AlexPosn]
(Maybe [SortArg AlexPosn])
(Declaration AlexPosn)
(Fixity AlexPosn)
String
[String]
(StackFunction AlexPosn)
[Declaration AlexPosn]
(Declaration AlexPosn)
(DataSortLeaf AlexPosn)
[DataSortLeaf AlexPosn]
(Declaration AlexPosn)
(Declaration AlexPosn)
(Declaration AlexPosn))
-> HappyStk
(HappyAbsSyn
(ATS AlexPosn)
[Declaration AlexPosn]
[Type AlexPosn]
[Type AlexPosn]
(Type AlexPosn)
[Arg AlexPosn]
[Arg AlexPosn]
(Arg AlexPosn)
(Arg AlexPosn)
(Expression AlexPosn)
[Pattern AlexPosn]
(Pattern AlexPosn)
[(Pattern AlexPosn, LambdaType AlexPosn, Expression AlexPosn)]
[(Expression AlexPosn, LambdaType AlexPosn, Expression AlexPosn)]
(Maybe [Expression AlexPosn], [Expression AlexPosn])
[Expression AlexPosn]
[Expression AlexPosn]
(LambdaType AlexPosn)
(LambdaType AlexPosn)
(Expression AlexPosn)
[Type AlexPosn]
(Expression AlexPosn)
[StaticExpression AlexPosn]
[Declaration AlexPosn]
(StaticExpression AlexPosn)
(Expression AlexPosn)
(AlexPosn, StaticExpression AlexPosn)
(Sort AlexPosn)
[String]
(Existential AlexPosn)
[StaticExpression AlexPosn]
(Universal AlexPosn)
[[Type AlexPosn]]
[[Type AlexPosn]]
(Either (StaticExpression AlexPosn) (Expression AlexPosn))
(Implementation AlexPosn)
(Implementation AlexPosn)
(Name AlexPosn)
(Name AlexPosn)
[(String, Expression AlexPosn)]
[(String, Type AlexPosn)]
[String]
(Maybe (Type AlexPosn))
[StaticExpression AlexPosn]
(Leaf AlexPosn)
[Leaf AlexPosn]
[Universal AlexPosn]
(Maybe (StaticExpression AlexPosn))
(UnOp AlexPosn)
(BinOp AlexPosn)
(Maybe (String, Type AlexPosn) -> (b0, b0) -> b0)
(DataPropLeaf AlexPosn)
[DataPropLeaf AlexPosn]
String
(Maybe (String, Type AlexPosn))
(PreFunction AlexPosn)
(Declaration AlexPosn)
(Declaration AlexPosn)
(Declaration AlexPosn)
[Declaration AlexPosn]
String
(Maybe (Type AlexPosn))
[Arg AlexPosn]
[SortArg AlexPosn]
(Maybe [SortArg AlexPosn])
(Declaration AlexPosn)
(Fixity AlexPosn)
String
[String]
(StackFunction AlexPosn)
[Declaration AlexPosn]
(Declaration AlexPosn)
(DataSortLeaf AlexPosn)
[DataSortLeaf AlexPosn]
(Declaration AlexPosn)
(Declaration AlexPosn)
(Declaration AlexPosn))
• In the third argument of ‘happyReduce’, namely
‘happyReduction_340’
In the expression: happyReduce 6# 55# happyReduction_340
In an equation for ‘happyReduce_340’:
happyReduce_340 = happyReduce 6# 55# happyReduction_340
|
4832 | happyReduce_340 = happyReduce 6# 55# happyReduction_340
| ^^^^^^^^^^^^^^^^^^
/home/vanessa/programming/haskell/done/ats/dist-newstyle/build/x86_64-linux/ghc-8.2.2/language-ats-1.0.1.0/opt/build/Language/ATS/Parser.hs:4845:38: error:
• Couldn't match expected type ‘Maybe String’
with actual type ‘Bool’
• In the second argument of ‘PreF’, namely
‘(fst < happy_var_6 happy_var_5)’
In the first argument of ‘happyIn59’, namely
‘((PreF
happy_var_1
(fst < happy_var_6 happy_var_5)
[]
[]
happy_var_3
(snd < happy_var_6 happy_var_5)
Nothing
happy_var_6))’
In the first argument of ‘HappyStk’, namely
‘happyIn59
((PreF
happy_var_1
(fst < happy_var_6 happy_var_5)
[]
[]
happy_var_3
(snd < happy_var_6 happy_var_5)
Nothing
happy_var_6))’
|
4845 | ((PreF happy_var_1 (fst <happy_var_6 happy_var_5) [] [] happy_var_3 (snd <happy_var_6 happy_var_5) Nothing happy_var_6)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/home/vanessa/programming/haskell/done/ats/dist-newstyle/build/x86_64-linux/ghc-8.2.2/language-ats-1.0.1.0/opt/build/Language/ATS/Parser.hs:4845:87: error:
• Couldn't match expected type ‘Maybe (Type a)’
with actual type ‘Bool’
• In the sixth argument of ‘PreF’, namely
‘(snd < happy_var_6 happy_var_5)’
In the first argument of ‘happyIn59’, namely
‘((PreF
happy_var_1
(fst < happy_var_6 happy_var_5)
[]
[]
happy_var_3
(snd < happy_var_6 happy_var_5)
Nothing
happy_var_6))’
In the first argument of ‘HappyStk’, namely
‘happyIn59
((PreF
happy_var_1
(fst < happy_var_6 happy_var_5)
[]
[]
happy_var_3
(snd < happy_var_6 happy_var_5)
Nothing
happy_var_6))’
• Relevant bindings include
happy_var_3 :: [Arg a]
(bound at /home/vanessa/programming/haskell/done/ats/dist-newstyle/build/x86_64-linux/ghc-8.2.2/language-ats-1.0.1.0/opt/build/Language/ATS/Parser.hs:4841:39)
happy_var_1 :: Name a
(bound at /home/vanessa/programming/haskell/done/ats/dist-newstyle/build/x86_64-linux/ghc-8.2.2/language-ats-1.0.1.0/opt/build/Language/ATS/Parser.hs:4840:43)
happyRest :: HappyStk
(HappyAbsSyn
t4
t5
t6
t7
t8
[Arg a]
t10
t11
t12
t13
t14
t15
t16
t17
t18
t19
t20
t21
t22
t23
t24
t25
t26
t27
t28
t29
t30
t31
t32
t33
t34
t35
t36
t37
t38
t39
t40
(Name a)
t42
t43
t44
t45
t46
t47
t48
t49
t50
t51
t52
t53
(t58 -> (b, b) -> b)
t55
t56
t57
t58
(PreFunction a)
t60
t61
t62
t63
t64
t65
t66
t67
t68
t69
t70
t71
t72
t73
t74
t75
t76
t77
t78
t79
t80)
(bound at /home/vanessa/programming/haskell/done/ats/dist-newstyle/build/x86_64-linux/ghc-8.2.2/language-ats-1.0.1.0/opt/build/Language/ATS/Parser.hs:4839:9)
happy_x_1 :: HappyAbsSyn
t4
t5
t6
t7
t8
[Arg a]
t10
t11
t12
t13
t14
t15
t16
t17
t18
t19
t20
t21
t22
t23
t24
t25
t26
t27
t28
t29
t30
t31
t32
t33
t34
t35
t36
t37
t38
t39
t40
(Name a)
t42
t43
t44
t45
t46
t47
t48
t49
t50
t51
t52
t53
(t58 -> (b, b) -> b)
t55
t56
t57
t58
(PreFunction a)
t60
t61
t62
t63
t64
t65
t66
t67
t68
t69
t70
t71
t72
t73
t74
t75
t76
t77
t78
t79
t80
(bound at /home/vanessa/programming/haskell/done/ats/dist-newstyle/build/x86_64-linux/ghc-8.2.2/language-ats-1.0.1.0/opt/build/Language/ATS/Parser.hs:4838:9)
happy_x_2 :: HappyAbsSyn
t4
t5
t6
t7
t8
[Arg a]
t10
t11
t12
t13
t14
t15
t16
t17
t18
t19
t20
t21
t22
t23
t24
t25
t26
t27
t28
t29
t30
t31
t32
t33
t34
t35
t36
t37
t38
t39
t40
(Name a)
t42
t43
t44
t45
t46
t47
t48
t49
t50
t51
t52
t53
(t58 -> (b, b) -> b)
t55
t56
t57
t58
(PreFunction a)
t60
t61
t62
t63
t64
t65
t66
t67
t68
t69
t70
t71
t72
t73
t74
t75
t76
t77
t78
t79
t80
(bound at /home/vanessa/programming/haskell/done/ats/dist-newstyle/build/x86_64-linux/ghc-8.2.2/language-ats-1.0.1.0/opt/build/Language/ATS/Parser.hs:4837:9)
happy_x_3 :: HappyAbsSyn
t4
t5
t6
t7
t8
[Arg a]
t10
t11
t12
t13
t14
t15
t16
t17
t18
t19
t20
t21
t22
t23
t24
t25
t26
t27
t28
t29
t30
t31
t32
t33
t34
t35
t36
t37
t38
t39
t40
(Name a)
t42
t43
t44
t45
t46
t47
t48
t49
t50
t51
t52
t53
(t58 -> (b, b) -> b)
t55
t56
t57
t58
(PreFunction a)
t60
t61
t62
t63
t64
t65
t66
t67
t68
t69
t70
t71
t72
t73
t74
t75
t76
t77
t78
t79
t80
(bound at /home/vanessa/programming/haskell/done/ats/dist-newstyle/build/x86_64-linux/ghc-8.2.2/language-ats-1.0.1.0/opt/build/Language/ATS/Parser.hs:4836:9)
(Some bindings suppressed; use -fmax-relevant-binds=N or -fno-max-relevant-binds)
|
4845 | ((PreF happy_var_1 (fst <happy_var_6 happy_var_5) [] [] happy_var_3 (snd <happy_var_6 happy_var_5) Nothing happy_var_6)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/home/vanessa/programming/haskell/done/ats/dist-newstyle/build/x86_64-linux/ghc-8.2.2/language-ats-1.0.1.0/opt/build/Language/ATS/Parser.hs:4845:125: error:
• Couldn't match expected type ‘Maybe (Expression a)’
with actual type ‘t58 -> (b, b) -> b’
• Probable cause: ‘happy_var_6’ is applied to too few arguments
In the 8th argument of ‘PreF’, namely ‘happy_var_6’
In the first argument of ‘happyIn59’, namely
‘((PreF
happy_var_1
(fst < happy_var_6 happy_var_5)
[]
[]
happy_var_3
(snd < happy_var_6 happy_var_5)
Nothing
happy_var_6))’
In the first argument of ‘HappyStk’, namely
‘happyIn59
((PreF
happy_var_1
(fst < happy_var_6 happy_var_5)
[]
[]
happy_var_3
(snd < happy_var_6 happy_var_5)
Nothing
happy_var_6))’
• Relevant bindings include
happy_var_6 :: t58 -> (b, b) -> b
(bound at /home/vanessa/programming/haskell/done/ats/dist-newstyle/build/x86_64-linux/ghc-8.2.2/language-ats-1.0.1.0/opt/build/Language/ATS/Parser.hs:4843:40)
happy_var_5 :: t58
(bound at /home/vanessa/programming/haskell/done/ats/dist-newstyle/build/x86_64-linux/ghc-8.2.2/language-ats-1.0.1.0/opt/build/Language/ATS/Parser.hs:4842:40)
happy_var_3 :: [Arg a]
(bound at /home/vanessa/programming/haskell/done/ats/dist-newstyle/build/x86_64-linux/ghc-8.2.2/language-ats-1.0.1.0/opt/build/Language/ATS/Parser.hs:4841:39)
happy_var_1 :: Name a
(bound at /home/vanessa/programming/haskell/done/ats/dist-newstyle/build/x86_64-linux/ghc-8.2.2/language-ats-1.0.1.0/opt/build/Language/ATS/Parser.hs:4840:43)
happyRest :: HappyStk
(HappyAbsSyn
t4
t5
t6
t7
t8
[Arg a]
t10
t11
t12
t13
t14
t15
t16
t17
t18
t19
t20
t21
t22
t23
t24
t25
t26
t27
t28
t29
t30
t31
t32
t33
t34
t35
t36
t37
t38
t39
t40
(Name a)
t42
t43
t44
t45
t46
t47
t48
t49
t50
t51
t52
t53
(t58 -> (b, b) -> b)
t55
t56
t57
t58
(PreFunction a)
t60
t61
t62
t63
t64
t65
t66
t67
t68
t69
t70
t71
t72
t73
t74
t75
t76
t77
t78
t79
t80)
(bound at /home/vanessa/programming/haskell/done/ats/dist-newstyle/build/x86_64-linux/ghc-8.2.2/language-ats-1.0.1.0/opt/build/Language/ATS/Parser.hs:4839:9)
happy_x_1 :: HappyAbsSyn
t4
t5
t6
t7
t8
[Arg a]
t10
t11
t12
t13
t14
t15
t16
t17
t18
t19
t20
t21
t22
t23
t24
t25
t26
t27
t28
t29
t30
t31
t32
t33
t34
t35
t36
t37
t38
t39
t40
(Name a)
t42
t43
t44
t45
t46
t47
t48
t49
t50
t51
t52
t53
(t58 -> (b, b) -> b)
t55
t56
t57
t58
(PreFunction a)
t60
t61
t62
t63
t64
t65
t66
t67
t68
t69
t70
t71
t72
t73
t74
t75
t76
t77
t78
t79
t80
(bound at /home/vanessa/programming/haskell/done/ats/dist-newstyle/build/x86_64-linux/ghc-8.2.2/language-ats-1.0.1.0/opt/build/Language/ATS/Parser.hs:4838:9)
(Some bindings suppressed; use -fmax-relevant-binds=N or -fno-max-relevant-binds)
|
4845 | ((PreF happy_var_1 (fst <happy_var_6 happy_var_5) [] [] happy_var_3 (snd <happy_var_6 happy_var_5) Nothing happy_var_6)
| ^^^^^^^^^^^
I didn't see anything in the manual indicating that this would not be allowed. I think it would be nice to have happy
return some sort of error message before GHC does - the one I ran into was not particularly user-friendly.
Thanks!
The error is fairly trivial:
Setup.lhs:12:21: Module `Data.Monoid' does not export `(<>)'
A complete build log is at http://hydra.cryp.to/build/32311/nixlog/12/raw.
It might be worthwhile to fix that in a new release ...
Originally reported here. If, as Happy's documentation indicates, all command-line flags are optional, there should be an inverse of every flag so that later flags override earlier ones.
I've been running across what I think is the same bug several times in the last couple of months while working on a pretty big grammar. Here are some more extreme things I've witnessed that seem to indicate the code generated is incorrect:
I've made a branch here which is as reduced an example as I've managed to get. There is one test suite included which has exactly one test case. Right now, I think the code generated by Happy (1.19.5 and HEAD) is incorrect (the test should pass). However, commenting out the pat_slice
production (which is used nowhere) makes the test pass again. In fact, as I've tried to reduce this grammar over the past weeks, I'm now finding it difficult to comment out anything without the test passing again.
I realize this is a huge test case, but I am at a complete loss at what to do to reduce the grammar since doing so seems to remove the bug.
This causes failure (on newer GHC it's a warning, not an error):
src/PrettyGrammar.hs:3:24: Module `Prelude' does not export `(<>)'
EDIT I made a revision on Hackage: https://hackage.haskell.org/package/happy-1.19.9/revisions/
I can install happy in Windows 10 x86_64, and I can install other packages like Shake in Windows 10 x86, however when I try to install happy in Windows 10 x86, I get a strange error.
PS C:\> choco install -force -y ghc
PS C:> $cabalPath = "C:\Users\vagrant\Application Data\cabal\bin;C:\Users\All Users\chocolatey\lib\cabal\tools\x86"
PS C:\> $env:PATH += ";$cabalPath"
PS C:\> $userPath = (Get-ItemProperty "Registry::HKEY_CURRENT_USER\Environment").PATH
PS C:\> Set-ItemProperty -Path "Registry::HKEY_CURRENT_USER\Environment" -Name PATH -Value "$userPath;$cabalPath"
PS C:\> cabal install -v happy
"C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\lib/../mingw/bin\gcc.exe" "-dumpversion"
looking for tool haddock near compiler in
C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\bin
found haddock in
C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\bin\haddock.exe
"C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\bin\haddock.exe" "--version"
looking for tool hpc near compiler in
C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\bin
found hpc in C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\bin\hpc.exe
"C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\bin\hpc.exe" "version"
looking for tool hsc2hs near compiler in
C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\bin
found hsc2hs in
C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\bin\hsc2hs.exe
"C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\bin\hsc2hs.exe" "--version"
"C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\bin\ghc.exe" "-hide-all-packages" "-c" "C:\Users\v
agrant\AppData\Local\Temp\6540-0.c" "-o" "C:\Users\vagrant\AppData\Local\Temp\6540-1.o"
"C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\lib/../mingw/bin\ld.exe" "-x" "-r" "C:\Users\vagra
nt\AppData\Local\Temp\6540-1.o" "-o" "C:\Users\vagrant\AppData\Local\Temp\6540-2.o"
looking for tool runghc near compiler in
C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\bin
found runghc in
C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\bin\runghc.exe
"C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\bin\runghc.exe" "--version"
"C:\Program Files\Git\usr\bin\tar.exe" "--help"
Reading available packages of hackage.haskell.org...
Using most recent state specified from most recent cabal update
index-state(hackage.haskell.org) = 2018-05-17T01:00:29Z
Failed to query pkg-config, Cabal will continue without solving for pkg-config
constraints: dieVerbatim: user error (CallStack (from HasCallStack):
die', called at .\Distribution\Simple\Program\Db.hs:423:28 in
Cabal-2.2.0.1-498b1ffb97317cbfc8432b5b6c862cebeca566be:Distribution.Simple.Program.Db
requireProgram, called at .\Distribution\Solver\Types\PkgConfigDb.hs:65:21 in
main:Distribution.Solver.Types.PkgConfigDb
cabal: The program 'pkg-config' is required but it could not be found.
)
Resolving dependencies...
Number of threads used: 2.
Extracting
C:\Users\vagrant\AppData\Roaming\cabal\packages\hackage.haskell.org\happy\1.19.9\happy-1.19.9.tar.gz
to C:\Users\vagrant\AppData\Local\Temp\cabal-tmp-6540...
Updating happy.cabal with the latest revision from the index.
Configuring happy-1.19.9...
creating
C:\Users\vagrant\AppData\Local\Temp\cabal-tmp-6540\happy-1.19.9\dist\setup
creating C:\Users\vagrant\AppData\Local\Temp\cabal-tmp-6540\happy-1.19.9\dist
creating
C:\Users\vagrant\AppData\Local\Temp\cabal-tmp-6540\happy-1.19.9\dist\setup
"C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\bin\ghc.exe" "--make" "-fbuilding-cabal-package" "
-odir" "C:\Users\vagrant\AppData\Local\Temp\cabal-tmp-6540\happy-1.19.9\dist\setup" "-hidir" "C:\User
s\vagrant\AppData\Local\Temp\cabal-tmp-6540\happy-1.19.9\dist\setup" "-i" "-iC:\Users\vagrant\AppData
\Local\Temp\cabal-tmp-6540\happy-1.19.9" "-optP-include" "-optPC:\Users\vagrant\AppData\Local\Temp\ca
bal-tmp-6540\happy-1.19.9\dist\setup\setup_macros.h" "-hide-all-packages" "-package-id" "Cabal-2.2.0.
1" "-package-id" "base-4.11.1.0" "-package-id" "directory-1.3.1.5" "-package-id" "filepath-1.4.2" "C:
\Users\vagrant\AppData\Local\Temp\cabal-tmp-6540\happy-1.19.9\dist\setup\setup.hs" "-o" "C:\Users\vag
rant\AppData\Local\Temp\cabal-tmp-6540\happy-1.19.9\dist\setup\setup.exe" "-threaded"
C:\Users\vagrant\AppData\Local\Temp\cabal-tmp-6540\happy-1.19.9\dist\setup\setup.exe
configure --verbose=2 --builddir=dist --ghc
--prefix=C:\Users\vagrant\AppData\Roaming\cabal
--bindir=C:\Users\vagrant\AppData\Roaming\cabal\bin
--libdir=C:\Users\vagrant\AppData\Roaming\cabal
--libsubdir=i386-windows-ghc-8.4.2\happy-1.19.9-KeeVHae3CJkAYnWGzas02f
--dynlibdir=C:\Users\vagrant\AppData\Roaming\cabal\i386-windows-ghc-8.4.2
--libexecdir=C:\Users\vagrant\AppData\Roaming\cabal\happy-1.19.9-KeeVHae3CJkAYnWGzas02f
--libexecsubdir=i386-windows-ghc-8.4.2\happy-1.19.9
--datadir=C:\Users\vagrant\AppData\Roaming\cabal
--datasubdir=i386-windows-ghc-8.4.2\happy-1.19.9
--docdir=C:\Users\vagrant\AppData\Roaming\cabal\doc\i386-windows-ghc-8.4.2\happy-1.19.9
--htmldir=C:\Users\vagrant\AppData\Roaming\cabal\doc\i386-windows-ghc-8.4.2\happy-1.19.9\html
--haddockdir=C:\Users\vagrant\AppData\Roaming\cabal\doc\i386-windows-ghc-8.4.2\happy-1.19.9\html
--sysconfdir=C:\Users\vagrant\AppData\Roaming\cabal\etc --user
--flags=small_base --ipid=happy-1.19.9-KeeVHae3CJkAYnWGzas02f
--extra-prog-path=C:\Users\vagrant\AppData\Roaming\cabal\bin
--dependency=array=array-0.5.2.0 --dependency=base=base-4.11.1.0
--dependency=containers=containers-0.5.11.0 --dependency=mtl=mtl-2.2.2
--disable-tests --exact-configuration --disable-benchmarks
Redirecting build log to {handle:
C:\Users\vagrant\AppData\Roaming\cabal\logs\ghc-8.4.2\happy-1.19.9-KeeVHae3CJkAYnWGzas02f.log}
Building happy-1.19.9...
creating
C:\Users\vagrant\AppData\Local\Temp\cabal-tmp-6540\happy-1.19.9\dist\setup
"C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\bin\ghc.exe" "--make" "-fbuilding-cabal-package" "
-odir" "C:\Users\vagrant\AppData\Local\Temp\cabal-tmp-6540\happy-1.19.9\dist\setup" "-hidir" "C:\User
s\vagrant\AppData\Local\Temp\cabal-tmp-6540\happy-1.19.9\dist\setup" "-i" "-iC:\Users\vagrant\AppData
\Local\Temp\cabal-tmp-6540\happy-1.19.9" "-optP-include" "-optPC:\Users\vagrant\AppData\Local\Temp\ca
bal-tmp-6540\happy-1.19.9\dist\setup\setup_macros.h" "-hide-all-packages" "-package-id" "Cabal-2.2.0.
1" "-package-id" "base-4.11.1.0" "-package-id" "directory-1.3.1.5" "-package-id" "filepath-1.4.2" "C:
\Users\vagrant\AppData\Local\Temp\cabal-tmp-6540\happy-1.19.9\dist\setup\setup.hs" "-o" "C:\Users\vag
rant\AppData\Local\Temp\cabal-tmp-6540\happy-1.19.9\dist\setup\setup.exe" "-threaded"
C:\Users\vagrant\AppData\Local\Temp\cabal-tmp-6540\happy-1.19.9\dist\setup\setup.exe
build --verbose=2 --builddir=dist
Redirecting build log to {handle:
C:\Users\vagrant\AppData\Roaming\cabal\logs\ghc-8.4.2\happy-1.19.9-KeeVHae3CJkAYnWGzas02f.log}
Failed to install happy-1.19.9
Build log ( C:\Users\vagrant\AppData\Roaming\cabal\logs\ghc-8.4.2\happy-1.19.9-KeeVHae3CJkAYnWGzas02f
.log ):
Component build order: executable 'happy'
"C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\bin\ghc-pkg.exe" "init" "dist\package.conf.inplace
"
\AppData\Local\Temp\cabal-tmp-6540\happy-1.19.9\dist\setup\setup.hs, C:\Users\vagrant\AppData\Local\T
emp\cabal-tmp-6540\happy-1.19.9\dist\setup\Main.o )
Linking C:\Users\vagrant\AppData\Local\Temp\cabal-tmp-6540\happy-1.19.9\dist\setup\setup.exe ...
Using Parsec parser
Warning: happy.cabal:25:2: Tabs used as indentation at 25:2, 26:2, 27:2, 28:2,
29:2, 30:2, 31:2, 32:2, 33:2, 34:2, 35:2, 36:2, 37:2, 38:2, 39:2, 40:2, 41:2,
42:2, 43:2, 44:2, 45:2, 46:2, 47:2, 48:2, 49:2, 50:2, 51:2, 52:2, 53:2, 54:2,
55:2, 56:2, 57:2, 58:2, 59:2, 60:2, 61:2, 62:2, 63:2, 64:2, 65:2, 66:2, 67:2,
68:2, 69:2, 70:2, 71:2, 72:2, 73:2, 74:2, 75:2, 76:2, 77:2, 78:2, 79:2, 80:2,
81:2, 82:2, 83:2, 84:2, 85:2, 86:2, 87:2, 88:2, 89:2, 90:2, 91:2, 92:2, 93:2,
94:2, 95:2, 96:2, 97:2, 98:2, 99:2, 100:2, 101:2, 102:2, 103:2, 104:2, 105:2,
106:2, 107:2, 108:2, 109:2, 110:2, 111:2, 112:2, 113:2, 114:2, 115:2, 116:2,
117:2, 118:2, 119:2, 120:2, 121:2, 122:2
Configuring happy-1.19.9...
Flags chosen: small_base=True
Dependency array ==0.5.2.0: using array-0.5.2.0
Dependency base ==4.11.1.0: using base-4.11.1.0
Dependency containers ==0.5.11.0: using containers-0.5.11.0
Dependency mtl ==2.2.2: using mtl-2.2.2
Source component graph: component exe:happy
Configured component graph:
component happy-1.19.9-KeeVHae3CJkAYnWGzas02f-happy
include base-4.11.1.0
include array-0.5.2.0
include containers-0.5.11.0
include mtl-2.2.2
Linked component graph:
unit happy-1.19.9-KeeVHae3CJkAYnWGzas02f-happy
include base-4.11.1.0
include array-0.5.2.0
include containers-0.5.11.0
include mtl-2.2.2
Ready component graph:
definite happy-1.19.9-KeeVHae3CJkAYnWGzas02f-happy
depends base-4.11.1.0
depends array-0.5.2.0
depends containers-0.5.11.0
depends mtl-2.2.2
Using Cabal-2.2.0.1 compiled by ghc-8.4
Using compiler: ghc-8.4.2
Using install prefix: C:\Users\vagrant\AppData\Roaming\cabal
Executables installed in: C:\Users\vagrant\AppData\Roaming\cabal\bin (fixed
location)
Libraries installed in:
C:\Users\vagrant\AppData\Roaming\cabal\i386-windows-ghc-8.4.2\happy-1.19.9-KeeVHae3CJkAYnWGzas02f
(fixed location)
Dynamic Libraries installed in:
C:\Users\vagrant\AppData\Roaming\cabal\i386-windows-ghc-8.4.2 (fixed location)
Private executables installed in:
C:\Users\vagrant\AppData\Roaming\cabal\happy-1.19.9-KeeVHae3CJkAYnWGzas02f\i386-windows-ghc-8.4.2\hap
py-1.19.9
(fixed location)
Data files installed in:
C:\Users\vagrant\AppData\Roaming\cabal\i386-windows-ghc-8.4.2\happy-1.19.9
(fixed location)
Documentation installed in:
C:\Users\vagrant\AppData\Roaming\cabal\doc\i386-windows-ghc-8.4.2\happy-1.19.9
(fixed location)
Configuration files installed in: C:\Users\vagrant\AppData\Roaming\cabal\etc
(fixed location)
No alex found
Using ar found on system at:
C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\lib/../mingw/bin\ar.exe
No c2hs found
No cpphs found
No doctest found
Using gcc version 7.2.0 found on system at:
C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\lib/../mingw/bin\gcc.exe
Using ghc version 8.4.2 found on system at:
C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\bin\ghc.exe
Using ghc-pkg version 8.4.2 found on system at:
C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\bin\ghc-pkg.exe
No ghcjs found
No ghcjs-pkg found
No greencard found
Using haddock version 2.20.0 found on system at:
C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\bin\haddock.exe
No happy found
Using haskell-suite found on system at: haskell-suite-dummy-location
Using haskell-suite-pkg found on system at: haskell-suite-pkg-dummy-location
No hmake found
Using hpc version 0.67 found on system at:
C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\bin\hpc.exe
Using hsc2hs version 0.68.3 found on system at:
C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\bin\hsc2hs.exe
No hscolour found
No jhc found
Using ld found on system at:
C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\lib/../mingw/bin\ld.exe
No lhc found
No lhc-pkg found
No pkg-config found
Using runghc version 8.4.2 found on system at:
C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\bin\runghc.exe
Using strip version 2.29 found on system at:
C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.4.2\mingw\bin\strip.exe
Using tar found on system at: C:\Program Files\Git\usr\bin\tar.exe
No uhc found
cabal: Leaving directory 'C:\Users\vagrant\AppData\Local\Temp\cabal-tmp-6540\happy-1.19.9'
World file is already up to date.
CallStack (from HasCallStack):
die', called at .\Distribution\Client\Install.hs:993:15 in main:Distribution.Client.Install
cabal: Error: some packages failed to install:
happy-1.19.9-KeeVHae3CJkAYnWGzas02f failed during the building phase. The
exception was:
ExitFailure (-1073741819)
I get this log:
$ cabal --verbose=3 build
Using external setup method with build-type Custom
creating dist\setup
Using Cabal library version 1.20.0.2
.\dist\setup\setup.exe build --verbose=3 --builddir=dist --jobs=1
Component build order: executable 'happy', test suite 'tests'
creating dist\build
creating dist\build\autogen
Building happy-1.19.4...
Preprocessing executable 'happy' for happy-1.19.4...
creating dist\build\happy\happy-tmp
setup.exe: The program 'happy' is required but it could not be found
$
... what, happy
is required to build happy the package? Reads like nonsense; this does not look like a package which bootstraps.
I unfortunately don't have on hand the grammar that let me trigger this bug (although I'll try to produce one later today or tomorrow). That said, I think it is pretty straightforward to understand the problem. The code template for happyMonad2Reduce
is here:
happyMonad2Reduce k nt fn ERROR_TOK tk st sts stk
= happyFail [] ERROR_TOK tk st sts stk
happyMonad2Reduce k nt fn j tk st sts stk =
case happyDrop k CONS(st,sts) of
sts1@(CONS(st1@HAPPYSTATE(action),_)) ->
let drop_stk = happyDropStk k stk
#if defined(HAPPY_ARRAY)
off = indexShortOffAddr happyGotoOffsets st1
off_i = PLUS(off,nt)
new_state = indexShortOffAddr happyTable off_i
#else
new_state = action
#endif
in
happyThen1 (fn stk tk) (\r -> happyNewToken new_state sts1 (r `HappyStk` drop_stk))
When -a
is not present, that reduces to the following:
happyMonad2Reduce k nt fn ERROR_TOK tk st sts stk
= happyFail [] ERROR_TOK tk st sts stk
happyMonad2Reduce k nt fn j tk st sts stk =
case happyDrop k CONS(st,sts) of
sts1@(CONS(st1@HAPPYSTATE(action),_)) ->
let drop_stk = happyDropStk k tsk
new_state = action
in
happyThen1 (fn stk tk) (\r -> happyNewToken new_state sts1 (r `HappyStk` drop_stk))
In this last snippet, the nt
argument is not used at all. In particular, GHC infers (as it always does) that nt
has a lifted type. In this case, however, nt :: Int#
, leading to a kind compilation error in the generated code.
This should be an easy bug to fix, but I'm not sure if you would prefer to fix it by adding a type signature to happyMonad2Reduce
as a whole or just some sort of type annotation on nt
in the non-array case.
There exists an easy workaround in the meantime: use -a
.
Happy says that it compiles with any version of mtl >=1
, but in fact it needs a version that includes Control.Monad.Except
, which exists only in mtl-2.2.1
(the latest version).
Since version 1.19.5 happy now add type signatures to the generated parser source file. These signatures can be too general and introduce type-errors into previous accepted parsers.
I haven't pinned down what specifically is triggering this bug, but you can reproduce it by trying to build cryptol-2.5.0
Cryptol makes use of the parameterized rules in happy, I'm going to explore if using these leads to the bug surfacing.
In the meantime, is there a flag I can use to disable these new type signatures?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.