| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 // IDL grammar variants. | |
| 6 final int WEBIDL_SYNTAX = 0; | |
| 7 final int WEBKIT_SYNTAX = 1; | |
| 8 final int FREMONTCUT_SYNTAX = 2; | |
| 9 | |
| 10 /** | |
| 11 * IDLFile is the top-level node in each IDL file. It may contain modules or | |
| 12 * interfaces. | |
| 13 */ | |
| 14 class IDLFile extends IDLNode { | |
| 15 | |
| 16 String filename; | |
| 17 List<IDLModule> modules; | |
| 18 List<IDLInterface> interfaces; | |
| 19 | |
| 20 IDLFile(this.filename, this.modules, this.interfaces); | |
| 21 } | |
| 22 | |
| 23 /** | |
| 24 * IDLModule has an id, and may contain interfaces, type defs andimplements | |
| 25 * statements. | |
| 26 */ | |
| 27 class IDLModule extends IDLNode { | |
| 28 String id; | |
| 29 List interfaces; | |
| 30 List typedefs; | |
| 31 List implementsStatements; | |
| 32 | |
| 33 IDLModule(String this.id, IDLExtAttrs extAttrs, IDLAnnotations annotations, | |
| 34 List<IDLNode> elements) { | |
| 35 setExtAttrs(extAttrs); | |
| 36 this.annotations = annotations; | |
| 37 this.interfaces = elements.filter((e) => e is IDLInterface); | |
| 38 this.typedefs = elements.filter((e) => e is IDLTypeDef); | |
| 39 this.implementsStatements = | |
| 40 elements.filter((e) => e is IDLImplementsStatement); | |
| 41 } | |
| 42 | |
| 43 toString() => '<IDLModule $id $extAttrs $annotations>'; | |
| 44 } | |
| 45 | |
| 46 class IDLNode { | |
| 47 IDLExtAttrs extAttrs; | |
| 48 IDLAnnotations annotations; | |
| 49 IDLNode(); | |
| 50 | |
| 51 setExtAttrs(IDLExtAttrs ea) { | |
| 52 assert(ea != null); | |
| 53 this.extAttrs = ea != null ? ea : new IDLExtAttrs(); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 class IDLType extends IDLNode { | |
| 58 String id; | |
| 59 IDLType parameter; | |
| 60 bool nullable = false; | |
| 61 IDLType(String this.id, [IDLType this.parameter, bool this.nullable = false]); | |
| 62 | |
| 63 // TODO: Figure out why this constructor was failing in mysterious ways. | |
| 64 // IDLType.nullable(IDLType base) { | |
| 65 // return new IDLType(base.id, base.parameter, true); | |
| 66 // } | |
| 67 | |
| 68 //String toString() => '<IDLType $nullable $id $parameter>'; | |
| 69 String toString() { | |
| 70 String nullableTag = nullable ? '?' : ''; | |
| 71 return '<IDLType $id${parameter == null ? '' : ' $parameter'}$nullableTag>'; | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 class IDLTypeDef extends IDLNode { | |
| 76 String id; | |
| 77 IDLType type; | |
| 78 IDLTypeDef(String this.id, IDLType this.type); | |
| 79 | |
| 80 toString() => '<IDLTypeDef $id $type>'; | |
| 81 } | |
| 82 | |
| 83 class IDLImplementsStatement extends IDLNode { | |
| 84 } | |
| 85 | |
| 86 class IDLInterface extends IDLNode { | |
| 87 String id; | |
| 88 List parents; | |
| 89 List operations; | |
| 90 List attributes; | |
| 91 List constants; | |
| 92 List snippets; | |
| 93 | |
| 94 bool isSupplemental; | |
| 95 bool isNoInterfaceObject; | |
| 96 bool isFcSuppressed; | |
| 97 | |
| 98 IDLInterface(String this.id, IDLExtAttrs ea, IDLAnnotations ann, | |
| 99 List this.parents, List members) { | |
| 100 setExtAttrs(ea); | |
| 101 this.annotations = ann; | |
| 102 if (this.parents == null) this.parents = []; | |
| 103 | |
| 104 operations = members.filter((e) => e is IDLOperation); | |
| 105 attributes = members.filter((e) => e is IDLAttribute); | |
| 106 constants = members.filter((e) => e is IDLConstant); | |
| 107 snippets = members.filter((e) => e is IDLSnippet); | |
| 108 | |
| 109 isSupplemental = extAttrs.has('Supplemental'); | |
| 110 isNoInterfaceObject = extAttrs.has('NoInterfaceObject'); | |
| 111 isFcSuppressed = extAttrs.has('Suppressed'); | |
| 112 } | |
| 113 | |
| 114 toString() => '<IDLInterface $id $extAttrs $annotations>'; | |
| 115 } | |
| 116 | |
| 117 class IDLMember extends IDLNode { | |
| 118 String id; | |
| 119 IDLType type; | |
| 120 bool isFcSuppressed; | |
| 121 | |
| 122 IDLMember(String this.id, IDLType this.type, IDLExtAttrs ea, IDLAnnotations an
n) { | |
| 123 setExtAttrs(ea); | |
| 124 this.annotations = ann; | |
| 125 | |
| 126 isFcSuppressed = extAttrs.has('Suppressed'); | |
| 127 } | |
| 128 } | |
| 129 | |
| 130 class IDLOperation extends IDLMember { | |
| 131 List arguments; | |
| 132 | |
| 133 // Ignore all forms of raises for now. | |
| 134 List specials; | |
| 135 bool isStringifier; | |
| 136 | |
| 137 IDLOperation(String id, IDLType type, IDLExtAttrs ea, IDLAnnotations ann, | |
| 138 List this.arguments, List this.specials, bool this.isStringifier) | |
| 139 : super(id, type, ea, ann) { | |
| 140 } | |
| 141 | |
| 142 toString() => '<IDLOperation $type $id ${printList(arguments)}>'; | |
| 143 } | |
| 144 | |
| 145 class IDLAttribute extends IDLMember { | |
| 146 } | |
| 147 | |
| 148 class IDLConstant extends IDLMember { | |
| 149 var value; | |
| 150 IDLConstant(String id, IDLType type, IDLExtAttrs ea, IDLAnnotations ann, | |
| 151 var this.value) | |
| 152 : super(id, type, ea, ann); | |
| 153 } | |
| 154 | |
| 155 class IDLSnippet extends IDLMember { | |
| 156 String text; | |
| 157 IDLSnippet(IDLAnnotations ann, String this.text) | |
| 158 : super(null, null, new IDLExtAttrs(), ann); | |
| 159 } | |
| 160 | |
| 161 /** Maps string to something. */ | |
| 162 class IDLDictNode { | |
| 163 Map<String, Object> map; | |
| 164 IDLDictNode() { | |
| 165 map = new Map<String, Object>(); | |
| 166 } | |
| 167 | |
| 168 setMap(List associationList) { | |
| 169 if (associationList == null) return; | |
| 170 for (var element in associationList) { | |
| 171 var name = element[0]; | |
| 172 var value = element[1]; | |
| 173 map[name] = value; | |
| 174 } | |
| 175 } | |
| 176 | |
| 177 bool has(String key) => map.containsKey(key); | |
| 178 | |
| 179 formatMap() { | |
| 180 if (map.isEmpty()) | |
| 181 return ''; | |
| 182 StringBuffer sb = new StringBuffer(); | |
| 183 map.forEach((k, v) { | |
| 184 sb.add(' $k'); | |
| 185 if (v != null) { | |
| 186 sb.add('=$v'); | |
| 187 } | |
| 188 }); | |
| 189 return sb.toString(); | |
| 190 } | |
| 191 | |
| 192 } | |
| 193 | |
| 194 class IDLExtAttrs extends IDLDictNode { | |
| 195 IDLExtAttrs([List attrs = const []]) : super() { | |
| 196 setMap(attrs); | |
| 197 } | |
| 198 | |
| 199 toString() => '<IDLExtAttrs${formatMap()}>'; | |
| 200 } | |
| 201 | |
| 202 class IDLArgument extends IDLNode { | |
| 203 String id; | |
| 204 IDLType type; | |
| 205 bool isOptional; | |
| 206 bool isIn; | |
| 207 bool hasElipsis; | |
| 208 IDLArgument(String this.id, IDLType this.type, IDLExtAttrs extAttrs, | |
| 209 bool this.isOptional, bool this.isIn, bool this.hasElipsis) { | |
| 210 setExtAttrs(extAttrs); | |
| 211 } | |
| 212 | |
| 213 toString() => '<IDLArgument $id>'; | |
| 214 } | |
| 215 | |
| 216 class IDLAnnotations extends IDLDictNode { | |
| 217 IDLAnnotations(List annotations) : super() { | |
| 218 for (var annotation in annotations) { | |
| 219 map[annotation.id] = annotation; | |
| 220 } | |
| 221 } | |
| 222 | |
| 223 toString() => '<IDLAnnotations${formatMap()}>'; | |
| 224 } | |
| 225 | |
| 226 class IDLAnnotation extends IDLDictNode { | |
| 227 String id; | |
| 228 IDLAnnotation(String this.id, List args) : super() { | |
| 229 setMap(args); | |
| 230 } | |
| 231 | |
| 232 toString() => '<IDLAnnotation $id${formatMap()}>'; | |
| 233 } | |
| 234 | |
| 235 class IDLExtAttrFunctionValue extends IDLNode { | |
| 236 String name; | |
| 237 List arguments; | |
| 238 IDLExtAttrFunctionValue(String this.name, this.arguments); | |
| 239 | |
| 240 toString() => '<IDLExtAttrFunctionValue $name(${arguments.length})>'; | |
| 241 } | |
| 242 | |
| 243 class IDLParentInterface extends IDLNode {} | |
| 244 | |
| 245 //////////////////////////////////////////////////////////////////////////////// | |
| 246 | |
| 247 class IDLParser { | |
| 248 final int syntax; | |
| 249 Grammar grammar; | |
| 250 var axiom; | |
| 251 | |
| 252 IDLParser([syntax=WEBIDL_SYNTAX]) : syntax = syntax { | |
| 253 grammar = new Grammar(); | |
| 254 axiom = _makeParser(); | |
| 255 } | |
| 256 | |
| 257 syntax_switch([WebIDL, WebKit, FremontCut]) { | |
| 258 assert(WebIDL != null && WebKit != null); // Not options, just want names. | |
| 259 if (syntax == WEBIDL_SYNTAX) | |
| 260 return WebIDL; | |
| 261 if (syntax == WEBKIT_SYNTAX) | |
| 262 return WebKit; | |
| 263 if (syntax == FREMONTCUT_SYNTAX) | |
| 264 return FremontCut == null ? WebIDL : FremontCut; | |
| 265 throw new Exception('unsupported IDL syntax $syntax'); | |
| 266 } | |
| 267 | |
| 268 _makeParser() { | |
| 269 Grammar g = grammar; | |
| 270 | |
| 271 // TODO: move syntax_switch back to here. | |
| 272 | |
| 273 var idStartCharSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_'
; | |
| 274 var idNextCharSet = idStartCharSet + '0123456789'; | |
| 275 var hexCharSet = '0123456789ABCDEFabcdef'; | |
| 276 | |
| 277 var idStartChar = CHAR(idStartCharSet); | |
| 278 var idNextChar = CHAR(idNextCharSet); | |
| 279 | |
| 280 var digit = CHAR('0123456789'); | |
| 281 | |
| 282 var Id = TEXT(LEX('an identifier',[idStartChar, MANY(idNextChar, min:0)])); | |
| 283 | |
| 284 var IN = SKIP(LEX("'in'", ['in',NOT(idNextChar)])); | |
| 285 | |
| 286 var BooleanLiteral = OR(['true', 'false']); | |
| 287 var IntegerLiteral = TEXT(LEX('hex-literal', OR([['0x', MANY(CHAR(hexCharSet
))], | |
| 288 [MANY(digit)]]))); | |
| 289 var FloatLiteral = TEXT(LEX('float-literal', [MANY(digit), '.', MANY(digit,
min:0)])); | |
| 290 | |
| 291 | |
| 292 var Argument = g['Argument']; | |
| 293 var Module = g['Module']; | |
| 294 var Member = g['Member']; | |
| 295 var Interface = g['Interface']; | |
| 296 var ExceptionDef = g['ExceptionDef']; | |
| 297 var Type = g['Type']; | |
| 298 var TypeDef = g['TypeDef']; | |
| 299 var ImplStmt = g['ImplStmt']; | |
| 300 var ValueTypeDef = g['ValueTypeDef']; | |
| 301 var Const = g['Const']; | |
| 302 var Attribute = g['Attribute']; | |
| 303 var Operation = g['Operation']; | |
| 304 var Snippet = g['Snippet']; | |
| 305 var ExtAttrs = g['ExtAttrs']; | |
| 306 var MaybeExtAttrs = g['MaybeExtAttrs']; | |
| 307 var MaybeAnnotations = g['MaybeAnnotations']; | |
| 308 var ParentInterfaces = g['ParentInterfaces']; | |
| 309 | |
| 310 | |
| 311 final ScopedName = TEXT(LEX('scoped-name', MANY(CHAR(idStartCharSet + '_:.<>
')))); | |
| 312 | |
| 313 final ScopedNames = MANY(ScopedName, separator:','); | |
| 314 | |
| 315 // Types | |
| 316 | |
| 317 final IntegerTypeName = OR([ | |
| 318 ['byte', () => 'byte'], | |
| 319 ['int', () => 'int'], | |
| 320 ['long', 'long', () => 'long long'], | |
| 321 ['long', () => 'long'], | |
| 322 ['octet', () => 'octet'], | |
| 323 ['short', () => 'short']]); | |
| 324 | |
| 325 final IntegerType = OR([ | |
| 326 ['unsigned', IntegerTypeName, (name) => new IDLType('unsigned $name')], | |
| 327 [IntegerTypeName, (name) => new IDLType(name)]]); | |
| 328 | |
| 329 final BooleanType = ['boolean', () => new IDLType('boolean')]; | |
| 330 final OctetType = ['octet', () => new IDLType('octet')]; | |
| 331 final FloatType = ['float', () => new IDLType('float')]; | |
| 332 final DoubleType = ['double', () => new IDLType('double')]; | |
| 333 | |
| 334 final SequenceType = ['sequence', '<', Type, '>', | |
| 335 (type) => new IDLType('sequence', type)]; | |
| 336 | |
| 337 final ScopedNameType = [ScopedName, (name) => new IDLType(name)]; | |
| 338 | |
| 339 final NullableType = | |
| 340 [OR([IntegerType, BooleanType, OctetType, FloatType, | |
| 341 DoubleType, SequenceType, ScopedNameType]), | |
| 342 MAYBE('?'), | |
| 343 (type, nullable) => | |
| 344 nullable ? new IDLType(type.id, type.parameter, true) : type]; | |
| 345 | |
| 346 final VoidType = ['void', () => new IDLType('void')]; | |
| 347 final AnyType = ['any', () => new IDLType('any')]; | |
| 348 final ObjectType = ['object', () => new IDLType('object')]; | |
| 349 | |
| 350 Type.def = OR([AnyType, ObjectType, NullableType]); | |
| 351 | |
| 352 final ReturnType = OR([VoidType, Type]); | |
| 353 | |
| 354 var Definition = syntax_switch( | |
| 355 WebIDL: OR([Module, Interface, ExceptionDef, TypeDef, ImplStmt, | |
| 356 ValueTypeDef, Const]), | |
| 357 WebKit: OR([Module, Interface])); | |
| 358 | |
| 359 var Definitions = MANY(Definition, min:0); | |
| 360 | |
| 361 Module.def = syntax_switch( | |
| 362 WebIDL: [MaybeExtAttrs, 'module', Id, '{', Definitions, '}', | |
| 363 SKIP(MAYBE(';')), | |
| 364 (ea, id, defs) => new IDLModule(id, ea, null, defs)], | |
| 365 WebKit: ['module', MaybeExtAttrs, Id, '{', Definitions, '}', | |
| 366 SKIP(MAYBE(';')), | |
| 367 (ea, id, defs) => new IDLModule(id, ea, null, defs)], | |
| 368 FremontCut: [MaybeAnnotations, MaybeExtAttrs, 'module', Id, | |
| 369 '{', Definitions, '}', SKIP(MAYBE(';')), | |
| 370 (ann, ea, id, defs) => new IDLModule(id, ea, ann, defs)]); | |
| 371 | |
| 372 Interface.def = syntax_switch( | |
| 373 WebIDL: [MaybeExtAttrs, 'interface', Id, MAYBE(ParentInterfaces), | |
| 374 MAYBE(['{', MANY0(Member), '}']), ';', | |
| 375 (ea, id, p, ms) => new IDLInterface(id, ea, null, p, ms)], | |
| 376 WebKit: ['interface', MaybeExtAttrs, Id, MAYBE(ParentInterfaces), | |
| 377 MAYBE(['{', MANY0(Member), '}']), ';', | |
| 378 (ea, id, p, ms) => new IDLInterface(id, ea, null, p, ms)], | |
| 379 FremontCut: [MaybeAnnotations, MaybeExtAttrs, 'interface', | |
| 380 Id, MAYBE(ParentInterfaces), | |
| 381 MAYBE(['{', MANY0(Member), '}']), ';', | |
| 382 (ann, ea, id, p, ms) => new IDLInterface(id, ea, ann, p, ms
)]); | |
| 383 | |
| 384 Member.def = syntax_switch( | |
| 385 WebIDL: OR([Const, Attribute, Operation, ExtAttrs]), | |
| 386 WebKit: OR([Const, Attribute, Operation]), | |
| 387 FremontCut: OR([Const, Attribute, Operation, Snippet])); | |
| 388 | |
| 389 var InterfaceType = ScopedName; | |
| 390 | |
| 391 var ParentInterface = syntax_switch( | |
| 392 WebIDL: [InterfaceType], | |
| 393 WebKit: [InterfaceType], | |
| 394 FremontCut: [MaybeAnnotations, InterfaceType]); | |
| 395 | |
| 396 ParentInterfaces.def = [':', MANY(ParentInterface, ',')]; | |
| 397 | |
| 398 // TypeDef (Web IDL): | |
| 399 TypeDef.def = ['typedef', Type, Id, ';', (type, id) => new IDLTypeDef(id, ty
pe)]; | |
| 400 | |
| 401 // TypeDef (Old-school W3C IDLs) | |
| 402 ValueTypeDef.def = ['valuetype', Id, Type, ';']; | |
| 403 | |
| 404 // Implements Statement (Web IDL): | |
| 405 var ImplStmtImplementor = ScopedName; | |
| 406 var ImplStmtImplemented = ScopedName; | |
| 407 | |
| 408 ImplStmt.def = [ImplStmtImplementor, 'implements', ImplStmtImplemented, ';']
; | |
| 409 | |
| 410 var ConstExpr = OR([BooleanLiteral, IntegerLiteral, FloatLiteral]); | |
| 411 | |
| 412 Const.def = syntax_switch( | |
| 413 WebIDL: [MaybeExtAttrs, 'const', Type, Id, '=', ConstExpr, ';', | |
| 414 (ea, type, id, v) => new IDLConstant(id, type, ea, null, v)], | |
| 415 WebKit: ['const', MaybeExtAttrs, Type, Id, '=', ConstExpr, ';', | |
| 416 (ea, type, id, v) => new IDLConstant(id, type, ea, null, v)], | |
| 417 FremontCut: [MaybeAnnotations, MaybeExtAttrs, | |
| 418 'const', Type, Id, '=', ConstExpr, ';', | |
| 419 (ann, ea, type, id, v) => | |
| 420 new IDLConstant(id, type, ea, ann, v)]); | |
| 421 | |
| 422 // Attributes | |
| 423 | |
| 424 var Stringifier = 'stringifier'; | |
| 425 var AttrGetter = 'getter'; | |
| 426 var AttrSetter = 'setter'; | |
| 427 var ReadOnly = 'readonly'; | |
| 428 var AttrGetterSetter = OR([AttrGetter, AttrSetter]); | |
| 429 | |
| 430 var GetRaises = syntax_switch( | |
| 431 WebIDL: ['getraises', '(', ScopedNames, ')'], | |
| 432 WebKit: ['getter', 'raises', '(', ScopedNames, ')']); | |
| 433 | |
| 434 var SetRaises = syntax_switch( | |
| 435 WebIDL: ['setraises', '(', ScopedNames, ')'], | |
| 436 WebKit: ['setter', 'raises', '(', ScopedNames, ')']); | |
| 437 | |
| 438 var Raises = ['raises', '(', ScopedNames, ')']; | |
| 439 | |
| 440 var AttrRaises = syntax_switch( | |
| 441 WebIDL: MANY(OR([GetRaises, SetRaises])), | |
| 442 WebKit: MANY(OR([GetRaises, SetRaises, Raises]), separator:',')); | |
| 443 | |
| 444 Attribute.def = syntax_switch( | |
| 445 WebIDL: [MaybeExtAttrs, MAYBE(Stringifier), MAYBE(ReadOnly), | |
| 446 'attribute', Type, Id, MAYBE(AttrRaises), ';'], | |
| 447 WebKit: [MAYBE(Stringifier), MAYBE(ReadOnly), 'attribute', | |
| 448 MaybeExtAttrs, Type, Id, MAYBE(AttrRaises), ';'], | |
| 449 FremontCut: [MaybeAnnotations, MaybeExtAttrs, | |
| 450 MAYBE(AttrGetterSetter), MAYBE(Stringifier), MAYBE(ReadOnly
), | |
| 451 'attribute', Type, Id, MAYBE(AttrRaises), ';' | |
| 452 ]); | |
| 453 | |
| 454 // Operations | |
| 455 | |
| 456 final Special = TEXT(OR(['getter', 'setter', 'creator', 'deleter', 'caller']
)); | |
| 457 final Specials = MANY(Special); | |
| 458 | |
| 459 final Optional = 'optional'; | |
| 460 final AnEllipsis = '...'; | |
| 461 | |
| 462 Argument.def = syntax_switch( | |
| 463 WebIDL: SEQ(MaybeExtAttrs, MAYBE(Optional), MAYBE(IN), | |
| 464 MAYBE(Optional), Type, MAYBE(AnEllipsis), Id, | |
| 465 (e, opt1, isin, opt2, type, el, id) => | |
| 466 new IDLArgument(id, type, e, opt1 || opt2, isin, el)), | |
| 467 | |
| 468 WebKit: SEQ(MAYBE(Optional), MAYBE('in'), MAYBE(Optional), | |
| 469 MaybeExtAttrs, Type, Id | |
| 470 (opt1, isin, opt2, e, type, id) => | |
| 471 new IDLArgument(id, type, e, opt1 || opt2, isin, false))
); | |
| 472 | |
| 473 final Arguments = MANY0(Argument, ','); | |
| 474 | |
| 475 Operation.def = syntax_switch( | |
| 476 WebIDL: [MaybeExtAttrs, MAYBE(Stringifier), MAYBE(Specials), | |
| 477 ReturnType, MAYBE(Id), '(', Arguments, ')', MAYBE(Raises), ';', | |
| 478 (ea, isStringifier, specials, type, id, args, raises) => | |
| 479 new IDLOperation(id, type, ea, null, args, specials, isStri
ngifier) | |
| 480 ], | |
| 481 WebKit: [MaybeExtAttrs, ReturnType, MAYBE(Id), '(', Arguments, ')', | |
| 482 MAYBE(Raises), ';', | |
| 483 (ea, type, id, args, raises) => | |
| 484 new IDLOperation(id, type, ea, null, args, [], false) | |
| 485 ], | |
| 486 FremontCut: [MaybeAnnotations, MaybeExtAttrs, MAYBE(Stringifier), | |
| 487 MAYBE(Specials), ReturnType, MAYBE(Id), '(', Arguments, ')'
, | |
| 488 MAYBE(Raises), ';', | |
| 489 (ann, ea, isStringifier, specials, type, id, args, raises)
=> | |
| 490 new IDLOperation(id, type, ea, ann, args, specials, isStr
ingifier) | |
| 491 ]); | |
| 492 | |
| 493 // Exceptions | |
| 494 | |
| 495 final ExceptionField = [Type, Id, ';']; | |
| 496 final ExceptionMember = OR([Const, ExceptionField, ExtAttrs]); | |
| 497 ExceptionDef.def = ['exception', Id, '{', MANY0(ExceptionMember), '}', ';']; | |
| 498 | |
| 499 // ExtendedAttributes | |
| 500 | |
| 501 var ExtAttrArgList = ['(', MANY0(Argument, ','), ')']; | |
| 502 | |
| 503 var ExtAttrFunctionValue = | |
| 504 [Id, '(', MANY0(Argument, ','), ')', | |
| 505 (name, args) => new IDLExtAttrFunctionValue(name, args) | |
| 506 ]; | |
| 507 | |
| 508 var ExtAttrValue = OR([ExtAttrFunctionValue, | |
| 509 TEXT(LEX('value', MANY(CHAR(idNextCharSet + '&:-|')))
)]); | |
| 510 | |
| 511 var ExtAttr = [Id, MAYBE(OR([['=', ExtAttrValue], ExtAttrArgList]))]; | |
| 512 | |
| 513 ExtAttrs.def = ['[', MANY(ExtAttr, ','), ']', | |
| 514 (list) => new IDLExtAttrs(list)];; | |
| 515 | |
| 516 MaybeExtAttrs.def = OR(ExtAttrs, | |
| 517 [ () => new IDLExtAttrs() ] ); | |
| 518 | |
| 519 // Annotations - used in the FremontCut IDL grammar. | |
| 520 | |
| 521 var AnnotationArgValue = TEXT(LEX('xx', MANY(CHAR(idNextCharSet + '&:-|'))))
; | |
| 522 | |
| 523 var AnnotationArg = [Id, MAYBE(['=', AnnotationArgValue])]; | |
| 524 | |
| 525 var AnnotationBody = ['(', MANY0(AnnotationArg, ','), ')']; | |
| 526 | |
| 527 var Annotation = ['@', Id, MAYBE(AnnotationBody), | |
| 528 (id, body) => new IDLAnnotation(id, body)]; | |
| 529 | |
| 530 MaybeAnnotations.def = [MANY0(Annotation), (list) => new IDLAnnotations(list
)]; | |
| 531 | |
| 532 // Snippets - used in the FremontCut IDL grammar. | |
| 533 | |
| 534 final SnippetText = TEXT(LEX('snippet body', MANY0([NOT('}'), CHAR()]))); | |
| 535 Snippet.def = [MaybeAnnotations, 'snippet', '{', SnippetText, '}', ';', | |
| 536 (ann, text) => new IDLSnippet(ann, text)]; | |
| 537 | |
| 538 | |
| 539 grammar.whitespace = | |
| 540 OR([MANY(CHAR(' \t\r\n')), | |
| 541 ['//', MANY0([NOT(CHAR('\r\n')), CHAR()])], | |
| 542 ['#', MANY0([NOT(CHAR('\r\n')), CHAR()])], | |
| 543 ['/*', MANY0([NOT('*/'), CHAR()]), '*/']]); | |
| 544 | |
| 545 // Top level - at least one definition. | |
| 546 return MANY(Definition); | |
| 547 | |
| 548 } | |
| 549 } | |
| OLD | NEW |