├── README.md ├── apache2.txt ├── epl.html ├── lib.d.ts ├── project.clj ├── src └── typescript_parser │ └── core.clj ├── test └── typescript_parser │ └── core_test.clj └── typescript.ebnf /README.md: -------------------------------------------------------------------------------- 1 | # typescript-parser 2 | 3 | Parse TypeScript type declaration files. 4 | 5 | ## Usage 6 | 7 | FIXME 8 | 9 | ## License 10 | 11 | Copyright © 2013 Ambrose Bonnaire-Sergeant 12 | 13 | Distributed under the Eclipse Public License, the same as Clojure. 14 | 15 | A copy of the Apache 2 license is provided to allow TypeScript files 16 | to be copied into this repository. 17 | -------------------------------------------------------------------------------- /apache2.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS -------------------------------------------------------------------------------- /epl.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Eclipse Public License - Version 1.0 8 | 25 | 26 | 27 | 28 | 29 | 30 |

Eclipse Public License - v 1.0

31 | 32 |

THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE 33 | PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR 34 | DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS 35 | AGREEMENT.

36 | 37 |

1. DEFINITIONS

38 | 39 |

"Contribution" means:

40 | 41 |

a) in the case of the initial Contributor, the initial 42 | code and documentation distributed under this Agreement, and

43 |

b) in the case of each subsequent Contributor:

44 |

i) changes to the Program, and

45 |

ii) additions to the Program;

46 |

where such changes and/or additions to the Program 47 | originate from and are distributed by that particular Contributor. A 48 | Contribution 'originates' from a Contributor if it was added to the 49 | Program by such Contributor itself or anyone acting on such 50 | Contributor's behalf. Contributions do not include additions to the 51 | Program which: (i) are separate modules of software distributed in 52 | conjunction with the Program under their own license agreement, and (ii) 53 | are not derivative works of the Program.

54 | 55 |

"Contributor" means any person or entity that distributes 56 | the Program.

57 | 58 |

"Licensed Patents" mean patent claims licensable by a 59 | Contributor which are necessarily infringed by the use or sale of its 60 | Contribution alone or when combined with the Program.

61 | 62 |

"Program" means the Contributions distributed in accordance 63 | with this Agreement.

64 | 65 |

"Recipient" means anyone who receives the Program under 66 | this Agreement, including all Contributors.

67 | 68 |

2. GRANT OF RIGHTS

69 | 70 |

a) Subject to the terms of this Agreement, each 71 | Contributor hereby grants Recipient a non-exclusive, worldwide, 72 | royalty-free copyright license to reproduce, prepare derivative works 73 | of, publicly display, publicly perform, distribute and sublicense the 74 | Contribution of such Contributor, if any, and such derivative works, in 75 | source code and object code form.

76 | 77 |

b) Subject to the terms of this Agreement, each 78 | Contributor hereby grants Recipient a non-exclusive, worldwide, 79 | royalty-free patent license under Licensed Patents to make, use, sell, 80 | offer to sell, import and otherwise transfer the Contribution of such 81 | Contributor, if any, in source code and object code form. This patent 82 | license shall apply to the combination of the Contribution and the 83 | Program if, at the time the Contribution is added by the Contributor, 84 | such addition of the Contribution causes such combination to be covered 85 | by the Licensed Patents. The patent license shall not apply to any other 86 | combinations which include the Contribution. No hardware per se is 87 | licensed hereunder.

88 | 89 |

c) Recipient understands that although each Contributor 90 | grants the licenses to its Contributions set forth herein, no assurances 91 | are provided by any Contributor that the Program does not infringe the 92 | patent or other intellectual property rights of any other entity. Each 93 | Contributor disclaims any liability to Recipient for claims brought by 94 | any other entity based on infringement of intellectual property rights 95 | or otherwise. As a condition to exercising the rights and licenses 96 | granted hereunder, each Recipient hereby assumes sole responsibility to 97 | secure any other intellectual property rights needed, if any. For 98 | example, if a third party patent license is required to allow Recipient 99 | to distribute the Program, it is Recipient's responsibility to acquire 100 | that license before distributing the Program.

101 | 102 |

d) Each Contributor represents that to its knowledge it 103 | has sufficient copyright rights in its Contribution, if any, to grant 104 | the copyright license set forth in this Agreement.

105 | 106 |

3. REQUIREMENTS

107 | 108 |

A Contributor may choose to distribute the Program in object code 109 | form under its own license agreement, provided that:

110 | 111 |

a) it complies with the terms and conditions of this 112 | Agreement; and

113 | 114 |

b) its license agreement:

115 | 116 |

i) effectively disclaims on behalf of all Contributors 117 | all warranties and conditions, express and implied, including warranties 118 | or conditions of title and non-infringement, and implied warranties or 119 | conditions of merchantability and fitness for a particular purpose;

120 | 121 |

ii) effectively excludes on behalf of all Contributors 122 | all liability for damages, including direct, indirect, special, 123 | incidental and consequential damages, such as lost profits;

124 | 125 |

iii) states that any provisions which differ from this 126 | Agreement are offered by that Contributor alone and not by any other 127 | party; and

128 | 129 |

iv) states that source code for the Program is available 130 | from such Contributor, and informs licensees how to obtain it in a 131 | reasonable manner on or through a medium customarily used for software 132 | exchange.

133 | 134 |

When the Program is made available in source code form:

135 | 136 |

a) it must be made available under this Agreement; and

137 | 138 |

b) a copy of this Agreement must be included with each 139 | copy of the Program.

140 | 141 |

Contributors may not remove or alter any copyright notices contained 142 | within the Program.

143 | 144 |

Each Contributor must identify itself as the originator of its 145 | Contribution, if any, in a manner that reasonably allows subsequent 146 | Recipients to identify the originator of the Contribution.

147 | 148 |

4. COMMERCIAL DISTRIBUTION

149 | 150 |

Commercial distributors of software may accept certain 151 | responsibilities with respect to end users, business partners and the 152 | like. While this license is intended to facilitate the commercial use of 153 | the Program, the Contributor who includes the Program in a commercial 154 | product offering should do so in a manner which does not create 155 | potential liability for other Contributors. Therefore, if a Contributor 156 | includes the Program in a commercial product offering, such Contributor 157 | ("Commercial Contributor") hereby agrees to defend and 158 | indemnify every other Contributor ("Indemnified Contributor") 159 | against any losses, damages and costs (collectively "Losses") 160 | arising from claims, lawsuits and other legal actions brought by a third 161 | party against the Indemnified Contributor to the extent caused by the 162 | acts or omissions of such Commercial Contributor in connection with its 163 | distribution of the Program in a commercial product offering. The 164 | obligations in this section do not apply to any claims or Losses 165 | relating to any actual or alleged intellectual property infringement. In 166 | order to qualify, an Indemnified Contributor must: a) promptly notify 167 | the Commercial Contributor in writing of such claim, and b) allow the 168 | Commercial Contributor to control, and cooperate with the Commercial 169 | Contributor in, the defense and any related settlement negotiations. The 170 | Indemnified Contributor may participate in any such claim at its own 171 | expense.

172 | 173 |

For example, a Contributor might include the Program in a commercial 174 | product offering, Product X. That Contributor is then a Commercial 175 | Contributor. If that Commercial Contributor then makes performance 176 | claims, or offers warranties related to Product X, those performance 177 | claims and warranties are such Commercial Contributor's responsibility 178 | alone. Under this section, the Commercial Contributor would have to 179 | defend claims against the other Contributors related to those 180 | performance claims and warranties, and if a court requires any other 181 | Contributor to pay any damages as a result, the Commercial Contributor 182 | must pay those damages.

183 | 184 |

5. NO WARRANTY

185 | 186 |

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS 187 | PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 188 | OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, 189 | ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY 190 | OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely 191 | responsible for determining the appropriateness of using and 192 | distributing the Program and assumes all risks associated with its 193 | exercise of rights under this Agreement , including but not limited to 194 | the risks and costs of program errors, compliance with applicable laws, 195 | damage to or loss of data, programs or equipment, and unavailability or 196 | interruption of operations.

197 | 198 |

6. DISCLAIMER OF LIABILITY

199 | 200 |

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT 201 | NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, 202 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING 203 | WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF 204 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 205 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR 206 | DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED 207 | HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

208 | 209 |

7. GENERAL

210 | 211 |

If any provision of this Agreement is invalid or unenforceable under 212 | applicable law, it shall not affect the validity or enforceability of 213 | the remainder of the terms of this Agreement, and without further action 214 | by the parties hereto, such provision shall be reformed to the minimum 215 | extent necessary to make such provision valid and enforceable.

216 | 217 |

If Recipient institutes patent litigation against any entity 218 | (including a cross-claim or counterclaim in a lawsuit) alleging that the 219 | Program itself (excluding combinations of the Program with other 220 | software or hardware) infringes such Recipient's patent(s), then such 221 | Recipient's rights granted under Section 2(b) shall terminate as of the 222 | date such litigation is filed.

223 | 224 |

All Recipient's rights under this Agreement shall terminate if it 225 | fails to comply with any of the material terms or conditions of this 226 | Agreement and does not cure such failure in a reasonable period of time 227 | after becoming aware of such noncompliance. If all Recipient's rights 228 | under this Agreement terminate, Recipient agrees to cease use and 229 | distribution of the Program as soon as reasonably practicable. However, 230 | Recipient's obligations under this Agreement and any licenses granted by 231 | Recipient relating to the Program shall continue and survive.

232 | 233 |

Everyone is permitted to copy and distribute copies of this 234 | Agreement, but in order to avoid inconsistency the Agreement is 235 | copyrighted and may only be modified in the following manner. The 236 | Agreement Steward reserves the right to publish new versions (including 237 | revisions) of this Agreement from time to time. No one other than the 238 | Agreement Steward has the right to modify this Agreement. The Eclipse 239 | Foundation is the initial Agreement Steward. The Eclipse Foundation may 240 | assign the responsibility to serve as the Agreement Steward to a 241 | suitable separate entity. Each new version of the Agreement will be 242 | given a distinguishing version number. The Program (including 243 | Contributions) may always be distributed subject to the version of the 244 | Agreement under which it was received. In addition, after a new version 245 | of the Agreement is published, Contributor may elect to distribute the 246 | Program (including its Contributions) under the new version. Except as 247 | expressly stated in Sections 2(a) and 2(b) above, Recipient receives no 248 | rights or licenses to the intellectual property of any Contributor under 249 | this Agreement, whether expressly, by implication, estoppel or 250 | otherwise. All rights in the Program not expressly granted under this 251 | Agreement are reserved.

252 | 253 |

This Agreement is governed by the laws of the State of New York and 254 | the intellectual property laws of the United States of America. No party 255 | to this Agreement will bring a legal action under this Agreement more 256 | than one year after the cause of action arose. Each party waives its 257 | rights to a jury trial in any resulting litigation.

258 | 259 | 260 | 261 | 262 | -------------------------------------------------------------------------------- /project.clj: -------------------------------------------------------------------------------- 1 | (defproject typescript-parser "0.1.0-SNAPSHOT" 2 | :description "FIXME: write description" 3 | :url "http://example.com/FIXME" 4 | :license {:name "Eclipse Public License" 5 | :url "http://www.eclipse.org/legal/epl-v10.html"} 6 | :profiles {:dev {:repl-options {:port 64450}}} 7 | :dependencies [[org.clojure/clojure "1.5.1"] 8 | [instaparse "1.3.1"]]) 9 | -------------------------------------------------------------------------------- /src/typescript_parser/core.clj: -------------------------------------------------------------------------------- 1 | (ns typescript-parser.core 2 | (:require [instaparse.core :as insta])) 3 | 4 | (def grammar 5 | (insta/parser (slurp "typescript.ebnf") 6 | :output-format :enlive 7 | :optimize :memory)) 8 | 9 | (defn parse-tree [s] 10 | (grammar s)) 11 | 12 | (defn output-ts [] 13 | (grammar (slurp "lib.d.ts"))) 14 | 15 | (defn transform [tree] 16 | (insta/transform 17 | {:Identifier 18 | (fn id [id] id) 19 | :QualifiedIdentifier 20 | (fn qid 21 | ([id] id) 22 | ([module id] (str module "." id))) 23 | :ModuleName 24 | (fn mn [nme & nms] 25 | (apply str (interpose "." (concat nme nms)))) 26 | :TypeReference 27 | (fn tr 28 | ([id] 29 | {:op :type-reference 30 | :id id}) 31 | ([id targs] 32 | {:op :type-reference 33 | :id id 34 | :targs targs})) 35 | :AmbientVariableDeclaration 36 | (fn avd 37 | ([id] 38 | {:op :ambient-var-declaration 39 | :id id}) 40 | ([id type] 41 | {:op :ambient-var-declaration 42 | :id id 43 | :type type})) 44 | :AmbientFunctionDeclaration 45 | (fn afd 46 | [id sig] 47 | {:op :ambient-fn-declaration 48 | :id id 49 | :sig sig}) 50 | ; :CallSignature 51 | ; (fn [& args] 52 | ; (merge {:op :call-signature} 53 | } 54 | 55 | tree)) 56 | 57 | #_(transform (first (output-ts))) 58 | 59 | (-> 60 | "declare function eval(x: string): any;" 61 | parse-tree 62 | transform) 63 | -------------------------------------------------------------------------------- /test/typescript_parser/core_test.clj: -------------------------------------------------------------------------------- 1 | (ns typescript-parser.core-test 2 | (:use clojure.test 3 | typescript-parser.core)) 4 | 5 | (deftest a-test 6 | (testing "FIXME, I fail." 7 | (is (= 0 1)))) 8 | -------------------------------------------------------------------------------- /typescript.ebnf: -------------------------------------------------------------------------------- 1 | (*The syntax of this file should be mostly self explanatory if you understand EBNF 2 | and regular expressions, The one unique feature is that a literal or a rule 3 | can be excluded from the resulting parse tree by surronding it with angle brackets*) 4 | ::= ws-opt DeclarationElement* 5 | TypeParameters ::= <'<'> TypeParameter (<','> TypeParameter)* <'>'> 6 | TypeParameter ::= ws-opt Identifier [ws Constraint] ws-opt 7 | Identifier ::= #"[$_\p{L}][$_\p{L}\p{N}]*" 8 | Constraint ::= <'extends'> ws Type 9 | Type ::= TypeLiteral 10 | | TypeReference 11 | | TypeQuery 12 | (*| PredefinedType*) 13 | 14 | (*PredefinedType ::= "any" 15 | | "number" 16 | | "boolean" 17 | | "string" 18 | | "void"*) 19 | TypeReference ::= QualifiedIdentifier [ws-opt TypeArguments] 20 | QualifiedIdentifier ::= Identifier 21 | | ModuleName <'.'> Identifier 22 | (*This isn't really necessary, but it's useful to seperate the module name*) 23 | ModuleName ::= Identifier [<'.'> Identifier]* 24 | TypeArguments ::= <'<'> TypeArgumentList <'>'> 25 | TypeArgumentList ::= TypeArgument (<','> TypeArgument)* 26 | TypeArgument ::= ws-opt Type ws-opt 27 | TypeQuery ::= <"typeof"> ws QualifiedIdentifier 28 | TypeLiteral ::= ObjectType 29 | | ArrayType 30 | | FunctionType 31 | | ConstructorType 32 | ArrayType ::= ElementType lbrace rbrace 33 | ::= TypeQuery 34 | | TypeReference 35 | (* some ambiguity with predefined types and type references *) 36 | (*| PredefinedType*) 37 | | ObjectType 38 | | ArrayType 39 | FunctionType ::= 40 | [TypeParameters] lparen [Parameter-List] rparen "=>" ws-opt Type 41 | ConstructorType ::= <"new"> ws FunctionType 42 | ObjectType ::= <'{'> ws-opt [TypeBody ws-opt] <'}'> 43 | TypeBody ::= TypeMemberList ws-opt [<';'>] 44 | TypeMemberList ::= TypeMember ws-opt [<';'> ws-opt TypeMember]* 45 | TypeMember ::= PropertySignature 46 | | CallSignature 47 | | ConstructSignature 48 | | IndexSignature 49 | | MethodSignature 50 | PropertySignature ::= PropertyName ['?'] ws-opt [TypeAnnotation] 51 | PropertyName ::= Identifier 52 | | StringLiteral 53 | | NumericLiteral 54 | CallSignature ::= 55 | [TypeParameters ws-opt] <'('> ws-opt [Parameter-List ws-opt] <')'> ws-opt [TypeAnnotation] 56 | Parameter-List ::= 57 | RequiredParameterList 58 | | OptionalParameterList 59 | | RestParameter 60 | | RequiredParameterList comma OptionalParameterList 61 | | RequiredParameterList comma RestParameter 62 | | OptionalParameterList comma RestParameter 63 | | RequiredParameterList comma OptionalParameterList comma RestParameter 64 | ::= RequiredParameter (comma RequiredParameter)* ws-opt 65 | RequiredParameter ::= 66 | [AccessLevel] Identifier [TypeAnnotation] 67 | | Identifier ':' ws-opt StringLiteral 68 | ::= OptionalParameter (comma OptionalParameter)* ws-opt 69 | OptionalParameter ::= 70 | [AccessLevel] Identifier <'?'> [TypeAnnotation] 71 | | [AccessLevel] Identifier [TypeAnnotation] Initialiser 72 | Initialiser ::= equals LiteralValue 73 | RestParameter ::= "..." Identifier [TypeAnnotation] ws-opt 74 | ConstructSignature ::= "new" ws-opt CallSignature 75 | IndexSignature ::= 76 | ['[' ws-opt] Identifier ws-opt ':' ws-opt #"string|number" rbrace TypeAnnotation 77 | MethodSignature ::= !("new" ws | "new(") PropertyName ['?'] ws-opt CallSignature 78 | TypeAnnotation ::= ws-opt <':'> ws Type 79 | InterfaceDeclaration ::= 80 | <"interface"> ws Identifier ([TypeParameters ws] | ws-opt) [InterfaceExtendsClause ws] ObjectType 81 | InterfaceExtendsClause ::= <"extends"> ws ClassOrInterfaceTypeList 82 | ClassOrInterfaceTypeList ::= 83 | TypeReference (comma TypeReference)* ws-opt 84 | ClassHeritage ::= [ClassExtendsClause] [ImplementsClause] 85 | ClassExtendsClause ::= "extends" ws TypeReference 86 | ImplementsClause ::= "implements" ws ClassOrInterfaceTypeList 87 | ::= ExportAssignment ws-opt 88 | | [<"export"> ws] InterfaceDeclaration ws-opt 89 | | [<"export"> ws] ImportDeclarartion ws-opt 90 | | [<"export"> ws] ExternalImportDeclaration ws-opt 91 | | [<"export"> ws] AmbientDeclaration ws-opt 92 | ImportDeclarartion ::= "import" ws Identifier equals QualifiedIdentifier ';' 93 | ExternalImportDeclaration ::= 94 | "import" ws Identifier equals ExternalModuleReference <';'> 95 | ExternalModuleReference ::= 96 | "require" lparen StringLiteral rparen 97 | ExportAssignment ::= "export" equals Identifier <';'> 98 | ::= <"declare"> ws AmbientVariableDeclaration 99 | | <"declare"> ws AmbientFunctionDeclaration 100 | | <"declare"> ws AmbientClassDeclaration 101 | | <"declare"> ws AmbientEnumDeclaration 102 | | <"declare"> ws AmbientModuleDeclaration 103 | | <"declare"> ws AmbientExternalModuleDeclaration 104 | AmbientVariableDeclaration ::= <"var"> ws Identifier [TypeAnnotation] [ws-opt <';'>] 105 | AmbientFunctionDeclaration ::= <"function"> ws Identifier ws-opt CallSignature <';'> 106 | AmbientClassDeclaration ::= 107 | <"class"> ws Identifier [TypeParameters] ClassHeritage <'{'> AmbientClassBody <'}'> 108 | AmbientClassBody ::= AmbientClassBodyElement* 109 | AmbientClassBodyElement ::= AmbientConstructorDeclaration 110 | | AmbientPropertyMemberDeclaration 111 | | IndexSignature 112 | AmbientConstructorDeclaration ::= <"constructor"> ws '(' [Parameter-List] ')' <';'> 113 | AmbientPropertyMemberDeclaration ::= 114 | [AccessLevel] ["static" ws] PropertyName [TypeAnnotation] <';'> 115 | [AccessLevel] ["static" ws] PropertyName CallSignature <';'> 116 | AmbientEnumDeclaration ::= "enum" Identifier '{' [AmbientEnumBody] '}' 117 | AmbientEnumBody ::= AmbientEnumMember [',' AmbientEnumMember]* [','] 118 | AmbientEnumMember ::= PropertyName [equals #"[0-9]+|0x\p{XDigit}+"] 119 | AmbientModuleDeclaration ::= 120 | "module" ws QualifiedIdentifier ws-opt '{' AmbientModuleBody '}' 121 | AmbientModuleBody ::= (ws-opt AmbientModuleElement)* ws-opt 122 | AmbientModuleElement ::= [<"export"> ws] AmbientVariableDeclaration 123 | | [<"export"> ws] AmbientFunctionDeclaration 124 | | [<"export"> ws] AmbientClassDeclaration 125 | | [<"export"> ws] AmbientEnumDeclaration 126 | | [<"export"> ws] AmbientModuleDeclaration 127 | | [<"export"> ws] AmbientExternalModuleDeclaration 128 | | [<"export"> ws] InterfaceDeclaration 129 | | [<"export"> ws] ImportDeclarartion 130 | AmbientExternalModuleDeclaration ::= 131 | "module" StringLiteral '{' AmbientExternalModuleBody '}' 132 | AmbientExternalModuleBody ::= AmbientExternalModuleElement* 133 | AmbientExternalModuleElement ::= AmbientModuleElement 134 | | ExportAssignment 135 | | [<"export">] ws ExternalImportDeclaration 136 | 137 | LiteralValue ::= #"true|false" 138 | | "null" 139 | | StringLiteral 140 | | NumericLiteral 141 | StringLiteral ::= #'".*"' 142 | NumericLiteral ::= 143 | (*Decimal: optional integer followed by optional '.' followed by mandatory 144 | integer followed by optional exponent*) 145 | #"((?:(?:[0-9]*)?\.?[0-f]+(?:[Ee][-+]?[0-9]+))|0[Xx]\p{XDigit}+)" 146 | ::= '//' #"[^\n]*" 147 | ::= '/*' InsideMultiLineComment* '*/' 148 | ::= !( '*/' | '/*' ) (#"." | #"[\n\r]") | MultiLineComment 149 | ::= <(#"\s+" | SingleLineComment | MultiLineComment)> 150 | AccessLevel ::= #"public|private" 151 | (*these are all for making the grammer easer to read*) 152 | 153 | ::= Whitespace+ 154 | ::= Whitespace* 155 | ::= ws-opt <'('> ws-opt 156 | ::= ws-opt <')'> ws-opt 157 | ::= ws-opt <'['> ws-opt 158 | ::= ws-opt <']'> ws-opt 159 | ::= ws-opt <','> ws-opt 160 | ::= ws-opt <'='> ws-opt 161 | --------------------------------------------------------------------------------