Skip to content

Commit c5e3f6c

Browse files
committed
New package happy-lib; make previous happy-* packages sublibraries (#288)
This is one design design discussed in #288. Fixes #288.
1 parent 48d3480 commit c5e3f6c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+219
-30
lines changed
File renamed without changes.

cabal.project

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
packages:
2-
packages/*/happy-*.cabal
3-
./
2+
happy.cabal
3+
lib/happy-lib.cabal

happy.cabal

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ tested-with:
3131
GHC == 8.4.4
3232
GHC == 8.2.2
3333
GHC == 8.0.2
34-
-- GHC == 7.10.3
35-
-- GHC == 7.8.4
36-
-- GHC == 7.6.3
37-
-- GHC == 7.4.2
38-
-- GHC == 7.0.4
3934

4035
extra-source-files:
4136
ChangeLog.md
@@ -137,18 +132,14 @@ source-repository head
137132
location: https://github.com/haskell/happy.git
138133

139134
executable happy
140-
hs-source-dirs: src
135+
hs-source-dirs: app
141136
main-is: Main.lhs
142137

143138
build-depends: base >= 4.9 && < 5,
144139
array,
145140
containers >= 0.4.2,
146141
mtl >= 2.2.1,
147-
happy-grammar == 2.0,
148-
happy-tabular == 2.0,
149-
happy-frontend == 2.0,
150-
happy-backend-lalr == 2.0,
151-
happy-backend-glr == 2.0
142+
happy-lib == 2.0
152143

153144
default-language: Haskell98
154145
default-extensions: CPP, MagicHash, FlexibleContexts, NamedFieldPuns

lib/ChangeLog.md

Lines changed: 1 addition & 0 deletions

lib/README.md

Lines changed: 1 addition & 0 deletions
File renamed without changes.
File renamed without changes.

packages/backend-glr/happy-backend-glr.cabal renamed to lib/backend-glr/happy-backend-glr.cabal

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@ synopsis: A GLR backend for happy
1515

1616
Description:
1717
Happy is a parser generator for Haskell.
18-
Happy-Backend-GLR is a backend which creates
19-
GLR-based Haskell code.
18+
This library translates the LR action and goto tables computed from a grammar
19+
description into table-driven GLR parsing code in Haskell.
20+
Ambiguous parses produce multiple parse trees.
2021

22+
The library happy-grammar defines the 'Grammar' AST type for grammar files.
23+
The library happy-frontend provides a parser for happy grammar files (.y) to
24+
produce a 'Grammar'.
25+
The library happy-tabular computes the LR action and goto tables for the
26+
given 'Grammar' and defines the data types representing said tables.
2127

2228
tested-with:
2329
GHC == 9.10.1
@@ -57,4 +63,4 @@ library
5763
default-language: Haskell98
5864
default-extensions: CPP, MagicHash, FlexibleContexts
5965
ghc-options: -Wall -Wincomplete-uni-patterns
60-
other-modules: Paths_happy_backend_glr
66+
other-modules: Paths_happy_lib
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Happy.Backend.GLR where
22

3-
import Paths_happy_backend_glr
3+
import Paths_happy_lib
44

55
glrBackendDataDir :: IO String
6-
glrBackendDataDir = getDataDir
6+
glrBackendDataDir = getDataDir

packages/backend-glr/src/Happy/Backend/GLR/ProduceCode.lhs renamed to lib/backend-glr/src/Happy/Backend/GLR/ProduceCode.lhs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This module is designed as an extension to the Haskell parser generator Happy.
1717
> , Options
1818
> ) where
1919

20-
> import Paths_happy_backend_glr ( version )
20+
> import Paths_happy_lib ( version )
2121
> import Happy.Grammar
2222
> import Happy.Tabular.LALR
2323
> import Data.Array ( Array, (!), array, assocs )
File renamed without changes.
File renamed without changes.

packages/backend-lalr/happy-backend-lalr.cabal renamed to lib/backend-lalr/happy-backend-lalr.cabal

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,17 @@ synopsis: A table-based backend for happy
1515

1616
Description:
1717
Happy is a parser generator for Haskell.
18-
Happy-Backend-LALR is responsible for code-generation:
19-
It converts action and goto tables into LALR Haskell code.
18+
This library translates LR action and goto tables computed from a grammar
19+
description into table-driven deterministic parsing code in Haskell.
20+
(Any shift/reduce conflicts are resolved in favour of shifting,
21+
while any reduce/reduce conflicts are resolved in favour of the rule with the
22+
lower number.)
2023

24+
The library happy-grammar defines the 'Grammar' AST type for grammar files.
25+
The library happy-frontend provides a parser for happy grammar files (.y) to
26+
produce a 'Grammar'.
27+
The library happy-tabular computes the LR action and goto tables for the
28+
given 'Grammar' and defines the data types representing said tables.
2129

2230
tested-with:
2331
GHC == 9.10.1
@@ -56,4 +64,4 @@ library
5664
default-language: Haskell98
5765
default-extensions: CPP, MagicHash, FlexibleContexts
5866
ghc-options: -Wall -Wincomplete-uni-patterns
59-
other-modules: Paths_happy_backend_lalr
67+
other-modules: Paths_happy_lib

packages/backend-lalr/src/Happy/Backend/LALR.hs renamed to lib/backend-lalr/src/Happy/Backend/LALR.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Happy.Backend.LALR where
22

3-
import Paths_happy_backend_lalr
3+
import Paths_happy_lib
44
import Data.Char
55

66
lalrBackendDataDir :: IO String

packages/backend-lalr/src/Happy/Backend/LALR/ProduceCode.lhs renamed to lib/backend-lalr/src/Happy/Backend/LALR/ProduceCode.lhs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The code generator.
66

77
> module Happy.Backend.LALR.ProduceCode (produceParser) where
88

9-
> import Paths_happy_backend_lalr ( version )
9+
> import Paths_happy_lib ( version )
1010
> import Data.Version ( showVersion )
1111
> import Happy.Grammar
1212
> import Happy.Tabular.LALR
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

packages/frontend/happy-frontend.cabal renamed to lib/frontend/happy-frontend.cabal

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@ synopsis: A yacc-like frontend for happy
1515

1616
Description:
1717
Happy is a parser generator for Haskell.
18-
Happy-Frontend is responsible for parsing .y- and .ly-files
19-
and mangling them into a Grammar datatype.
18+
This library provides a parser for happy grammar files (.y/.ly) to produce a
19+
'Grammar' AST type.
2020
These .y- and .ly-files work similar to yacc's .y-files, but
2121
have some Haskell-specific features.
2222

23+
The library happy-grammar defines the 'Grammar' AST type for grammar files.
24+
The library happy-tabular computes the LR action and goto tables for the
25+
given 'Grammar'.
26+
The library happy-backend-lalr defines functions to produce Haskell code
27+
for the LR action and goto tables.
28+
2329
tested-with:
2430
GHC == 9.10.1
2531
GHC == 9.8.2
File renamed without changes.
File renamed without changes.

packages/grammar/happy-grammar.cabal renamed to lib/grammar/happy-grammar.cabal

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ synopsis: happy's Grammar datatype
1515

1616
Description:
1717
Happy is a parser generator for Haskell.
18-
Happy-Grammar exposes the cross-package Grammar datatype,
18+
This library exposes the cross-package Grammar datatype,
1919
which represents a grammar as can be parsed and processed by happy.
2020

21+
The package happy-frontend provides a parser for happy grammar files (.y) to
22+
produce a 'Grammar'.
23+
2124
tested-with:
2225
GHC == 9.10.1
2326
GHC == 9.8.2

lib/happy-lib.cabal

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
cabal-version: 3.0
2+
name: happy-lib
3+
version: 2.0
4+
license: BSD-2-Clause
5+
copyright: (c) Andy Gill, Simon Marlow
6+
author: Andy Gill and Simon Marlow
7+
maintainer: https://github.com/haskell/happy
8+
bug-reports: https://github.com/haskell/happy/issues
9+
stability: stable
10+
homepage: https://www.haskell.org/happy/
11+
synopsis: Happy is a parser generator for Haskell implemented using this library
12+
category: Development
13+
build-type: Simple
14+
15+
Description:
16+
Happy is a parser generator for Haskell. Given a grammar
17+
specification in BNF, Happy generates Haskell code to parse the
18+
grammar. Happy works in a similar way to the @yacc@ tool for C.
19+
20+
This library provides the following functionality:
21+
22+
* Data type definitions for the Grammar AST type, capturing the information in .y-files (Happy.Grammar)
23+
24+
* A parser for happy grammar files (.y) to produce a Grammar (Happy.Frontend.*)
25+
26+
* Implementations of the text book algorithms that compute the LR action and
27+
goto tables for the given 'Grammar' (Happy.Tabular.*)
28+
29+
* An LALR code generator to produce table-driven, deterministic parsing code
30+
in Haskell (Happy.Backend.LALR.*)
31+
32+
* A (less maintained) GLR code generator to produce table-driven,
33+
non-deterministic parsing code in Haskell, where ambiguous parses produce
34+
multiple parse trees (Happy.Backend.GLR.*)
35+
36+
tested-with:
37+
GHC == 9.10.1
38+
GHC == 9.8.2
39+
GHC == 9.6.5
40+
GHC == 9.4.8
41+
GHC == 9.2.8
42+
GHC == 9.0.2
43+
GHC == 8.10.7
44+
GHC == 8.8.4
45+
GHC == 8.6.5
46+
GHC == 8.4.4
47+
GHC == 8.2.2
48+
GHC == 8.0.2
49+
50+
extra-source-files:
51+
ChangeLog.md
52+
README.md
53+
frontend/bootstrap.sh
54+
frontend/boot-src/Parser.ly
55+
frontend/boot-src/AttrGrammarParser.ly
56+
57+
data-dir: data
58+
59+
data-files:
60+
HappyTemplate.hs
61+
GLR_Base.hs
62+
GLR_Lib.hs
63+
64+
source-repository head
65+
type: git
66+
location: https://github.com/haskell/happy.git
67+
68+
library grammar
69+
hs-source-dirs: grammar/src
70+
71+
exposed-modules: Happy.Grammar
72+
build-depends: base, array
73+
74+
default-language: Haskell98
75+
default-extensions: CPP, MagicHash, FlexibleContexts
76+
ghc-options: -Wall
77+
other-modules:
78+
79+
library frontend
80+
hs-source-dirs: frontend/src
81+
exposed-modules: Happy.Frontend,
82+
Happy.Frontend.AbsSyn,
83+
Happy.Frontend.Mangler,
84+
Happy.Frontend.PrettyGrammar
85+
86+
build-depends: base, array, transformers, containers, mtl, happy-lib:grammar
87+
88+
default-language: Haskell98
89+
default-extensions: CPP, MagicHash, FlexibleContexts
90+
ghc-options: -Wall -Wno-incomplete-uni-patterns
91+
other-modules:
92+
Happy.Frontend.ParseMonad
93+
Happy.Frontend.ParseMonad.Class
94+
Happy.Frontend.Mangler.Monad
95+
Happy.Frontend.Parser
96+
Happy.Frontend.Lexer
97+
Happy.Frontend.ParamRules
98+
Happy.Frontend.AttrGrammar
99+
Happy.Frontend.AttrGrammar.Parser
100+
Happy.Frontend.AttrGrammar.Mangler
101+
102+
library tabular
103+
hs-source-dirs: tabular/src
104+
105+
exposed-modules: Happy.Tabular,
106+
Happy.Tabular.First,
107+
Happy.Tabular.Info,
108+
Happy.Tabular.LALR,
109+
Happy.Tabular.NameSet
110+
build-depends: base, array, containers, happy-lib:grammar
111+
112+
default-language: Haskell98
113+
default-extensions: CPP, MagicHash, FlexibleContexts, NamedFieldPuns
114+
ghc-options: -Wall
115+
116+
library backend-lalr
117+
hs-source-dirs: backend-lalr/src
118+
119+
exposed-modules: Happy.Backend.LALR,
120+
Happy.Backend.LALR.ProduceCode
121+
build-depends: base, array, happy-lib:grammar, happy-lib:tabular
122+
123+
default-language: Haskell98
124+
default-extensions: CPP, MagicHash, FlexibleContexts
125+
ghc-options: -Wall -Wno-incomplete-uni-patterns
126+
other-modules: Paths_happy_lib
127+
128+
library backend-glr
129+
hs-source-dirs: backend-glr/src
130+
131+
exposed-modules: Happy.Backend.GLR,
132+
Happy.Backend.GLR.ProduceCode
133+
build-depends: base, array, happy-lib:grammar, happy-lib:tabular
134+
135+
default-language: Haskell98
136+
default-extensions: CPP, MagicHash, FlexibleContexts
137+
ghc-options: -Wall -Wno-incomplete-uni-patterns
138+
other-modules: Paths_happy_lib
139+
140+
library
141+
reexported-modules: Happy.Grammar,
142+
Happy.Frontend,
143+
Happy.Frontend.AbsSyn,
144+
Happy.Frontend.Mangler,
145+
Happy.Frontend.PrettyGrammar,
146+
Happy.Tabular,
147+
Happy.Tabular.First,
148+
Happy.Tabular.Info,
149+
Happy.Tabular.LALR,
150+
Happy.Tabular.NameSet,
151+
Happy.Backend.LALR,
152+
Happy.Backend.LALR.ProduceCode,
153+
Happy.Backend.GLR,
154+
Happy.Backend.GLR.ProduceCode
155+
156+
build-depends: base >= 4.9 && < 5,
157+
array,
158+
containers >= 0.4.2,
159+
transformers >= 0.5.6.2,
160+
mtl >= 2.2.1,
161+
happy-lib:grammar,
162+
happy-lib:tabular,
163+
happy-lib:frontend,
164+
happy-lib:backend-lalr,
165+
happy-lib:backend-glr
166+
default-language: Haskell98
File renamed without changes.
File renamed without changes.

packages/tabular/happy-tabular.cabal renamed to lib/tabular/happy-tabular.cabal

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,16 @@ synopsis: Action and goto tables for happy
1515

1616
Description:
1717
Happy is a parser generator for Haskell.
18-
Happy-Tabular converts `Grammar`s, coming from
19-
a frontend, into LALR action and goto tables,
20-
which are further processed by a backend.
18+
For a given description of a happy grammar file (.y),
19+
this library implements the text book computation of the LALR automaton and
20+
generates the final LR action and goto tables, which are further processed by
21+
a backend.
22+
23+
The library happy-grammar defines the 'Grammar' AST type for grammar files.
24+
The library happy-frontend provides a parser for happy grammar files (.y) to
25+
produce a 'Grammar'.
26+
The library happy-backend-lalr defines functions to produce Haskell code
27+
for the LR action and goto tables.
2128

2229
tested-with:
2330
GHC == 9.10.1

0 commit comments

Comments
 (0)