| 1 |
(* spec.grm |
| 2 |
* |
| 3 |
* COPYRIGHT (c) 2006 |
| 4 |
* John Reppy (http://www.cs.uchicago.edu/~jhr) |
| 5 |
* Aaron Turon (http://www.cs.uchicago.edu/~adrassi) |
| 6 |
* All rights reserved. |
| 7 |
*) |
| 8 |
|
| 9 |
structure GS = GrammarSyntax |
| 10 |
|
| 11 |
type code = Int.int * String.string |
| 12 |
|
| 13 |
%% |
| 14 |
|
| 15 |
%name MLY |
| 16 |
|
| 17 |
%term EOF |
| 18 |
| KW_tokens | KW_defs | KW_keywords | KW_import | KW_name | KW_start | KW_entry | KW_refcell |
| 19 |
| KW_try | KW_where | KW_debugact | KW_unitact | KW_header |
| 20 |
| KW_drop | KW_extend | KW_replace |
| 21 |
| LP | RP (* ( ) *) |
| 22 |
| LSB | RSB (* [ ] *) |
| 23 |
| LCB | RCB (* { } *) |
| 24 |
| SLASH (* / *) |
| 25 |
| COLON |
| 26 |
| SEMI |
| 27 |
| COMMA |
| 28 |
| AT |
| 29 |
| DOLLAR |
| 30 |
| BAR (* | *) |
| 31 |
| STAR (* * *) |
| 32 |
| PLUS (* + *) |
| 33 |
| QUERY (* ? *) |
| 34 |
| CODE of string |
| 35 |
| EQ (* = *) |
| 36 |
| ARROW (* -> *) |
| 37 |
| DARROW (* => *) |
| 38 |
| REFSET (* :== *) |
| 39 |
| OF |
| 40 |
| ID of string |
| 41 |
| STRING of string |
| 42 |
| IDDOT of string (* identifier with dot (e.g., "module.") *) |
| 43 |
| TYVAR of string (* ML-style type variable name *) |
| 44 |
| INT of string (* integer label within record *) |
| 45 |
| BOGUS |
| 46 |
|
| 47 |
%nonterm |
| 48 |
File of GS.grammar |
| 49 |
| Decls of GS.grammar |
| 50 |
| Rule of GS.rule |
| 51 |
| Formals of Atom.atom list |
| 52 |
| IDList of string list |
| 53 |
| SymList of Atom.atom list |
| 54 |
| AltList of GS.alt list |
| 55 |
| Alt of GS.alt |
| 56 |
| IsTry of bool |
| 57 |
| AltPred of code option |
| 58 |
| AltCode of code option |
| 59 |
| ItemList of (string option * GS.item) list |
| 60 |
| NamedItem of string option * GS.item |
| 61 |
| Item of GS.item |
| 62 |
| PrimItem of GS.item |
| 63 |
| Args of GS.action option |
| 64 |
| LHS of Atom.atom |
| 65 |
| Symbol of Atom.atom |
| 66 |
| ConstrList of GS.constr list |
| 67 |
| OptTy of GS.ty option |
| 68 |
| Ty of GS.ty |
| 69 |
| OptAbbrev of Atom.atom option |
| 70 |
| RecordList of string |
| 71 |
| Label of string |
| 72 |
| QualID of string |
| 73 |
| Code of code |
| 74 |
|
| 75 |
%arg (errFn, startGrm) : ((string * int * int) -> unit) * GS.grammar |
| 76 |
|
| 77 |
%pos int |
| 78 |
%eop EOF |
| 79 |
%noshift EOF |
| 80 |
%start File |
| 81 |
%verbose |
| 82 |
|
| 83 |
%right ARROW |
| 84 |
%left STAR |
| 85 |
|
| 86 |
%% |
| 87 |
|
| 88 |
File : Decls |
| 89 |
(Decls) |
| 90 |
|
| 91 |
Decls |
| 92 |
: |
| 93 |
(startGrm) |
| 94 |
| Decls KW_name ID SEMI |
| 95 |
(GS.updName (Decls, ID)) |
| 96 |
| Decls KW_start ID SEMI |
| 97 |
(GS.updStartSym (Decls, Atom.atom ID)) |
| 98 |
| Decls KW_entry IDList SEMI |
| 99 |
(GS.updEntryPoints (Decls, map Atom.atom IDList)) |
| 100 |
| Decls KW_keywords SymList SEMI |
| 101 |
(GS.updKeywords (Decls, SymList)) |
| 102 |
(* | Decls KW_header STRING SEMI |
| 103 |
(GS.updHeader (Decls, STRING)) *) |
| 104 |
| Decls KW_defs Code SEMI |
| 105 |
(GS.updDefs (Decls, Code)) |
| 106 |
| Decls KW_tokens COLON ConstrList SEMI |
| 107 |
(GS.updToks (Decls, ConstrList)) |
| 108 |
| Decls KW_import STRING SEMI |
| 109 |
(GS.updImport (Decls, |
| 110 |
(Substring.string o |
| 111 |
(Substring.triml 1) o |
| 112 |
(Substring.trimr 1) o |
| 113 |
Substring.full) STRING)) |
| 114 |
| Decls KW_refcell ID COLON Ty REFSET Code SEMI |
| 115 |
(GS.addRefcell (Decls, (ID, Ty, Code))) |
| 116 |
| Decls Rule SEMI |
| 117 |
(GS.addRule (Decls, Rule)) |
| 118 |
| Decls KW_extend Rule SEMI |
| 119 |
(GS.addImportChange (Decls, GS.ICExtend Rule)) |
| 120 |
| Decls KW_replace Rule SEMI |
| 121 |
(GS.addImportChange (Decls, GS.ICReplace Rule)) |
| 122 |
| Decls KW_drop IDList SEMI |
| 123 |
(foldl |
| 124 |
(fn (id, g) => |
| 125 |
GS.addImportChange (g, GS.ICDrop (Atom.atom id))) |
| 126 |
Decls |
| 127 |
IDList) |
| 128 |
| Decls KW_debugact SEMI |
| 129 |
(GS.debugAct Decls) |
| 130 |
| Decls KW_unitact SEMI |
| 131 |
(GS.unitAct Decls) |
| 132 |
|
| 133 |
Rule |
| 134 |
: LHS Formals COLON AltList |
| 135 |
(GS.RULE{lhs=LHS, formals = Formals, alts=AltList}) |
| 136 |
|
| 137 |
Formals |
| 138 |
: LP IDList RP |
| 139 |
(map Atom.atom IDList) |
| 140 |
| |
| 141 |
([]) |
| 142 |
|
| 143 |
IDList |
| 144 |
: ID |
| 145 |
([ID]) |
| 146 |
| ID COMMA IDList |
| 147 |
(ID::IDList) |
| 148 |
|
| 149 |
SymList |
| 150 |
: Symbol |
| 151 |
([Symbol]) |
| 152 |
| Symbol COMMA SymList |
| 153 |
(Symbol::SymList) |
| 154 |
|
| 155 |
AltList |
| 156 |
: Alt |
| 157 |
([Alt]) |
| 158 |
| Alt BAR AltList |
| 159 |
(Alt :: AltList) |
| 160 |
|
| 161 |
Alt |
| 162 |
: IsTry ItemList AltPred AltCode |
| 163 |
(GS.ALT {items = ItemList, action = AltCode, |
| 164 |
try = IsTry, pred = AltPred}) |
| 165 |
|
| 166 |
IsTry |
| 167 |
: KW_try |
| 168 |
(true) |
| 169 |
| |
| 170 |
(false) |
| 171 |
|
| 172 |
AltPred |
| 173 |
: KW_where Code |
| 174 |
(SOME Code) |
| 175 |
| |
| 176 |
(NONE) |
| 177 |
|
| 178 |
AltCode |
| 179 |
: DARROW Code |
| 180 |
(SOME Code) |
| 181 |
| |
| 182 |
(NONE) |
| 183 |
|
| 184 |
ItemList |
| 185 |
: (* empty *) |
| 186 |
([]) |
| 187 |
| NamedItem ItemList |
| 188 |
(NamedItem :: ItemList) |
| 189 |
|
| 190 |
NamedItem |
| 191 |
: ID EQ Item |
| 192 |
(SOME ID, Item) |
| 193 |
| Item |
| 194 |
(NONE, Item) |
| 195 |
|
| 196 |
Item |
| 197 |
: PrimItem |
| 198 |
(PrimItem) |
| 199 |
| PrimItem STAR |
| 200 |
(GS.CLOS PrimItem) |
| 201 |
| PrimItem PLUS |
| 202 |
(GS.POSCLOS PrimItem) |
| 203 |
| PrimItem QUERY |
| 204 |
(GS.OPT PrimItem) |
| 205 |
|
| 206 |
PrimItem |
| 207 |
: Symbol Args |
| 208 |
(GS.SYMBOL (Symbol, Args)) |
| 209 |
| LP AltList RP |
| 210 |
(GS.SUBRULE AltList) |
| 211 |
|
| 212 |
Args |
| 213 |
: |
| 214 |
(NONE) |
| 215 |
| AT Code |
| 216 |
(SOME Code) |
| 217 |
|
| 218 |
LHS |
| 219 |
: ID |
| 220 |
(Atom.atom ID) |
| 221 |
|
| 222 |
Symbol |
| 223 |
: ID |
| 224 |
(Atom.atom ID) |
| 225 |
| STRING |
| 226 |
(Atom.atom STRING) |
| 227 |
|
| 228 |
ConstrList |
| 229 |
: ConstrList BAR ID OptTy OptAbbrev |
| 230 |
((Atom.atom ID, OptTy, OptAbbrev)::ConstrList) |
| 231 |
| ID OptTy OptAbbrev |
| 232 |
([(Atom.atom ID, OptTy, OptAbbrev)]) |
| 233 |
|
| 234 |
OptTy |
| 235 |
: |
| 236 |
(NONE) |
| 237 |
| OF Ty |
| 238 |
(SOME Ty) |
| 239 |
|
| 240 |
Ty |
| 241 |
: TYVAR |
| 242 |
(TYVAR) |
| 243 |
| LCB RecordList RCB |
| 244 |
("{ " ^ RecordList ^" } ") |
| 245 |
| LCB RCB |
| 246 |
("{}") |
| 247 |
| LP Ty RP |
| 248 |
("(" ^ Ty ^ ")") |
| 249 |
| Ty QualID |
| 250 |
(Ty ^ " " ^ QualID) |
| 251 |
| QualID |
| 252 |
(QualID) |
| 253 |
| Ty STAR Ty |
| 254 |
(Ty1 ^ "*" ^ Ty2) |
| 255 |
| Ty ARROW Ty |
| 256 |
(Ty1 ^ " -> " ^ Ty2) |
| 257 |
|
| 258 |
OptAbbrev |
| 259 |
: |
| 260 |
(NONE) |
| 261 |
| LP STRING RP |
| 262 |
(SOME (Atom.atom STRING)) |
| 263 |
|
| 264 |
RecordList |
| 265 |
: RecordList COMMA Label COLON Ty |
| 266 |
(RecordList ^ "," ^ Label ^ ":" ^ Ty) |
| 267 |
| Label COLON Ty |
| 268 |
(Label ^ ":" ^ Ty) |
| 269 |
|
| 270 |
Label |
| 271 |
: ID |
| 272 |
(ID) |
| 273 |
| INT |
| 274 |
(INT) |
| 275 |
|
| 276 |
QualID |
| 277 |
: ID |
| 278 |
(ID) |
| 279 |
| IDDOT QualID |
| 280 |
(IDDOT ^ QualID) |
| 281 |
|
| 282 |
Code |
| 283 |
: CODE |
| 284 |
(CODEleft, CODE) |