semantic_attr.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  1. var __rest = (this && this.__rest) || function (s, e) {
  2. var t = {};
  3. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  4. t[p] = s[p];
  5. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  6. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  7. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  8. t[p[i]] = s[p[i]];
  9. }
  10. return t;
  11. };
  12. import { SemanticRole, SemanticType, SemanticFont, SemanticSecondary } from './semantic_meaning.js';
  13. import * as Alphabet from '../speech_rules/alphabet.js';
  14. export const NamedSymbol = {
  15. functionApplication: String.fromCodePoint(0x2061),
  16. invisibleTimes: String.fromCodePoint(0x2062),
  17. invisibleComma: String.fromCodePoint(0x2063),
  18. invisiblePlus: String.fromCodePoint(0x2064)
  19. };
  20. class meaningMap extends Map {
  21. get(symbol) {
  22. return (super.get(symbol) || {
  23. role: SemanticRole.UNKNOWN,
  24. type: SemanticType.UNKNOWN,
  25. font: SemanticFont.UNKNOWN
  26. });
  27. }
  28. }
  29. class secondaryMap extends Map {
  30. set(char, kind, annotation = '') {
  31. super.set(this.secKey(kind, char), annotation || kind);
  32. return this;
  33. }
  34. has(char, kind) {
  35. return super.has(this.secKey(kind, char));
  36. }
  37. get(char, kind) {
  38. return super.get(this.secKey(kind, char));
  39. }
  40. secKey(kind, char) {
  41. return char ? `${kind} ${char}` : `${kind}`;
  42. }
  43. }
  44. export const SemanticMap = {
  45. Meaning: new meaningMap(),
  46. Secondary: new secondaryMap(),
  47. FencesHoriz: new Map(),
  48. FencesVert: new Map(),
  49. LatexCommands: new Map()
  50. };
  51. function addMeaning(symbols, meaning) {
  52. for (const symbol of symbols) {
  53. SemanticMap.Meaning.set(symbol, {
  54. role: meaning.role || SemanticRole.UNKNOWN,
  55. type: meaning.type || SemanticType.UNKNOWN,
  56. font: meaning.font || SemanticFont.UNKNOWN
  57. });
  58. if (meaning.secondary) {
  59. SemanticMap.Secondary.set(symbol, meaning.secondary);
  60. }
  61. }
  62. }
  63. function initMeaning() {
  64. const sets = [
  65. {
  66. set: [
  67. '23',
  68. '26',
  69. '40',
  70. '5c',
  71. 'a1',
  72. 'a7',
  73. 'b6',
  74. 'bf',
  75. '2017',
  76. ['2022', '2025'],
  77. '2027',
  78. '203b',
  79. '203c',
  80. ['2041', '2043'],
  81. ['2047', '2049'],
  82. ['204b', '204d'],
  83. '2050',
  84. '2055',
  85. '2056',
  86. ['2058', '205e'],
  87. '2234',
  88. '2235',
  89. 'fe45',
  90. 'fe46',
  91. 'fe5f',
  92. 'fe60',
  93. 'fe68',
  94. 'fe6b',
  95. 'ff03',
  96. 'ff06',
  97. 'ff0f',
  98. 'ff20',
  99. 'ff3c'
  100. ],
  101. type: SemanticType.PUNCTUATION,
  102. role: SemanticRole.UNKNOWN
  103. },
  104. {
  105. set: [
  106. '22',
  107. 'ab',
  108. 'bb',
  109. '2dd',
  110. ['2018', '201f'],
  111. '2039',
  112. '203a',
  113. ['301d', '301f'],
  114. 'fe10',
  115. 'ff02',
  116. 'ff07'
  117. ],
  118. type: SemanticType.PUNCTUATION,
  119. role: SemanticRole.QUOTES
  120. },
  121. {
  122. set: ['3b', '204f', '2a1f', '2a3e', 'fe14', 'fe54', 'ff1b'],
  123. type: SemanticType.PUNCTUATION,
  124. role: SemanticRole.SEMICOLON
  125. },
  126. {
  127. set: ['3f', '203d', 'fe16', 'fe56', 'ff1f'],
  128. type: SemanticType.PUNCTUATION,
  129. role: SemanticRole.QUESTION
  130. },
  131. {
  132. set: ['21', 'fe15', 'fe57', 'ff01'],
  133. type: SemanticType.PUNCTUATION,
  134. role: SemanticRole.EXCLAMATION
  135. },
  136. {
  137. set: [
  138. '5e',
  139. '60',
  140. 'a8',
  141. 'aa',
  142. 'b4',
  143. 'ba',
  144. '2c7',
  145. ['2d8', '2da'],
  146. '2040',
  147. '207a',
  148. '207d',
  149. '207e',
  150. 'ff3e',
  151. 'ff40'
  152. ],
  153. type: SemanticType.PUNCTUATION,
  154. role: SemanticRole.OVERACCENT
  155. },
  156. {
  157. set: ['b8', '2db', '2038', '203f', '2054', '208a', '208d', '208e'],
  158. type: SemanticType.PUNCTUATION,
  159. role: SemanticRole.UNDERACCENT
  160. },
  161. {
  162. set: ['3a', '2982', 'fe13', 'fe30', 'fe55', 'ff1a'],
  163. type: SemanticType.PUNCTUATION,
  164. role: SemanticRole.COLON
  165. },
  166. {
  167. set: ['2c', '2063', 'fe50', 'ff0c'],
  168. type: SemanticType.PUNCTUATION,
  169. role: SemanticRole.COMMA
  170. },
  171. {
  172. set: ['2026', ['22ee', '22f1'], 'fe19'],
  173. type: SemanticType.PUNCTUATION,
  174. role: SemanticRole.ELLIPSIS
  175. },
  176. {
  177. set: ['2e', 'fe52', 'ff0e'],
  178. type: SemanticType.PUNCTUATION,
  179. role: SemanticRole.FULLSTOP
  180. },
  181. {
  182. set: ['2d', '207b', '208b', '2212', '2796', 'fe63', 'ff0d'],
  183. type: SemanticType.OPERATOR,
  184. role: SemanticRole.DASH,
  185. secondary: SemanticSecondary.BAR
  186. },
  187. {
  188. set: [
  189. '5f',
  190. 'af',
  191. ['2010', '2015'],
  192. '203e',
  193. '208b',
  194. ['fe49', 'fe4f'],
  195. 'fe58',
  196. 'ff3f',
  197. 'ffe3'
  198. ],
  199. type: SemanticType.PUNCTUATION,
  200. role: SemanticRole.DASH,
  201. secondary: SemanticSecondary.BAR
  202. },
  203. {
  204. set: [
  205. '7e',
  206. '2dc',
  207. '2f7',
  208. '303',
  209. '330',
  210. '334',
  211. '2053',
  212. '223c',
  213. '223d',
  214. '301c',
  215. 'ff5e'
  216. ],
  217. type: SemanticType.OPERATOR,
  218. role: SemanticRole.TILDE,
  219. secondary: SemanticSecondary.TILDE
  220. },
  221. {
  222. set: ['27', '2b9', '2ba', ['2032', '2037'], '2057'],
  223. type: SemanticType.PUNCTUATION,
  224. role: SemanticRole.PRIME
  225. },
  226. {
  227. set: ['b0'],
  228. type: SemanticType.PUNCTUATION,
  229. role: SemanticRole.DEGREE
  230. },
  231. {
  232. set: [
  233. '2b',
  234. 'b1',
  235. '2064',
  236. '2213',
  237. '2214',
  238. '2228',
  239. '222a',
  240. ['228c', '228e'],
  241. '2294',
  242. '2295',
  243. '229d',
  244. '229e',
  245. '22bb',
  246. '22bd',
  247. '22c4',
  248. '22ce',
  249. '22d3',
  250. '2304',
  251. '271b',
  252. '271c',
  253. '2795',
  254. '27cf',
  255. '29fa',
  256. '29fb',
  257. '29fe',
  258. ['2a22', '2a28'],
  259. '2a2d',
  260. '2a2e',
  261. '2a39',
  262. '2a42',
  263. '2a45',
  264. '2a46',
  265. '2a48',
  266. '2a4a',
  267. '2a4c',
  268. '2a4f',
  269. '2a50',
  270. '2a52',
  271. '2a54',
  272. '2a56',
  273. '2a57',
  274. '2a59',
  275. '2a5b',
  276. '2a5d',
  277. ['2a61', '2a63'],
  278. '2adc',
  279. '2add',
  280. 'fe62',
  281. 'ff0b'
  282. ],
  283. type: SemanticType.OPERATOR,
  284. role: SemanticRole.ADDITION
  285. },
  286. {
  287. set: [
  288. '2a',
  289. 'b7',
  290. 'd7',
  291. '2020',
  292. '2021',
  293. '204e',
  294. '2051',
  295. '2062',
  296. ['2217', '2219'],
  297. '2227',
  298. '2229',
  299. '2240',
  300. '2293',
  301. '2297',
  302. ['2299', '229b'],
  303. '22a0',
  304. '22a1',
  305. '22b9',
  306. '22bc',
  307. ['22c5', '22cc'],
  308. '22cf',
  309. '22d2',
  310. '22d4',
  311. '2303',
  312. '2305',
  313. '2306',
  314. '25cb',
  315. '2715',
  316. '2716',
  317. '27ce',
  318. '27d1',
  319. ['29d1', '29d7'],
  320. '29e2',
  321. '2a1d',
  322. ['2a2f', '2a37'],
  323. ['2a3b', '2a3d'],
  324. '2a40',
  325. '2a43',
  326. '2a44',
  327. '2a47',
  328. '2a49',
  329. '2a4b',
  330. '2a4d',
  331. '2a4e',
  332. '2a51',
  333. '2a53',
  334. '2a55',
  335. '2a58',
  336. '2a5a',
  337. '2a5c',
  338. ['2a5e', '2a60'],
  339. '2ada',
  340. '2adb',
  341. 'fe61',
  342. 'ff0a'
  343. ],
  344. type: SemanticType.OPERATOR,
  345. role: SemanticRole.MULTIPLICATION
  346. },
  347. {
  348. set: [
  349. '2d',
  350. 'af',
  351. '2010',
  352. '2011',
  353. '2052',
  354. '207b',
  355. '208b',
  356. '2212',
  357. '2216',
  358. '2238',
  359. '2242',
  360. '2296',
  361. '229f',
  362. '2796',
  363. '29ff',
  364. ['2a29', '2a2c'],
  365. '2a3a',
  366. '2a41',
  367. 'fe63',
  368. 'ff0d'
  369. ],
  370. type: SemanticType.OPERATOR,
  371. role: SemanticRole.SUBTRACTION
  372. },
  373. {
  374. set: [
  375. '2f',
  376. 'f7',
  377. '2044',
  378. '2215',
  379. '2298',
  380. '2797',
  381. '27cc',
  382. '29bc',
  383. ['29f5', '29f9'],
  384. '2a38'
  385. ],
  386. type: SemanticType.OPERATOR,
  387. role: SemanticRole.DIVISION
  388. },
  389. {
  390. set: ['25', '2030', '2031', 'ff05', 'fe6a'],
  391. type: SemanticType.OPERATOR,
  392. role: SemanticRole.POSTFIXOP
  393. },
  394. {
  395. set: [
  396. 'ac',
  397. '2200',
  398. '2201',
  399. '2203',
  400. '2204',
  401. '2206',
  402. ['221a', '221c'],
  403. '2310',
  404. 'ffe2'
  405. ],
  406. type: SemanticType.OPERATOR,
  407. role: SemanticRole.PREFIXOP
  408. },
  409. {
  410. set: [
  411. '2320',
  412. '2321',
  413. '23aa',
  414. '23ae',
  415. '23af',
  416. '23b2',
  417. '23b3',
  418. '23b6',
  419. '23b7'
  420. ],
  421. type: SemanticType.OPERATOR,
  422. role: SemanticRole.PREFIXOP
  423. },
  424. {
  425. set: ['1d7ca', '1d7cb'],
  426. type: SemanticType.OPERATOR,
  427. role: SemanticRole.PREFIXOP,
  428. font: SemanticFont.BOLD
  429. },
  430. {
  431. set: [
  432. '3d',
  433. '7e',
  434. '207c',
  435. '208c',
  436. '221d',
  437. '2237',
  438. ['223a', '223f'],
  439. '2243',
  440. '2245',
  441. '2248',
  442. ['224a', '224e'],
  443. ['2251', '225f'],
  444. '2261',
  445. '2263',
  446. '229c',
  447. '22cd',
  448. '22d5',
  449. '29e4',
  450. '29e6',
  451. '2a66',
  452. '2a67',
  453. ['2a6a', '2a6c'],
  454. ['2a6c', '2a78'],
  455. 'fe66',
  456. 'ff1d'
  457. ],
  458. type: SemanticType.RELATION,
  459. role: SemanticRole.EQUALITY
  460. },
  461. {
  462. set: [
  463. '3c',
  464. '3e',
  465. '2241',
  466. '2242',
  467. '2244',
  468. '2246',
  469. '2247',
  470. '2249',
  471. '224f',
  472. '2250',
  473. '2260',
  474. '2262',
  475. ['2264', '2281'],
  476. '22b0',
  477. '22b1',
  478. ['22d6', '22e1'],
  479. ['22e6', '22e9'],
  480. ['2976', '2978'],
  481. '29c0',
  482. '29c1',
  483. '29e1',
  484. '29e3',
  485. '29e5',
  486. ['2a79', '2abc'],
  487. ['2af7', '2afa'],
  488. 'fe64',
  489. 'fe65',
  490. 'ff1c',
  491. 'ff1e'
  492. ],
  493. type: SemanticType.RELATION,
  494. role: SemanticRole.INEQUALITY
  495. },
  496. {
  497. set: [
  498. ['2282', '228b'],
  499. ['228f', '2292'],
  500. ['22b2', '22b8'],
  501. '22d0',
  502. '22d1',
  503. ['22e2', '22e5'],
  504. ['22ea', '22ed'],
  505. '27c3',
  506. '27c4',
  507. ['27c7', '27c9'],
  508. ['27d5', '27d7'],
  509. '27dc',
  510. ['2979', '297b'],
  511. '29df',
  512. ['2abd', '2ad8']
  513. ],
  514. type: SemanticType.RELATION,
  515. role: SemanticRole.SET
  516. },
  517. {
  518. set: [
  519. '2236',
  520. ['27e0', '27e5'],
  521. '292b',
  522. '292c',
  523. ['29b5', '29bb'],
  524. '29be',
  525. '29bf',
  526. ['29c2', '29d0']
  527. ],
  528. type: SemanticType.RELATION,
  529. role: SemanticRole.UNKNOWN
  530. },
  531. {
  532. set: ['2205', ['29b0', '29b4']],
  533. type: SemanticType.IDENTIFIER,
  534. role: SemanticRole.SETEMPTY
  535. },
  536. {
  537. set: ['1ab2', '221e', ['29dc', '29de']],
  538. type: SemanticType.IDENTIFIER,
  539. role: SemanticRole.INFTY
  540. },
  541. {
  542. set: [
  543. '22a2',
  544. '22a3',
  545. ['22a6', '22af'],
  546. '27da',
  547. '27db',
  548. '27dd',
  549. '27de',
  550. '2ade',
  551. ['2ae2', '2ae6'],
  552. '2aec',
  553. '2aed'
  554. ],
  555. type: SemanticType.RELATION,
  556. role: SemanticRole.LOGIC
  557. },
  558. {
  559. set: [
  560. '22a4',
  561. '22a5',
  562. '22ba',
  563. '27d8',
  564. '27d9',
  565. '27df',
  566. '2adf',
  567. '2ae0',
  568. ['2ae7', '2aeb'],
  569. '2af1'
  570. ],
  571. type: SemanticType.IDENTIFIER,
  572. role: SemanticRole.LOGIC
  573. },
  574. {
  575. set: [
  576. ['2190', '21ff'],
  577. '2301',
  578. '2324',
  579. '238b',
  580. '2794',
  581. ['2798', '27af'],
  582. ['27b1', '27be'],
  583. ['27f0', '27ff'],
  584. ['2900', '292a'],
  585. ['292d', '2975'],
  586. ['297c', '297f'],
  587. ['2b00', '2b11'],
  588. ['2b30', '2b4c'],
  589. ['ffe9', 'ffec']
  590. ],
  591. type: SemanticType.RELATION,
  592. role: SemanticRole.ARROW
  593. },
  594. {
  595. set: ['2208', '220a', ['22f2', '22f9'], '22ff', '27d2', '2ad9'],
  596. type: SemanticType.OPERATOR,
  597. role: SemanticRole.ELEMENT
  598. },
  599. {
  600. set: ['2209'],
  601. type: SemanticType.OPERATOR,
  602. role: SemanticRole.NONELEMENT
  603. },
  604. {
  605. set: ['220b', '220d', ['22fa', '22fe']],
  606. type: SemanticType.OPERATOR,
  607. role: SemanticRole.REELEMENT
  608. },
  609. {
  610. set: ['220c'],
  611. type: SemanticType.OPERATOR,
  612. role: SemanticRole.RENONELEMENT
  613. },
  614. {
  615. set: [
  616. ['220f', '2211'],
  617. ['22c0', '22c3'],
  618. ['2a00', '2a0b'],
  619. '2a3f',
  620. '2afc',
  621. '2aff'
  622. ],
  623. type: SemanticType.LARGEOP,
  624. role: SemanticRole.SUM
  625. },
  626. {
  627. set: ['2140'],
  628. type: SemanticType.LARGEOP,
  629. role: SemanticRole.SUM,
  630. font: SemanticFont.DOUBLESTRUCK
  631. },
  632. {
  633. set: [
  634. ['222b', '2233'],
  635. ['2a0c', '2a17'],
  636. ['2a17', '2a1c']
  637. ],
  638. type: SemanticType.LARGEOP,
  639. role: SemanticRole.INTEGRAL
  640. },
  641. {
  642. set: [['2500', '257F']],
  643. type: SemanticType.RELATION,
  644. role: SemanticRole.BOX
  645. },
  646. {
  647. set: [['2580', '259F']],
  648. type: SemanticType.IDENTIFIER,
  649. role: SemanticRole.BLOCK
  650. },
  651. {
  652. set: [
  653. ['25A0', '25FF'],
  654. ['2B12', '2B2F'],
  655. ['2B50', '2B59']
  656. ],
  657. type: SemanticType.RELATION,
  658. role: SemanticRole.GEOMETRY
  659. },
  660. {
  661. set: [
  662. '220e',
  663. '2300',
  664. '2302',
  665. '2311',
  666. '29bd',
  667. '29e0',
  668. ['29e8', '29f3'],
  669. '2a1e',
  670. '2afe',
  671. 'ffed',
  672. 'ffee'
  673. ],
  674. type: SemanticType.OPERATOR,
  675. role: SemanticRole.GEOMETRY
  676. },
  677. {
  678. set: [
  679. ['221f', '2222'],
  680. '22be',
  681. '22bf',
  682. ['2312', '2314'],
  683. '237c',
  684. '27c0',
  685. ['299b', '29af']
  686. ],
  687. type: SemanticType.OPERATOR,
  688. role: SemanticRole.GEOMETRY
  689. },
  690. {
  691. set: [
  692. '24',
  693. ['a2', 'a5'],
  694. 'b5',
  695. '2123',
  696. ['2125', '2127'],
  697. '212a',
  698. '212b',
  699. 'fe69',
  700. 'ff04',
  701. 'ffe0',
  702. 'ffe1',
  703. 'ffe5',
  704. 'ffe6'
  705. ],
  706. type: SemanticType.IDENTIFIER,
  707. role: SemanticRole.UNKNOWN
  708. },
  709. {
  710. set: [
  711. 'a9',
  712. 'ae',
  713. '210f',
  714. '2114',
  715. '2116',
  716. '2117',
  717. ['211e', '2122'],
  718. '212e',
  719. '2132',
  720. ['2139', '213b'],
  721. ['2141', '2144'],
  722. '214d',
  723. '214e',
  724. ['1f12a', '1f12c'],
  725. '1f18a'
  726. ],
  727. type: SemanticType.IDENTIFIER,
  728. role: SemanticRole.OTHERLETTER
  729. },
  730. {
  731. set: [
  732. '2224',
  733. '2226',
  734. '2239',
  735. '2307',
  736. '27b0',
  737. '27bf',
  738. '27c1',
  739. '27c2',
  740. '27ca',
  741. '27cb',
  742. '27cd',
  743. '27d0',
  744. '27d3',
  745. '27d4',
  746. '2981',
  747. '2999',
  748. '299a',
  749. '29e7',
  750. '29f4',
  751. '2a20',
  752. '2a21',
  753. '2a64',
  754. '2a65',
  755. '2a68',
  756. '2a69',
  757. '2ae1',
  758. ['2aee', '2af0'],
  759. '2af2',
  760. '2af3',
  761. '2af5',
  762. '2af6',
  763. '2afb',
  764. '2afd'
  765. ],
  766. type: SemanticType.OPERATOR,
  767. role: SemanticRole.UNKNOWN
  768. },
  769. {
  770. set: ['2605', '2606', '26aa', '26ab', ['2720', '274d']],
  771. type: SemanticType.OPERATOR,
  772. role: SemanticRole.UNKNOWN
  773. },
  774. {
  775. set: [['2145', '2149']],
  776. type: SemanticType.IDENTIFIER,
  777. role: SemanticRole.LATINLETTER,
  778. font: SemanticFont.DOUBLESTRUCKITALIC,
  779. secondary: SemanticSecondary.ALLLETTERS
  780. },
  781. {
  782. set: [['213c', '213f']],
  783. type: SemanticType.IDENTIFIER,
  784. role: SemanticRole.GREEKLETTER,
  785. font: SemanticFont.DOUBLESTRUCK,
  786. secondary: SemanticSecondary.ALLLETTERS
  787. },
  788. {
  789. set: [
  790. '3d0',
  791. '3d7',
  792. '3f6',
  793. ['1d26', '1d2a'],
  794. '1d5e',
  795. '1d60',
  796. ['1d66', '1d6a']
  797. ],
  798. type: SemanticType.IDENTIFIER,
  799. role: SemanticRole.GREEKLETTER,
  800. font: SemanticFont.NORMAL,
  801. secondary: SemanticSecondary.ALLLETTERS
  802. },
  803. {
  804. set: [['2135', '2138']],
  805. type: SemanticType.IDENTIFIER,
  806. role: SemanticRole.OTHERLETTER,
  807. font: SemanticFont.NORMAL,
  808. secondary: SemanticSecondary.ALLLETTERS
  809. },
  810. {
  811. set: ['131', '237'],
  812. type: SemanticType.IDENTIFIER,
  813. role: SemanticRole.LATINLETTER,
  814. font: SemanticFont.NORMAL
  815. },
  816. {
  817. set: ['1d6a4', '1d6a5'],
  818. type: SemanticType.IDENTIFIER,
  819. role: SemanticRole.LATINLETTER,
  820. font: SemanticFont.ITALIC
  821. },
  822. {
  823. set: ['2113', '2118'],
  824. type: SemanticType.IDENTIFIER,
  825. role: SemanticRole.LATINLETTER,
  826. font: SemanticFont.SCRIPT
  827. },
  828. {
  829. set: [
  830. ['c0', 'd6'],
  831. ['d8', 'f6'],
  832. ['f8', '1bf'],
  833. ['1c4', '2af'],
  834. ['1d00', '1d25'],
  835. ['1d6b', '1d9a'],
  836. ['1e00', '1ef9'],
  837. ['363', '36f'],
  838. ['1dd3', '1de6'],
  839. ['1d62', '1d65'],
  840. '1dca',
  841. '2071',
  842. '207f',
  843. ['2090', '209c'],
  844. '2c7c'
  845. ],
  846. type: SemanticType.IDENTIFIER,
  847. role: SemanticRole.LATINLETTER,
  848. font: SemanticFont.NORMAL
  849. },
  850. {
  851. set: [['00bc', '00be'], ['2150', '215f'], '2189'],
  852. type: SemanticType.NUMBER,
  853. role: SemanticRole.FLOAT
  854. },
  855. {
  856. set: ['23E8', ['3248', '324f']],
  857. type: SemanticType.NUMBER,
  858. role: SemanticRole.INTEGER
  859. },
  860. {
  861. set: [['214A', '214C'], '2705', '2713', '2714', '2717', '2718'],
  862. type: SemanticType.IDENTIFIER,
  863. role: SemanticRole.UNKNOWN
  864. },
  865. {
  866. set: [
  867. '20',
  868. 'a0',
  869. 'ad',
  870. ['2000', '200f'],
  871. ['2028', '202f'],
  872. ['205f', '2060'],
  873. '206a',
  874. '206b',
  875. '206e',
  876. '206f',
  877. 'feff',
  878. ['fff9', 'fffb']
  879. ],
  880. type: SemanticType.TEXT,
  881. role: SemanticRole.SPACE
  882. },
  883. {
  884. set: [
  885. '7c',
  886. 'a6',
  887. '2223',
  888. '23b8',
  889. '23b9',
  890. '23d0',
  891. '2758',
  892. ['fe31', 'fe34'],
  893. 'ff5c',
  894. 'ffe4',
  895. 'ffe8'
  896. ],
  897. type: SemanticType.FENCE,
  898. role: SemanticRole.NEUTRAL
  899. },
  900. {
  901. set: ['2016', '2225', '2980', '2af4'],
  902. type: SemanticType.FENCE,
  903. role: SemanticRole.METRIC
  904. }
  905. ];
  906. sets.forEach((_a) => {
  907. var { set: s } = _a, m = __rest(_a, ["set"]);
  908. return addMeaning(Alphabet.makeMultiInterval(s), m);
  909. });
  910. }
  911. function addFences(map, ints, sep = 1) {
  912. const used = {};
  913. const codes = Alphabet.makeCodeInterval(ints);
  914. for (const code of codes) {
  915. if (used[code])
  916. continue;
  917. map.set(String.fromCodePoint(code), String.fromCodePoint(code + sep));
  918. used[code] = true;
  919. used[code + sep] = true;
  920. }
  921. }
  922. function initFences() {
  923. addFences(SemanticMap.FencesVert, [
  924. '23b4',
  925. ['23dc', '23e1'],
  926. ['fe35', 'fe44'],
  927. 'fe47'
  928. ]);
  929. addFences(SemanticMap.FencesHoriz, [
  930. '28',
  931. '2045',
  932. ['2308', '230f'],
  933. ['231c', '231f'],
  934. '2329',
  935. '23b0',
  936. ['2768', '2775'],
  937. '27c5',
  938. ['27e6', '27ef'],
  939. ['2983', '2998'],
  940. ['29d8', '29db'],
  941. '29fc',
  942. ['2e22', '2e29'],
  943. ['3008', '3011'],
  944. ['3014', '301b'],
  945. 'fd3e',
  946. 'fe17',
  947. ['fe59', 'fe5e'],
  948. 'ff08',
  949. 'ff5f',
  950. 'ff62'
  951. ]);
  952. addFences(SemanticMap.FencesHoriz, ['5b', '7b', 'ff3b', 'ff5b'], 2);
  953. addFences(SemanticMap.FencesHoriz, [['239b', '23a6']], 3);
  954. addFences(SemanticMap.FencesHoriz, [['23a7', '23a9']], 4);
  955. addMeaning([...SemanticMap.FencesHoriz.keys()], {
  956. type: SemanticType.FENCE,
  957. role: SemanticRole.OPEN
  958. });
  959. addMeaning([...SemanticMap.FencesHoriz.values()], {
  960. type: SemanticType.FENCE,
  961. role: SemanticRole.CLOSE
  962. });
  963. addMeaning([...SemanticMap.FencesVert.keys()], {
  964. type: SemanticType.FENCE,
  965. role: SemanticRole.TOP
  966. });
  967. addMeaning([...SemanticMap.FencesVert.values()], {
  968. type: SemanticType.FENCE,
  969. role: SemanticRole.BOTTOM
  970. });
  971. }
  972. const trigonometricFunctions = [
  973. 'cos',
  974. 'cot',
  975. 'csc',
  976. 'sec',
  977. 'sin',
  978. 'tan',
  979. 'arccos',
  980. 'arccot',
  981. 'arccsc',
  982. 'arcsec',
  983. 'arcsin',
  984. 'arctan'
  985. ];
  986. const hyperbolicFunctions = [
  987. 'cosh',
  988. 'coth',
  989. 'csch',
  990. 'sech',
  991. 'sinh',
  992. 'tanh',
  993. 'arcosh',
  994. 'arcoth',
  995. 'arcsch',
  996. 'arsech',
  997. 'arsinh',
  998. 'artanh'
  999. ];
  1000. const algebraicFunctions = ['deg', 'det', 'dim', 'hom', 'ker', 'Tr'];
  1001. const elementaryFunctions = [
  1002. 'log',
  1003. 'ln',
  1004. 'lg',
  1005. 'exp',
  1006. 'gcd',
  1007. 'lcm',
  1008. 'arg',
  1009. 'im',
  1010. 're',
  1011. 'Pr'
  1012. ];
  1013. const prefixFunctions = trigonometricFunctions.concat(hyperbolicFunctions, algebraicFunctions, elementaryFunctions);
  1014. function initFunctions() {
  1015. addMeaning([
  1016. 'inf',
  1017. 'lim',
  1018. 'liminf',
  1019. 'limsup',
  1020. 'max',
  1021. 'min',
  1022. 'sup',
  1023. 'injlim',
  1024. 'projlim'
  1025. ], {
  1026. type: SemanticType.FUNCTION,
  1027. role: SemanticRole.LIMFUNC
  1028. });
  1029. addMeaning(prefixFunctions, {
  1030. type: SemanticType.FUNCTION,
  1031. role: SemanticRole.PREFIXFUNC
  1032. });
  1033. addMeaning(['mod', 'rem'], {
  1034. type: SemanticType.OPERATOR,
  1035. role: SemanticRole.PREFIXFUNC
  1036. });
  1037. }
  1038. export function addFunctionSemantic(base, names) {
  1039. const meaning = SemanticMap.Meaning.get(base) || {
  1040. type: SemanticType.FUNCTION,
  1041. role: SemanticRole.PREFIXFUNC
  1042. };
  1043. addMeaning(names, meaning);
  1044. }
  1045. export function equal(meaning1, meaning2) {
  1046. return (meaning1.type === meaning2.type &&
  1047. meaning1.role === meaning2.role &&
  1048. meaning1.font === meaning2.font);
  1049. }
  1050. export function isMatchingFence(open, close) {
  1051. const meaning = SemanticMap.Meaning.get(open);
  1052. if (meaning.type !== SemanticType.FENCE) {
  1053. return false;
  1054. }
  1055. if (meaning.role === SemanticRole.NEUTRAL ||
  1056. meaning.role === SemanticRole.METRIC) {
  1057. return open === close;
  1058. }
  1059. return (SemanticMap.FencesHoriz.get(open) === close ||
  1060. SemanticMap.FencesVert.get(open) === close);
  1061. }
  1062. function changeSemantics(alphabet, change) {
  1063. for (const [pos, meaning] of Object.entries(change)) {
  1064. const character = alphabet[pos];
  1065. if (character !== undefined) {
  1066. SemanticMap.Meaning.set(character, meaning);
  1067. }
  1068. }
  1069. }
  1070. function addSecondaries(alphabet, change) {
  1071. for (const [pos, meaning] of Object.entries(change)) {
  1072. const character = alphabet[pos];
  1073. if (character !== undefined) {
  1074. SemanticMap.Secondary.set(character, meaning);
  1075. }
  1076. }
  1077. }
  1078. function singleAlphabet(alphabet, type, role, font, semfont, secondaries = [], change = {}, secondary = {}) {
  1079. const interval = Alphabet.INTERVALS.get(Alphabet.alphabetName(alphabet, font));
  1080. if (interval) {
  1081. interval.unicode.forEach((x) => {
  1082. SemanticMap.Meaning.set(x, {
  1083. type: type,
  1084. role: role,
  1085. font: semfont
  1086. });
  1087. secondaries.forEach((sec) => SemanticMap.Secondary.set(x, sec));
  1088. });
  1089. changeSemantics(interval.unicode, change);
  1090. addSecondaries(interval.unicode, secondary);
  1091. }
  1092. }
  1093. function initAlphabets() {
  1094. for (const [name, font] of Object.entries(SemanticFont)) {
  1095. const emb = !!Alphabet.Embellish[name];
  1096. const semfont = emb
  1097. ? SemanticFont.UNKNOWN
  1098. : font === SemanticFont.FULLWIDTH
  1099. ? SemanticFont.NORMAL
  1100. : font;
  1101. singleAlphabet(Alphabet.Base.LATINCAP, SemanticType.IDENTIFIER, SemanticRole.LATINLETTER, font, semfont, [SemanticSecondary.ALLLETTERS]);
  1102. singleAlphabet(Alphabet.Base.LATINSMALL, SemanticType.IDENTIFIER, SemanticRole.LATINLETTER, font, semfont, [SemanticSecondary.ALLLETTERS], {}, { 3: SemanticSecondary.D });
  1103. singleAlphabet(Alphabet.Base.GREEKCAP, SemanticType.IDENTIFIER, SemanticRole.GREEKLETTER, font, semfont, [SemanticSecondary.ALLLETTERS]);
  1104. singleAlphabet(Alphabet.Base.GREEKSMALL, SemanticType.IDENTIFIER, SemanticRole.GREEKLETTER, font, semfont, [SemanticSecondary.ALLLETTERS], {
  1105. 0: {
  1106. type: SemanticType.OPERATOR,
  1107. role: SemanticRole.PREFIXOP,
  1108. font: semfont
  1109. },
  1110. 26: {
  1111. type: SemanticType.OPERATOR,
  1112. role: SemanticRole.PREFIXOP,
  1113. font: semfont
  1114. }
  1115. });
  1116. singleAlphabet(Alphabet.Base.DIGIT, SemanticType.NUMBER, SemanticRole.INTEGER, font, semfont);
  1117. }
  1118. }
  1119. initMeaning();
  1120. initFences();
  1121. initAlphabets();
  1122. initFunctions();