Advertisement
Guest User

CS.g4

a guest
Jul 28th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.23 KB | None | 0 0
  1. grammar CS;
  2. import Unicode;
  3.  
  4. start: namespaceOrTypeName EOF;
  5.  
  6. /**********
  7. *
  8. * Basic Concepts
  9. *
  10. **********/
  11.  
  12. namespaceName
  13. : namespaceOrTypeName
  14. ;
  15.  
  16. typeName
  17. : namespaceOrTypeName
  18. ;
  19.  
  20. namespaceOrTypeName
  21. : Identifier typeArgumentList?
  22. | namespaceOrTypeName '.' Identifier typeArgumentList?
  23. | qualifiedAliasMember
  24. ;
  25.  
  26. /**********
  27. *
  28. * Types
  29. *
  30. **********/
  31.  
  32. type
  33. : (typeName
  34. | simpleType
  35. | enumType
  36. | classType
  37. | interfaceType
  38. | delegateType
  39. | typeParameter
  40. | 'void' '*'
  41. ) ('?' | rankSpecifiers | '*')*
  42. ;
  43.  
  44. valueType
  45. : structType
  46. | enumType
  47. ;
  48.  
  49. structType
  50. : typeName
  51. | simpleType
  52. | nullableType
  53. ;
  54.  
  55. simpleType
  56. : numericType
  57. | 'bool'
  58. ;
  59.  
  60. numericType
  61. : integralType
  62. | floatingPointType
  63. | 'decimal'
  64. ;
  65.  
  66. integralType
  67. : 'sbyte'
  68. | 'byte'
  69. | 'short'
  70. | 'ushort'
  71. | 'int'
  72. | 'uint'
  73. | 'long'
  74. | 'ulong'
  75. | 'char'
  76. ;
  77.  
  78. floatingPointType
  79. : 'float'
  80. | 'double'
  81. ;
  82.  
  83. nullableType
  84. : nonNullableValueType '?'
  85. ;
  86.  
  87. nonNullableValueType
  88. : type
  89. ;
  90.  
  91. enumType
  92. : typeName
  93. ;
  94.  
  95. referenceType
  96. : classType
  97. | interfaceType
  98. | arrayType
  99. | delegateType
  100. ;
  101.  
  102. classType
  103. : typeName
  104. | 'object'
  105. | 'dynamic'
  106. | 'string'
  107. ;
  108.  
  109. interfaceType
  110. : typeName
  111. ;
  112.  
  113. rankSpecifiers
  114. : rankSpecifier
  115. | rankSpecifiers rankSpecifier
  116. ;
  117.  
  118. rankSpecifier
  119. : '[' dimSeparators? ']'
  120. ;
  121.  
  122. dimSeparators
  123. : ','
  124. | dimSeparators ','
  125. ;
  126.  
  127. delegateType
  128. : typeName
  129. ;
  130.  
  131. typeArgumentList
  132. : '<' typeArguments '>'
  133. ;
  134.  
  135. typeArguments
  136. : typeArgument
  137. | typeArguments ',' typeArgument
  138. ;
  139.  
  140. typeArgument
  141. : type
  142. ;
  143.  
  144. typeParameter
  145. : Identifier
  146. ;
  147.  
  148. pointerType
  149. : unmanagedType '*'
  150. | 'void' '*'
  151. ;
  152.  
  153. unmanagedType
  154. : type
  155. ;
  156.  
  157. /**********
  158. *
  159. * Variable
  160. *
  161. **********/
  162.  
  163. variableReference
  164. : expression
  165. ;
  166.  
  167. /**********
  168. *
  169. * Expressions
  170. *
  171. **********/
  172.  
  173. argumentList
  174. : argument
  175. | argumentList ',' argument
  176. ;
  177.  
  178. argument
  179. : argumentName? argumentValue
  180. ;
  181.  
  182. argumentName
  183. : Identifier ':'
  184. ;
  185.  
  186. argumentValue
  187. : expression
  188. | 'ref' variableReference
  189. | 'out' variableReference
  190. ;
  191.  
  192. primaryExpression
  193. : (literal
  194. | simpleName
  195. | parenthesizedExpression
  196. | predefinedType '.' Identifier typeArgumentList?
  197. | qualifiedAliasMember '.' Identifier
  198. | thisAccess
  199. | baseAccess
  200. | objectCreationExpression
  201. | delegateCreationExpression
  202. | anonymousObjectCreationExpression
  203. | typeofExpression
  204. | checkedExpression
  205. | uncheckedExpression
  206. | defaultValueExpression
  207. | anonymousMethodExpression
  208. | sizeofExpression
  209. ) ('[' argumentList ']' | '[' expression ']')* ( ('.' Identifier typeArgumentList? | '(' argumentList? ')' | '++' | '--' | '->' Identifier typeArgumentList?) ('[' argumentList ']' | '[' expression ']')*)*
  210. | arrayCreationExpression
  211. ;
  212.  
  213. primaryNoArrayCreationExpression
  214. : (literal
  215. | simpleName
  216. | parenthesizedExpression
  217. | memberAccess
  218. | invocationExpression
  219. | thisAccess
  220. | baseAccess
  221. | postIncrementExpression
  222. | postDecrementExpression
  223. | objectCreationExpression
  224. | delegateCreationExpression
  225. | anonymousObjectCreationExpression
  226. | typeofExpression
  227. | checkedExpression
  228. | uncheckedExpression
  229. | defaultValueExpression
  230. | anonymousMethodExpression
  231. | pointerMemberAccess
  232. | sizeofExpression
  233. ) ('[' argumentList ']' | '[' expression ']')*
  234. ;
  235.  
  236. simpleName
  237. : Identifier typeArgumentList?
  238. ;
  239.  
  240. parenthesizedExpression
  241. : '(' expression ')'
  242. ;
  243.  
  244. memberAccess
  245. : primaryExpression '.' Identifier typeArgumentList?
  246. | predefinedType '.' Identifier typeArgumentList?
  247. | qualifiedAliasMember '.' Identifier
  248. ;
  249.  
  250. predefinedType
  251. : 'bool'
  252. | 'byte'
  253. | 'char'
  254. | 'decimal'
  255. | 'double'
  256. | 'float'
  257. | 'int'
  258. | 'long'
  259. | 'object'
  260. | 'sbyte'
  261. | 'short'
  262. | 'string'
  263. | 'uint'
  264. | 'ulong'
  265. | 'ushort'
  266. ;
  267.  
  268. invocationExpression
  269. : primaryExpression '(' argumentList? ')'
  270. ;
  271.  
  272. elementAccess
  273. : primaryNoArrayCreationExpression '[' argumentList ']'
  274. ;
  275.  
  276. thisAccess
  277. : 'this'
  278. ;
  279.  
  280. baseAccess
  281. : 'base' '.' Identifier
  282. | 'base' '[' argumentList ']'
  283. ;
  284.  
  285. postIncrementExpression
  286. : primaryExpression '++'
  287. ;
  288.  
  289. postDecrementExpression
  290. : primaryExpression '--'
  291. ;
  292.  
  293. objectCreationExpression
  294. : 'new' type '(' argumentList? ')' objectOrCollectionInitializer?
  295. | 'new' type objectOrCollectionInitializer
  296. ;
  297.  
  298. objectOrCollectionInitializer
  299. : objectInitializer
  300. | collectionInitializer
  301. ;
  302.  
  303. objectInitializer
  304. : '{' memberInitializerList? '}'
  305. | '{' memberInitializerList ',' '}'
  306. ;
  307.  
  308. memberInitializerList
  309. : memberInitializer
  310. | memberInitializer ',' memberInitializer
  311. ;
  312.  
  313. memberInitializer
  314. : Identifier '=' initializerValue
  315. ;
  316.  
  317. initializerValue
  318. : expression
  319. | objectOrCollectionInitializer
  320. ;
  321.  
  322. collectionInitializer
  323. : '{' elementInitializerList '}'
  324. | '{' elementInitializerList ',' '}'
  325. ;
  326.  
  327. elementInitializerList
  328. : elementInitializer
  329. | elementInitializerList ',' elementInitializer
  330. ;
  331.  
  332. elementInitializer
  333. : nonAssignmentExpression
  334. | '{' expressionList '}'
  335. ;
  336.  
  337. expressionList
  338. : expression
  339. | expressionList ',' expression
  340. ;
  341.  
  342. arrayCreationExpression
  343. : 'new' nonArrayType '[' expressionList ']' rankSpecifiers? arrayInitializer?
  344. | 'new' arrayType arrayInitializer
  345. | 'new' rankSpecifier arrayInitializer
  346. ;
  347.  
  348. delegateCreationExpression
  349. : 'new' delegateType '(' expression ')'
  350. ;
  351.  
  352. anonymousObjectCreationExpression
  353. : 'new' anonymousObjectInitializer
  354. ;
  355.  
  356. anonymousObjectInitializer
  357. : '{' memberDeclaratorList? '}'
  358. | '{' memberDeclaratorList ',' '}'
  359. ;
  360.  
  361. memberDeclaratorList
  362. : memberDeclarator
  363. | memberDeclaratorList ',' memberDeclarator
  364. ;
  365.  
  366. memberDeclarator
  367. : simpleName
  368. | memberAccess
  369. | Identifier '=' expression
  370. ;
  371.  
  372. typeofExpression
  373. : 'typeof' '(' type ')'
  374. | 'typeof' '(' unboundTypeName ')'
  375. | 'typeof' '(' 'void' ')'
  376. ;
  377.  
  378. unboundTypeName
  379. : Identifier genericDimensionSpecifier?
  380. | Identifier '::' Identifier genericDimensionSpecifier?
  381. | unboundTypeName '.' Identifier genericDimensionSpecifier?
  382. ;
  383.  
  384. genericDimensionSpecifier
  385. : '<' commas? '>'
  386. ;
  387.  
  388. commas
  389. : ','
  390. | commas ','
  391. ;
  392.  
  393. checkedExpression
  394. : 'checked' '(' expression ')'
  395. ;
  396.  
  397. uncheckedExpression
  398. : 'unchecked' '(' expression ')'
  399. ;
  400.  
  401. defaultValueExpression
  402. : 'default' '(' type ')'
  403. ;
  404.  
  405. unaryExpression
  406. : primaryExpression
  407. | '+' unaryExpression
  408. | '-' unaryExpression
  409. | '!' unaryExpression
  410. | '~' unaryExpression
  411. | preIncrementExpression
  412. | preDecrementExpression
  413. | castExpression
  414. | pointerIndirectionExpression
  415. | addressofExpression
  416. ;
  417.  
  418. pointerIndirectionExpression
  419. : '*' unaryExpression
  420. ;
  421.  
  422. pointerMemberAccess
  423. : primaryExpression '->' Identifier typeArgumentList?
  424. ;
  425.  
  426. pointerElementAccess
  427. : primaryNoArrayCreationExpression '[' expression ']'
  428. ;
  429.  
  430. addressofExpression
  431. : '&' unaryExpression
  432. ;
  433.  
  434. sizeofExpression
  435. : 'sizeof' '(' unmanagedType ')'
  436. ;
  437.  
  438. fixedStatement
  439. : 'fixed' '(' pointerType fixedPointerDeclarators ')' embeddedStatement
  440. ;
  441.  
  442. fixedPointerDeclarators
  443. : fixedPointerDeclarator
  444. | fixedPointerDeclarators ',' fixedPointerDeclarator
  445. ;
  446.  
  447. fixedPointerDeclarator
  448. : Identifier '=' fixedPointerInitializer
  449. ;
  450.  
  451. fixedPointerInitializer
  452. : '&' variableReference
  453. | expression
  454. ;
  455.  
  456. preIncrementExpression
  457. : '++' unaryExpression
  458. ;
  459.  
  460. preDecrementExpression
  461. : '--' unaryExpression
  462. ;
  463.  
  464. castExpression
  465. : '(' type ')' unaryExpression
  466. ;
  467.  
  468. multiplicativeExpression
  469. : unaryExpression
  470. | multiplicativeExpression '*' unaryExpression
  471. | multiplicativeExpression '/' unaryExpression
  472. | multiplicativeExpression '%' unaryExpression
  473. ;
  474.  
  475. additiveExpression
  476. : multiplicativeExpression
  477. | additiveExpression '+' multiplicativeExpression
  478. | additiveExpression '-' multiplicativeExpression
  479. ;
  480.  
  481. shiftExpression
  482. : additiveExpression
  483. | shiftExpression '<<' additiveExpression
  484. | shiftExpression '>>' additiveExpression
  485. ;
  486.  
  487. relationalExpression
  488. : shiftExpression
  489. | relationalExpression '<' shiftExpression
  490. | relationalExpression '>' shiftExpression
  491. | relationalExpression '<=' shiftExpression
  492. | relationalExpression '>=' shiftExpression
  493. | relationalExpression 'is' type
  494. | relationalExpression 'as' type
  495. ;
  496.  
  497. equalityExpression
  498. : relationalExpression
  499. | equalityExpression '==' relationalExpression
  500. | equalityExpression '!=' relationalExpression
  501. ;
  502.  
  503. andExpression
  504. : equalityExpression
  505. | andExpression '&' equalityExpression
  506. ;
  507.  
  508. exclusiveOrExpression
  509. : andExpression
  510. | exclusiveOrExpression '^' andExpression
  511. ;
  512.  
  513. inclusiveOrExpression
  514. : exclusiveOrExpression
  515. | inclusiveOrExpression '|' exclusiveOrExpression
  516. ;
  517.  
  518. conditionalAndExpression
  519. : inclusiveOrExpression
  520. | conditionalAndExpression '&&' inclusiveOrExpression
  521. ;
  522.  
  523. conditionalOrExpression
  524. : conditionalAndExpression
  525. | conditionalOrExpression '||' conditionalAndExpression
  526. ;
  527.  
  528. nullCoalescingExpression
  529. : conditionalOrExpression
  530. | conditionalOrExpression '??' nullCoalescingExpression
  531. ;
  532.  
  533. conditionalExpression
  534. : nullCoalescingExpression
  535. | nullCoalescingExpression '?' expression ':' expression
  536. ;
  537.  
  538. lambdaExpression
  539. : anonymousFunctionSignature '=>' anonymousFunctionBody
  540. ;
  541.  
  542. anonymousMethodExpression
  543. : 'delegate' explicitAnonymousFunctionSignature? block
  544. ;
  545.  
  546. anonymousFunctionSignature
  547. : explicitAnonymousFunctionSignature
  548. | implicitAnonymousFunctionSignature
  549. ;
  550.  
  551. explicitAnonymousFunctionSignature
  552. : '(' explicitAnonymousFunctionParameterList? ')'
  553. ;
  554.  
  555. explicitAnonymousFunctionParameterList
  556. : explicitAnonymousFunctionParameter
  557. | explicitAnonymousFunctionParameterList ',' explicitAnonymousFunctionParameter
  558. ;
  559.  
  560. explicitAnonymousFunctionParameter
  561. : anonymousFunctionParameterModifier? type Identifier
  562. ;
  563.  
  564. anonymousFunctionParameterModifier
  565. : 'ref'
  566. | 'out'
  567. ;
  568.  
  569. implicitAnonymousFunctionSignature
  570. : '(' implicitAnonymousFunctionParameterList? ')'
  571. | implicitAnonymousFunctionParameter
  572. ;
  573.  
  574. implicitAnonymousFunctionParameterList
  575. : implicitAnonymousFunctionParameter
  576. | implicitAnonymousFunctionParameterList ',' implicitAnonymousFunctionParameter
  577. ;
  578.  
  579. implicitAnonymousFunctionParameter
  580. : Identifier
  581. ;
  582.  
  583. anonymousFunctionBody
  584. : expression
  585. | block
  586. ;
  587.  
  588. queryExpression
  589. : fromClause queryBody
  590. ;
  591.  
  592. fromClause
  593. : 'from' type? Identifier 'in' expression
  594. ;
  595.  
  596. queryBody
  597. : queryBodyClauses? selectOrGroupClause queryContinuation?
  598. ;
  599.  
  600. queryBodyClauses
  601. : queryBodyClause
  602. | queryBodyClauses queryBodyClause
  603. ;
  604.  
  605. queryBodyClause
  606. : fromClause
  607. | letClause
  608. | whereClause
  609. | joinClause
  610. | joinIntoClause
  611. | orderbyClause
  612. ;
  613.  
  614. letClause
  615. : 'let' Identifier '=' expression
  616. ;
  617.  
  618. whereClause
  619. : 'where' booleanExpression
  620. ;
  621.  
  622. joinClause
  623. : 'join' type? Identifier 'in' expression 'on' expression 'equals' expression
  624. ;
  625.  
  626. joinIntoClause
  627. : 'join' type? Identifier 'in' expression 'on' expression 'equals' expression 'into' Identifier
  628. ;
  629.  
  630. orderbyClause
  631. : 'orderby' orderings
  632. ;
  633.  
  634. orderings
  635. : ordering
  636. | orderings ',' ordering
  637. ;
  638.  
  639. ordering
  640. : expression orderingDirection?
  641. ;
  642.  
  643. orderingDirection
  644. : 'ascending'
  645. | 'descending'
  646. ;
  647.  
  648. selectOrGroupClause
  649. : selectClause
  650. | groupClause
  651. ;
  652.  
  653. selectClause
  654. : 'select' expression
  655. ;
  656.  
  657. groupClause
  658. : 'group' expression 'by' expression
  659. ;
  660.  
  661. queryContinuation
  662. : 'into' Identifier queryBody
  663. ;
  664.  
  665. assignment
  666. : unaryExpression assignmentOperator expression
  667. ;
  668.  
  669. assignmentOperator
  670. : '='
  671. | '+='
  672. | '-='
  673. | '*='
  674. | '/='
  675. | '%='
  676. | '&='
  677. | '|='
  678. | '^='
  679. | '<<='
  680. | '>>='
  681. ;
  682.  
  683. expression
  684. : nonAssignmentExpression
  685. | assignment
  686. ;
  687.  
  688. nonAssignmentExpression
  689. : conditionalExpression
  690. | lambdaExpression
  691. | queryExpression
  692. ;
  693.  
  694. constantExpression
  695. : expression
  696. ;
  697.  
  698. booleanExpression
  699. : expression
  700. ;
  701.  
  702.  
  703. /**********
  704. *
  705. * Statements
  706. *
  707. **********/
  708.  
  709. statement
  710. : labeledStatement
  711. | declarationStatement
  712. | embeddedStatement
  713. ;
  714.  
  715. embeddedStatement
  716. : block
  717. | emptyStatement
  718. | expressionStatement
  719. | selectionStatement
  720. | iterationStatement
  721. | jumpStatement
  722. | tryStatement
  723. | checkedStatement
  724. | uncheckedStatement
  725. | lockStatement
  726. | usingStatement
  727. | yieldStatement
  728. | unsafeStatement
  729. | fixedStatement
  730. ;
  731.  
  732. unsafeStatement
  733. : 'unsafe' block
  734. ;
  735.  
  736. block
  737. : '{' statementList? '}'
  738. ;
  739.  
  740. statementList
  741. : statement
  742. | statementList statement
  743. ;
  744.  
  745. emptyStatement
  746. : ';'
  747. ;
  748.  
  749. labeledStatement
  750. : Identifier ':' statement
  751. ;
  752.  
  753. declarationStatement
  754. : localVariableDeclaration ';'
  755. | localConstantDeclaration ';'
  756. ;
  757.  
  758. localVariableDeclaration
  759. : localVariableType localVariableDeclarators
  760. ;
  761.  
  762. localVariableType
  763. : type
  764. | 'var'
  765. ;
  766.  
  767. localVariableDeclarators
  768. : localVariableDeclarator
  769. | localVariableDeclarators ',' localVariableDeclarator
  770. ;
  771.  
  772. localVariableDeclarator
  773. : Identifier
  774. | Identifier '=' localVariableInitializer
  775. ;
  776.  
  777. localVariableInitializer
  778. : expression
  779. | arrayInitializer
  780. | stackallocInitializer
  781. ;
  782.  
  783. stackallocInitializer
  784. : 'stackalloc' unmanagedType '[' expression ']'
  785. ;
  786.  
  787. localConstantDeclaration
  788. : 'const' type constantDeclarators
  789. ;
  790.  
  791. constantDeclarators
  792. : constantDeclarator
  793. | constantDeclarators ',' constantDeclarator
  794. ;
  795.  
  796. constantDeclarator
  797. : Identifier '=' constantExpression
  798. ;
  799.  
  800. expressionStatement
  801. : statementExpression ';'
  802. ;
  803.  
  804. statementExpression
  805. : invocationExpression
  806. | objectCreationExpression
  807. | assignment
  808. | postIncrementExpression
  809. | postDecrementExpression
  810. | preIncrementExpression
  811. | preDecrementExpression
  812. ;
  813.  
  814. selectionStatement
  815. : ifStatement
  816. | switchStatement
  817. ;
  818.  
  819. ifStatement
  820. : 'if' '(' booleanExpression ')' embeddedStatement
  821. | 'if' '(' booleanExpression ')' embeddedStatement 'else' embeddedStatement
  822. ;
  823.  
  824. switchStatement
  825. : 'switch' '(' expression ')' switchBlock
  826. ;
  827.  
  828. switchBlock
  829. : '{' switchSections? '}'
  830. ;
  831.  
  832. switchSections
  833. : switchSection
  834. | switchSections switchSection
  835. ;
  836.  
  837. switchSection
  838. : switchLabels statementList
  839. ;
  840.  
  841. switchLabels
  842. : switchLabel
  843. | switchLabels switchLabel
  844. ;
  845.  
  846. switchLabel
  847. : 'case' constantExpression ':'
  848. | 'default' ':'
  849. ;
  850.  
  851. iterationStatement
  852. : whileStatement
  853. | doStatement
  854. | forStatement
  855. | foreachStatement
  856. ;
  857.  
  858. whileStatement
  859. : 'while' '(' booleanExpression ')' embeddedStatement
  860. ;
  861.  
  862. doStatement
  863. : 'do' embeddedStatement 'while' '(' booleanExpression ')' ';'
  864. ;
  865.  
  866. forStatement
  867. : 'for' '(' forInitializer? ';' forCondition? ';' forIterator? ')' embeddedStatement
  868. ;
  869.  
  870. forInitializer
  871. : localVariableDeclaration
  872. | statementExpressionList
  873. ;
  874.  
  875. forCondition
  876. : booleanExpression
  877. ;
  878.  
  879. forIterator
  880. : statementExpressionList
  881. ;
  882.  
  883. statementExpressionList
  884. : statementExpression
  885. | statementExpressionList ',' statementExpression
  886. ;
  887.  
  888. foreachStatement
  889. : 'foreach' '(' localVariableType Identifier 'in' expression ')' embeddedStatement
  890. ;
  891.  
  892. jumpStatement
  893. : breakStatement
  894. | continueStatement
  895. | gotoStatement
  896. | returnStatement
  897. | throwStatement
  898. ;
  899.  
  900. breakStatement
  901. : 'break' ';'
  902. ;
  903.  
  904. continueStatement
  905. : 'continue' ';'
  906. ;
  907.  
  908. gotoStatement
  909. : 'goto' Identifier ';'
  910. | 'goto' 'case' constantExpression ';'
  911. | 'goto' 'default' ';'
  912. ;
  913.  
  914. returnStatement
  915. : 'return' expression? ';'
  916. ;
  917.  
  918. throwStatement
  919. : 'throw' expression? ';'
  920. ;
  921.  
  922. tryStatement
  923. : 'try' block catchClauses
  924. | 'try' block finallyClause
  925. | 'try' block catchClauses finallyClause
  926. ;
  927.  
  928. catchClauses
  929. : specificCatchClauses generalCatchClause?
  930. | specificCatchClauses? generalCatchClause
  931. ;
  932.  
  933. specificCatchClauses
  934. : specificCatchClause
  935. | specificCatchClauses specificCatchClause
  936. ;
  937.  
  938. specificCatchClause
  939. : 'catch' '(' classType Identifier? ')' block
  940. ;
  941.  
  942. generalCatchClause
  943. : 'catch' block
  944. ;
  945.  
  946. finallyClause
  947. : 'finally' block
  948. ;
  949.  
  950. checkedStatement
  951. : 'checked' block
  952. ;
  953.  
  954. uncheckedStatement
  955. : 'unchecked' block
  956. ;
  957.  
  958. lockStatement
  959. : 'lock' '(' expression ')' embeddedStatement
  960. ;
  961.  
  962. usingStatement
  963. : 'using' '(' resourceAcquisition ')' embeddedStatement
  964. ;
  965.  
  966. resourceAcquisition
  967. : localVariableDeclaration
  968. | expression
  969. ;
  970.  
  971. yieldStatement
  972. : 'yield' 'return' expression ';'
  973. | 'yield' 'break' ';'
  974. ;
  975.  
  976. /**********
  977. *
  978. * Namespaces
  979. *
  980. **********/
  981.  
  982. compilationUnit
  983. : externAliasDirectives? usingDirectives? globalAttributes? namespaceMemberDeclarations?
  984. ;
  985.  
  986. namespaceDeclaration
  987. : 'namespace' qualifiedIdentifier namespaceBody ';'?
  988. ;
  989.  
  990. qualifiedIdentifier
  991. : Identifier
  992. | qualifiedIdentifier '.' Identifier
  993. ;
  994.  
  995. namespaceBody
  996. : '{' externAliasDirectives? usingDirectives? namespaceMemberDeclarations? '}'
  997. ;
  998.  
  999. externAliasDirectives
  1000. : externAliasDirective
  1001. | externAliasDirectives externAliasDirective
  1002. ;
  1003.  
  1004. externAliasDirective
  1005. : 'extern' 'alias' Identifier ';'
  1006. ;
  1007.  
  1008. usingDirectives
  1009. : usingDirective
  1010. | usingDirectives usingDirective
  1011. ;
  1012.  
  1013. usingDirective
  1014. : usingAliasDirective
  1015. | usingNamespaceDirective
  1016. ;
  1017.  
  1018. usingAliasDirective
  1019. : 'using' Identifier '=' namespaceOrTypeName ';'
  1020. ;
  1021.  
  1022. usingNamespaceDirective
  1023. : 'using' namespaceName ';'
  1024. ;
  1025.  
  1026. namespaceMemberDeclarations
  1027. : namespaceMemberDeclaration
  1028. | namespaceMemberDeclarations namespaceMemberDeclaration
  1029. ;
  1030.  
  1031. namespaceMemberDeclaration
  1032. : namespaceDeclaration
  1033. | typeDeclaration
  1034. ;
  1035.  
  1036. typeDeclaration
  1037. : classDeclaration
  1038. | structDeclaration
  1039. | interfaceDeclaration
  1040. | enumDeclaration
  1041. | delegateDeclaration
  1042. ;
  1043.  
  1044. qualifiedAliasMember
  1045. : Identifier '::' Identifier typeArgumentList?
  1046. ;
  1047.  
  1048. /**********
  1049. *
  1050. * Classes
  1051. *
  1052. **********/
  1053.  
  1054. classDeclaration
  1055. : attributes? classModifiers? 'partial'? 'class' Identifier typeParameterList? classBase? typeParameterConstraintsClauses? classBody ';'?
  1056. ;
  1057.  
  1058. classModifiers
  1059. : classModifier
  1060. | classModifiers classModifier
  1061. ;
  1062.  
  1063. classModifier
  1064. : 'new'
  1065. | 'public'
  1066. | 'protected'
  1067. | 'internal'
  1068. | 'private'
  1069. | 'abstract'
  1070. | 'sealed'
  1071. | 'static'
  1072. | 'unsafe'
  1073. ;
  1074.  
  1075. typeParameterList
  1076. : '<' typeParameters '>'
  1077. ;
  1078.  
  1079. typeParameters
  1080. : attributes? typeParameter
  1081. | typeParameters ',' attributes? typeParameter
  1082. ;
  1083.  
  1084. classBase
  1085. : ':' classType
  1086. | ':' interfaceTypeList
  1087. | ':' classType ',' interfaceTypeList
  1088. ;
  1089.  
  1090. interfaceTypeList
  1091. : interfaceType
  1092. | interfaceTypeList ',' interfaceType
  1093. ;
  1094.  
  1095. typeParameterConstraintsClauses
  1096. : typeParameterConstraintsClause
  1097. | typeParameterConstraintsClauses typeParameterConstraintsClause
  1098. ;
  1099.  
  1100. typeParameterConstraintsClause
  1101. : 'where' typeParameter ':' typeParameterConstraints
  1102. ;
  1103.  
  1104. typeParameterConstraints
  1105. : primaryConstraint
  1106. | secondaryConstraints
  1107. | constructorConstraint
  1108. | primaryConstraint ',' secondaryConstraints
  1109. | primaryConstraint ',' constructorConstraint
  1110. | secondaryConstraints ',' constructorConstraint
  1111. | primaryConstraint ',' secondaryConstraints ',' constructorConstraint
  1112. ;
  1113.  
  1114. primaryConstraint
  1115. : classType
  1116. | 'class'
  1117. | 'struct'
  1118. ;
  1119.  
  1120. secondaryConstraints
  1121. : interfaceType
  1122. | typeParameter
  1123. | secondaryConstraints ',' interfaceType
  1124. | secondaryConstraints ',' typeParameter
  1125. ;
  1126.  
  1127. constructorConstraint
  1128. : 'new' '(' ')'
  1129. ;
  1130.  
  1131. classBody
  1132. : '{' classMemberDeclarations? '}'
  1133. ;
  1134.  
  1135. classMemberDeclarations
  1136. : classMemberDeclaration
  1137. | classMemberDeclarations classMemberDeclaration
  1138. ;
  1139.  
  1140. classMemberDeclaration
  1141. : constantDeclaration
  1142. | fieldDeclaration
  1143. | methodDeclaration
  1144. | propertyDeclaration
  1145. | eventDeclaration
  1146. | indexerDeclaration
  1147. | operatorDeclaration
  1148. | constructorDeclaration
  1149. | destructorDeclaration
  1150. | staticConstructorDeclaration
  1151. | typeDeclaration
  1152. ;
  1153.  
  1154. constantDeclaration
  1155. : attributes? constantModifiers? 'const' type constantDeclarators ';'
  1156. ;
  1157.  
  1158. constantModifiers
  1159. : constantModifier
  1160. | constantModifiers constantModifier
  1161. ;
  1162.  
  1163. constantModifier
  1164. : 'new'
  1165. | 'public'
  1166. | 'protected'
  1167. | 'internal'
  1168. | 'private'
  1169. ;
  1170.  
  1171. fieldDeclaration
  1172. : attributes? fieldModifiers? type variableDeclarators ';'
  1173. ;
  1174.  
  1175. fieldModifiers
  1176. : fieldModifier
  1177. | fieldModifiers fieldModifier
  1178. ;
  1179.  
  1180. fieldModifier
  1181. : 'new'
  1182. | 'public'
  1183. | 'protected'
  1184. | 'internal'
  1185. | 'private'
  1186. | 'static'
  1187. | 'readonly'
  1188. | 'volatile'
  1189. | 'unsafe'
  1190. ;
  1191.  
  1192. variableDeclarators
  1193. : variableDeclarator
  1194. | variableDeclarators ',' variableDeclarator
  1195. ;
  1196.  
  1197. variableDeclarator
  1198. : Identifier
  1199. | Identifier '=' variableInitializer
  1200. ;
  1201.  
  1202. variableInitializer
  1203. : expression
  1204. | arrayInitializer
  1205. ;
  1206.  
  1207. methodDeclaration
  1208. : methodHeader methodBody
  1209. ;
  1210.  
  1211. methodHeader
  1212. : attributes? methodModifiers? 'partial'? returnType memberName typeParameterList? '(' formalParameterList? ')' typeParameterConstraintsClauses?
  1213. ;
  1214.  
  1215. methodModifiers
  1216. : methodModifier
  1217. | methodModifiers methodModifier
  1218. ;
  1219.  
  1220. methodModifier
  1221. : 'new'
  1222. | 'public'
  1223. | 'protected'
  1224. | 'internal'
  1225. | 'private'
  1226. | 'static'
  1227. | 'virtual'
  1228. | 'sealed'
  1229. | 'override'
  1230. | 'abstract'
  1231. | 'extern'
  1232. | 'unsafe'
  1233. ;
  1234.  
  1235. returnType
  1236. : type
  1237. | 'void'
  1238. ;
  1239.  
  1240. memberName
  1241. : Identifier
  1242. | interfaceType '.' Identifier
  1243. ;
  1244.  
  1245. methodBody
  1246. : block
  1247. | ';'
  1248. ;
  1249.  
  1250. formalParameterList
  1251. : fixedParameters
  1252. | fixedParameters ',' parameterArray
  1253. | parameterArray
  1254. ;
  1255.  
  1256. fixedParameters
  1257. : fixedParameter
  1258. | fixedParameters ',' fixedParameter
  1259. ;
  1260.  
  1261. fixedParameter
  1262. : attributes? parameterModifier? type Identifier defaultArgument?
  1263. ;
  1264.  
  1265. defaultArgument
  1266. : '=' expression
  1267. ;
  1268.  
  1269. parameterModifier
  1270. : 'ref'
  1271. | 'out'
  1272. | 'this'
  1273. ;
  1274.  
  1275. parameterArray
  1276. : attributes? 'params' arrayType Identifier
  1277. ;
  1278.  
  1279. propertyDeclaration
  1280. : attributes? propertyModifiers? type memberName '{' accessorDeclarations '}'
  1281. ;
  1282.  
  1283. propertyModifiers
  1284. : propertyModifier
  1285. | propertyModifiers propertyModifier
  1286. ;
  1287.  
  1288. propertyModifier
  1289. : 'new'
  1290. | 'public'
  1291. | 'protected'
  1292. | 'internal'
  1293. | 'private'
  1294. | 'static'
  1295. | 'virtual'
  1296. | 'sealed'
  1297. | 'override'
  1298. | 'abstract'
  1299. | 'extern'
  1300. | 'unsafe'
  1301. ;
  1302.  
  1303. accessorDeclarations
  1304. : getAccessorDeclaration setAccessorDeclaration?
  1305. | setAccessorDeclaration getAccessorDeclaration?
  1306. ;
  1307.  
  1308. getAccessorDeclaration
  1309. : attributes? accessorModifier? 'get' accessorBody
  1310. ;
  1311.  
  1312. setAccessorDeclaration
  1313. : attributes? accessorModifier? 'set' accessorBody
  1314. ;
  1315.  
  1316. accessorModifier
  1317. : 'protected'
  1318. | 'internal'
  1319. | 'private'
  1320. | 'protected' 'internal'
  1321. | 'internal' 'protected'
  1322. ;
  1323.  
  1324. accessorBody
  1325. : block
  1326. | ';'
  1327. ;
  1328.  
  1329. eventDeclaration
  1330. : attributes? eventModifiers? 'event' type variableDeclarators ';'
  1331. | attributes? eventModifiers? 'event' type memberName '{' eventAccessorDeclarations '}'
  1332. ;
  1333.  
  1334. eventModifiers
  1335. : eventModifier
  1336. | eventModifiers eventModifier
  1337. ;
  1338.  
  1339. eventModifier
  1340. : 'new'
  1341. | 'public'
  1342. | 'protected'
  1343. | 'internal'
  1344. | 'private'
  1345. | 'static'
  1346. | 'virtual'
  1347. | 'sealed'
  1348. | 'override'
  1349. | 'abstract'
  1350. | 'extern'
  1351. | 'unsafe'
  1352. ;
  1353.  
  1354. eventAccessorDeclarations
  1355. : addAccessorDeclaration removeAccessorDeclaration
  1356. | removeAccessorDeclaration addAccessorDeclaration
  1357. ;
  1358.  
  1359. addAccessorDeclaration
  1360. : attributes? 'add' block
  1361. ;
  1362.  
  1363. removeAccessorDeclaration
  1364. : attributes? 'remove' block
  1365. ;
  1366.  
  1367. indexerDeclaration
  1368. : attributes? indexerModifiers? indexerDeclarator '{' accessorDeclarations '}'
  1369. ;
  1370.  
  1371. indexerModifiers
  1372. : indexerModifier
  1373. | indexerModifiers indexerModifier
  1374. ;
  1375.  
  1376. indexerModifier
  1377. : 'new'
  1378. | 'public'
  1379. | 'protected'
  1380. | 'internal'
  1381. | 'private'
  1382. | 'virtual'
  1383. | 'sealed'
  1384. | 'override'
  1385. | 'abstract'
  1386. | 'extern'
  1387. | 'unsafe'
  1388. ;
  1389.  
  1390. indexerDeclarator
  1391. : type 'this' '[' formalParameterList ']'
  1392. | type interfaceType '.' 'this' '[' formalParameterList ']'
  1393. ;
  1394.  
  1395. operatorDeclaration
  1396. : attributes? operatorModifiers operatorDeclarator operatorBody
  1397. ;
  1398.  
  1399. operatorModifiers
  1400. : operatorModifier
  1401. | operatorModifiers operatorModifier
  1402. ;
  1403.  
  1404. operatorModifier
  1405. : 'public'
  1406. | 'static'
  1407. | 'extern'
  1408. | 'unsafe'
  1409. ;
  1410.  
  1411. operatorDeclarator
  1412. : unaryOperatorDeclarator
  1413. | binaryOperatorDeclarator
  1414. | conversionOperatorDeclarator
  1415. ;
  1416.  
  1417. unaryOperatorDeclarator
  1418. : type 'operator' overloadableUnaryOperator '(' type Identifier ')'
  1419. ;
  1420.  
  1421. overloadableUnaryOperator
  1422. : '+'
  1423. | '-'
  1424. | '!'
  1425. | '~'
  1426. | '++'
  1427. | '--'
  1428. | 'true'
  1429. | 'false'
  1430. ;
  1431.  
  1432. binaryOperatorDeclarator
  1433. : type 'operator' overloadableBinaryOperator '(' type Identifier ',' type Identifier ')'
  1434. ;
  1435.  
  1436. overloadableBinaryOperator
  1437. : '+'
  1438. | '-'
  1439. | '*'
  1440. | '/'
  1441. | '%'
  1442. | '&'
  1443. | '|'
  1444. | '^'
  1445. | '<<'
  1446. | '>>'
  1447. | '=='
  1448. | '!='
  1449. | '>'
  1450. | '<'
  1451. | '>='
  1452. | '<='
  1453. ;
  1454.  
  1455. conversionOperatorDeclarator
  1456. : 'implicit' 'operator' type '(' type Identifier ')'
  1457. | 'explicit' 'operator' type '(' type Identifier ')'
  1458. ;
  1459.  
  1460. operatorBody
  1461. : block
  1462. | ';'
  1463. ;
  1464.  
  1465. constructorDeclaration
  1466. : attributes? constructorModifiers? constructorDeclarator constructorBody
  1467. ;
  1468.  
  1469. constructorModifiers
  1470. : constructorModifier
  1471. | constructorModifiers constructorModifier
  1472. ;
  1473.  
  1474. constructorModifier
  1475. : 'public'
  1476. | 'protected'
  1477. | 'internal'
  1478. | 'private'
  1479. | 'extern'
  1480. | 'unsafe'
  1481. ;
  1482.  
  1483. constructorDeclarator
  1484. : Identifier '(' formalParameterList? ')' constructorInitializer?
  1485. ;
  1486.  
  1487. constructorInitializer
  1488. : ':' 'base' '(' argumentList? ')'
  1489. | ':' 'this' '(' argumentList? ')'
  1490. ;
  1491.  
  1492. constructorBody
  1493. : block
  1494. | ';'
  1495. ;
  1496.  
  1497. staticConstructorDeclaration
  1498. : attributes? staticConstructorModifiers Identifier '(' ')' staticConstructorBody
  1499. ;
  1500.  
  1501. staticConstructorModifiers
  1502. : 'extern'? 'unsafe'? 'static'
  1503. | 'unsafe'? 'extern'? 'static'
  1504. | 'extern'? 'static' 'unsafe'?
  1505. | 'unsafe'? 'static' 'extern'?
  1506. | 'static' 'extern'? 'unsafe'?
  1507. | 'static' 'unsafe'? 'extern'?
  1508. ;
  1509.  
  1510. staticConstructorBody
  1511. : block
  1512. | ';'
  1513. ;
  1514.  
  1515. destructorDeclaration
  1516. : attributes? 'extern'? 'unsafe'? '~' Identifier '(' ')' destructorBody
  1517. | attributes? 'unsafe'? 'extern'? '~' Identifier '(' ')' destructorBody
  1518. ;
  1519.  
  1520. destructorBody
  1521. : block
  1522. | ';'
  1523. ;
  1524.  
  1525. /**********
  1526. *
  1527. * Structs
  1528. *
  1529. **********/
  1530.  
  1531. structDeclaration
  1532. : attributes? structModifiers? 'partial'? 'struct' Identifier typeParameterList? structInterfaces? typeParameterConstraintsClauses? structBody ';'?
  1533. ;
  1534.  
  1535. structModifiers
  1536. : structModifier
  1537. | structModifiers structModifier
  1538. ;
  1539.  
  1540. structModifier
  1541. : 'new'
  1542. | 'public'
  1543. | 'protected'
  1544. | 'internal'
  1545. | 'private'
  1546. | 'unsafe'
  1547. ;
  1548.  
  1549. structInterfaces
  1550. : ':' interfaceTypeList
  1551. ;
  1552.  
  1553. structBody
  1554. : '{' structMemberDeclarations? '}'
  1555. ;
  1556.  
  1557. structMemberDeclarations
  1558. : structMemberDeclaration
  1559. | structMemberDeclarations structMemberDeclaration
  1560. ;
  1561.  
  1562. structMemberDeclaration
  1563. : constantDeclaration
  1564. | fieldDeclaration
  1565. | methodDeclaration
  1566. | propertyDeclaration
  1567. | eventDeclaration
  1568. | indexerDeclaration
  1569. | operatorDeclaration
  1570. | constructorDeclaration
  1571. | staticConstructorDeclaration
  1572. | typeDeclaration
  1573. | fixedSizeBufferDeclaration
  1574. ;
  1575.  
  1576. fixedSizeBufferDeclaration
  1577. : attributes? fixedSizeBufferModifiers? 'fixed' bufferElementType fixedSizeBufferDeclarators ';'
  1578. ;
  1579.  
  1580. fixedSizeBufferModifiers
  1581. : fixedSizeBufferModifier
  1582. | fixedSizeBufferModifier fixedSizeBufferModifiers
  1583. ;
  1584.  
  1585. fixedSizeBufferModifier
  1586. : 'new'
  1587. | 'public'
  1588. | 'protected'
  1589. | 'internal'
  1590. | 'private'
  1591. | 'unsafe'
  1592. ;
  1593.  
  1594. bufferElementType
  1595. : type
  1596. ;
  1597.  
  1598. fixedSizeBufferDeclarators
  1599. : fixedSizeBufferDeclarator
  1600. | fixedSizeBufferDeclarator fixedSizeBufferDeclarators
  1601. ;
  1602.  
  1603. fixedSizeBufferDeclarator
  1604. : Identifier '[' constantExpression ']'
  1605. ;
  1606.  
  1607. /**********
  1608. *
  1609. * Arrays
  1610. *
  1611. **********/
  1612.  
  1613. arrayType
  1614. : nonArrayType rankSpecifiers
  1615. ;
  1616.  
  1617. nonArrayType
  1618. : type
  1619. ;
  1620.  
  1621. arrayInitializer
  1622. : '{' variableInitializerList? '}'
  1623. | '{' variableInitializerList ',' '}'
  1624. ;
  1625.  
  1626. variableInitializerList
  1627. : variableInitializer
  1628. | variableInitializerList ',' variableInitializer
  1629. ;
  1630.  
  1631. /**********
  1632. *
  1633. * Interfaces
  1634. *
  1635. **********/
  1636.  
  1637. interfaceDeclaration
  1638. : attributes? interfaceModifiers? 'partial'? 'interface' Identifier variantTypeParameterList? interfaceBase? typeParameterConstraintsClauses? interfaceBody ';'?
  1639. ;
  1640.  
  1641. interfaceModifiers
  1642. : interfaceModifier
  1643. | interfaceModifiers interfaceModifier
  1644. ;
  1645.  
  1646. interfaceModifier
  1647. : 'new'
  1648. | 'public'
  1649. | 'protected'
  1650. | 'internal'
  1651. | 'private'
  1652. | 'unsafe'
  1653. ;
  1654.  
  1655. variantTypeParameterList
  1656. : '<' variantTypeParameters '>'
  1657. ;
  1658.  
  1659. variantTypeParameters
  1660. : attributes? varianceAnnotation? typeParameter
  1661. | variantTypeParameters ',' attributes? varianceAnnotation? typeParameter
  1662. ;
  1663.  
  1664. varianceAnnotation
  1665. : 'in'
  1666. | 'out'
  1667. ;
  1668.  
  1669. interfaceBase
  1670. : ':' interfaceTypeList
  1671. ;
  1672.  
  1673. interfaceBody
  1674. : '{' interfaceMemberDeclarations? '}'
  1675. ;
  1676.  
  1677. interfaceMemberDeclarations
  1678. : interfaceMemberDeclaration
  1679. | interfaceMemberDeclarations interfaceMemberDeclaration
  1680. ;
  1681.  
  1682. interfaceMemberDeclaration
  1683. : interfaceMethodDeclaration
  1684. | interfacePropertyDeclaration
  1685. | interfaceEventDeclaration
  1686. | interfaceIndexerDeclaration
  1687. ;
  1688.  
  1689. interfaceMethodDeclaration
  1690. : attributes? 'new'? returnType Identifier typeParameterList? '(' formalParameterList? ')' typeParameterConstraintsClauses? ';'
  1691. ;
  1692.  
  1693. interfacePropertyDeclaration
  1694. : attributes? 'new'? type Identifier '{' interfaceAccessors '}'
  1695. ;
  1696.  
  1697. interfaceAccessors
  1698. : attributes? 'get' ';'
  1699. | attributes? 'set' ';'
  1700. | attributes? 'get' ';' attributes? 'set' ';'
  1701. | attributes? 'set' ';' attributes? 'get' ';'
  1702. ;
  1703.  
  1704. interfaceEventDeclaration
  1705. : attributes? 'new'? 'event' type Identifier ';'
  1706. ;
  1707.  
  1708. interfaceIndexerDeclaration
  1709. : attributes? 'new'? type 'this' '[' formalParameterList ']' '{' interfaceAccessors '}'
  1710. ;
  1711.  
  1712. /**********
  1713. *
  1714. * Enums
  1715. *
  1716. **********/
  1717.  
  1718. enumDeclaration
  1719. : attributes? enumModifiers? 'enum' Identifier enumBase? enumBody ';'?
  1720. ;
  1721.  
  1722. enumBase
  1723. : ':' integralType
  1724. ;
  1725.  
  1726. enumBody
  1727. : '{' enumMemberDeclarations? '}'
  1728. | '{' enumMemberDeclarations ',' '}'
  1729. ;
  1730.  
  1731. enumModifiers
  1732. : enumModifier
  1733. | enumModifiers enumModifier
  1734. ;
  1735.  
  1736. enumModifier
  1737. : 'new'
  1738. | 'public'
  1739. | 'protected'
  1740. | 'internal'
  1741. | 'private'
  1742. ;
  1743.  
  1744. enumMemberDeclarations
  1745. : enumMemberDeclaration
  1746. | enumMemberDeclarations ',' enumMemberDeclaration
  1747. ;
  1748.  
  1749. enumMemberDeclaration
  1750. : attributes? Identifier
  1751. | attributes? Identifier '=' constantExpression
  1752. ;
  1753.  
  1754.  
  1755. /**********
  1756. *
  1757. * Delegates
  1758. *
  1759. **********/
  1760.  
  1761. delegateDeclaration
  1762. : attributes? delegateModifiers? 'delegate' returnType Identifier variantTypeParameterList? '(' formalParameterList? ')' typeParameterConstraintsClauses? ';'
  1763. ;
  1764.  
  1765. delegateModifiers
  1766. : delegateModifier
  1767. | delegateModifiers delegateModifier
  1768. ;
  1769.  
  1770. delegateModifier
  1771. : 'new'
  1772. | 'public'
  1773. | 'protected'
  1774. | 'internal'
  1775. | 'private'
  1776. | 'unsafe'
  1777. ;
  1778.  
  1779.  
  1780. /**********
  1781. *
  1782. * Attributes
  1783. *
  1784. **********/
  1785.  
  1786. globalAttributes
  1787. : globalAttributeSections
  1788. ;
  1789.  
  1790. globalAttributeSections
  1791. : globalAttributeSection
  1792. | globalAttributeSections globalAttributeSection
  1793. ;
  1794.  
  1795. globalAttributeSection
  1796. : '[' globalAttributeTargetSpecifier attributeList ']'
  1797. | '[' globalAttributeTargetSpecifier attributeList ',' ']'
  1798. ;
  1799.  
  1800. globalAttributeTargetSpecifier
  1801. : globalAttributeTarget ':'
  1802. ;
  1803.  
  1804. globalAttributeTarget
  1805. : 'assembly'
  1806. | 'module'
  1807. ;
  1808.  
  1809. attributes
  1810. : attributeSections
  1811. ;
  1812.  
  1813. attributeSections
  1814. : attributeSection
  1815. | attributeSections attributeSection
  1816. ;
  1817.  
  1818. attributeSection
  1819. : '[' attributeTargetSpecifier? attributeList ']'
  1820. | '[' attributeTargetSpecifier? attributeList ',' ']'
  1821. ;
  1822.  
  1823. attributeTargetSpecifier
  1824. : attributeTarget ':'
  1825. ;
  1826.  
  1827. attributeTarget
  1828. : 'field'
  1829. | 'event'
  1830. | 'method'
  1831. | 'param'
  1832. | 'property'
  1833. | 'return'
  1834. | 'type'
  1835. ;
  1836.  
  1837. attributeList
  1838. : attribute
  1839. | attributeList ',' attribute
  1840. ;
  1841.  
  1842. attribute
  1843. : attributeName attributeArguments?
  1844. ;
  1845.  
  1846. attributeName
  1847. : typeName
  1848. ;
  1849.  
  1850. attributeArguments
  1851. : '(' positionalArgumentList? ')'
  1852. | '(' positionalArgumentList ',' namedArgumentList ')'
  1853. | '(' namedArgumentList ')'
  1854. ;
  1855.  
  1856. positionalArgumentList
  1857. : positionalArgument
  1858. | positionalArgumentList ',' positionalArgument
  1859. ;
  1860.  
  1861. positionalArgument
  1862. : argumentName? attributeArgumentExpression
  1863. ;
  1864.  
  1865. namedArgumentList
  1866. : namedArgument
  1867. | namedArgumentList ',' namedArgument
  1868. ;
  1869.  
  1870. namedArgument
  1871. : Identifier '=' attributeArgumentExpression
  1872. ;
  1873.  
  1874. attributeArgumentExpression
  1875. : expression
  1876. ;
  1877.  
  1878. /**********
  1879. *
  1880. * Literals
  1881. *
  1882. **********/
  1883.  
  1884. literal
  1885. : booleanLiteral
  1886. | IntegerLiteral
  1887. | RealLiteral
  1888. | CharacterLiteral
  1889. | StringLiteral
  1890. | NullLiteral
  1891. ;
  1892.  
  1893. booleanLiteral
  1894. : 'true'
  1895. | 'false'
  1896. ;
  1897.  
  1898. IntegerLiteral
  1899. : DecimalIntegerLiteral
  1900. | HexadecimalIntegerLiteral
  1901. ;
  1902.  
  1903. DecimalIntegerLiteral
  1904. : DecimalDigits IntegerTypeSuffix?
  1905. ;
  1906.  
  1907. fragment
  1908. DecimalDigits
  1909. : DecimalDigit+
  1910. ;
  1911.  
  1912. fragment
  1913. DecimalDigit
  1914. : [0-9]
  1915. ;
  1916.  
  1917. fragment
  1918. IntegerTypeSuffix
  1919. : 'U'
  1920. | 'u'
  1921. | 'L'
  1922. | 'l'
  1923. | 'UL'
  1924. | 'Ul'
  1925. | 'uL'
  1926. | 'ul'
  1927. | 'LU'
  1928. | 'Lu'
  1929. | 'lU'
  1930. | 'lu'
  1931. ;
  1932.  
  1933. HexadecimalIntegerLiteral
  1934. : ('0x' | '0X') HexDigits IntegerTypeSuffix?
  1935. ;
  1936.  
  1937. fragment
  1938. HexDigits
  1939. : HexDigit+
  1940. ;
  1941.  
  1942. fragment
  1943. HexDigit
  1944. : [0-9A-Fa-f]
  1945. ;
  1946.  
  1947. RealLiteral
  1948. : DecimalDigits '.' DecimalDigits ExponentPart? RealTypeSuffix?
  1949. | '.' DecimalDigits ExponentPart? RealTypeSuffix?
  1950. | DecimalDigits ExponentPart RealTypeSuffix?
  1951. | DecimalDigits RealTypeSuffix
  1952. ;
  1953.  
  1954. fragment
  1955. ExponentPart
  1956. : ('e' | 'E') Sign? DecimalDigits
  1957. ;
  1958.  
  1959. fragment
  1960. Sign
  1961. : '+'
  1962. | '-'
  1963. ;
  1964.  
  1965. fragment
  1966. RealTypeSuffix
  1967. : 'F'
  1968. | 'f'
  1969. | 'D'
  1970. | 'd'
  1971. | 'M'
  1972. | 'm'
  1973. ;
  1974.  
  1975. CharacterLiteral
  1976. : '\'' Character '\''
  1977. ;
  1978.  
  1979. fragment
  1980. Character
  1981. : SingleCharacter
  1982. | SimpleEscapeSequence
  1983. | HexadecimalEscapeSequence
  1984. | UnicodeEscapeSequence
  1985. ;
  1986.  
  1987. fragment
  1988. UnicodeEscapeSequence
  1989. : '\\' 'u' HexDigit HexDigit HexDigit HexDigit
  1990. | '\\' 'U' HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit
  1991. ;
  1992.  
  1993. fragment
  1994. SingleCharacter
  1995. : ~[\u0027\u005C\u000D\u000A\u0085\u2028\u2029]
  1996. ;
  1997.  
  1998. fragment
  1999. SimpleEscapeSequence
  2000. : '\\\''
  2001. | '\\"'
  2002. | '\\\\'
  2003. | '\\0'
  2004. | '\\a'
  2005. | '\\b'
  2006. | '\\f'
  2007. | '\\n'
  2008. | '\\r'
  2009. | '\\t'
  2010. | '\\v'
  2011. ;
  2012.  
  2013. fragment
  2014. HexadecimalEscapeSequence
  2015. : '\\x' HexDigit HexDigit? HexDigit? HexDigit?
  2016. ;
  2017.  
  2018. StringLiteral
  2019. : RegularStringLiteral
  2020. | VerbatimStringLiteral
  2021. ;
  2022.  
  2023. RegularStringLiteral
  2024. : '"' RegularStringLiteralCharacters? '"'
  2025. ;
  2026.  
  2027. fragment
  2028. RegularStringLiteralCharacters
  2029. : RegularStringLiteralCharacter+
  2030. ;
  2031.  
  2032. fragment
  2033. RegularStringLiteralCharacter
  2034. : SingleRegularStringLiteralCharacter
  2035. | SimpleEscapeSequence
  2036. | HexadecimalEscapeSequence
  2037. | UnicodeEscapeSequence
  2038. ;
  2039.  
  2040. fragment
  2041. SingleRegularStringLiteralCharacter
  2042. : ~["\\\u000D\u000A\u0085\u2028\u2029]
  2043. ;
  2044.  
  2045. VerbatimStringLiteral
  2046. : '@"' VerbatimStringLiteralCharacters? '"'
  2047. ;
  2048.  
  2049. fragment
  2050. VerbatimStringLiteralCharacters
  2051. : VerbatimStringLiteralCharacter+
  2052. ;
  2053.  
  2054. fragment
  2055. VerbatimStringLiteralCharacter
  2056. : SingleVerbatimStringLiteralCharacter
  2057. | QuoteEscapeSequence
  2058. ;
  2059.  
  2060. fragment
  2061. SingleVerbatimStringLiteralCharacter
  2062. : ~["]
  2063. ;
  2064.  
  2065. fragment
  2066. QuoteEscapeSequence
  2067. : '""'
  2068. ;
  2069.  
  2070. NullLiteral
  2071. : 'null'
  2072. ;
  2073.  
  2074. /**********
  2075. *
  2076. * Identifiers
  2077. *
  2078. **********/
  2079.  
  2080. Identifier
  2081. : AvailableIdentifier
  2082. | '@' IdentifierOrKeyword
  2083. ;
  2084.  
  2085. AvailableIdentifier
  2086. : IdentifierOrKeyword
  2087. ;
  2088.  
  2089. IdentifierOrKeyword
  2090. : IdentifierStartCharacter IdentifierPartCharacter*
  2091. ;
  2092.  
  2093. IdentifierStartCharacter
  2094. : LetterCharacter
  2095. | '_'
  2096. ;
  2097.  
  2098. fragment
  2099. IdentifierPartCharacter
  2100. : LetterCharacter
  2101. | DecimalDigitCharacter
  2102. | ConnectingCharacter
  2103. | CombiningCharacter
  2104. | FormattingCharacter
  2105. ;
  2106.  
  2107. fragment
  2108. LetterCharacter
  2109. : UNICODE_CLASS_LU
  2110. | UNICODE_CLASS_LL
  2111. | UNICODE_CLASS_LT
  2112. | UNICODE_CLASS_LM
  2113. | UNICODE_CLASS_LO
  2114. | UNICODE_CLASS_NL
  2115. ;
  2116.  
  2117. fragment
  2118. CombiningCharacter
  2119. : UNICODE_CLASS_MN
  2120. | UNICODE_CLASS_MC
  2121. ;
  2122.  
  2123. fragment
  2124. DecimalDigitCharacter
  2125. : UNICODE_CLASS_ND
  2126. ;
  2127.  
  2128. fragment
  2129. ConnectingCharacter
  2130. : UNICODE_CLASS_PC
  2131. ;
  2132.  
  2133. fragment
  2134. FormattingCharacter
  2135. : UNICODE_CLASS_CF
  2136. ;
  2137.  
  2138. /**********
  2139. *
  2140. * Whitespace and comments
  2141. *
  2142. **********/
  2143.  
  2144. WS : [ \t\r\n\u000C]+ -> skip
  2145. ;
  2146.  
  2147. COMMENT
  2148. : '/*' .*? '*/' -> skip
  2149. ;
  2150.  
  2151. LINE_COMMENT
  2152. : '//' ~[\r\n]* -> skip
  2153. ;
  2154.  
  2155. DIRECTIVE
  2156. : '#' ~[\r\n]* -> skip
  2157. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement