blob: 09e3a4b5ad6a0d94ce521ef66a74b27823a48a57 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
-- This Happy file was machine-generated by the BNF converter
{
module ParCFG where
import AbsCFG
import LexCFG
import ErrM
}
%name pGrammars Grammars
%monad { Err } { thenM } { returnM }
%tokentype { Token }
%token
';' { PT _ (TS ";") }
':' { PT _ (TS ":") }
'.' { PT _ (TS ".") }
'->' { PT _ (TS "->") }
'[' { PT _ (TS "[") }
']' { PT _ (TS "]") }
',' { PT _ (TS ",") }
'/' { PT _ (TS "/") }
'{' { PT _ (TS "{") }
'}' { PT _ (TS "}") }
'!' { PT _ (TS "!") }
'end' { PT _ (TS "end") }
'grammar' { PT _ (TS "grammar") }
'startcat' { PT _ (TS "startcat") }
L_ident { PT _ (TV $$) }
L_integ { PT _ (TI $$) }
L_quoted { PT _ (TL $$) }
L_err { _ }
%%
Ident : L_ident { Ident $1 }
Integer : L_integ { (read $1) :: Integer }
String : L_quoted { $1 }
Grammars :: { Grammars }
Grammars : ListGrammar { Grammars (reverse $1) }
Grammar :: { Grammar }
Grammar : 'grammar' Ident ListFlag ListRule 'end' 'grammar' { Grammar $2 (reverse $3) (reverse $4) }
ListGrammar :: { [Grammar] }
ListGrammar : {- empty -} { [] }
| ListGrammar Grammar { flip (:) $1 $2 }
Flag :: { Flag }
Flag : 'startcat' Category { StartCat $2 }
ListFlag :: { [Flag] }
ListFlag : {- empty -} { [] }
| ListFlag Flag ';' { flip (:) $1 $2 }
Rule :: { Rule }
Rule : Ident ':' Name Profile '.' Category '->' ListSymbol { Rule $1 $3 $4 $6 (reverse $8) }
ListRule :: { [Rule] }
ListRule : {- empty -} { [] }
| ListRule Rule ';' { flip (:) $1 $2 }
Profile :: { Profile }
Profile : '[' ListInts ']' { Profile $2 }
Ints :: { Ints }
Ints : '[' ListInteger ']' { Ints $2 }
ListInts :: { [Ints] }
ListInts : {- empty -} { [] }
| Ints { (:[]) $1 }
| Ints ',' ListInts { (:) $1 $3 }
ListInteger :: { [Integer] }
ListInteger : {- empty -} { [] }
| Integer { (:[]) $1 }
| Integer ',' ListInteger { (:) $1 $3 }
Symbol :: { Symbol }
Symbol : Category { CatS $1 }
| String { TermS $1 }
ListSymbol :: { [Symbol] }
ListSymbol : {- empty -} { [] }
| ListSymbol Symbol { flip (:) $1 $2 }
Name :: { Name }
Name : ListIdentParam Category { Name (reverse $1) $2 }
ListIdentParam :: { [IdentParam] }
ListIdentParam : {- empty -} { [] }
| ListIdentParam IdentParam '/' { flip (:) $1 $2 }
Category :: { Category }
Category : IdentParam '.' Ident ListParam { Category $1 $3 (reverse $4) }
IdentParam :: { IdentParam }
IdentParam : Ident '{' ListParam '}' { IdentParam $1 (reverse $3) }
Param :: { Param }
Param : '!' Ident { Param $2 }
ListParam :: { [Param] }
ListParam : {- empty -} { [] }
| ListParam Param { flip (:) $1 $2 }
{
returnM :: a -> Err a
returnM = return
thenM :: Err a -> (a -> Err b) -> Err b
thenM = (>>=)
happyError :: [Token] -> Err a
happyError ts =
Bad $ "syntax error at " ++ tokenPos ts ++ if null ts then [] else (" before " ++ unwords (map prToken (take 4 ts)))
myLexer = tokens
}
|