├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── build.rs └── src ├── main.rs ├── rusty.lalrpop └── token └── mod.rs /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | *~ 3 | src/rusty.rs 4 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | [root] 2 | name = "rustypop" 3 | version = "0.1.0" 4 | dependencies = [ 5 | "lalrpop 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", 6 | "lalrpop-util 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", 7 | ] 8 | 9 | [[package]] 10 | name = "aho-corasick" 11 | version = "0.5.2" 12 | source = "registry+https://github.com/rust-lang/crates.io-index" 13 | dependencies = [ 14 | "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", 15 | ] 16 | 17 | [[package]] 18 | name = "atty" 19 | version = "0.1.2" 20 | source = "registry+https://github.com/rust-lang/crates.io-index" 21 | dependencies = [ 22 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 23 | "libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", 24 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 25 | ] 26 | 27 | [[package]] 28 | name = "bit-set" 29 | version = "0.3.0" 30 | source = "registry+https://github.com/rust-lang/crates.io-index" 31 | dependencies = [ 32 | "bit-vec 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", 33 | ] 34 | 35 | [[package]] 36 | name = "bit-vec" 37 | version = "0.4.3" 38 | source = "registry+https://github.com/rust-lang/crates.io-index" 39 | 40 | [[package]] 41 | name = "bitflags" 42 | version = "0.4.0" 43 | source = "registry+https://github.com/rust-lang/crates.io-index" 44 | 45 | [[package]] 46 | name = "diff" 47 | version = "0.1.9" 48 | source = "registry+https://github.com/rust-lang/crates.io-index" 49 | 50 | [[package]] 51 | name = "docopt" 52 | version = "0.6.82" 53 | source = "registry+https://github.com/rust-lang/crates.io-index" 54 | dependencies = [ 55 | "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 56 | "regex 0.1.73 (registry+https://github.com/rust-lang/crates.io-index)", 57 | "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", 58 | "strsim 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 59 | ] 60 | 61 | [[package]] 62 | name = "fixedbitset" 63 | version = "0.1.1" 64 | source = "registry+https://github.com/rust-lang/crates.io-index" 65 | 66 | [[package]] 67 | name = "itertools" 68 | version = "0.3.25" 69 | source = "registry+https://github.com/rust-lang/crates.io-index" 70 | 71 | [[package]] 72 | name = "kernel32-sys" 73 | version = "0.2.2" 74 | source = "registry+https://github.com/rust-lang/crates.io-index" 75 | dependencies = [ 76 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 77 | "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 78 | ] 79 | 80 | [[package]] 81 | name = "lalrpop" 82 | version = "0.12.4" 83 | source = "registry+https://github.com/rust-lang/crates.io-index" 84 | dependencies = [ 85 | "atty 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 86 | "bit-set 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 87 | "bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 88 | "diff 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", 89 | "docopt 0.6.82 (registry+https://github.com/rust-lang/crates.io-index)", 90 | "itertools 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)", 91 | "lalrpop-intern 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", 92 | "lalrpop-snap 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", 93 | "lalrpop-util 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", 94 | "petgraph 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", 95 | "regex 0.1.73 (registry+https://github.com/rust-lang/crates.io-index)", 96 | "regex-syntax 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 97 | "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", 98 | "term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", 99 | "unicode-xid 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 100 | ] 101 | 102 | [[package]] 103 | name = "lalrpop-intern" 104 | version = "0.12.4" 105 | source = "registry+https://github.com/rust-lang/crates.io-index" 106 | 107 | [[package]] 108 | name = "lalrpop-snap" 109 | version = "0.12.4" 110 | source = "registry+https://github.com/rust-lang/crates.io-index" 111 | dependencies = [ 112 | "atty 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 113 | "bit-set 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 114 | "bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 115 | "diff 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", 116 | "docopt 0.6.82 (registry+https://github.com/rust-lang/crates.io-index)", 117 | "itertools 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)", 118 | "lalrpop-intern 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", 119 | "lalrpop-util 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", 120 | "petgraph 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", 121 | "regex 0.1.73 (registry+https://github.com/rust-lang/crates.io-index)", 122 | "regex-syntax 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 123 | "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", 124 | "term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", 125 | "unicode-xid 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 126 | ] 127 | 128 | [[package]] 129 | name = "lalrpop-util" 130 | version = "0.12.4" 131 | source = "registry+https://github.com/rust-lang/crates.io-index" 132 | 133 | [[package]] 134 | name = "lazy_static" 135 | version = "0.2.1" 136 | source = "registry+https://github.com/rust-lang/crates.io-index" 137 | 138 | [[package]] 139 | name = "libc" 140 | version = "0.2.15" 141 | source = "registry+https://github.com/rust-lang/crates.io-index" 142 | 143 | [[package]] 144 | name = "memchr" 145 | version = "0.1.11" 146 | source = "registry+https://github.com/rust-lang/crates.io-index" 147 | dependencies = [ 148 | "libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", 149 | ] 150 | 151 | [[package]] 152 | name = "petgraph" 153 | version = "0.1.18" 154 | source = "registry+https://github.com/rust-lang/crates.io-index" 155 | dependencies = [ 156 | "fixedbitset 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 157 | ] 158 | 159 | [[package]] 160 | name = "regex" 161 | version = "0.1.73" 162 | source = "registry+https://github.com/rust-lang/crates.io-index" 163 | dependencies = [ 164 | "aho-corasick 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", 165 | "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", 166 | "regex-syntax 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", 167 | "thread_local 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 168 | "utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 169 | ] 170 | 171 | [[package]] 172 | name = "regex-syntax" 173 | version = "0.2.6" 174 | source = "registry+https://github.com/rust-lang/crates.io-index" 175 | 176 | [[package]] 177 | name = "regex-syntax" 178 | version = "0.3.4" 179 | source = "registry+https://github.com/rust-lang/crates.io-index" 180 | 181 | [[package]] 182 | name = "rustc-serialize" 183 | version = "0.3.19" 184 | source = "registry+https://github.com/rust-lang/crates.io-index" 185 | 186 | [[package]] 187 | name = "strsim" 188 | version = "0.3.0" 189 | source = "registry+https://github.com/rust-lang/crates.io-index" 190 | 191 | [[package]] 192 | name = "term" 193 | version = "0.4.4" 194 | source = "registry+https://github.com/rust-lang/crates.io-index" 195 | dependencies = [ 196 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 197 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 198 | ] 199 | 200 | [[package]] 201 | name = "thread-id" 202 | version = "2.0.0" 203 | source = "registry+https://github.com/rust-lang/crates.io-index" 204 | dependencies = [ 205 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 206 | "libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", 207 | ] 208 | 209 | [[package]] 210 | name = "thread_local" 211 | version = "0.2.6" 212 | source = "registry+https://github.com/rust-lang/crates.io-index" 213 | dependencies = [ 214 | "thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 215 | ] 216 | 217 | [[package]] 218 | name = "unicode-xid" 219 | version = "0.0.2" 220 | source = "registry+https://github.com/rust-lang/crates.io-index" 221 | 222 | [[package]] 223 | name = "utf8-ranges" 224 | version = "0.1.3" 225 | source = "registry+https://github.com/rust-lang/crates.io-index" 226 | 227 | [[package]] 228 | name = "winapi" 229 | version = "0.2.8" 230 | source = "registry+https://github.com/rust-lang/crates.io-index" 231 | 232 | [[package]] 233 | name = "winapi-build" 234 | version = "0.1.1" 235 | source = "registry+https://github.com/rust-lang/crates.io-index" 236 | 237 | [metadata] 238 | "checksum aho-corasick 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2b3fb52b09c1710b961acb35390d514be82e4ac96a9969a8e38565a29b878dc9" 239 | "checksum atty 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d0fd4c0631f06448cc45a6bbb3b710ebb7ff8ccb96a0800c994afe23a70d5df2" 240 | "checksum bit-set 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "84527c7b0452f22545cc010e72d366a435561d2b28b978035550b3778c4d428d" 241 | "checksum bit-vec 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5b97c2c8e8bbb4251754f559df8af22fb264853c7d009084a576cdf12565089d" 242 | "checksum bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dead7461c1127cf637931a1e50934eb6eee8bff2f74433ac7909e9afcee04a3" 243 | "checksum diff 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e48977eec6d3b7707462c2dc2e1363ad91b5dd822cf942537ccdc2085dc87587" 244 | "checksum docopt 0.6.82 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20016093b4e545dccf6ad4a01099de0b695f9bc99b08210e68f6425db2d37d" 245 | "checksum fixedbitset 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c59882225c22dfcd2db6f0fce45dabe334e64ffa5efacb785b7ffb5af690cc6f" 246 | "checksum itertools 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)" = "16b73f1c685cfd8ff8d75698ed87e6188cd09944b30c0863d45c2c3699d1da0c" 247 | "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" 248 | "checksum lalrpop 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)" = "95af72b26d2056ca73387cb71d29e727c336d2b8a766ee09b210bed44d6f857b" 249 | "checksum lalrpop-intern 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4e76b1f6eead09c4edde090dc69e3757775ab36cbf907fb0857181160b9ca5a1" 250 | "checksum lalrpop-snap 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a096006ebe9cef49295a142af7cb3cf2f782bf594213c786e0cc070b0d237073" 251 | "checksum lalrpop-util 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5ab0e358c557ea426b05719c82ac649cae0f0f7f2855145111fe59eab207b285" 252 | "checksum lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "49247ec2a285bb3dcb23cbd9c35193c025e7251bfce77c1d5da97e6362dffe7f" 253 | "checksum libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)" = "23e3757828fa702a20072c37ff47938e9dd331b92fac6e223d26d4b7a55f7ee2" 254 | "checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20" 255 | "checksum petgraph 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "bfd1de18b0a5f1777162e5b61aaf498032467d5409ab4ca6dbd03049f5708de1" 256 | "checksum regex 0.1.73 (registry+https://github.com/rust-lang/crates.io-index)" = "56b7ee9f764ecf412c6e2fff779bca4b22980517ae335a21aeaf4e32625a5df2" 257 | "checksum regex-syntax 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a21935ce5a4dfa48e3ded1aefbbe353fb9ab258b0d3fa0bd168bef00797b3dc7" 258 | "checksum regex-syntax 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "31040aad7470ad9d8c46302dcffba337bb4289ca5da2e3cd6e37b64109a85199" 259 | "checksum rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "6159e4e6e559c81bd706afe9c8fd68f547d3e851ce12e76b1de7914bab61691b" 260 | "checksum strsim 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e4d73a2c36a4d095ed1a6df5cbeac159863173447f7a82b3f4757426844ab825" 261 | "checksum term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3deff8a2b3b6607d6d7cc32ac25c0b33709453ca9cceac006caac51e963cf94a" 262 | "checksum thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03" 263 | "checksum thread_local 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "55dd963dbaeadc08aa7266bf7f91c3154a7805e32bb94b820b769d2ef3b4744d" 264 | "checksum unicode-xid 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f69506a2561962651710609304bbb961fa3da598c812f877975a82e48ee144f9" 265 | "checksum utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f" 266 | "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" 267 | "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" 268 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rustypop" 3 | version = "0.1.0" 4 | authors = ["Niko Matsakis "] 5 | build = "build.rs" # LALRPOP preprocessing 6 | 7 | # Add a dependency on the LALRPOP runtime library: 8 | [dependencies] 9 | lalrpop-util = "0.12.4" 10 | 11 | [build-dependencies] 12 | lalrpop = "0.12.4" 13 | 14 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 The Rust Project Developers 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Rustypop 2 | 3 | This is a not-yet-functional port of lalr-parser.y, from the Rust 4 | repository, into LALRPOP. As of the moment, I am still in the process 5 | of working my way through shift-reduce failures. 6 | 7 | Eventually, I am aiming for the following conventions: 8 | 9 | 1. Terminal names will use `""` if they are keywords or other 10 | literals, otherwise the terminal will be named with camel-case like 11 | `Ident`. 12 | 2. For multi-character symbols that can also be interpreted as single characters, 13 | like `&&`, `<<`, or `||`, we will introduce two terminals: 14 | 15 | - One for the character when following by another of the same character, written with 16 | a `[]` to denote lookahead, e.g. `<[<]`. 17 | - One for the character alone, written with empty lookahead, e.g., `<[]`. 18 | 19 | Therefore, to match `<<`, you would match `"<[<]" "<[]"`. In cases, 20 | like types, where `<<` is to be considered as two distinct `<` 21 | tokens, we would match either `"<[<]"` OR `"<[]"` equivalently. 22 | 3. Nonterminal names will be camel-case like `Expr`. 23 | 4. Variants on expressions and the like will be implemented with 24 | LALRPOP macros, as will comma-separated lists (`Comma`) and so 25 | forth. We can also employ `Foo?` instead of conventions like `maybe_foo`. 26 | 27 | The easiest way to experiment right now is to just run `cargo build 28 | --release`; make sure you build release, because other LALRPOP itself 29 | builds in debug mode, and that is horribly slow. 30 | 31 | ### Licensing 32 | 33 | Licensed under the same terms as Rust itself: dual MIT and Apache2. 34 | -------------------------------------------------------------------------------- /build.rs: -------------------------------------------------------------------------------- 1 | extern crate lalrpop; 2 | 3 | fn main() { 4 | lalrpop::process_root().unwrap(); 5 | } 6 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | mod rusty; 2 | mod token; 3 | 4 | fn main() { 5 | println!("Hello, world!"); 6 | } 7 | -------------------------------------------------------------------------------- /src/rusty.lalrpop: -------------------------------------------------------------------------------- 1 | // FIXME#1 2 | // 3 | // We currently accept `if return { /* expr */ } { /* then */ }` but 4 | // it is unclear if we *should* do so (in fact, I would argue that we 5 | // should not, because it is inconsistent with `if Struct { ... }`) 6 | // and `if 3 .. {`. Options to resolve: 7 | // 8 | // - disallow `if return/break/continue` altogether 9 | // - I lump in `break/continue` to allow for future compat where 10 | // they take an argument, but also because they are all 11 | // unconditionall diverging control-flow expressions 12 | // - permit `if return/break/continue` but not with a block argument 13 | // - consistent, but what's the point? 14 | // - kepe things as they are today 15 | // 16 | // I opted for #1 so far. 17 | // 18 | // FIXME#2 19 | // 20 | // I am currently disallowing things like `x as (i32) < y as (i32)`; 21 | // to fix this I have to propagate the restrictions against type 22 | // arguments into the Ty grammar. 23 | 24 | use token::Token; 25 | 26 | grammar<'input>; 27 | 28 | pub Crate: () = { 29 | Shebang? InnerAttr* ModItem*, 30 | }; 31 | 32 | Shebang: () = { 33 | "#!", 34 | }; 35 | 36 | InnerAttr: () = { 37 | "#!" "[" MetaItem "]", 38 | "//!...", 39 | }; 40 | 41 | MaybeOuterAttrs: () = { 42 | OuterAttrs?, 43 | }; 44 | 45 | OuterAttrs: () = { 46 | OuterAttr, 47 | OuterAttrs OuterAttr, 48 | }; 49 | 50 | OuterAttr: () = { 51 | "#" "[" MetaItem "]", 52 | "///...", 53 | }; 54 | 55 | MetaItem: () = { 56 | Identifier, 57 | Identifier "=" Lit, 58 | Identifier "(" Comma ")", 59 | }; 60 | 61 | AttrsAndVis: () = { 62 | MaybeOuterAttrs visibility, 63 | }; 64 | 65 | ModItem: () = { 66 | AttrsAndVis item, 67 | }; 68 | 69 | item: () = { 70 | StmtItem, 71 | ItemMacro, 72 | }; 73 | 74 | StmtItem: () = { 75 | ItemStatic, 76 | ItemConst, 77 | ItemType, 78 | BlockItem, 79 | ViewItem, 80 | }; 81 | 82 | ItemStatic: () = { 83 | "static" "mut"? Identifier ":" ty "=" Expr ";", 84 | }; 85 | 86 | ItemConst: () = { 87 | "const" Identifier ":" ty "=" Expr ";", 88 | }; 89 | 90 | ItemMacro: () = { 91 | PathExpr "!" Identifier? parens_delimited_token_trees ";", 92 | PathExpr "!" Identifier? braces_delimited_token_trees, 93 | PathExpr "!" Identifier? brackets_delimited_token_trees ";", 94 | }; 95 | 96 | ViewItem: () = { 97 | ItemUse, 98 | ExternFnItem, 99 | "extern" "crate" Identifier ("as" Identifier)? ";", 100 | }; 101 | 102 | ExternFnItem: () = { 103 | "extern" Abi ItemFn, 104 | }; 105 | 106 | ItemUse: () = { 107 | "use" ViewPath ";", 108 | }; 109 | 110 | ViewPath: () = { 111 | PathNoTypes, 112 | PathNoTypes "::" "{" "}", 113 | "::" "{" "}", 114 | PathNoTypes "::" "{" IdentifiersOrSelf "}", 115 | "::" "{" IdentifiersOrSelf "}", 116 | PathNoTypes "::" "{" IdentifiersOrSelf "," "}", 117 | "::" "{" IdentifiersOrSelf "," "}", 118 | PathNoTypes "::" "*", 119 | "{" "}", 120 | "{" IdentifiersOrSelf "}", 121 | "{" IdentifiersOrSelf "," "}", 122 | PathNoTypes "as" Identifier, 123 | }; 124 | 125 | BlockItem: () = { 126 | ItemFn, 127 | ItemUnsafeFn, 128 | ItemMod, 129 | ItemForeignMod, 130 | ItemStruct, 131 | ItemEnum, 132 | ItemTrait, 133 | ItemImpl, 134 | }; 135 | 136 | MaybeTyAscription: () = { 137 | (":" TySum)? 138 | }; 139 | 140 | MaybeInitExpr: () = { 141 | ("=" Expr)? 142 | }; 143 | 144 | ItemStruct: () = { 145 | "struct" Identifier GenericParams MaybeWhereClause StructDeclArgs, 146 | "struct" Identifier GenericParams StructTupleArgs MaybeWhereClause ";", 147 | "struct" Identifier GenericParams MaybeWhereClause ";", 148 | }; 149 | 150 | StructDeclArgs: () = { 151 | "{" StructDeclFields "}" 152 | }; 153 | 154 | StructTupleArgs: () = { 155 | "(" StructTupleFields ")" 156 | }; 157 | 158 | StructDeclFields: () = { 159 | Comma, 160 | }; 161 | 162 | StructDeclField: () = { 163 | AttrsAndVis Identifier ":" TySum, 164 | }; 165 | 166 | StructTupleFields: () = { 167 | Comma 168 | }; 169 | 170 | StructTupleField: () = { 171 | AttrsAndVis TySum, 172 | }; 173 | 174 | ItemEnum: () = { 175 | "enum" Identifier GenericParams MaybeWhereClause "{" Comma1 "}", 176 | }; 177 | 178 | EnumDef: () = { 179 | AttrsAndVis Identifier EnumArgs 180 | }; 181 | 182 | EnumArgs: () = { 183 | "{" StructDeclFields "}", 184 | "(" MaybeTySums ")", 185 | "=" Expr, 186 | (), 187 | }; 188 | 189 | ItemMod: () = { 190 | "mod" Identifier ";", 191 | "mod" Identifier "{" InnerAttr* ModItem* "}", 192 | }; 193 | 194 | ItemForeignMod: () = { 195 | "extern" Abi "{" InnerAttr* ForeignItem* "}", 196 | }; 197 | 198 | Abi: () = { 199 | StringLiteral? 200 | }; 201 | 202 | ForeignItem: () = { 203 | AttrsAndVis "static" item_foreign_static, 204 | AttrsAndVis item_foreign_fn, 205 | AttrsAndVis "unsafe" item_foreign_fn, 206 | }; 207 | item_foreign_static: () = { 208 | "mut"? Identifier ":" ty ";", 209 | }; 210 | item_foreign_fn: () = { 211 | "fn" Identifier GenericParams fn_decl_allow_variadic MaybeWhereClause ";", 212 | }; 213 | fn_decl_allow_variadic: () = { 214 | fn_params_allow_variadic RetTy, 215 | }; 216 | fn_params_allow_variadic: () = { 217 | "(" ")", 218 | "(" Comma1NoTrail ")", 219 | "(" Comma1NoTrail "," ")", 220 | "(" Comma1NoTrail "," "..." ")", 221 | }; 222 | visibility: () = { 223 | "pub", 224 | (), 225 | }; 226 | IdentifiersOrSelf: () = { 227 | IdentifierOrSelf, 228 | IdentifierOrSelf "as" Identifier, 229 | IdentifiersOrSelf "," IdentifierOrSelf, 230 | }; 231 | IdentifierOrSelf: () = { 232 | Identifier, 233 | "self", 234 | }; 235 | ItemType: () = { 236 | "type" Identifier GenericParams MaybeWhereClause "=" TySum ";", 237 | }; 238 | ItemTrait: () = { 239 | MaybeUnsafe "trait" Identifier GenericParams MaybeTyParamBounds MaybeWhereClause 240 | "{" 241 | TraitItem* 242 | "}", 243 | }; 244 | 245 | TraitItem: () = { 246 | TraitConst, 247 | TraitType, 248 | TraitMethod, 249 | }; 250 | 251 | TraitConst: () = { 252 | MaybeOuterAttrs "const" Identifier MaybeTyAscription MaybeConstDefault ";", 253 | }; 254 | 255 | MaybeConstDefault: () = { 256 | ("=" Expr)? 257 | }; 258 | 259 | TraitType: () = { 260 | MaybeOuterAttrs "type" TyParam ";", 261 | }; 262 | 263 | MaybeUnsafe: () = { 264 | "unsafe"? 265 | }; 266 | 267 | TraitMethod: () = { 268 | TypeMethod, 269 | Method, 270 | }; 271 | 272 | TypeMethod: () = { 273 | AttrsAndVis MaybeUnsafe "fn" Identifier GenericParams fn_decl_with_self_allow_AnonParams MaybeWhereClause ";", 274 | AttrsAndVis MaybeUnsafe "extern" Abi "fn" Identifier GenericParams fn_decl_with_self_allow_AnonParams MaybeWhereClause ";", 275 | }; 276 | 277 | Method: () = { 278 | AttrsAndVis MaybeUnsafe "fn" Identifier GenericParams fn_decl_with_self_allow_AnonParams MaybeWhereClause InnerAttrs_and_block, 279 | AttrsAndVis MaybeUnsafe "extern" Abi "fn" Identifier GenericParams fn_decl_with_self_allow_AnonParams MaybeWhereClause InnerAttrs_and_block, 280 | }; 281 | 282 | ImplMethod: () = { 283 | AttrsAndVis MaybeUnsafe "fn" Identifier GenericParams fn_decl_with_self MaybeWhereClause InnerAttrs_and_block, 284 | AttrsAndVis MaybeUnsafe "extern" Abi "fn" Identifier GenericParams fn_decl_with_self MaybeWhereClause InnerAttrs_and_block, 285 | }; 286 | 287 | ItemImpl: () = { 288 | MaybeUnsafe "impl" GenericParams TyPrimSum MaybeWhereClause "{" InnerAttr* MaybeImplItems "}", 289 | MaybeUnsafe "impl" GenericParams "(" ty ")" MaybeWhereClause "{" InnerAttr* MaybeImplItems "}", 290 | MaybeUnsafe "impl" GenericParams TraitRef "for" TySum MaybeWhereClause "{" InnerAttr* MaybeImplItems "}", 291 | MaybeUnsafe "impl" GenericParams "!" TraitRef "for" TySum MaybeWhereClause "{" InnerAttr* MaybeImplItems "}", 292 | MaybeUnsafe "impl" GenericParams TraitRef "for" ".." "{" "}", 293 | MaybeUnsafe "impl" GenericParams "!" TraitRef "for" ".." "{" "}", 294 | }; 295 | 296 | MaybeImplItems: () = { 297 | ImplItems, 298 | (), 299 | }; 300 | 301 | ImplItems: () = { 302 | ImplItem, 303 | ImplItem ImplItems, 304 | }; 305 | 306 | ImplItem: () = { 307 | ImplMethod, 308 | AttrsAndVis ItemMacro, 309 | ImplConst, 310 | ImplType, 311 | }; 312 | 313 | ImplConst: () = { 314 | AttrsAndVis ItemConst, 315 | }; 316 | 317 | ImplType: () = { 318 | AttrsAndVis "type" Identifier GenericParams "=" TySum ";", 319 | }; 320 | 321 | ItemFn: () = { 322 | "fn" Identifier GenericParams fn_decl MaybeWhereClause InnerAttrs_and_block, 323 | }; 324 | 325 | ItemUnsafeFn: () = { 326 | "unsafe" "fn" Identifier GenericParams fn_decl MaybeWhereClause InnerAttrs_and_block, 327 | "unsafe" "extern" Abi "fn" Identifier GenericParams fn_decl MaybeWhereClause InnerAttrs_and_block, 328 | }; 329 | 330 | fn_decl: () = { 331 | fn_params RetTy, 332 | }; 333 | 334 | fn_decl_with_self: () = { 335 | fn_params_with_self RetTy, 336 | }; 337 | 338 | fn_decl_with_self_allow_AnonParams: () = { 339 | fn_AnonParams_with_self RetTy, 340 | }; 341 | 342 | fn_params: () = { 343 | "(" Comma ")", 344 | }; 345 | fn_AnonParams: () = { 346 | "(" AnonParam AnonParams_allow_variadic_tail ")", 347 | "(" ")", 348 | }; 349 | fn_params_with_self: () = { 350 | "(" "mut"? "self" MaybeTyAscription Maybecomma_params ")", 351 | "(" "&[]" "mut"? "self" MaybeTyAscription Maybecomma_params ")", 352 | "(" "&[]" Lifetime "mut"? "self" MaybeTyAscription Maybecomma_params ")", 353 | "(" Comma ")", 354 | }; 355 | fn_AnonParams_with_self: () = { 356 | "(" "mut"? "self" MaybeTyAscription Maybecomma_AnonParams ")", 357 | "(" "&[]" "mut"? "self" MaybeTyAscription Maybecomma_AnonParams ")", 358 | "(" "&[]" Lifetime "mut"? "self" MaybeTyAscription Maybecomma_AnonParams ")", 359 | "(" MaybeAnonParams ")", 360 | }; 361 | param: () = { 362 | Pat ":" TySum, 363 | }; 364 | InferrableParam: () = { 365 | Pat MaybeTyAscription, 366 | }; 367 | Maybecomma_params: () = { 368 | "," Comma, 369 | (), 370 | }; 371 | Maybecomma_AnonParams: () = { 372 | ",", 373 | "," AnonParams, 374 | "," AnonParams ",", 375 | (), 376 | }; 377 | MaybeAnonParams: () = { 378 | AnonParams, 379 | AnonParams ",", 380 | (), 381 | }; 382 | AnonParams: () = { 383 | AnonParam, 384 | AnonParams "," AnonParam, 385 | }; 386 | AnonParam: () = { 387 | NamedArg ":" ty, 388 | ty, 389 | }; 390 | AnonParams_allow_variadic_tail: () = { 391 | "," "...", 392 | "," AnonParam AnonParams_allow_variadic_tail, 393 | (), 394 | }; 395 | 396 | NamedArg: () = { 397 | Identifier, 398 | "_", 399 | "&[]" Identifier, 400 | "&[]" "_", 401 | "mut" Identifier, 402 | }; 403 | 404 | RetTy: () = { 405 | "->" "!", 406 | "->" ty, 407 | (), 408 | }; 409 | 410 | GenericParams: () = { 411 | TyLt Comma1 TyGt, 412 | TyLt (LifetimeAndBounds ",")+ Comma1 TyGt, 413 | TyLt Comma1 TyGt, 414 | TyLt TyGt, 415 | }; 416 | MaybeWhereClause: () = { 417 | WhereClause? 418 | }; 419 | WhereClause: () = { 420 | "where" Comma 421 | }; 422 | WherePredicate: () = { 423 | ForLifetimes? Lifetime ":" bounds, 424 | ForLifetimes ty ":" TyParamBounds, 425 | }; 426 | ForLifetimes: () = { 427 | "for" TyLt Lifetimes TyGt, 428 | }; 429 | 430 | PathNoTypes: () = { 431 | Identifier, 432 | "::" Identifier, 433 | "self", 434 | "::" "self", 435 | PathNoTypes "::" Identifier, 436 | }; 437 | GenericArgs: () = { 438 | TyLt GenericValues TyGt, 439 | }; 440 | GenericValues: () = { 441 | Lifetimes? MaybeTySumsAndOrBindings, 442 | }; 443 | MaybeTySumsAndOrBindings: () = { 444 | TySums, 445 | TySums ",", 446 | TySums "," bindings, 447 | bindings, 448 | bindings ",", 449 | (), 450 | }; 451 | Maybebindings: () = { 452 | "," bindings, 453 | (), 454 | }; 455 | 456 | #[inline] 457 | Pat: () = PatWithBindingMode; 458 | 459 | PatWithBindingMode: () = { 460 | "_", 461 | AnyAmp PatWithBindingMode, 462 | AnyAmp "mut" Pat, 463 | "(" Comma ")", 464 | "[" PatVec "]", 465 | LitOrPath, 466 | LitOrPath "..." LitOrPath, 467 | PathExpr "{" PatStruct "}", 468 | PathExpr "(" ".." ")", 469 | PathExpr "(" Comma ")", 470 | PathExpr "!" Identifier? delimited_token_trees, 471 | BM Identifier, 472 | Identifier "@" Pat, 473 | BM Identifier "@" Pat, 474 | "box" Pat, 475 | TyLt TySum MaybeAsTraitRef TyGt "::" Identifier, 476 | }; 477 | 478 | PatsOr: () = { 479 | Delim1NoTrail 480 | }; 481 | 482 | BindingMode: () = { 483 | RefBindingMode, 484 | "mut", 485 | }; 486 | 487 | RefBindingMode: () = { 488 | "ref", 489 | "ref" "mut", 490 | }; 491 | 492 | LitOrPath: () = { 493 | PathExpr, 494 | Lit, 495 | "-" Lit, 496 | }; 497 | 498 | PatField: () = { 499 | Identifier, 500 | BindingMode Identifier, 501 | "box" Identifier, 502 | "box" BindingMode Identifier, 503 | Identifier ":" Pat, 504 | BindingMode Identifier ":" Pat, 505 | }; 506 | 507 | // LALRPOP BUG: Removing the `#[inline]` causes LALRPOP to fail with 508 | // no useful output, unless you pipe through a file. Can I reduce 509 | // this? [Also, the error message is confusing.] 510 | #[inline] 511 | PatFields: () = { 512 | Comma1NoTrail 513 | }; 514 | 515 | PatStruct: () = { 516 | PatFields, 517 | PatFields ",", 518 | PatFields "," "..", 519 | "..", 520 | }; 521 | 522 | PatVec: () = { 523 | PatVecElts, 524 | PatVecElts ",", 525 | PatVecElts "..", 526 | PatVecElts "," "..", 527 | PatVecElts ".." "," PatVecElts, 528 | PatVecElts ".." "," PatVecElts ",", 529 | PatVecElts "," ".." "," PatVecElts, 530 | PatVecElts "," ".." "," PatVecElts ",", 531 | ".." "," PatVecElts, 532 | ".." "," PatVecElts ",", 533 | "..", 534 | (), 535 | }; 536 | 537 | PatVecElts: () = { 538 | Pat, 539 | PatVecElts "," Pat, 540 | }; 541 | 542 | ty: () = { 543 | TyPrim, 544 | TyLt TySum MaybeAsTraitRef TyGt "::" Identifier, 545 | "(" TySums ")", 546 | "(" TySums "," ")", 547 | "(" ")", 548 | }; 549 | TyPrim: () = { 550 | Path, 551 | "box" ty, 552 | "*" mut_or_const ty, 553 | AnyAmp ty, 554 | AnyAmp "mut" ty, 555 | AnyAmp Lifetime "mut"? ty, 556 | "[" ty "]", 557 | "[" ty "," ".." Expr "]", 558 | "[" ty ";" Expr "]", 559 | "typeof" "(" Expr ")", 560 | "_", 561 | ty_bare_fn, 562 | for_in_type, 563 | }; 564 | ty_bare_fn: () = { 565 | "fn" ty_fn_decl, 566 | "unsafe" "fn" ty_fn_decl, 567 | "extern" Abi "fn" ty_fn_decl, 568 | "unsafe" "extern" Abi "fn" ty_fn_decl, 569 | }; 570 | ty_fn_decl: () = { 571 | GenericParams fn_AnonParams RetTy, 572 | }; 573 | for_in_type: () = { 574 | "for" TyLt MaybeLifetimes TyGt for_in_type_suffix, 575 | }; 576 | for_in_type_suffix: () = { 577 | ty_bare_fn, 578 | TraitRef, 579 | }; 580 | mut_or_const: () = { 581 | "mut", 582 | "const", 583 | }; 584 | ty_qualified_path_and_GenericValues: () = { 585 | ty_qualified_path Maybebindings, 586 | ty_qualified_path "," TySums Maybebindings, 587 | }; 588 | ty_qualified_path: () = { 589 | TySum "as" TraitRef TyGt "::" Identifier, 590 | TySum "as" TraitRef TyGt "::" Identifier "+" TyParamBounds, 591 | }; 592 | MaybeTySums: () = { 593 | TySums, 594 | TySums ",", 595 | (), 596 | }; 597 | TySums: () = { 598 | TySum, 599 | TySums "," TySum, 600 | }; 601 | TySum: () = { 602 | ty, 603 | ty "+" TyParamBounds, 604 | }; 605 | TyPrimSum: () = { 606 | TyPrim, 607 | TyPrim "+" TyParamBounds, 608 | }; 609 | MaybeTyParamBounds: () = { 610 | (":" TyParamBounds)? 611 | }; 612 | TyParamBounds: () = { 613 | boundseq, 614 | (), 615 | }; 616 | boundseq: () = { 617 | polybound, 618 | boundseq "+" polybound, 619 | }; 620 | polybound: () = { 621 | "for" TyLt MaybeLifetimes TyGt bound, 622 | bound, 623 | "?" bound, 624 | }; 625 | bindings: () = { 626 | binding, 627 | bindings "," binding, 628 | }; 629 | binding: () = { 630 | Identifier "=" ty, 631 | }; 632 | TyParam: () = { 633 | Identifier MaybeTyParamBounds MaybeTyDefault, 634 | Identifier "?" Identifier MaybeTyParamBounds MaybeTyDefault, 635 | }; 636 | Maybebounds: () = { 637 | ":" bounds, 638 | (), 639 | }; 640 | bounds: () = { 641 | bound, 642 | bounds "+" bound, 643 | }; 644 | bound: () = { 645 | Lifetime, 646 | TraitRef, 647 | }; 648 | MaybeLifetimeBounds: () = { 649 | (":" LifetimeBounds)? 650 | }; 651 | LifetimeBounds: () = { 652 | Lifetime, 653 | LifetimeBounds "+" Lifetime, 654 | }; 655 | MaybeTyDefault: () = { 656 | ("=" TySum)? 657 | }; 658 | MaybeLifetimes: () = Comma; 659 | Lifetimes: () = Comma1; 660 | LifetimeAndBounds: () = { 661 | Lifetime MaybeLifetimeBounds, 662 | }; 663 | TraitRef: () = { 664 | Path, 665 | }; 666 | InnerAttrs_and_block: () = { 667 | "{" InnerAttr* Maybestmts "}", 668 | }; 669 | block: () = { 670 | "{" Maybestmts "}", 671 | }; 672 | Maybestmts: () = { 673 | stmts, 674 | stmts ExprNoStmtLike, 675 | ExprNoStmtLike, 676 | (), 677 | }; 678 | stmts: () = { 679 | stmt, 680 | stmts stmt, 681 | }; 682 | stmt: () = { 683 | Let, 684 | StmtItem, 685 | "pub" StmtItem, 686 | OuterAttrs StmtItem, 687 | OuterAttrs "pub" StmtItem, 688 | ExprStmtLike, 689 | block, 690 | ExprNoStmtLike ";", 691 | ";", 692 | }; 693 | 694 | PathExpr: () = { 695 | Path<"::"> 696 | }; 697 | 698 | // Parses a path like `x::y::z`, where A is the token that separates 699 | // the generic arguments. 700 | Path: () = { 701 | Identifier, 702 | "::" Identifier, 703 | "self" "::" Identifier, 704 | "super" "::" Identifier, 705 | Path "::" Identifier, 706 | Path ARG_SEP GenericArgs, 707 | }; 708 | 709 | MacroExpr: () = { 710 | PathExpr "!" Identifier? parens_delimited_token_trees, 711 | PathExpr "!" Identifier? brackets_delimited_token_trees, 712 | }; 713 | 714 | // New-style names: 715 | Expr: () = ExprRestricted<"S","B","L">; 716 | ExprNoStruct: () = ExprRestricted<"","B","L">; 717 | ExprNoStmtLike: () = ExprRestricted<"S","","">; 718 | 719 | // The parameters must be either "" or "[SBLT]". They 720 | // are used to select subsets of expressions. Not all 721 | // the parameters apply to all subsets of expressions. 722 | // 723 | // - S: if non-empty, include struct expressions 724 | // - B: if non-empty, include block expressions 725 | // - L: if non-empty, include stmt-like expressions 726 | // - T: if non-empty, include expressions ending in a type 727 | ExprRestricted: () = { 728 | ExprOrOr, 729 | "return" if S != "", // FIXME#1 730 | "return" ExprOptionalRhs if S != "", // FIXME#1 731 | "..", 732 | LambdaExpr, 733 | "move" LambdaExpr, 734 | ExprOrOr "=" ExprRestricted, 735 | ExprOrOr "<-" ExprRestricted, 736 | ExprOrOr "..", 737 | ExprOrOr ".." ExprOptionalRhs, 738 | ExprOrOr "<<=" ExprRestricted, 739 | ExprOrOr ">>=" ExprRestricted, 740 | ExprOrOr "-=" ExprRestricted, 741 | ExprOrOr "&=" ExprRestricted, 742 | ExprOrOr "|=" ExprRestricted, 743 | ExprOrOr "+=" ExprRestricted, 744 | ExprOrOr "*=" ExprRestricted, 745 | ExprOrOr "/=" ExprRestricted, 746 | ExprOrOr "^=" ExprRestricted, 747 | ExprOrOr "%=" ExprRestricted, 748 | }; 749 | 750 | // When you have an optional RHS, such as in a `..` expression, we 751 | // can't allow block expressions if we are not allowed struct 752 | // expressions. So toggle B to "" if S is "". The reason is that 753 | // otherwise you get an ambiguity: 754 | // 755 | // ... if 0 .. { 22 } ... 756 | // ^~~~~~ body of the if, or RHS of the `..`? 757 | ExprOptionalRhs: () = { 758 | ExprRestricted if S == "", // if structs are disabled, disable blocks 759 | ExprRestricted if S != "", // if structs are enabled, pass everything thru 760 | }; 761 | 762 | ExprOrOr: () = { 763 | ExprAndAnd, 764 | ExprOrOr "|[|]" "|[]" ExprAndAnd, 765 | }; 766 | 767 | ExprAndAnd: () = { 768 | ExprEq, 769 | ExprAndAnd "&[&]" "&[]" ExprEq, 770 | }; 771 | 772 | ExprEq: () = { 773 | ExprEqOp, 774 | }; 775 | 776 | ExprEqOp: () = { 777 | ExprOr, 778 | ExprOr "==" ExprOr, 779 | ExprOr "!=" ExprOr, 780 | ExprOr "<[]" ExprOr, 781 | ExprOr ">[]" ExprOr, 782 | ExprOr "<=" ExprOr, 783 | ExprOr ">=" ExprOr, 784 | }; 785 | 786 | ExprOr: () = { 787 | ExprXor, 788 | ExprOr "|[]" ExprXor, 789 | }; 790 | 791 | ExprXor: () = { 792 | ExprAnd, 793 | ExprXor "^" ExprAnd, 794 | }; 795 | 796 | ExprAnd: () = { 797 | ExprShift, 798 | ExprAnd "&[]" ExprShift, 799 | }; 800 | 801 | ExprShift: () = { 802 | ExprPlusMinus, 803 | ExprShift "<[<]" "<[]" ExprPlusMinus, 804 | ExprShift ">[>]" ">[]" ExprPlusMinus, 805 | }; 806 | 807 | ExprPlusMinus: () = { 808 | ExprMulDiv, 809 | ExprPlusMinus "+" ExprMulDiv, 810 | ExprPlusMinus "-" ExprMulDiv, 811 | }; 812 | 813 | ExprMulDiv: () = { 814 | ExprAs, 815 | ExprMulDiv "*" ExprAs, 816 | ExprMulDiv "/" ExprAs, 817 | ExprMulDiv "%" ExprAs, 818 | }; 819 | 820 | ExprAs: () = { 821 | ExprPrefix, 822 | ExprPrefix "as" ty if T != "", // FIXME#2 823 | }; 824 | 825 | ExprPrefix: () = { 826 | "box" ExprSuffix, 827 | "-" ExprSuffix, 828 | "!" ExprSuffix, 829 | "*" ExprSuffix, 830 | AnyAmp "mut"? ExprSuffix, 831 | }; 832 | 833 | ExprSuffix: () = { 834 | ExprAtom, 835 | ExprSuffix "." Path<"::">, 836 | ExprSuffix "." LiteralInteger, 837 | ExprSuffix "[" Expr "]", 838 | ExprSuffix "(" Comma ")", 839 | }; 840 | 841 | ExprAtom: () = { 842 | Lit, 843 | PathExpr, 844 | "self", 845 | MacroExpr, 846 | PathExpr "{" StructExprFields "}" if S != "", 847 | "(" Comma ")", 848 | "[" Comma "]", 849 | "[" Expr ";" Expr "]", 850 | "continue" if S != "", // FIXME#1 851 | "continue" Identifier if S != "", // FIXME#1 852 | "break" if S != "", // FIXME#1 853 | "break" Identifier if S != "", // FIXME#1 854 | Expr_qualified_path, 855 | ExprStmtLike if L != "", 856 | block if B != "", 857 | }; 858 | 859 | Expr_qualified_path: () = { 860 | TyLt TySum MaybeAsTraitRef TyGt "::" Identifier Maybeqpath_params, 861 | }; 862 | 863 | Maybeqpath_params: () = { 864 | "::" GenericArgs, 865 | (), 866 | }; 867 | 868 | MaybeAsTraitRef: () = { 869 | ("as" TraitRef)? 870 | }; 871 | 872 | LambdaExpr: () = { 873 | AnyPipe Comma "|[]" ExprRestricted, 874 | AnyPipe Comma "|[]" "->" ty "{" Expr "}", 875 | }; 876 | 877 | StructExprFields: () = { 878 | FieldValues, 879 | FieldValues ",", 880 | FieldValues "," ".." Expr, 881 | ".." Expr, 882 | }; 883 | 884 | // Note: this is not the same as Comma, because it does 885 | // not admit an empty list, and it also does not accept a trailing `,`. 886 | FieldValues: () = { 887 | FieldValue, 888 | FieldValues "," FieldValue, 889 | }; 890 | 891 | FieldValue: () = { 892 | Identifier ":" Expr, 893 | }; 894 | 895 | ExprStmtLike: () = { 896 | ExprMatch, 897 | ExprIf, 898 | ExprIfLet, 899 | ExprWhile, 900 | ExprWhileLet, 901 | ExprLoop, 902 | ExprFor, 903 | "unsafe" block, 904 | PathExpr "!" Identifier? braces_delimited_token_trees, 905 | }; 906 | ExprStmtLikeSuffix: () = { 907 | ExprStmtLike, 908 | ExprStmtLikeSuffix "." Path<"::">, 909 | ExprStmtLikeSuffix "." Path<"::"> "[" Expr? "]", 910 | ExprStmtLikeSuffix "." Path<"::"> "(" Comma ")", 911 | ExprStmtLikeSuffix "." LiteralInteger, 912 | }; 913 | ExprMatch: () = { 914 | "match" ExprNoStruct "{" "}", 915 | "match" ExprNoStruct "{" MatchClauses "}", 916 | "match" ExprNoStruct "{" MatchClauses NonBlockMatchClause "}", 917 | "match" ExprNoStruct "{" NonBlockMatchClause "}", 918 | }; 919 | MatchClauses: () = { 920 | MatchClause, 921 | MatchClauses MatchClause, 922 | }; 923 | MatchClause: () = { 924 | NonBlockMatchClause ",", 925 | BlockMatchClause, 926 | BlockMatchClause ",", 927 | }; 928 | NonBlockMatchClause: () = { 929 | MaybeOuterAttrs PatsOr MaybeGuard "=>" ExprNoStmtLike, 930 | MaybeOuterAttrs PatsOr MaybeGuard "=>" ExprStmtLikeSuffix, 931 | }; 932 | BlockMatchClause: () = { 933 | MaybeOuterAttrs PatsOr MaybeGuard "=>" block, 934 | }; 935 | MaybeGuard: () = { 936 | "if" ExprNoStruct, 937 | (), 938 | }; 939 | ExprIf: () = { 940 | "if" ExprNoStruct block, 941 | "if" ExprNoStruct block "else" BlockOrIf, 942 | }; 943 | ExprIfLet: () = { 944 | "if" "let" Pat "=" ExprNoStruct block, 945 | "if" "let" Pat "=" ExprNoStruct block "else" BlockOrIf, 946 | }; 947 | 948 | BlockOrIf: () = { 949 | block, 950 | ExprIf, 951 | ExprIfLet, 952 | }; 953 | 954 | ExprWhile: () = { 955 | MaybeLabel "while" ExprNoStruct block, 956 | }; 957 | 958 | ExprWhileLet: () = { 959 | MaybeLabel "while" "let" Pat "=" ExprNoStruct block, 960 | }; 961 | 962 | ExprLoop: () = { 963 | MaybeLabel "loop" block, 964 | }; 965 | 966 | ExprFor: () = { 967 | MaybeLabel "for" Pat "in" ExprNoStruct block, 968 | }; 969 | 970 | MaybeLabel: () = { 971 | (Lifetime ":")? 972 | }; 973 | 974 | Let: () = { 975 | "let" Pat MaybeTyAscription MaybeInitExpr ";", 976 | }; 977 | 978 | Lit: () = { 979 | LiteralByte, 980 | LiteralChar, 981 | LiteralInteger, 982 | LiteralFloat, 983 | "true", 984 | "false", 985 | StringLiteral, 986 | }; 987 | 988 | StringLiteral: () = { 989 | LiteralString, 990 | LiteralStringRaw, 991 | LiteralByteString, 992 | LiteralByteStringRaw, 993 | }; 994 | 995 | unpaired_token: () = { 996 | "==", 997 | "!=", 998 | "-=", 999 | "&=", 1000 | "|=", 1001 | "+=", 1002 | "*=", 1003 | "/=", 1004 | "^=", 1005 | "%=", 1006 | "..", 1007 | "...", 1008 | "::", 1009 | "->", 1010 | LiteralByte, 1011 | LiteralChar, 1012 | LiteralInteger, 1013 | LiteralFloat, 1014 | LiteralString, 1015 | LiteralStringRaw, 1016 | LiteralByteString, 1017 | LiteralByteStringRaw, 1018 | Identifier, 1019 | "_", 1020 | Lifetime, 1021 | "self", 1022 | "super", 1023 | "static", 1024 | "as", 1025 | "break", 1026 | "crate", 1027 | "else", 1028 | "enum", 1029 | "extern", 1030 | "false", 1031 | "fn", 1032 | "for", 1033 | "if", 1034 | "impl", 1035 | "in", 1036 | "let", 1037 | "loop", 1038 | "match", 1039 | "mod", 1040 | "move", 1041 | "mut", 1042 | "priv", 1043 | "pub", 1044 | "ref", 1045 | "return", 1046 | "struct", 1047 | "true", 1048 | "trait", 1049 | "type", 1050 | "unsafe", 1051 | "use", 1052 | "while", 1053 | "continue", 1054 | "box", 1055 | "const", 1056 | "where", 1057 | "typeof", 1058 | "//!...", 1059 | "///...", 1060 | "#!", 1061 | ";", 1062 | ",", 1063 | ".", 1064 | "@", 1065 | "#", 1066 | "~", 1067 | ":", 1068 | "$", 1069 | "=", 1070 | "?", 1071 | "!", 1072 | "<<=", 1073 | ">>=", 1074 | "<-", 1075 | "<=", 1076 | ">=", 1077 | "<[<]", 1078 | "<[]", 1079 | ">[>]", 1080 | ">[]", 1081 | "-", 1082 | "|[|]", 1083 | "|[]", 1084 | "&[&]", 1085 | "&[]", 1086 | "+", 1087 | "*", 1088 | "/", 1089 | "^", 1090 | "%", 1091 | }; 1092 | token_trees: () = { 1093 | (), 1094 | token_trees token_tree, 1095 | }; 1096 | token_tree: () = { 1097 | delimited_token_trees, 1098 | unpaired_token, 1099 | }; 1100 | delimited_token_trees: () = { 1101 | parens_delimited_token_trees, 1102 | braces_delimited_token_trees, 1103 | brackets_delimited_token_trees, 1104 | }; 1105 | parens_delimited_token_trees: () = { 1106 | "(" token_trees ")", 1107 | }; 1108 | braces_delimited_token_trees: () = { 1109 | "{" token_trees "}", 1110 | }; 1111 | brackets_delimited_token_trees: () = { 1112 | "[" token_trees "]", 1113 | }; 1114 | 1115 | MaybeIdentifier: () = { 1116 | (), 1117 | Identifier, 1118 | }; 1119 | 1120 | // Comma-separated list with optional trailing comma. Potentially 1121 | // empty. 1122 | #[inline] 1123 | Comma: () = 1124 | Delim; 1125 | 1126 | // Delimeted list of E with optional trailing delimeter. Potentially 1127 | // empty. 1128 | #[inline] 1129 | Delim: () = 1130 | (E D)* E?; 1131 | 1132 | // Comma-separated list of length at least 1. Trailing comma accepted. 1133 | #[inline] 1134 | Comma1: () = 1135 | Delim1; 1136 | 1137 | // Comma-separated list of length at least 1. No trailing comma accepted. 1138 | #[inline] 1139 | Comma1NoTrail: () = 1140 | Delim1NoTrail; 1141 | 1142 | // Delimited list of length at least 1. Trailing delimeter accepted. 1143 | #[inline] 1144 | Delim1: () = { 1145 | (E D)+, 1146 | Delim1NoTrail, 1147 | }; 1148 | 1149 | // Delimited list of length at least 1. No trailing delimeter accepted. 1150 | #[inline] 1151 | Delim1NoTrail: () = { 1152 | (E D)* E, 1153 | }; 1154 | 1155 | #[inline] 1156 | AnyPipe: () = { 1157 | "|[|]", 1158 | "|[]", 1159 | }; 1160 | 1161 | #[inline] 1162 | AnyAmp: () = { 1163 | "&[&]", 1164 | "&[]", 1165 | }; 1166 | 1167 | // Extract one `<` when used as part of a series of `<` in a row, like 1168 | // `<<` or `<<<` or `<<<<<`. Intended for use in types. 1169 | #[inline] 1170 | TyLt: () = { 1171 | "<[<]", 1172 | "<[]", 1173 | }; 1174 | 1175 | // Extract one `>` when used as part of a series of `>` in a row, like 1176 | // `>>` or `>>>` or `>>>>>`. Intended for use in types. 1177 | #[inline] 1178 | TyGt: () = { 1179 | ">[>]", 1180 | ">[]", 1181 | }; 1182 | 1183 | #[inline] 1184 | Epsilon: () = { 1185 | (), 1186 | }; 1187 | 1188 | extern { 1189 | enum Token { 1190 | "!" => Token::Bang, 1191 | "#" => Token::Pound, 1192 | "$" => Token::Dollar, 1193 | "%" => Token::Percent, 1194 | "(" => Token::ParenOpen, 1195 | ")" => Token::ParenClose, 1196 | "*" => Token::Star, 1197 | "+" => Token::Plus, 1198 | "," => Token::Comma, 1199 | "-" => Token::Dash, 1200 | "." => Token::Dot, 1201 | "/" => Token::Slash, 1202 | ":" => Token::Colon, 1203 | ";" => Token::Semi, 1204 | "=" => Token::Equals, 1205 | "?" => Token::QuestionMark, 1206 | "@" => Token::At, 1207 | "[" => Token::SquareBracketOpen, 1208 | "]" => Token::SquareBracketClose, 1209 | "^" => Token::Hat, 1210 | "{" => Token::CurlyBraceOpen, 1211 | "}" => Token::CurlyBraceClose, 1212 | "~" => Token::Twiddle, 1213 | "==" => Token::EqualsEquals, 1214 | "!=" => Token::BangEquals, 1215 | "-=" => Token::DashEquals, 1216 | "&=" => Token::AmpersandEquals, 1217 | "|=" => Token::PipeEquals, 1218 | "+=" => Token::PlusEquals, 1219 | "*=" => Token::StarEquals, 1220 | "/=" => Token::SlashEquals, 1221 | "^=" => Token::HatEquals, 1222 | "%=" => Token::PercentEquals, 1223 | ".." => Token::DotDot, 1224 | "..." => Token::DotDotDot, 1225 | "::" => Token::ColonColon, 1226 | "->" => Token::ThinArrow, 1227 | "=>" => Token::FatArrow, 1228 | "<<=" => Token::LessLessEqual, 1229 | ">>=" => Token::RightRightEqual, 1230 | "<-" => Token::LeftThinArrow, 1231 | "<=" => Token::LessEqual, 1232 | ">=" => Token::RightEqual, 1233 | "_" => Token::Underscore, 1234 | "|[|]" => Token::PipeFollowedByPipe, 1235 | "|[]" => Token::PipeFollowedByOther, 1236 | "&[&]" => Token::AmpersandFollowedByAmpersand, 1237 | "&[]" => Token::AmpersandFollowedByOther, 1238 | "<[<]" => Token::LessFollowedByLess, 1239 | "<[]" => Token::LessFollowedByOther, 1240 | ">[>]" => Token::GreaterFollowedByGreater, 1241 | ">[]" => Token::GreaterFollowedByOther, 1242 | 1243 | "self" => Token::KeywordSelf, 1244 | "super" => Token::KeywordSuper, 1245 | "static" => Token::KeywordStatic, 1246 | "as" => Token::KeywordAs, 1247 | "break" => Token::KeywordBreak, 1248 | "crate" => Token::KeywordCrate, 1249 | "else" => Token::KeywordElse, 1250 | "enum" => Token::KeywordEnum, 1251 | "extern" => Token::KeywordExtern, 1252 | "false" => Token::KeywordFalse, 1253 | "fn" => Token::KeywordFn, 1254 | "for" => Token::KeywordFor, 1255 | "if" => Token::KeywordIf, 1256 | "impl" => Token::KeywordImpl, 1257 | "in" => Token::KeywordIn, 1258 | "let" => Token::KeywordLet, 1259 | "loop" => Token::KeywordLoop, 1260 | "match" => Token::KeywordMatch, 1261 | "mod" => Token::KeywordMod, 1262 | "move" => Token::KeywordMove, 1263 | "mut" => Token::KeywordMut, 1264 | "priv" => Token::KeywordPriv, 1265 | "pub" => Token::KeywordPub, 1266 | "ref" => Token::KeywordRef, 1267 | "return" => Token::KeywordReturn, 1268 | "struct" => Token::KeywordStruct, 1269 | "true" => Token::KeywordTrue, 1270 | "trait" => Token::KeywordTrait, 1271 | "type" => Token::KeywordType, 1272 | "unsafe" => Token::KeywordUnsafe, 1273 | "use" => Token::KeywordUse, 1274 | "while" => Token::KeywordWhile, 1275 | "continue" => Token::KeywordContinue, 1276 | "box" => Token::KeywordBox, 1277 | "const" => Token::KeywordConst, 1278 | "where" => Token::KeywordWhere, 1279 | "typeof" => Token::KeywordTypeof, 1280 | 1281 | LiteralByte => Token::LiteralByte, 1282 | LiteralChar => Token::LiteralChar, 1283 | LiteralInteger => Token::LiteralInteger, 1284 | LiteralFloat => Token::LiteralFloat, 1285 | LiteralString => Token::LiteralString, 1286 | LiteralStringRaw => Token::LiteralStringRaw, 1287 | LiteralByteString => Token::LiteralByteString, 1288 | LiteralByteStringRaw => Token::LiteralByteStringRaw, 1289 | Identifier => Token::Identifier, 1290 | Lifetime => Token::Lifetime, 1291 | 1292 | "//!..." => Token::InnerDocComment, 1293 | "///..." => Token::OuterDocComment, 1294 | "#!" => Token::Shebang, 1295 | "#!..." => Token::ShebangLine, 1296 | } 1297 | } 1298 | -------------------------------------------------------------------------------- /src/token/mod.rs: -------------------------------------------------------------------------------- 1 | pub enum Token { 2 | Bang, // "!" 3 | Pound, // "#" 4 | Dollar, // "$" 5 | Percent, // "%" 6 | ParenOpen, // "(" 7 | ParenClose, // ")" 8 | Star, // "*" 9 | Plus, // "+" 10 | Comma, // "," 11 | Dash, // "-" 12 | Dot, // "." 13 | Slash, // "/" 14 | Colon, // ":" 15 | Semi, // ";" 16 | Equals, // "=" 17 | QuestionMark, // "?" 18 | At, // "@" 19 | SquareBracketOpen, // "[" 20 | SquareBracketClose, // "]" 21 | Hat, // "^" 22 | CurlyBraceOpen, // "{" 23 | CurlyBraceClose, // "}" 24 | Twiddle, // "~" 25 | EqualsEquals, // "==" 26 | BangEquals, // "!=" 27 | DashEquals, // "-=" 28 | AmpersandEquals, // "&=" 29 | PipeEquals, // "|=" 30 | PlusEquals, // "+=" 31 | StarEquals, // "*=" 32 | SlashEquals, // "/=" 33 | HatEquals, // "^=" 34 | PercentEquals, // "%=" 35 | DotDot, // ".." 36 | DotDotDot, // "..." 37 | ColonColon, // "::" 38 | ThinArrow, // "->" 39 | FatArrow, // "=>" 40 | LessLessEqual, // "<<=" 41 | RightRightEqual, // ">>=" 42 | LeftThinArrow, // "<-" 43 | LessEqual, // "<=" 44 | RightEqual, // ">=" 45 | Underscore, // "_" 46 | 47 | // Compute tokens. The notation `x[y]` means "an x adjacent to 48 | // a y" and the notation `x[]` means "an x adjacent to nothing 49 | // of interest". So if we see `<<`, we will produce two 50 | // tokens: `<[<] <[]`, but if we see `<<=`, we would produce 51 | // three tokens: `<[<=] <[=] =`. 52 | PipeFollowedByPipe, // "|[|]" 53 | PipeFollowedByOther, // "|[]" 54 | AmpersandFollowedByAmpersand, // "&[&]" 55 | AmpersandFollowedByOther, // "&[]" 56 | LessFollowedByLess, // "<[<]" 57 | LessFollowedByOther, // "<[]" 58 | GreaterFollowedByGreater, // ">[>]" 59 | GreaterFollowedByOther, // ">[]" 60 | 61 | KeywordSelf, // "self" 62 | KeywordSuper, // "super" 63 | KeywordStatic, // "static" 64 | KeywordAs, // "as" 65 | KeywordBreak, // "break" 66 | KeywordCrate, // "crate" 67 | KeywordElse, // "else" 68 | KeywordEnum, // "enum" 69 | KeywordExtern, // "extern" 70 | KeywordFalse, // "false" 71 | KeywordFn, // "fn" 72 | KeywordFor, // "for" 73 | KeywordIf, // "if" 74 | KeywordImpl, // "impl" 75 | KeywordIn, // "in" 76 | KeywordLet, // "let" 77 | KeywordLoop, // "loop" 78 | KeywordMatch, // "match" 79 | KeywordMod, // "mod" 80 | KeywordMove, // "move" 81 | KeywordMut, // "mut" 82 | KeywordPriv, // "priv" 83 | KeywordPub, // "pub" 84 | KeywordRef, // "ref" 85 | KeywordReturn, // "return" 86 | KeywordStruct, // "struct" 87 | KeywordTrue, // "true" 88 | KeywordTrait, // "trait" 89 | KeywordType, // "type" 90 | KeywordUnsafe, // "unsafe" 91 | KeywordUse, // "use" 92 | KeywordWhile, // "while" 93 | KeywordContinue, // "continue" 94 | KeywordBox, // "box" 95 | KeywordConst, // "const" 96 | KeywordWhere, // "where" 97 | KeywordTypeof, // "typeof" 98 | 99 | LiteralByte, 100 | LiteralChar, 101 | LiteralInteger, 102 | LiteralFloat, 103 | LiteralString, 104 | LiteralStringRaw, 105 | LiteralByteString, 106 | LiteralByteStringRaw, 107 | Identifier, 108 | Lifetime, 109 | 110 | InnerDocComment, 111 | OuterDocComment, 112 | Shebang, 113 | ShebangLine, 114 | } 115 | --------------------------------------------------------------------------------