~ubuntu-branches/ubuntu/trusty/happy/trusty-proposed

« back to all changes in this revision

Viewing changes to happy/src/AbsSyn.lhs

  • Committer: Bazaar Package Importer
  • Author(s): Ian Lynagh (wibble)
  • Date: 2006-10-26 22:52:14 UTC
  • mfrom: (1.2.2 upstream) (3.1.1 dapper)
  • Revision ID: james.westby@ubuntu.com-20061026225214-6jmf0n3ykkc9elyw
Tags: 1.16~rc2-1
* New upstream (release candidate) version.
* Removed happy/ prefixes from various paths in debian/rules and
  debian/docs.
* doc/configure generated by autoconf is in the Debian diff.
* Build using cabal:
  * Various debian/rules changes.
  * Create debian/get_version.hs for extracting the version from the cabal
    file.
  * Requires ghc6 >= 6.4.2.
  * No longer tries to detect platform. Closes: #340325, #332979.
  * Removed autotool-dev build-dep.
* Add 'XSLTPROC_OPTS = --nonet' to doc/config.mk.in.
* Remove src/Parser.ly and src/AttrGrammarParser.ly before cleaning so
  the generated files don't get cleaned.
* Set Standards-Version to 3.7.2 (no changes needed).
* Removed PS and DVI stanzas from debian/doc-base as we don't build
  the documentation those ways.
* Removed content-free postinst and prerm.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
-----------------------------------------------------------------------------
2
 
$Id$
3
 
 
4
 
Abstract syntax for grammar files.
5
 
 
6
 
(c) 1993-2001 Andy Gill, Simon Marlow
7
 
-----------------------------------------------------------------------------
8
 
 
9
 
Here is the abstract syntax of the language we parse.
10
 
 
11
 
> module AbsSyn (
12
 
>       AbsSyn(..), Directive(..),
13
 
>       getTokenType, getTokenSpec, getParserNames, getLexer, getImportedIdentity, getMonad,
14
 
>       getPrios, getPrioNames, getExpect
15
 
>  ) where
16
 
 
17
 
> data AbsSyn
18
 
>     = AbsSyn
19
 
>         (Maybe String)                                        -- header
20
 
>         [Directive String]                                    -- directives
21
 
>         [(String,[([String],String,Int,Maybe String)],Maybe String)]  -- productions
22
 
>         (Maybe String)                                        -- footer
23
 
 
24
 
#ifdef DEBUG
25
 
 
26
 
>   deriving Show
27
 
 
28
 
#endif
29
 
 
30
 
%-----------------------------------------------------------------------------
31
 
Parser Generator Directives.
32
 
 
33
 
ToDo: find a consistent way to analyse all the directives together and
34
 
generate some error messages.
35
 
 
36
 
> data Directive a
37
 
>       = TokenType     String                  -- %tokentype
38
 
>       | TokenSpec     [(a,String)]            -- %token
39
 
>       | TokenName     String (Maybe String) Bool -- %name/%partial (True <=> %partial)
40
 
>       | TokenLexer    String String           -- %lexer
41
 
>       | TokenImportedIdentity                                 -- %importedidentity
42
 
>       | TokenMonad    String String String String -- %monad
43
 
>       | TokenNonassoc [String]                -- %nonassoc
44
 
>       | TokenRight    [String]                -- %right
45
 
>       | TokenLeft     [String]                -- %left
46
 
>       | TokenExpect   Int                     -- %expect
47
 
 
48
 
#ifdef DEBUG
49
 
 
50
 
>   deriving Show
51
 
 
52
 
#endif
53
 
 
54
 
> getTokenType ds 
55
 
>       = case [ t | (TokenType t) <- ds ] of 
56
 
>               [t] -> t
57
 
>               []  -> error "no token type given"
58
 
>               _   -> error "multiple token types"
59
 
 
60
 
> getParserNames ds = [ t | t@(TokenName _ _ _) <- ds ]
61
 
 
62
 
> getLexer ds 
63
 
>       = case [ (a,b) | (TokenLexer a b) <- ds ] of
64
 
>               [t] -> Just t
65
 
>               []  -> Nothing
66
 
>               _   -> error "multiple lexer directives"
67
 
 
68
 
> getImportedIdentity ds 
69
 
>       = case [ (()) | TokenImportedIdentity <- ds ] of
70
 
>               [_] -> True
71
 
>               []  -> False
72
 
>               _   -> error "multiple importedidentity directives"
73
 
 
74
 
> getMonad ds 
75
 
>       = case [ (True,a,b,c,d) | (TokenMonad a b c d) <- ds ] of
76
 
>               [t] -> t
77
 
>               []  -> (False,"()","HappyIdentity",">>=","return")
78
 
>               _   -> error "multiple monad directives"
79
 
 
80
 
> getTokenSpec ds = concat [ t | (TokenSpec t) <- ds ]
81
 
 
82
 
> getPrios ds = [ d | d <- ds,
83
 
>                 case d of
84
 
>                   TokenNonassoc _ -> True
85
 
>                   TokenLeft _ -> True
86
 
>                   TokenRight _ -> True
87
 
>                   _ -> False
88
 
>               ]
89
 
 
90
 
> getPrioNames (TokenNonassoc s) = s
91
 
> getPrioNames (TokenLeft s)     = s
92
 
> getPrioNames (TokenRight s)    = s
93
 
 
94
 
> getExpect ds
95
 
>         = case [ n | (TokenExpect n) <- ds ] of
96
 
>                 [t] -> Just t
97
 
>                 []  -> Nothing
98
 
>                 _   -> error "multiple expect directives"