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

« back to all changes in this revision

Viewing changes to src/Parser.ly

  • 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: Parser.ly,v 1.15 2005/01/26 01:10:42 ross Exp $
 
3
 
 
4
The parser.
 
5
 
 
6
(c) 1993-2000 Andy Gill, Simon Marlow
 
7
-----------------------------------------------------------------------------
 
8
 
 
9
> {
 
10
> module Parser (ourParser,AbsSyn) where
 
11
> import ParseMonad
 
12
> import AbsSyn
 
13
> import Lexer
 
14
> }
 
15
 
 
16
> %name ourParser
 
17
> %tokentype { Token }
 
18
> %token
 
19
>       id              { TokenInfo $$ TokId }
 
20
>       spec_tokentype  { TokenKW      TokSpecId_TokenType }
 
21
>       spec_token      { TokenKW      TokSpecId_Token }
 
22
>       spec_name       { TokenKW      TokSpecId_Name }
 
23
>       spec_partial    { TokenKW      TokSpecId_Partial }
 
24
>       spec_lexer      { TokenKW      TokSpecId_Lexer }
 
25
>       spec_imported_identity  { TokenKW      TokSpecId_ImportedIdentity }
 
26
>       spec_monad      { TokenKW      TokSpecId_Monad }
 
27
>       spec_nonassoc   { TokenKW      TokSpecId_Nonassoc }
 
28
>       spec_left       { TokenKW      TokSpecId_Left }
 
29
>       spec_right      { TokenKW      TokSpecId_Right }
 
30
>       spec_prec       { TokenKW      TokSpecId_Prec }
 
31
>       spec_expect     { TokenKW      TokSpecId_Expect }
 
32
>       spec_error      { TokenKW      TokSpecId_Error }
 
33
>       spec_attribute  { TokenKW      TokSpecId_Attribute }
 
34
>       spec_attributetype      { TokenKW      TokSpecId_Attributetype }
 
35
>       code            { TokenInfo $$ TokCodeQuote }
 
36
>       int             { TokenNum $$  TokNum }
 
37
>       ":"             { TokenKW      TokColon }
 
38
>       ";"             { TokenKW      TokSemiColon }
 
39
>       "::"            { TokenKW      TokDoubleColon }
 
40
>       "%%"            { TokenKW      TokDoublePercent }
 
41
>       "|"             { TokenKW      TokBar }
 
42
 
 
43
> %monad { P }
 
44
> %lexer { lexer } { TokenEOF }
 
45
 
 
46
> %%
 
47
 
 
48
> parser :: { AbsSyn }
 
49
>       : optCode tokInfos "%%" rules optCode
 
50
>                               { AbsSyn $1 (reverse $2) (reverse $4) $5 }
 
51
 
 
52
> rules :: { [(String, [([String],String,Int,Maybe String)], Maybe String)] }
 
53
>       : rules rule    { $2 : $1 }
 
54
>       | rule          { [$1] }
 
55
 
 
56
> rule :: { (String, [([String],String,Int,Maybe String)], Maybe String) }
 
57
>       : id "::" code ":" prods        { ($1,$5,Just $3) }
 
58
>       | id "::" code id ":" prods     { ($1,$6,Just $3) }
 
59
>       | id ":" prods                  { ($1,$3,Nothing) }
 
60
 
 
61
 
 
62
> prods :: { [([String],String,Int,Maybe String)] }
 
63
>       : prod "|" prods                { $1 : $3 }
 
64
>       | prod                          { [$1] }
 
65
 
 
66
> prod :: { ([String],String,Int,Maybe String) }
 
67
>       : ids prec code ";"             {% lineP >>= \l -> return ($1,$3,l,$2) }
 
68
>       | ids prec code                 {% lineP >>= \l -> return ($1,$3,l,$2) }
 
69
 
 
70
> prec :: { Maybe String }
 
71
>       : spec_prec id                  { Just $2 }
 
72
>       |                               { Nothing }
 
73
 
 
74
> tokInfos :: { [Directive String] } 
 
75
>       : tokInfos tokInfo              { $2 : $1 }
 
76
>       | tokInfo                       { [$1] }
 
77
 
 
78
> tokInfo :: { Directive String } 
 
79
>       : spec_tokentype code           { TokenType $2 }
 
80
>       | spec_token tokenSpecs         { TokenSpec $2 }
 
81
>       | spec_name id optStart         { TokenName $2 $3 False }
 
82
>       | spec_partial id optStart      { TokenName $2 $3 True  }
 
83
>       | spec_imported_identity        { TokenImportedIdentity }
 
84
>       | spec_lexer code code          { TokenLexer $2 $3 }
 
85
>       | spec_monad code               { TokenMonad "()" $2 ">>=" "return" }
 
86
>       | spec_monad code code          { TokenMonad $2 $3 ">>=" "return" }
 
87
>       | spec_monad code code code     { TokenMonad "()" $2 $3 $4 }
 
88
>       | spec_monad code code code code        { TokenMonad $2 $3 $4 $5 }
 
89
>       | spec_nonassoc ids             { TokenNonassoc $2 }
 
90
>       | spec_right ids                { TokenRight $2 }
 
91
>       | spec_left ids                 { TokenLeft $2 }
 
92
>       | spec_expect int               { TokenExpect $2 }
 
93
>       | spec_error code               { TokenError $2 }
 
94
>       | spec_attributetype code       { TokenAttributetype $2 }
 
95
>       | spec_attribute id code        { TokenAttribute $2 $3 }
 
96
 
 
97
> optStart :: { Maybe String }
 
98
>       : id                            { Just $1 }
 
99
>       | {- nothing -}                 { Nothing }
 
100
 
 
101
> tokenSpecs :: { [(String,String)] }
 
102
>       : tokenSpec tokenSpecs          { $1:$2 }
 
103
>       | tokenSpec                     { [$1] }
 
104
 
 
105
> tokenSpec :: { (String,String) }
 
106
>       : id code                       { ($1,$2) }
 
107
 
 
108
> ids   :: { [String] }
 
109
>       : id ids                        { $1 : $2 }
 
110
>       | {- nothing -}                 { [] }
 
111
 
 
112
> optCode :: { Maybe String }
 
113
>       : code                          { Just $1 }
 
114
>       | {- nothing -}                 { Nothing }
 
115
 
 
116
> {
 
117
> happyError :: P a
 
118
> happyError = lineP >>= \l -> fail (show l ++ ": Parse error\n")
 
119
> }