@typespec/compiler 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (352) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +9 -0
  3. package/cmd/tsp-server.js +3 -0
  4. package/cmd/tsp.js +3 -0
  5. package/dist/cmd/runner.d.ts +9 -0
  6. package/dist/cmd/runner.d.ts.map +1 -0
  7. package/dist/cmd/runner.js +62 -0
  8. package/dist/cmd/runner.js.map +1 -0
  9. package/dist/config/config-interpolation.d.ts +11 -0
  10. package/dist/config/config-interpolation.d.ts.map +1 -0
  11. package/dist/config/config-interpolation.js +109 -0
  12. package/dist/config/config-interpolation.js.map +1 -0
  13. package/dist/config/config-loader.d.ts +25 -0
  14. package/dist/config/config-loader.d.ts.map +1 -0
  15. package/dist/config/config-loader.js +182 -0
  16. package/dist/config/config-loader.js.map +1 -0
  17. package/dist/config/config-schema.d.ts +4 -0
  18. package/dist/config/config-schema.d.ts.map +1 -0
  19. package/dist/config/config-schema.js +84 -0
  20. package/dist/config/config-schema.js.map +1 -0
  21. package/dist/config/index.d.ts +3 -0
  22. package/dist/config/index.d.ts.map +1 -0
  23. package/dist/config/index.js +3 -0
  24. package/dist/config/index.js.map +1 -0
  25. package/dist/config/types.d.ts +79 -0
  26. package/dist/config/types.d.ts.map +1 -0
  27. package/dist/config/types.js +2 -0
  28. package/dist/config/types.js.map +1 -0
  29. package/dist/core/binder.d.ts +29 -0
  30. package/dist/core/binder.d.ts.map +1 -0
  31. package/dist/core/binder.js +455 -0
  32. package/dist/core/binder.js.map +1 -0
  33. package/dist/core/charcode.d.ts +130 -0
  34. package/dist/core/charcode.d.ts.map +1 -0
  35. package/dist/core/charcode.js +115 -0
  36. package/dist/core/charcode.js.map +1 -0
  37. package/dist/core/checker.d.ts +138 -0
  38. package/dist/core/checker.d.ts.map +1 -0
  39. package/dist/core/checker.js +4070 -0
  40. package/dist/core/checker.js.map +1 -0
  41. package/dist/core/cli/args.d.ts +18 -0
  42. package/dist/core/cli/args.d.ts.map +1 -0
  43. package/dist/core/cli/args.js +108 -0
  44. package/dist/core/cli/args.js.map +1 -0
  45. package/dist/core/cli/cli.d.ts +2 -0
  46. package/dist/core/cli/cli.d.ts.map +1 -0
  47. package/dist/core/cli/cli.js +477 -0
  48. package/dist/core/cli/cli.js.map +1 -0
  49. package/dist/core/cli/index.d.ts +2 -0
  50. package/dist/core/cli/index.d.ts.map +1 -0
  51. package/dist/core/cli/index.js +2 -0
  52. package/dist/core/cli/index.js.map +1 -0
  53. package/dist/core/decorator-utils.d.ts +108 -0
  54. package/dist/core/decorator-utils.d.ts.map +1 -0
  55. package/dist/core/decorator-utils.js +326 -0
  56. package/dist/core/decorator-utils.js.map +1 -0
  57. package/dist/core/diagnostics.d.ts +93 -0
  58. package/dist/core/diagnostics.d.ts.map +1 -0
  59. package/dist/core/diagnostics.js +315 -0
  60. package/dist/core/diagnostics.js.map +1 -0
  61. package/dist/core/emitter-utils.d.ts +14 -0
  62. package/dist/core/emitter-utils.d.ts.map +1 -0
  63. package/dist/core/emitter-utils.js +16 -0
  64. package/dist/core/emitter-utils.js.map +1 -0
  65. package/dist/core/formatter-fs.d.ts +21 -0
  66. package/dist/core/formatter-fs.d.ts.map +1 -0
  67. package/dist/core/formatter-fs.js +79 -0
  68. package/dist/core/formatter-fs.js.map +1 -0
  69. package/dist/core/formatter.d.ts +10 -0
  70. package/dist/core/formatter.d.ts.map +1 -0
  71. package/dist/core/formatter.js +24 -0
  72. package/dist/core/formatter.js.map +1 -0
  73. package/dist/core/helpers/discriminator-utils.d.ts +14 -0
  74. package/dist/core/helpers/discriminator-utils.d.ts.map +1 -0
  75. package/dist/core/helpers/discriminator-utils.js +169 -0
  76. package/dist/core/helpers/discriminator-utils.js.map +1 -0
  77. package/dist/core/helpers/index.d.ts +6 -0
  78. package/dist/core/helpers/index.d.ts.map +1 -0
  79. package/dist/core/helpers/index.js +6 -0
  80. package/dist/core/helpers/index.js.map +1 -0
  81. package/dist/core/helpers/operation-utils.d.ts +15 -0
  82. package/dist/core/helpers/operation-utils.d.ts.map +1 -0
  83. package/dist/core/helpers/operation-utils.js +35 -0
  84. package/dist/core/helpers/operation-utils.js.map +1 -0
  85. package/dist/core/helpers/projected-names-utils.d.ts +20 -0
  86. package/dist/core/helpers/projected-names-utils.d.ts.map +1 -0
  87. package/dist/core/helpers/projected-names-utils.js +40 -0
  88. package/dist/core/helpers/projected-names-utils.js.map +1 -0
  89. package/dist/core/helpers/type-name-utils.d.ts +14 -0
  90. package/dist/core/helpers/type-name-utils.d.ts.map +1 -0
  91. package/dist/core/helpers/type-name-utils.js +122 -0
  92. package/dist/core/helpers/type-name-utils.js.map +1 -0
  93. package/dist/core/helpers/usage-resolver.d.ts +20 -0
  94. package/dist/core/helpers/usage-resolver.d.ts.map +1 -0
  95. package/dist/core/helpers/usage-resolver.js +108 -0
  96. package/dist/core/helpers/usage-resolver.js.map +1 -0
  97. package/dist/core/index.d.ts +26 -0
  98. package/dist/core/index.d.ts.map +1 -0
  99. package/dist/core/index.js +26 -0
  100. package/dist/core/index.js.map +1 -0
  101. package/dist/core/install.d.ts +2 -0
  102. package/dist/core/install.d.ts.map +1 -0
  103. package/dist/core/install.js +26 -0
  104. package/dist/core/install.js.map +1 -0
  105. package/dist/core/library.d.ts +34 -0
  106. package/dist/core/library.d.ts.map +1 -0
  107. package/dist/core/library.js +100 -0
  108. package/dist/core/library.js.map +1 -0
  109. package/dist/core/logger/console-sink.browser.d.ts +4 -0
  110. package/dist/core/logger/console-sink.browser.d.ts.map +1 -0
  111. package/dist/core/logger/console-sink.browser.js +14 -0
  112. package/dist/core/logger/console-sink.browser.js.map +1 -0
  113. package/dist/core/logger/console-sink.d.ts +9 -0
  114. package/dist/core/logger/console-sink.d.ts.map +1 -0
  115. package/dist/core/logger/console-sink.js +81 -0
  116. package/dist/core/logger/console-sink.js.map +1 -0
  117. package/dist/core/logger/index.d.ts +3 -0
  118. package/dist/core/logger/index.d.ts.map +1 -0
  119. package/dist/core/logger/index.js +3 -0
  120. package/dist/core/logger/index.js.map +1 -0
  121. package/dist/core/logger/logger.d.ts +7 -0
  122. package/dist/core/logger/logger.d.ts.map +1 -0
  123. package/dist/core/logger/logger.js +32 -0
  124. package/dist/core/logger/logger.js.map +1 -0
  125. package/dist/core/logger/tracer.d.ts +3 -0
  126. package/dist/core/logger/tracer.d.ts.map +1 -0
  127. package/dist/core/logger/tracer.js +91 -0
  128. package/dist/core/logger/tracer.js.map +1 -0
  129. package/dist/core/manifest.d.ts +21 -0
  130. package/dist/core/manifest.d.ts.map +1 -0
  131. package/dist/core/manifest.js +8 -0
  132. package/dist/core/manifest.js.map +1 -0
  133. package/dist/core/messages.d.ts +2253 -0
  134. package/dist/core/messages.d.ts.map +1 -0
  135. package/dist/core/messages.js +749 -0
  136. package/dist/core/messages.js.map +1 -0
  137. package/dist/core/module-resolver.d.ts +84 -0
  138. package/dist/core/module-resolver.d.ts.map +1 -0
  139. package/dist/core/module-resolver.js +170 -0
  140. package/dist/core/module-resolver.js.map +1 -0
  141. package/dist/core/node-host.browser.d.ts +2 -0
  142. package/dist/core/node-host.browser.d.ts.map +1 -0
  143. package/dist/core/node-host.browser.js +2 -0
  144. package/dist/core/node-host.browser.js.map +1 -0
  145. package/dist/core/node-host.d.ts +7 -0
  146. package/dist/core/node-host.d.ts.map +1 -0
  147. package/dist/core/node-host.js +43 -0
  148. package/dist/core/node-host.js.map +1 -0
  149. package/dist/core/nonascii.d.ts +2 -0
  150. package/dist/core/nonascii.d.ts.map +1 -0
  151. package/dist/core/nonascii.js +712 -0
  152. package/dist/core/nonascii.js.map +1 -0
  153. package/dist/core/options.d.ts +46 -0
  154. package/dist/core/options.d.ts.map +1 -0
  155. package/dist/core/options.js +2 -0
  156. package/dist/core/options.js.map +1 -0
  157. package/dist/core/parser.d.ts +17 -0
  158. package/dist/core/parser.d.ts.map +1 -0
  159. package/dist/core/parser.js +2561 -0
  160. package/dist/core/parser.js.map +1 -0
  161. package/dist/core/path-utils.d.ts +193 -0
  162. package/dist/core/path-utils.d.ts.map +1 -0
  163. package/dist/core/path-utils.js +427 -0
  164. package/dist/core/path-utils.js.map +1 -0
  165. package/dist/core/program.d.ts +104 -0
  166. package/dist/core/program.d.ts.map +1 -0
  167. package/dist/core/program.js +898 -0
  168. package/dist/core/program.js.map +1 -0
  169. package/dist/core/projection-members.d.ts +8 -0
  170. package/dist/core/projection-members.d.ts.map +1 -0
  171. package/dist/core/projection-members.js +387 -0
  172. package/dist/core/projection-members.js.map +1 -0
  173. package/dist/core/projector.d.ts +26 -0
  174. package/dist/core/projector.d.ts.map +1 -0
  175. package/dist/core/projector.js +523 -0
  176. package/dist/core/projector.js.map +1 -0
  177. package/dist/core/scanner.d.ts +125 -0
  178. package/dist/core/scanner.d.ts.map +1 -0
  179. package/dist/core/scanner.js +1012 -0
  180. package/dist/core/scanner.js.map +1 -0
  181. package/dist/core/schema-validator.d.ts +6 -0
  182. package/dist/core/schema-validator.d.ts.map +1 -0
  183. package/dist/core/schema-validator.js +38 -0
  184. package/dist/core/schema-validator.js.map +1 -0
  185. package/dist/core/semantic-walker.d.ts +53 -0
  186. package/dist/core/semantic-walker.d.ts.map +1 -0
  187. package/dist/core/semantic-walker.js +355 -0
  188. package/dist/core/semantic-walker.js.map +1 -0
  189. package/dist/core/type-utils.d.ts +49 -0
  190. package/dist/core/type-utils.d.ts.map +1 -0
  191. package/dist/core/type-utils.js +95 -0
  192. package/dist/core/type-utils.js.map +1 -0
  193. package/dist/core/types.d.ts +1345 -0
  194. package/dist/core/types.d.ts.map +1 -0
  195. package/dist/core/types.js +105 -0
  196. package/dist/core/types.js.map +1 -0
  197. package/dist/core/util.d.ts +150 -0
  198. package/dist/core/util.d.ts.map +1 -0
  199. package/dist/core/util.js +417 -0
  200. package/dist/core/util.js.map +1 -0
  201. package/dist/emitter-framework/asset-emitter.d.ts +5 -0
  202. package/dist/emitter-framework/asset-emitter.d.ts.map +1 -0
  203. package/dist/emitter-framework/asset-emitter.js +610 -0
  204. package/dist/emitter-framework/asset-emitter.js.map +1 -0
  205. package/dist/emitter-framework/builders/array-builder.d.ts +7 -0
  206. package/dist/emitter-framework/builders/array-builder.d.ts.map +1 -0
  207. package/dist/emitter-framework/builders/array-builder.js +45 -0
  208. package/dist/emitter-framework/builders/array-builder.js.map +1 -0
  209. package/dist/emitter-framework/builders/object-builder.d.ts +9 -0
  210. package/dist/emitter-framework/builders/object-builder.d.ts.map +1 -0
  211. package/dist/emitter-framework/builders/object-builder.js +30 -0
  212. package/dist/emitter-framework/builders/object-builder.js.map +1 -0
  213. package/dist/emitter-framework/builders/string-builder.d.ts +13 -0
  214. package/dist/emitter-framework/builders/string-builder.d.ts.map +1 -0
  215. package/dist/emitter-framework/builders/string-builder.js +98 -0
  216. package/dist/emitter-framework/builders/string-builder.js.map +1 -0
  217. package/dist/emitter-framework/custom-key-map.d.ts +29 -0
  218. package/dist/emitter-framework/custom-key-map.d.ts.map +1 -0
  219. package/dist/emitter-framework/custom-key-map.js +62 -0
  220. package/dist/emitter-framework/custom-key-map.js.map +1 -0
  221. package/dist/emitter-framework/index.d.ts +8 -0
  222. package/dist/emitter-framework/index.d.ts.map +1 -0
  223. package/dist/emitter-framework/index.js +8 -0
  224. package/dist/emitter-framework/index.js.map +1 -0
  225. package/dist/emitter-framework/placeholder.d.ts +12 -0
  226. package/dist/emitter-framework/placeholder.d.ts.map +1 -0
  227. package/dist/emitter-framework/placeholder.js +27 -0
  228. package/dist/emitter-framework/placeholder.js.map +1 -0
  229. package/dist/emitter-framework/type-emitter.d.ts +314 -0
  230. package/dist/emitter-framework/type-emitter.d.ts.map +1 -0
  231. package/dist/emitter-framework/type-emitter.js +612 -0
  232. package/dist/emitter-framework/type-emitter.js.map +1 -0
  233. package/dist/emitter-framework/types.d.ts +124 -0
  234. package/dist/emitter-framework/types.d.ts.map +1 -0
  235. package/dist/emitter-framework/types.js +39 -0
  236. package/dist/emitter-framework/types.js.map +1 -0
  237. package/dist/formatter/index.d.ts +11 -0
  238. package/dist/formatter/index.d.ts.map +1 -0
  239. package/dist/formatter/index.js +28 -0
  240. package/dist/formatter/index.js.map +1 -0
  241. package/dist/formatter/parser.d.ts +16 -0
  242. package/dist/formatter/parser.d.ts.map +1 -0
  243. package/dist/formatter/parser.js +23 -0
  244. package/dist/formatter/parser.js.map +1 -0
  245. package/dist/formatter/print/comment-handler.d.ts +7 -0
  246. package/dist/formatter/print/comment-handler.d.ts.map +1 -0
  247. package/dist/formatter/print/comment-handler.js +81 -0
  248. package/dist/formatter/print/comment-handler.js.map +1 -0
  249. package/dist/formatter/print/index.d.ts +3 -0
  250. package/dist/formatter/print/index.d.ts.map +1 -0
  251. package/dist/formatter/print/index.js +3 -0
  252. package/dist/formatter/print/index.js.map +1 -0
  253. package/dist/formatter/print/needs-parens.d.ts +10 -0
  254. package/dist/formatter/print/needs-parens.d.ts.map +1 -0
  255. package/dist/formatter/print/needs-parens.js +27 -0
  256. package/dist/formatter/print/needs-parens.js.map +1 -0
  257. package/dist/formatter/print/printer.d.ts +62 -0
  258. package/dist/formatter/print/printer.d.ts.map +1 -0
  259. package/dist/formatter/print/printer.js +1025 -0
  260. package/dist/formatter/print/printer.js.map +1 -0
  261. package/dist/formatter/print/types.d.ts +9 -0
  262. package/dist/formatter/print/types.d.ts.map +1 -0
  263. package/dist/formatter/print/types.js +2 -0
  264. package/dist/formatter/print/types.js.map +1 -0
  265. package/dist/init/index.d.ts +2 -0
  266. package/dist/init/index.d.ts.map +1 -0
  267. package/dist/init/index.js +2 -0
  268. package/dist/init/index.js.map +1 -0
  269. package/dist/init/init-template.d.ts +45 -0
  270. package/dist/init/init-template.d.ts.map +1 -0
  271. package/dist/init/init-template.js +45 -0
  272. package/dist/init/init-template.js.map +1 -0
  273. package/dist/init/init.d.ts +49 -0
  274. package/dist/init/init.d.ts.map +1 -0
  275. package/dist/init/init.js +224 -0
  276. package/dist/init/init.js.map +1 -0
  277. package/dist/lib/decorators.d.ts +222 -0
  278. package/dist/lib/decorators.d.ts.map +1 -0
  279. package/dist/lib/decorators.js +745 -0
  280. package/dist/lib/decorators.js.map +1 -0
  281. package/dist/lib/service.d.ts +38 -0
  282. package/dist/lib/service.d.ts.map +1 -0
  283. package/dist/lib/service.js +78 -0
  284. package/dist/lib/service.js.map +1 -0
  285. package/dist/manifest.js +4 -0
  286. package/dist/server/completion.d.ts +10 -0
  287. package/dist/server/completion.d.ts.map +1 -0
  288. package/dist/server/completion.js +207 -0
  289. package/dist/server/completion.js.map +1 -0
  290. package/dist/server/index.d.ts +3 -0
  291. package/dist/server/index.d.ts.map +1 -0
  292. package/dist/server/index.js +3 -0
  293. package/dist/server/index.js.map +1 -0
  294. package/dist/server/language-config.d.ts +195 -0
  295. package/dist/server/language-config.d.ts.map +1 -0
  296. package/dist/server/language-config.js +102 -0
  297. package/dist/server/language-config.js.map +1 -0
  298. package/dist/server/server.d.ts +2 -0
  299. package/dist/server/server.d.ts.map +1 -0
  300. package/dist/server/server.js +131 -0
  301. package/dist/server/server.js.map +1 -0
  302. package/dist/server/serverlib.d.ts +72 -0
  303. package/dist/server/serverlib.d.ts.map +1 -0
  304. package/dist/server/serverlib.js +1034 -0
  305. package/dist/server/serverlib.js.map +1 -0
  306. package/dist/server/symbol-structure.d.ts +4 -0
  307. package/dist/server/symbol-structure.d.ts.map +1 -0
  308. package/dist/server/symbol-structure.js +121 -0
  309. package/dist/server/symbol-structure.js.map +1 -0
  310. package/dist/server/tmlanguage.d.ts +3 -0
  311. package/dist/server/tmlanguage.d.ts.map +1 -0
  312. package/dist/server/tmlanguage.js +713 -0
  313. package/dist/server/tmlanguage.js.map +1 -0
  314. package/dist/server/type-details.d.ts +11 -0
  315. package/dist/server/type-details.d.ts.map +1 -0
  316. package/dist/server/type-details.js +72 -0
  317. package/dist/server/type-details.js.map +1 -0
  318. package/dist/server/type-signature.d.ts +2 -0
  319. package/dist/server/type-signature.d.ts.map +1 -0
  320. package/dist/server/type-signature.js +108 -0
  321. package/dist/server/type-signature.js.map +1 -0
  322. package/dist/testing/expect.d.ts +49 -0
  323. package/dist/testing/expect.d.ts.map +1 -0
  324. package/dist/testing/expect.js +83 -0
  325. package/dist/testing/expect.js.map +1 -0
  326. package/dist/testing/index.d.ts +6 -0
  327. package/dist/testing/index.d.ts.map +1 -0
  328. package/dist/testing/index.js +6 -0
  329. package/dist/testing/index.js.map +1 -0
  330. package/dist/testing/test-host.d.ts +14 -0
  331. package/dist/testing/test-host.d.ts.map +1 -0
  332. package/dist/testing/test-host.js +271 -0
  333. package/dist/testing/test-host.js.map +1 -0
  334. package/dist/testing/test-server-host.d.ts +39 -0
  335. package/dist/testing/test-server-host.d.ts.map +1 -0
  336. package/dist/testing/test-server-host.js +112 -0
  337. package/dist/testing/test-server-host.js.map +1 -0
  338. package/dist/testing/test-utils.d.ts +22 -0
  339. package/dist/testing/test-utils.d.ts.map +1 -0
  340. package/dist/testing/test-utils.js +60 -0
  341. package/dist/testing/test-utils.js.map +1 -0
  342. package/dist/testing/types.d.ts +69 -0
  343. package/dist/testing/types.d.ts.map +1 -0
  344. package/dist/testing/types.js +7 -0
  345. package/dist/testing/types.js.map +1 -0
  346. package/dist/typespec.tmLanguage +1760 -0
  347. package/lib/decorators.tsp +420 -0
  348. package/lib/lib.tsp +158 -0
  349. package/lib/main.tsp +4 -0
  350. package/lib/projected-names.tsp +94 -0
  351. package/lib/reflection.tsp +10 -0
  352. package/package.json +119 -0
@@ -0,0 +1,1012 @@
1
+ import { isAsciiIdentifierContinue, isAsciiIdentifierStart, isBinaryDigit, isDigit, isHexDigit, isIdentifierContinue, isIdentifierStart, isLineBreak, isLowercaseAsciiLetter, isNonAsciiIdentifierCharacter, isNonAsciiWhiteSpaceSingleLine, isWhiteSpace, isWhiteSpaceSingleLine, utf16CodeUnits, } from "./charcode.js";
2
+ import { compilerAssert, createSourceFile } from "./diagnostics.js";
3
+ import { createDiagnostic } from "./messages.js";
4
+ // All conflict markers consist of the same character repeated seven times. If it is
5
+ // a <<<<<<< or >>>>>>> marker then it is also followed by a space.
6
+ const mergeConflictMarkerLength = 7;
7
+ export var Token;
8
+ (function (Token) {
9
+ Token[Token["None"] = 0] = "None";
10
+ Token[Token["Invalid"] = 1] = "Invalid";
11
+ Token[Token["EndOfFile"] = 2] = "EndOfFile";
12
+ Token[Token["Identifier"] = 3] = "Identifier";
13
+ Token[Token["NumericLiteral"] = 4] = "NumericLiteral";
14
+ Token[Token["StringLiteral"] = 5] = "StringLiteral";
15
+ // Add new tokens above if they don't fit any of the categories below
16
+ ///////////////////////////////////////////////////////////////
17
+ // Trivia
18
+ /**@internal */ Token[Token["__StartTrivia"] = 6] = "__StartTrivia";
19
+ Token[Token["SingleLineComment"] = 6] = "SingleLineComment";
20
+ Token[Token["MultiLineComment"] = 7] = "MultiLineComment";
21
+ Token[Token["NewLine"] = 8] = "NewLine";
22
+ Token[Token["Whitespace"] = 9] = "Whitespace";
23
+ Token[Token["ConflictMarker"] = 10] = "ConflictMarker";
24
+ // Add new trivia above
25
+ /** @internal */ Token[Token["__EndTrivia"] = 11] = "__EndTrivia";
26
+ ///////////////////////////////////////////////////////////////
27
+ ///////////////////////////////////////////////////////////////
28
+ // Doc comment content
29
+ /** @internal */ Token[Token["__StartDocComment"] = 11] = "__StartDocComment";
30
+ Token[Token["DocText"] = 11] = "DocText";
31
+ Token[Token["DocCodeSpan"] = 12] = "DocCodeSpan";
32
+ Token[Token["DocCodeFenceDelimiter"] = 13] = "DocCodeFenceDelimiter";
33
+ /** @internal */ Token[Token["__EndDocComment"] = 14] = "__EndDocComment";
34
+ ///////////////////////////////////////////////////////////////
35
+ ///////////////////////////////////////////////////////////////
36
+ // Punctuation
37
+ /** @internal */ Token[Token["__StartPunctuation"] = 14] = "__StartPunctuation";
38
+ Token[Token["OpenBrace"] = 14] = "OpenBrace";
39
+ Token[Token["CloseBrace"] = 15] = "CloseBrace";
40
+ Token[Token["OpenParen"] = 16] = "OpenParen";
41
+ Token[Token["CloseParen"] = 17] = "CloseParen";
42
+ Token[Token["OpenBracket"] = 18] = "OpenBracket";
43
+ Token[Token["CloseBracket"] = 19] = "CloseBracket";
44
+ Token[Token["Dot"] = 20] = "Dot";
45
+ Token[Token["Ellipsis"] = 21] = "Ellipsis";
46
+ Token[Token["Semicolon"] = 22] = "Semicolon";
47
+ Token[Token["Comma"] = 23] = "Comma";
48
+ Token[Token["LessThan"] = 24] = "LessThan";
49
+ Token[Token["GreaterThan"] = 25] = "GreaterThan";
50
+ Token[Token["Equals"] = 26] = "Equals";
51
+ Token[Token["Ampersand"] = 27] = "Ampersand";
52
+ Token[Token["Bar"] = 28] = "Bar";
53
+ Token[Token["Question"] = 29] = "Question";
54
+ Token[Token["Colon"] = 30] = "Colon";
55
+ Token[Token["ColonColon"] = 31] = "ColonColon";
56
+ Token[Token["At"] = 32] = "At";
57
+ Token[Token["AtAt"] = 33] = "AtAt";
58
+ Token[Token["Hash"] = 34] = "Hash";
59
+ Token[Token["Star"] = 35] = "Star";
60
+ Token[Token["ForwardSlash"] = 36] = "ForwardSlash";
61
+ Token[Token["Plus"] = 37] = "Plus";
62
+ Token[Token["Hyphen"] = 38] = "Hyphen";
63
+ Token[Token["Exclamation"] = 39] = "Exclamation";
64
+ Token[Token["LessThanEquals"] = 40] = "LessThanEquals";
65
+ Token[Token["GreaterThanEquals"] = 41] = "GreaterThanEquals";
66
+ Token[Token["AmpsersandAmpersand"] = 42] = "AmpsersandAmpersand";
67
+ Token[Token["BarBar"] = 43] = "BarBar";
68
+ Token[Token["EqualsEquals"] = 44] = "EqualsEquals";
69
+ Token[Token["ExclamationEquals"] = 45] = "ExclamationEquals";
70
+ Token[Token["EqualsGreaterThan"] = 46] = "EqualsGreaterThan";
71
+ // Add new punctuation above
72
+ /** @internal */ Token[Token["__EndPunctuation"] = 47] = "__EndPunctuation";
73
+ ///////////////////////////////////////////////////////////////
74
+ ///////////////////////////////////////////////////////////////
75
+ // Statement keywords
76
+ /** @internal */ Token[Token["__StartKeyword"] = 47] = "__StartKeyword";
77
+ /** @internal */ Token[Token["__StartStatementKeyword"] = 47] = "__StartStatementKeyword";
78
+ Token[Token["ImportKeyword"] = 47] = "ImportKeyword";
79
+ Token[Token["ModelKeyword"] = 48] = "ModelKeyword";
80
+ Token[Token["ScalarKeyword"] = 49] = "ScalarKeyword";
81
+ Token[Token["NamespaceKeyword"] = 50] = "NamespaceKeyword";
82
+ Token[Token["UsingKeyword"] = 51] = "UsingKeyword";
83
+ Token[Token["OpKeyword"] = 52] = "OpKeyword";
84
+ Token[Token["EnumKeyword"] = 53] = "EnumKeyword";
85
+ Token[Token["AliasKeyword"] = 54] = "AliasKeyword";
86
+ Token[Token["IsKeyword"] = 55] = "IsKeyword";
87
+ Token[Token["InterfaceKeyword"] = 56] = "InterfaceKeyword";
88
+ Token[Token["UnionKeyword"] = 57] = "UnionKeyword";
89
+ Token[Token["ProjectionKeyword"] = 58] = "ProjectionKeyword";
90
+ Token[Token["ElseKeyword"] = 59] = "ElseKeyword";
91
+ Token[Token["IfKeyword"] = 60] = "IfKeyword";
92
+ Token[Token["DecKeyword"] = 61] = "DecKeyword";
93
+ Token[Token["FnKeyword"] = 62] = "FnKeyword";
94
+ // Add new statement keyword above
95
+ /** @internal */ Token[Token["__EndStatementKeyword"] = 63] = "__EndStatementKeyword";
96
+ ///////////////////////////////////////////////////////////////
97
+ ///////////////////////////////////////////////////////////////
98
+ /** @internal */ Token[Token["__StartModifierKeyword"] = 63] = "__StartModifierKeyword";
99
+ Token[Token["ExternKeyword"] = 63] = "ExternKeyword";
100
+ /** @internal */ Token[Token["__EndModifierKeyword"] = 64] = "__EndModifierKeyword";
101
+ ///////////////////////////////////////////////////////////////
102
+ ///////////////////////////////////////////////////////////////
103
+ // Other keywords
104
+ Token[Token["ExtendsKeyword"] = 64] = "ExtendsKeyword";
105
+ Token[Token["TrueKeyword"] = 65] = "TrueKeyword";
106
+ Token[Token["FalseKeyword"] = 66] = "FalseKeyword";
107
+ Token[Token["ReturnKeyword"] = 67] = "ReturnKeyword";
108
+ Token[Token["VoidKeyword"] = 68] = "VoidKeyword";
109
+ Token[Token["NeverKeyword"] = 69] = "NeverKeyword";
110
+ Token[Token["UnknownKeyword"] = 70] = "UnknownKeyword";
111
+ // Add new non-statement keyword above
112
+ /** @internal */ Token[Token["__EndKeyword"] = 71] = "__EndKeyword";
113
+ ///////////////////////////////////////////////////////////////
114
+ /** @internal */ Token[Token["__Count"] = 71] = "__Count";
115
+ })(Token = Token || (Token = {}));
116
+ /** @internal */
117
+ export const TokenDisplay = getTokenDisplayTable([
118
+ [Token.None, "none"],
119
+ [Token.Invalid, "invalid"],
120
+ [Token.EndOfFile, "end of file"],
121
+ [Token.SingleLineComment, "single-line comment"],
122
+ [Token.MultiLineComment, "multi-line comment"],
123
+ [Token.ConflictMarker, "conflict marker"],
124
+ [Token.NumericLiteral, "numeric literal"],
125
+ [Token.StringLiteral, "string literal"],
126
+ [Token.NewLine, "newline"],
127
+ [Token.Whitespace, "whitespace"],
128
+ [Token.DocCodeFenceDelimiter, "doc code fence delimiter"],
129
+ [Token.DocCodeSpan, "doc code span"],
130
+ [Token.DocText, "doc text"],
131
+ [Token.OpenBrace, "'{'"],
132
+ [Token.CloseBrace, "'}'"],
133
+ [Token.OpenParen, "'('"],
134
+ [Token.CloseParen, "')'"],
135
+ [Token.OpenBracket, "'['"],
136
+ [Token.CloseBracket, "']'"],
137
+ [Token.Dot, "'.'"],
138
+ [Token.Ellipsis, "'...'"],
139
+ [Token.Semicolon, "';'"],
140
+ [Token.Comma, "','"],
141
+ [Token.LessThan, "'<'"],
142
+ [Token.GreaterThan, "'>'"],
143
+ [Token.Equals, "'='"],
144
+ [Token.Ampersand, "'&'"],
145
+ [Token.Bar, "'|'"],
146
+ [Token.Question, "'?'"],
147
+ [Token.Colon, "':'"],
148
+ [Token.ColonColon, "'::'"],
149
+ [Token.At, "'@'"],
150
+ [Token.AtAt, "'@@'"],
151
+ [Token.Hash, "'#'"],
152
+ [Token.Star, "'*'"],
153
+ [Token.ForwardSlash, "'/'"],
154
+ [Token.Plus, "'+'"],
155
+ [Token.Hyphen, "'-'"],
156
+ [Token.Exclamation, "'!'"],
157
+ [Token.LessThanEquals, "'<='"],
158
+ [Token.GreaterThanEquals, "'>='"],
159
+ [Token.AmpsersandAmpersand, "'&&'"],
160
+ [Token.BarBar, "'||'"],
161
+ [Token.EqualsEquals, "'=='"],
162
+ [Token.ExclamationEquals, "'!='"],
163
+ [Token.EqualsGreaterThan, "'=>'"],
164
+ [Token.Identifier, "identifier"],
165
+ [Token.ImportKeyword, "'import'"],
166
+ [Token.ModelKeyword, "'model'"],
167
+ [Token.ScalarKeyword, "'scalar'"],
168
+ [Token.NamespaceKeyword, "'namespace'"],
169
+ [Token.UsingKeyword, "'using'"],
170
+ [Token.OpKeyword, "'op'"],
171
+ [Token.EnumKeyword, "'enum'"],
172
+ [Token.AliasKeyword, "'alias'"],
173
+ [Token.IsKeyword, "'is'"],
174
+ [Token.InterfaceKeyword, "'interface'"],
175
+ [Token.UnionKeyword, "'union'"],
176
+ [Token.ProjectionKeyword, "'projection'"],
177
+ [Token.ElseKeyword, "'else'"],
178
+ [Token.IfKeyword, "'if'"],
179
+ [Token.DecKeyword, "'dec'"],
180
+ [Token.FnKeyword, "'fn'"],
181
+ [Token.ExtendsKeyword, "'extends'"],
182
+ [Token.TrueKeyword, "'true'"],
183
+ [Token.FalseKeyword, "'false'"],
184
+ [Token.ReturnKeyword, "'return'"],
185
+ [Token.VoidKeyword, "'void'"],
186
+ [Token.NeverKeyword, "'never'"],
187
+ [Token.UnknownKeyword, "'unknown'"],
188
+ [Token.ExternKeyword, "'extern'"],
189
+ ]);
190
+ /** @internal */
191
+ export const Keywords = new Map([
192
+ ["import", Token.ImportKeyword],
193
+ ["model", Token.ModelKeyword],
194
+ ["scalar", Token.ScalarKeyword],
195
+ ["namespace", Token.NamespaceKeyword],
196
+ ["interface", Token.InterfaceKeyword],
197
+ ["union", Token.UnionKeyword],
198
+ ["if", Token.IfKeyword],
199
+ ["else", Token.ElseKeyword],
200
+ ["projection", Token.ProjectionKeyword],
201
+ ["using", Token.UsingKeyword],
202
+ ["op", Token.OpKeyword],
203
+ ["extends", Token.ExtendsKeyword],
204
+ ["is", Token.IsKeyword],
205
+ ["enum", Token.EnumKeyword],
206
+ ["alias", Token.AliasKeyword],
207
+ ["dec", Token.DecKeyword],
208
+ ["fn", Token.FnKeyword],
209
+ ["true", Token.TrueKeyword],
210
+ ["false", Token.FalseKeyword],
211
+ ["return", Token.ReturnKeyword],
212
+ ["void", Token.VoidKeyword],
213
+ ["never", Token.NeverKeyword],
214
+ ["unknown", Token.UnknownKeyword],
215
+ ["extern", Token.ExternKeyword],
216
+ ]);
217
+ export var TokenFlags;
218
+ (function (TokenFlags) {
219
+ TokenFlags[TokenFlags["None"] = 0] = "None";
220
+ TokenFlags[TokenFlags["Escaped"] = 1] = "Escaped";
221
+ TokenFlags[TokenFlags["TripleQuoted"] = 2] = "TripleQuoted";
222
+ TokenFlags[TokenFlags["Unterminated"] = 4] = "Unterminated";
223
+ TokenFlags[TokenFlags["NonAscii"] = 8] = "NonAscii";
224
+ TokenFlags[TokenFlags["DocComment"] = 16] = "DocComment";
225
+ TokenFlags[TokenFlags["Backticked"] = 32] = "Backticked";
226
+ })(TokenFlags = TokenFlags || (TokenFlags = {}));
227
+ export function isTrivia(token) {
228
+ return token >= Token.__StartTrivia && token < Token.__EndTrivia;
229
+ }
230
+ export function isComment(token) {
231
+ return token === Token.SingleLineComment || token === Token.MultiLineComment;
232
+ }
233
+ export function isKeyword(token) {
234
+ return token >= Token.__StartKeyword && token < Token.__EndKeyword;
235
+ }
236
+ export function isPunctuation(token) {
237
+ return token >= Token.__StartPunctuation && token < Token.__EndPunctuation;
238
+ }
239
+ export function isModifier(token) {
240
+ return token >= Token.__StartModifierKeyword && token < Token.__EndModifierKeyword;
241
+ }
242
+ export function isStatementKeyword(token) {
243
+ return token >= Token.__StartStatementKeyword && token < Token.__EndStatementKeyword;
244
+ }
245
+ export function createScanner(source, diagnosticHandler) {
246
+ const file = typeof source === "string" ? createSourceFile(source, "<anonymous file>") : source;
247
+ const input = file.text;
248
+ let position = 0;
249
+ let endPosition = input.length;
250
+ let token = Token.None;
251
+ let tokenPosition = -1;
252
+ let tokenFlags = TokenFlags.None;
253
+ // Skip BOM
254
+ if (position < endPosition && input.charCodeAt(position) === 65279 /* CharCode.ByteOrderMark */) {
255
+ position++;
256
+ }
257
+ return {
258
+ get position() {
259
+ return position;
260
+ },
261
+ get token() {
262
+ return token;
263
+ },
264
+ get tokenPosition() {
265
+ return tokenPosition;
266
+ },
267
+ get tokenFlags() {
268
+ return tokenFlags;
269
+ },
270
+ file,
271
+ scan,
272
+ scanRange,
273
+ scanDoc,
274
+ eof,
275
+ getTokenText,
276
+ getTokenValue,
277
+ };
278
+ function eof() {
279
+ return position >= endPosition;
280
+ }
281
+ function getTokenText() {
282
+ return input.substring(tokenPosition, position);
283
+ }
284
+ function getTokenValue() {
285
+ switch (token) {
286
+ case Token.StringLiteral:
287
+ return getStringTokenValue();
288
+ case Token.Identifier:
289
+ return getIdentifierTokenValue();
290
+ default:
291
+ return getTokenText();
292
+ }
293
+ }
294
+ function lookAhead(offset) {
295
+ const p = position + offset;
296
+ if (p >= endPosition) {
297
+ return Number.NaN;
298
+ }
299
+ return input.charCodeAt(p);
300
+ }
301
+ function scan() {
302
+ tokenPosition = position;
303
+ tokenFlags = TokenFlags.None;
304
+ if (!eof()) {
305
+ const ch = input.charCodeAt(position);
306
+ switch (ch) {
307
+ case 13 /* CharCode.CarriageReturn */:
308
+ if (lookAhead(1) === 10 /* CharCode.LineFeed */) {
309
+ position++;
310
+ }
311
+ // fallthrough
312
+ case 10 /* CharCode.LineFeed */:
313
+ return next(Token.NewLine);
314
+ case 32 /* CharCode.Space */:
315
+ case 9 /* CharCode.Tab */:
316
+ case 11 /* CharCode.VerticalTab */:
317
+ case 12 /* CharCode.FormFeed */:
318
+ return scanWhitespace();
319
+ case 40 /* CharCode.OpenParen */:
320
+ return next(Token.OpenParen);
321
+ case 41 /* CharCode.CloseParen */:
322
+ return next(Token.CloseParen);
323
+ case 44 /* CharCode.Comma */:
324
+ return next(Token.Comma);
325
+ case 58 /* CharCode.Colon */:
326
+ return lookAhead(1) === 58 /* CharCode.Colon */ ? next(Token.ColonColon, 2) : next(Token.Colon);
327
+ case 59 /* CharCode.Semicolon */:
328
+ return next(Token.Semicolon);
329
+ case 91 /* CharCode.OpenBracket */:
330
+ return next(Token.OpenBracket);
331
+ case 93 /* CharCode.CloseBracket */:
332
+ return next(Token.CloseBracket);
333
+ case 123 /* CharCode.OpenBrace */:
334
+ return next(Token.OpenBrace);
335
+ case 125 /* CharCode.CloseBrace */:
336
+ return next(Token.CloseBrace);
337
+ case 64 /* CharCode.At */:
338
+ return lookAhead(1) === 64 /* CharCode.At */ ? next(Token.AtAt, 2) : next(Token.At);
339
+ case 35 /* CharCode.Hash */:
340
+ return next(Token.Hash);
341
+ case 43 /* CharCode.Plus */:
342
+ return isDigit(lookAhead(1)) ? scanSignedNumber() : next(Token.Plus);
343
+ case 45 /* CharCode.Minus */:
344
+ return isDigit(lookAhead(1)) ? scanSignedNumber() : next(Token.Hyphen);
345
+ case 42 /* CharCode.Asterisk */:
346
+ return next(Token.Star);
347
+ case 63 /* CharCode.Question */:
348
+ return next(Token.Question);
349
+ case 38 /* CharCode.Ampersand */:
350
+ return lookAhead(1) === 38 /* CharCode.Ampersand */
351
+ ? next(Token.AmpsersandAmpersand, 2)
352
+ : next(Token.Ampersand);
353
+ case 46 /* CharCode.Dot */:
354
+ return lookAhead(1) === 46 /* CharCode.Dot */ && lookAhead(2) === 46 /* CharCode.Dot */
355
+ ? next(Token.Ellipsis, 3)
356
+ : next(Token.Dot);
357
+ case 47 /* CharCode.Slash */:
358
+ switch (lookAhead(1)) {
359
+ case 47 /* CharCode.Slash */:
360
+ return scanSingleLineComment();
361
+ case 42 /* CharCode.Asterisk */:
362
+ return scanMultiLineComment();
363
+ }
364
+ return next(Token.ForwardSlash);
365
+ case 48 /* CharCode._0 */:
366
+ switch (lookAhead(1)) {
367
+ case 120 /* CharCode.x */:
368
+ return scanHexNumber();
369
+ case 98 /* CharCode.b */:
370
+ return scanBinaryNumber();
371
+ }
372
+ // fallthrough
373
+ case 49 /* CharCode._1 */:
374
+ case 50 /* CharCode._2 */:
375
+ case 51 /* CharCode._3 */:
376
+ case 52 /* CharCode._4 */:
377
+ case 53 /* CharCode._5 */:
378
+ case 54 /* CharCode._6 */:
379
+ case 55 /* CharCode._7 */:
380
+ case 56 /* CharCode._8 */:
381
+ case 57 /* CharCode._9 */:
382
+ return scanNumber();
383
+ case 60 /* CharCode.LessThan */:
384
+ if (atConflictMarker())
385
+ return scanConflictMarker();
386
+ return lookAhead(1) === 61 /* CharCode.Equals */
387
+ ? next(Token.LessThanEquals, 2)
388
+ : next(Token.LessThan);
389
+ case 62 /* CharCode.GreaterThan */:
390
+ if (atConflictMarker())
391
+ return scanConflictMarker();
392
+ return lookAhead(1) === 61 /* CharCode.Equals */
393
+ ? next(Token.GreaterThanEquals, 2)
394
+ : next(Token.GreaterThan);
395
+ case 61 /* CharCode.Equals */:
396
+ if (atConflictMarker())
397
+ return scanConflictMarker();
398
+ switch (lookAhead(1)) {
399
+ case 61 /* CharCode.Equals */:
400
+ return next(Token.EqualsEquals, 2);
401
+ case 62 /* CharCode.GreaterThan */:
402
+ return next(Token.EqualsGreaterThan, 2);
403
+ }
404
+ return next(Token.Equals);
405
+ case 124 /* CharCode.Bar */:
406
+ if (atConflictMarker())
407
+ return scanConflictMarker();
408
+ return lookAhead(1) === 124 /* CharCode.Bar */ ? next(Token.BarBar, 2) : next(Token.Bar);
409
+ case 34 /* CharCode.DoubleQuote */:
410
+ return lookAhead(1) === 34 /* CharCode.DoubleQuote */ && lookAhead(2) === 34 /* CharCode.DoubleQuote */
411
+ ? scanTripleQuotedString()
412
+ : scanString();
413
+ case 33 /* CharCode.Exclamation */:
414
+ return lookAhead(1) === 61 /* CharCode.Equals */
415
+ ? next(Token.ExclamationEquals, 2)
416
+ : next(Token.Exclamation);
417
+ case 96 /* CharCode.Backtick */:
418
+ return scanBacktickedIdentifier();
419
+ default:
420
+ if (isLowercaseAsciiLetter(ch)) {
421
+ return scanIdentifierOrKeyword();
422
+ }
423
+ if (isAsciiIdentifierStart(ch)) {
424
+ return scanIdentifier();
425
+ }
426
+ if (ch <= 127 /* CharCode.MaxAscii */) {
427
+ return scanInvalidCharacter();
428
+ }
429
+ return scanNonAsciiToken();
430
+ }
431
+ }
432
+ return (token = Token.EndOfFile);
433
+ }
434
+ function scanDoc() {
435
+ tokenPosition = position;
436
+ tokenFlags = TokenFlags.None;
437
+ if (!eof()) {
438
+ const ch = input.charCodeAt(position);
439
+ switch (ch) {
440
+ case 13 /* CharCode.CarriageReturn */:
441
+ if (lookAhead(1) === 10 /* CharCode.LineFeed */) {
442
+ position++;
443
+ }
444
+ // fallthrough
445
+ case 10 /* CharCode.LineFeed */:
446
+ return next(Token.NewLine);
447
+ case 32 /* CharCode.Space */:
448
+ case 9 /* CharCode.Tab */:
449
+ case 11 /* CharCode.VerticalTab */:
450
+ case 12 /* CharCode.FormFeed */:
451
+ return scanWhitespace();
452
+ case 125 /* CharCode.CloseBrace */:
453
+ return next(Token.CloseBrace);
454
+ case 64 /* CharCode.At */:
455
+ return next(Token.At);
456
+ case 42 /* CharCode.Asterisk */:
457
+ return next(Token.Star);
458
+ case 96 /* CharCode.Backtick */:
459
+ return lookAhead(1) === 96 /* CharCode.Backtick */ && lookAhead(2) === 96 /* CharCode.Backtick */
460
+ ? next(Token.DocCodeFenceDelimiter, 3)
461
+ : scanDocCodeSpan();
462
+ case 60 /* CharCode.LessThan */:
463
+ case 62 /* CharCode.GreaterThan */:
464
+ case 61 /* CharCode.Equals */:
465
+ case 124 /* CharCode.Bar */:
466
+ if (atConflictMarker())
467
+ return scanConflictMarker();
468
+ return next(Token.DocText);
469
+ }
470
+ if (isAsciiIdentifierStart(ch)) {
471
+ return scanIdentifier();
472
+ }
473
+ if (ch <= 127 /* CharCode.MaxAscii */) {
474
+ return next(Token.DocText);
475
+ }
476
+ const cp = input.codePointAt(position);
477
+ if (isIdentifierStart(cp)) {
478
+ return scanNonAsciiIdentifier(cp);
479
+ }
480
+ return scanUnknown(Token.DocText);
481
+ }
482
+ return (token = Token.EndOfFile);
483
+ }
484
+ function scanRange(range, callback) {
485
+ const savedPosition = position;
486
+ const savedEndPosition = endPosition;
487
+ const savedToken = token;
488
+ const savedTokenPosition = tokenPosition;
489
+ const savedTokenFlags = tokenFlags;
490
+ position = range.pos;
491
+ endPosition = range.end;
492
+ token = Token.None;
493
+ tokenPosition = -1;
494
+ tokenFlags = TokenFlags.None;
495
+ const result = callback();
496
+ position = savedPosition;
497
+ endPosition = savedEndPosition;
498
+ token = savedToken;
499
+ tokenPosition = savedTokenPosition;
500
+ tokenFlags = savedTokenFlags;
501
+ return result;
502
+ }
503
+ function next(t, count = 1) {
504
+ position += count;
505
+ return (token = t);
506
+ }
507
+ function unterminated(t) {
508
+ tokenFlags |= TokenFlags.Unterminated;
509
+ error({ code: "unterminated", format: { token: TokenDisplay[t] } });
510
+ return (token = t);
511
+ }
512
+ function scanNonAsciiToken() {
513
+ tokenFlags |= TokenFlags.NonAscii;
514
+ const ch = input.charCodeAt(position);
515
+ if (isNonAsciiWhiteSpaceSingleLine(ch)) {
516
+ return scanWhitespace();
517
+ }
518
+ const cp = input.codePointAt(position);
519
+ if (isNonAsciiIdentifierCharacter(cp)) {
520
+ return scanNonAsciiIdentifier(cp);
521
+ }
522
+ return scanInvalidCharacter();
523
+ }
524
+ function scanInvalidCharacter() {
525
+ token = scanUnknown(Token.Invalid);
526
+ error({ code: "invalid-character" });
527
+ return token;
528
+ }
529
+ function scanUnknown(t) {
530
+ const codePoint = input.codePointAt(position);
531
+ return (token = next(t, utf16CodeUnits(codePoint)));
532
+ }
533
+ function error(report) {
534
+ const diagnostic = createDiagnostic({
535
+ ...report,
536
+ target: { file, pos: tokenPosition, end: position },
537
+ });
538
+ diagnosticHandler(diagnostic);
539
+ }
540
+ function scanWhitespace() {
541
+ do {
542
+ position++;
543
+ } while (!eof() && isWhiteSpaceSingleLine(input.charCodeAt(position)));
544
+ return (token = Token.Whitespace);
545
+ }
546
+ function scanSignedNumber() {
547
+ position++; // consume '+/-'
548
+ return scanNumber();
549
+ }
550
+ function scanNumber() {
551
+ scanKnownDigits();
552
+ if (!eof() && input.charCodeAt(position) === 46 /* CharCode.Dot */) {
553
+ position++;
554
+ scanRequiredDigits();
555
+ }
556
+ if (!eof() && input.charCodeAt(position) === 101 /* CharCode.e */) {
557
+ position++;
558
+ const ch = input.charCodeAt(position);
559
+ if (ch === 43 /* CharCode.Plus */ || ch === 45 /* CharCode.Minus */) {
560
+ position++;
561
+ }
562
+ scanRequiredDigits();
563
+ }
564
+ return (token = Token.NumericLiteral);
565
+ }
566
+ function scanKnownDigits() {
567
+ do {
568
+ position++;
569
+ } while (!eof() && isDigit(input.charCodeAt(position)));
570
+ }
571
+ function scanRequiredDigits() {
572
+ if (eof() || !isDigit(input.charCodeAt(position))) {
573
+ error({ code: "digit-expected" });
574
+ return;
575
+ }
576
+ scanKnownDigits();
577
+ }
578
+ function scanHexNumber() {
579
+ position += 2; // consume '0x'
580
+ if (eof() || !isHexDigit(input.charCodeAt(position))) {
581
+ error({ code: "hex-digit-expected" });
582
+ return (token = Token.NumericLiteral);
583
+ }
584
+ do {
585
+ position++;
586
+ } while (!eof() && isHexDigit(input.charCodeAt(position)));
587
+ return (token = Token.NumericLiteral);
588
+ }
589
+ function scanBinaryNumber() {
590
+ position += 2; // consume '0b'
591
+ if (eof() || !isBinaryDigit(input.charCodeAt(position))) {
592
+ error({ code: "binary-digit-expected" });
593
+ return (token = Token.NumericLiteral);
594
+ }
595
+ do {
596
+ position++;
597
+ } while (!eof() && isBinaryDigit(input.charCodeAt(position)));
598
+ return (token = Token.NumericLiteral);
599
+ }
600
+ function scanSingleLineComment() {
601
+ position = skipSingleLineComment(input, position, endPosition);
602
+ return (token = Token.SingleLineComment);
603
+ }
604
+ function scanMultiLineComment() {
605
+ token = Token.MultiLineComment;
606
+ if (lookAhead(2) === 42 /* CharCode.Asterisk */) {
607
+ tokenFlags |= TokenFlags.DocComment;
608
+ }
609
+ const [newPosition, terminated] = skipMultiLineComment(input, position);
610
+ position = newPosition;
611
+ return terminated ? token : unterminated(token);
612
+ }
613
+ function scanDocCodeSpan() {
614
+ position++; // consume '`'
615
+ loop: for (; !eof(); position++) {
616
+ const ch = input.charCodeAt(position);
617
+ switch (ch) {
618
+ case 96 /* CharCode.Backtick */:
619
+ position++;
620
+ return (token = Token.DocCodeSpan);
621
+ case 13 /* CharCode.CarriageReturn */:
622
+ case 10 /* CharCode.LineFeed */:
623
+ break loop;
624
+ }
625
+ }
626
+ return unterminated(Token.DocCodeSpan);
627
+ }
628
+ function scanString() {
629
+ position++; // consume '"'
630
+ loop: for (; !eof(); position++) {
631
+ const ch = input.charCodeAt(position);
632
+ switch (ch) {
633
+ case 92 /* CharCode.Backslash */:
634
+ tokenFlags |= TokenFlags.Escaped;
635
+ position++;
636
+ if (eof()) {
637
+ break loop;
638
+ }
639
+ continue;
640
+ case 34 /* CharCode.DoubleQuote */:
641
+ position++;
642
+ return (token = Token.StringLiteral);
643
+ case 13 /* CharCode.CarriageReturn */:
644
+ case 10 /* CharCode.LineFeed */:
645
+ break loop;
646
+ }
647
+ }
648
+ return unterminated(Token.StringLiteral);
649
+ }
650
+ function scanTripleQuotedString() {
651
+ tokenFlags |= TokenFlags.TripleQuoted;
652
+ position += 3; // consume '"""'
653
+ for (; !eof(); position++) {
654
+ if (input.charCodeAt(position) === 34 /* CharCode.DoubleQuote */ &&
655
+ lookAhead(1) === 34 /* CharCode.DoubleQuote */ &&
656
+ lookAhead(2) === 34 /* CharCode.DoubleQuote */) {
657
+ position += 3;
658
+ return (token = Token.StringLiteral);
659
+ }
660
+ }
661
+ return unterminated(Token.StringLiteral);
662
+ }
663
+ function getStringTokenValue() {
664
+ const quoteLength = tokenFlags & TokenFlags.TripleQuoted ? 3 : 1;
665
+ const start = tokenPosition + quoteLength;
666
+ const end = tokenFlags & TokenFlags.Unterminated ? position : position - quoteLength;
667
+ if (tokenFlags & TokenFlags.TripleQuoted) {
668
+ return unindentAndUnescapeTripleQuotedString(start, end);
669
+ }
670
+ if (tokenFlags & TokenFlags.Escaped) {
671
+ return unescapeString(start, end);
672
+ }
673
+ return input.substring(start, end);
674
+ }
675
+ function getIdentifierTokenValue() {
676
+ const start = tokenFlags & TokenFlags.Backticked ? tokenPosition + 1 : tokenPosition;
677
+ const end = tokenFlags & TokenFlags.Backticked && !(tokenFlags & TokenFlags.Unterminated)
678
+ ? position - 1
679
+ : position;
680
+ const text = tokenFlags & TokenFlags.Escaped ? unescapeString(start, end) : input.substring(start, end);
681
+ if (tokenFlags & TokenFlags.NonAscii) {
682
+ return text.normalize("NFC");
683
+ }
684
+ return text;
685
+ }
686
+ function unindentAndUnescapeTripleQuotedString(start, end) {
687
+ // ignore leading whitespace before required initial line break
688
+ while (start < end && isWhiteSpaceSingleLine(input.charCodeAt(start))) {
689
+ start++;
690
+ }
691
+ // remove required initial line break
692
+ if (isLineBreak(input.charCodeAt(start))) {
693
+ if (isCrlf(start, start, end)) {
694
+ start++;
695
+ }
696
+ start++;
697
+ }
698
+ else {
699
+ error({ code: "no-new-line-start-triple-quote" });
700
+ }
701
+ // remove whitespace before closing delimiter and record it as required
702
+ // indentation for all lines
703
+ const indentationEnd = end;
704
+ while (end > start && isWhiteSpaceSingleLine(input.charCodeAt(end - 1))) {
705
+ end--;
706
+ }
707
+ const indentationStart = end;
708
+ // remove required final line break
709
+ if (isLineBreak(input.charCodeAt(end - 1))) {
710
+ if (isCrlf(end - 2, start, end)) {
711
+ end--;
712
+ }
713
+ end--;
714
+ }
715
+ else {
716
+ error({ code: "no-new-line-end-triple-quote" });
717
+ }
718
+ // remove required matching indentation from each line and unescape in the
719
+ // process of doing so
720
+ let result = "";
721
+ let pos = start;
722
+ while (pos < end) {
723
+ // skip indentation at start of line
724
+ start = skipMatchingIndentation(pos, end, indentationStart, indentationEnd);
725
+ let ch;
726
+ while (pos < end && !isLineBreak((ch = input.charCodeAt(pos)))) {
727
+ if (ch !== 92 /* CharCode.Backslash */) {
728
+ pos++;
729
+ continue;
730
+ }
731
+ result += input.substring(start, pos);
732
+ if (pos === end - 1) {
733
+ error({ code: "invalid-escape-sequence" });
734
+ pos++;
735
+ }
736
+ else {
737
+ result += unescapeOne(pos);
738
+ pos += 2;
739
+ }
740
+ start = pos;
741
+ }
742
+ if (pos < end) {
743
+ if (isCrlf(pos, start, end)) {
744
+ // CRLF in multi-line string is normalized to LF in string value.
745
+ // This keeps program behavior unchanged by line-ending conversion.
746
+ result += input.substring(start, pos);
747
+ result += "\n";
748
+ pos += 2;
749
+ }
750
+ else {
751
+ pos++; // include non-CRLF newline
752
+ result += input.substring(start, pos);
753
+ }
754
+ start = pos;
755
+ }
756
+ }
757
+ result += input.substring(start, pos);
758
+ return result;
759
+ }
760
+ function isCrlf(pos, start, end) {
761
+ return (pos >= start &&
762
+ pos < end - 1 &&
763
+ input.charCodeAt(pos) === 13 /* CharCode.CarriageReturn */ &&
764
+ input.charCodeAt(pos + 1) === 10 /* CharCode.LineFeed */);
765
+ }
766
+ function skipMatchingIndentation(pos, end, indentationStart, indentationEnd) {
767
+ let indentationPos = indentationStart;
768
+ end = Math.min(end, pos + (indentationEnd - indentationStart));
769
+ while (pos < end) {
770
+ const ch = input.charCodeAt(pos);
771
+ if (isLineBreak(ch)) {
772
+ // allow subset of indentation if line has only whitespace
773
+ break;
774
+ }
775
+ if (ch !== input.charCodeAt(indentationPos)) {
776
+ error({ code: "triple-quote-indent" });
777
+ break;
778
+ }
779
+ indentationPos++;
780
+ pos++;
781
+ }
782
+ return pos;
783
+ }
784
+ function unescapeString(start, end) {
785
+ let result = "";
786
+ let pos = start;
787
+ while (pos < end) {
788
+ const ch = input.charCodeAt(pos);
789
+ if (ch !== 92 /* CharCode.Backslash */) {
790
+ pos++;
791
+ continue;
792
+ }
793
+ if (pos === end - 1) {
794
+ error({ code: "invalid-escape-sequence" });
795
+ break;
796
+ }
797
+ result += input.substring(start, pos);
798
+ result += unescapeOne(pos);
799
+ pos += 2;
800
+ start = pos;
801
+ }
802
+ result += input.substring(start, pos);
803
+ return result;
804
+ }
805
+ function unescapeOne(pos) {
806
+ const ch = input.charCodeAt(pos + 1);
807
+ switch (ch) {
808
+ case 114 /* CharCode.r */:
809
+ return "\r";
810
+ case 110 /* CharCode.n */:
811
+ return "\n";
812
+ case 116 /* CharCode.t */:
813
+ return "\t";
814
+ case 34 /* CharCode.DoubleQuote */:
815
+ return '"';
816
+ case 92 /* CharCode.Backslash */:
817
+ return "\\";
818
+ case 96 /* CharCode.Backtick */:
819
+ return "`";
820
+ default:
821
+ error({ code: "invalid-escape-sequence" });
822
+ return String.fromCharCode(ch);
823
+ }
824
+ }
825
+ function scanIdentifierOrKeyword() {
826
+ let count = 0;
827
+ let ch = input.charCodeAt(position);
828
+ while (true) {
829
+ position++;
830
+ count++;
831
+ if (eof()) {
832
+ break;
833
+ }
834
+ ch = input.charCodeAt(position);
835
+ if (count < 10 /* KeywordLimit.MaxLength */ && isLowercaseAsciiLetter(ch)) {
836
+ continue;
837
+ }
838
+ if (isAsciiIdentifierContinue(ch)) {
839
+ return scanIdentifier();
840
+ }
841
+ if (ch > 127 /* CharCode.MaxAscii */) {
842
+ const cp = input.codePointAt(position);
843
+ if (isNonAsciiIdentifierCharacter(cp)) {
844
+ return scanNonAsciiIdentifier(cp);
845
+ }
846
+ }
847
+ break;
848
+ }
849
+ if (count >= 2 /* KeywordLimit.MinLength */ && count <= 10 /* KeywordLimit.MaxLength */) {
850
+ const keyword = Keywords.get(getTokenText());
851
+ if (keyword) {
852
+ return (token = keyword);
853
+ }
854
+ }
855
+ return (token = Token.Identifier);
856
+ }
857
+ function scanIdentifier() {
858
+ let ch;
859
+ do {
860
+ position++;
861
+ if (eof()) {
862
+ return (token = Token.Identifier);
863
+ }
864
+ } while (isAsciiIdentifierContinue((ch = input.charCodeAt(position))));
865
+ if (ch > 127 /* CharCode.MaxAscii */) {
866
+ const cp = input.codePointAt(position);
867
+ if (isNonAsciiIdentifierCharacter(cp)) {
868
+ return scanNonAsciiIdentifier(cp);
869
+ }
870
+ }
871
+ return (token = Token.Identifier);
872
+ }
873
+ function scanBacktickedIdentifier() {
874
+ position++; // consume '`'
875
+ tokenFlags |= TokenFlags.Backticked;
876
+ loop: for (; !eof(); position++) {
877
+ const ch = input.charCodeAt(position);
878
+ switch (ch) {
879
+ case 92 /* CharCode.Backslash */:
880
+ position++;
881
+ tokenFlags |= TokenFlags.Escaped;
882
+ continue;
883
+ case 96 /* CharCode.Backtick */:
884
+ position++;
885
+ return (token = Token.Identifier);
886
+ case 13 /* CharCode.CarriageReturn */:
887
+ case 10 /* CharCode.LineFeed */:
888
+ break loop;
889
+ default:
890
+ if (ch > 127 /* CharCode.MaxAscii */) {
891
+ tokenFlags |= TokenFlags.NonAscii;
892
+ }
893
+ }
894
+ }
895
+ return unterminated(Token.Identifier);
896
+ }
897
+ function scanNonAsciiIdentifier(startCodePoint) {
898
+ tokenFlags |= TokenFlags.NonAscii;
899
+ let cp = startCodePoint;
900
+ do {
901
+ position += utf16CodeUnits(cp);
902
+ } while (!eof() && isIdentifierContinue((cp = input.codePointAt(position))));
903
+ return (token = Token.Identifier);
904
+ }
905
+ function atConflictMarker() {
906
+ return isConflictMarker(input, position, endPosition);
907
+ }
908
+ function scanConflictMarker() {
909
+ const marker = input.charCodeAt(position);
910
+ position += mergeConflictMarkerLength;
911
+ error({ code: "conflict-marker" });
912
+ if (marker === 60 /* CharCode.LessThan */ || marker === 62 /* CharCode.GreaterThan */) {
913
+ // Consume everything from >>>>>>> or <<<<<<< to the end of the line.
914
+ while (position < endPosition && !isLineBreak(input.charCodeAt(position))) {
915
+ position++;
916
+ }
917
+ }
918
+ else {
919
+ // Consume everything from the start of a ||||||| or =======
920
+ // marker to the start of the next ======= or >>>>>>> marker.
921
+ while (position < endPosition) {
922
+ const ch = input.charCodeAt(position);
923
+ if ((ch === 61 /* CharCode.Equals */ || ch === 62 /* CharCode.GreaterThan */) &&
924
+ ch !== marker &&
925
+ isConflictMarker(input, position, endPosition)) {
926
+ break;
927
+ }
928
+ position++;
929
+ }
930
+ }
931
+ return (token = Token.ConflictMarker);
932
+ }
933
+ }
934
+ export function skipTrivia(input, position, endPosition = input.length) {
935
+ while (position < endPosition) {
936
+ const ch = input.charCodeAt(position);
937
+ if (isWhiteSpace(ch)) {
938
+ position++;
939
+ continue;
940
+ }
941
+ if (ch === 47 /* CharCode.Slash */) {
942
+ switch (input.charCodeAt(position + 1)) {
943
+ case 47 /* CharCode.Slash */:
944
+ position = skipSingleLineComment(input, position, endPosition);
945
+ continue;
946
+ case 42 /* CharCode.Asterisk */:
947
+ position = skipMultiLineComment(input, position, endPosition)[0];
948
+ continue;
949
+ }
950
+ }
951
+ break;
952
+ }
953
+ return position;
954
+ }
955
+ export function skipWhiteSpace(input, position, endPosition = input.length) {
956
+ while (position < endPosition) {
957
+ const ch = input.charCodeAt(position);
958
+ if (!isWhiteSpace(ch)) {
959
+ break;
960
+ }
961
+ position++;
962
+ }
963
+ return position;
964
+ }
965
+ function skipSingleLineComment(input, position, endPosition = input.length) {
966
+ position += 2; // consume '//'
967
+ for (; position < endPosition; position++) {
968
+ if (isLineBreak(input.charCodeAt(position))) {
969
+ break;
970
+ }
971
+ }
972
+ return position;
973
+ }
974
+ function skipMultiLineComment(input, position, endPosition = input.length) {
975
+ position += 2; // consume '/*'
976
+ for (; position < endPosition; position++) {
977
+ if (input.charCodeAt(position) === 42 /* CharCode.Asterisk */ &&
978
+ input.charCodeAt(position + 1) === 47 /* CharCode.Slash */) {
979
+ return [position + 2, true];
980
+ }
981
+ }
982
+ return [position, false];
983
+ }
984
+ function isConflictMarker(input, position, endPosition = input.length) {
985
+ // Conflict markers must be at the start of a line.
986
+ const ch = input.charCodeAt(position);
987
+ if (position === 0 || isLineBreak(input.charCodeAt(position - 1))) {
988
+ if (position + mergeConflictMarkerLength < endPosition) {
989
+ for (let i = 0; i < mergeConflictMarkerLength; i++) {
990
+ if (input.charCodeAt(position + i) !== ch) {
991
+ return false;
992
+ }
993
+ }
994
+ return (ch === 61 /* CharCode.Equals */ ||
995
+ input.charCodeAt(position + mergeConflictMarkerLength) === 32 /* CharCode.Space */);
996
+ }
997
+ }
998
+ return false;
999
+ }
1000
+ function getTokenDisplayTable(entries) {
1001
+ const table = new Array(entries.length);
1002
+ for (const [token, display] of entries) {
1003
+ compilerAssert(token >= 0 && token < Token.__Count, `Invalid entry in token display table, ${token}, ${Token[token]}, ${display}`);
1004
+ compilerAssert(!table[token], `Duplicate entry in token display table for: ${token}, ${Token[token]}, ${display}`);
1005
+ table[token] = display;
1006
+ }
1007
+ for (let token = 0; token < Token.__Count; token++) {
1008
+ compilerAssert(table[token], `Missing entry in token display table: ${token}, ${Token[token]}`);
1009
+ }
1010
+ return table;
1011
+ }
1012
+ //# sourceMappingURL=scanner.js.map