├── README.md ├── LICENSE └── syntaxes └── mojo.syntax.json /README.md: -------------------------------------------------------------------------------- 1 | # mojo-syntax 2 | 3 | This repository contains a TextMate grammar for the Mojo 🔥 programming 4 | language. 5 | 6 | ## Contributing 7 | 8 | The Mojo syntax has been converted from [VS Code's Python syntax][1], which 9 | itself was converted from [MagicPython.tmLanguage][2]. Many fixes or 10 | improvements to Mojo's syntax also apply to these two projects, so in many 11 | cases, creating a pull request against one of these two repositories is the way 12 | to go. Once accepted there, we can pull down the changes into this project. 13 | 14 | For Mojo-specific updates, we'd be happy to review pull requests sent here. 15 | Please include a description of the problem that the change addresses. 16 | 17 | Reports of general issues with Mojo or how its syntax is highlighted on GitHub, 18 | or requests to update this grammar based on changes to the VS Code or 19 | MagicPython syntax files, can be sent as issues on the main Mojo repository 20 | [here][3]. 21 | 22 | [1]: https://github.com/microsoft/vscode/blob/c4cfd83472c59f183d79cb9526c42105880bf8ab/extensions/python/syntaxes/MagicPython.tmLanguage.json 23 | [2]: https://github.com/MagicStack/MagicPython/blob/7d0f2b22a5ad8fccbd7341bc7b7a715169283044/grammars/MagicPython.tmLanguage 24 | [3]: https://github.com/modularml/mojo 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2022-present Modular Inc. https://www.modular.com 4 | Copyright (c) 2015-present MagicStack Inc. http://magic.io 5 | Copyright (c) 2015-present Microsoft Corporation 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /syntaxes/mojo.syntax.json: -------------------------------------------------------------------------------- 1 | { 2 | "information_for_contributors": [ 3 | "This file has been converted from https://github.com/MagicStack/MagicPython/blob/master/grammars/MagicPython.tmLanguage", 4 | "If you want to provide a fix or improvement, please create a pull request against the original repository.", 5 | "Once accepted there, we are happy to receive an update request." 6 | ], 7 | "version": "https://github.com/MagicStack/MagicPython/commit/7d0f2b22a5ad8fccbd7341bc7b7a715169283044", 8 | "name": "MagicPython", 9 | "scopeName": "source.mojo", 10 | "patterns": [ 11 | { 12 | "include": "#statement" 13 | }, 14 | { 15 | "include": "#expression" 16 | } 17 | ], 18 | "repository": { 19 | "impossible": { 20 | "comment": "This is a special rule that should be used where no match is desired. It is not a good idea to match something like '1{0}' because in some cases that can result in infinite loops in token generation. So the rule instead matches and impossible expression to allow a match to fail and move to the next token.", 21 | "match": "$.^" 22 | }, 23 | "statement": { 24 | "patterns": [ 25 | { 26 | "include": "#import" 27 | }, 28 | { 29 | "include": "#class-declaration" 30 | }, 31 | { 32 | "include": "#function-declaration" 33 | }, 34 | { 35 | "include": "#generator" 36 | }, 37 | { 38 | "include": "#statement-keyword" 39 | }, 40 | { 41 | "include": "#assignment-operator" 42 | }, 43 | { 44 | "include": "#decorator" 45 | }, 46 | { 47 | "include": "#semicolon" 48 | } 49 | ] 50 | }, 51 | "semicolon": { 52 | "patterns": [ 53 | { 54 | "name": "invalid.deprecated.semicolon.python", 55 | "match": "\\;$" 56 | } 57 | ] 58 | }, 59 | "comments": { 60 | "patterns": [ 61 | { 62 | "name": "comment.line.number-sign.python", 63 | "contentName": "meta.typehint.comment.python", 64 | "begin": "(?x)\n (?:\n \\# \\s* (type:)\n \\s*+ (?# we want `\\s*+` which is possessive quantifier since\n we do not actually want to backtrack when matching\n whitespace here)\n (?! $ | \\#)\n )\n", 65 | "end": "(?:$|(?=\\#))", 66 | "beginCaptures": { 67 | "0": { 68 | "name": "meta.typehint.comment.python" 69 | }, 70 | "1": { 71 | "name": "comment.typehint.directive.notation.python" 72 | } 73 | }, 74 | "patterns": [ 75 | { 76 | "name": "comment.typehint.ignore.notation.python", 77 | "match": "(?x)\n \\G ignore\n (?= \\s* (?: $ | \\#))\n" 78 | }, 79 | { 80 | "name": "comment.typehint.type.notation.python", 81 | "match": "(?x)\n (?))" 86 | }, 87 | { 88 | "name": "comment.typehint.variable.notation.python", 89 | "match": "([[:alpha:]_]\\w*)" 90 | } 91 | ] 92 | }, 93 | { 94 | "include": "#comments-base" 95 | } 96 | ] 97 | }, 98 | "statement-keyword": { 99 | "patterns": [ 100 | { 101 | "name": "storage.type.function.python", 102 | "match": "\\b((async\\s+)?\\s*(def|fn))\\b" 103 | }, 104 | { 105 | "name": "keyword.control.flow.python", 106 | "comment": "if `as` is eventually followed by `:` or line continuation\nit's probably control flow like:\n with foo as bar, \\\n Foo as Bar:\n try:\n do_stuff()\n except Exception as e:\n pass\n", 107 | "match": "\\b(?>= | //= | \\*\\*=\n | \\+= | -= | /= | @=\n | \\*= | %= | ~= | \\^= | &= | \\|=\n | =(?!=)\n" 416 | }, 417 | "operator": { 418 | "match": "(?x)\n \\b(?> | & | \\| | \\^ | ~) (?# 3)\n\n | (\\*\\* | \\* | \\+ | - | % | // | / | @) (?# 4)\n\n | (!= | == | >= | <= | < | >) (?# 5)\n\n | (:=) (?# 6)\n", 419 | "captures": { 420 | "1": { 421 | "name": "keyword.operator.logical.python" 422 | }, 423 | "2": { 424 | "name": "keyword.control.flow.python" 425 | }, 426 | "3": { 427 | "name": "keyword.operator.bitwise.python" 428 | }, 429 | "4": { 430 | "name": "keyword.operator.arithmetic.python" 431 | }, 432 | "5": { 433 | "name": "keyword.operator.comparison.python" 434 | }, 435 | "6": { 436 | "name": "keyword.operator.assignment.python" 437 | } 438 | } 439 | }, 440 | "punctuation": { 441 | "patterns": [ 442 | { 443 | "name": "punctuation.separator.colon.python", 444 | "match": ":" 445 | }, 446 | { 447 | "name": "punctuation.separator.element.python", 448 | "match": "," 449 | } 450 | ] 451 | }, 452 | "literal": { 453 | "patterns": [ 454 | { 455 | "name": "constant.language.python", 456 | "match": "\\b(True|False|None|NotImplemented|Ellipsis)\\b" 457 | }, 458 | { 459 | "include": "#number" 460 | } 461 | ] 462 | }, 463 | "number": { 464 | "name": "constant.numeric.python", 465 | "patterns": [ 466 | { 467 | "include": "#number-float" 468 | }, 469 | { 470 | "include": "#number-dec" 471 | }, 472 | { 473 | "include": "#number-hex" 474 | }, 475 | { 476 | "include": "#number-oct" 477 | }, 478 | { 479 | "include": "#number-bin" 480 | }, 481 | { 482 | "include": "#number-long" 483 | }, 484 | { 485 | "name": "invalid.illegal.name.python", 486 | "match": "\\b[0-9]+\\w+" 487 | } 488 | ] 489 | }, 490 | "number-float": { 491 | "name": "constant.numeric.float.python", 492 | "match": "(?x)\n (?=^]? [-+ ]? \\#?\n \\d* ,? (\\.\\d+)? [bcdeEfFgGnosxX%]? )?\n })\n )\n", 766 | "captures": { 767 | "1": { 768 | "name": "constant.character.format.placeholder.other.python" 769 | }, 770 | "3": { 771 | "name": "storage.type.format.python" 772 | }, 773 | "4": { 774 | "name": "storage.type.format.python" 775 | } 776 | } 777 | }, 778 | { 779 | "name": "meta.format.brace.python", 780 | "match": "(?x)\n (\n {\n \\w* (\\.[[:alpha:]_]\\w* | \\[[^\\]'\"]+\\])*\n (![rsa])?\n (:)\n [^'\"{}\\n]* (?:\n \\{ [^'\"}\\n]*? \\} [^'\"{}\\n]*\n )*\n }\n )\n", 781 | "captures": { 782 | "1": { 783 | "name": "constant.character.format.placeholder.other.python" 784 | }, 785 | "3": { 786 | "name": "storage.type.format.python" 787 | }, 788 | "4": { 789 | "name": "storage.type.format.python" 790 | } 791 | } 792 | } 793 | ] 794 | }, 795 | "fstring-formatting": { 796 | "patterns": [ 797 | { 798 | "include": "#fstring-formatting-braces" 799 | }, 800 | { 801 | "include": "#fstring-formatting-singe-brace" 802 | } 803 | ] 804 | }, 805 | "fstring-formatting-singe-brace": { 806 | "name": "invalid.illegal.brace.python", 807 | "match": "(}(?!}))" 808 | }, 809 | "import": { 810 | "comment": "Import statements used to correctly mark `from`, `import`, and `as`\n", 811 | "patterns": [ 812 | { 813 | "begin": "\\b(?)", 1337 | "end": "(?=:)", 1338 | "beginCaptures": { 1339 | "1": { 1340 | "name": "punctuation.separator.annotation.result.python" 1341 | } 1342 | }, 1343 | "patterns": [ 1344 | { 1345 | "include": "#expression" 1346 | } 1347 | ] 1348 | }, 1349 | "item-access": { 1350 | "patterns": [ 1351 | { 1352 | "name": "meta.item-access.python", 1353 | "begin": "(?x)\n \\b(?=\n [[:alpha:]_]\\w* \\s* \\[\n )\n", 1354 | "end": "(\\])", 1355 | "endCaptures": { 1356 | "1": { 1357 | "name": "punctuation.definition.arguments.end.python" 1358 | } 1359 | }, 1360 | "patterns": [ 1361 | { 1362 | "include": "#item-name" 1363 | }, 1364 | { 1365 | "include": "#item-index" 1366 | }, 1367 | { 1368 | "include": "#expression" 1369 | } 1370 | ] 1371 | } 1372 | ] 1373 | }, 1374 | "item-name": { 1375 | "patterns": [ 1376 | { 1377 | "include": "#special-variables" 1378 | }, 1379 | { 1380 | "include": "#builtin-functions" 1381 | }, 1382 | { 1383 | "include": "#special-names" 1384 | }, 1385 | { 1386 | "name": "meta.indexed-name.python", 1387 | "match": "(?x)\n \\b ([[:alpha:]_]\\w*) \\b\n" 1388 | } 1389 | ] 1390 | }, 1391 | "item-index": { 1392 | "begin": "(\\[)", 1393 | "end": "(?=\\])", 1394 | "beginCaptures": { 1395 | "1": { 1396 | "name": "punctuation.definition.arguments.begin.python" 1397 | } 1398 | }, 1399 | "contentName": "meta.item-access.arguments.python", 1400 | "patterns": [ 1401 | { 1402 | "name": "punctuation.separator.slice.python", 1403 | "match": ":" 1404 | }, 1405 | { 1406 | "include": "#expression" 1407 | } 1408 | ] 1409 | }, 1410 | "decorator": { 1411 | "name": "meta.function.decorator.python", 1412 | "begin": "(?x)\n ^\\s*\n ((@)) \\s* (?=[[:alpha:]_]\\w*)\n", 1413 | "end": "(?x)\n ( \\) )\n # trailing whitespace and comments are legal\n (?: (.*?) (?=\\s*(?:\\#|$)) )\n | (?=\\n|\\#)\n", 1414 | "beginCaptures": { 1415 | "1": { 1416 | "name": "entity.name.function.decorator.python" 1417 | }, 1418 | "2": { 1419 | "name": "punctuation.definition.decorator.python" 1420 | } 1421 | }, 1422 | "endCaptures": { 1423 | "1": { 1424 | "name": "punctuation.definition.arguments.end.python" 1425 | }, 1426 | "2": { 1427 | "name": "invalid.illegal.decorator.python" 1428 | } 1429 | }, 1430 | "patterns": [ 1431 | { 1432 | "include": "#decorator-name" 1433 | }, 1434 | { 1435 | "include": "#function-arguments" 1436 | } 1437 | ] 1438 | }, 1439 | "decorator-name": { 1440 | "patterns": [ 1441 | { 1442 | "include": "#builtin-callables" 1443 | }, 1444 | { 1445 | "include": "#illegal-object-name" 1446 | }, 1447 | { 1448 | "name": "entity.name.function.decorator.python", 1449 | "match": "(?x)\n ([[:alpha:]_]\\w*) | (\\.)\n", 1450 | "captures": { 1451 | "2": { 1452 | "name": "punctuation.separator.period.python" 1453 | } 1454 | } 1455 | }, 1456 | { 1457 | "include": "#line-continuation" 1458 | }, 1459 | { 1460 | "name": "invalid.illegal.decorator.python", 1461 | "match": "(?x)\n \\s* ([^([:alpha:]\\s_\\.#\\\\] .*?) (?=\\#|$)\n", 1462 | "captures": { 1463 | "1": { 1464 | "name": "invalid.illegal.decorator.python" 1465 | } 1466 | } 1467 | } 1468 | ] 1469 | }, 1470 | "call-wrapper-inheritance": { 1471 | "comment": "same as a function call, but in inheritance context", 1472 | "name": "meta.function-call.python", 1473 | "begin": "(?x)\n \\b(?=\n ([[:alpha:]_]\\w*) \\s* (\\()\n )\n", 1474 | "end": "(\\))", 1475 | "endCaptures": { 1476 | "1": { 1477 | "name": "punctuation.definition.arguments.end.python" 1478 | } 1479 | }, 1480 | "patterns": [ 1481 | { 1482 | "include": "#inheritance-name" 1483 | }, 1484 | { 1485 | "include": "#function-arguments" 1486 | } 1487 | ] 1488 | }, 1489 | "inheritance-name": { 1490 | "patterns": [ 1491 | { 1492 | "include": "#lambda-incomplete" 1493 | }, 1494 | { 1495 | "include": "#builtin-possible-callables" 1496 | }, 1497 | { 1498 | "include": "#inheritance-identifier" 1499 | } 1500 | ] 1501 | }, 1502 | "function-call": { 1503 | "name": "meta.function-call.python", 1504 | "comment": "Regular function call of the type \"name(args)\"", 1505 | "begin": "(?x)\n \\b(?=\n ([[:alpha:]_]\\w*) \\s* (\\()\n )\n", 1506 | "end": "(\\))", 1507 | "endCaptures": { 1508 | "1": { 1509 | "name": "punctuation.definition.arguments.end.python" 1510 | } 1511 | }, 1512 | "patterns": [ 1513 | { 1514 | "include": "#special-variables" 1515 | }, 1516 | { 1517 | "include": "#function-name" 1518 | }, 1519 | { 1520 | "include": "#function-arguments" 1521 | } 1522 | ] 1523 | }, 1524 | "function-name": { 1525 | "patterns": [ 1526 | { 1527 | "include": "#builtin-possible-callables" 1528 | }, 1529 | { 1530 | "comment": "Some color schemas support meta.function-call.generic scope", 1531 | "name": "meta.function-call.generic.python", 1532 | "match": "(?x)\n \\b ([[:alpha:]_]\\w*) \\b\n" 1533 | } 1534 | ] 1535 | }, 1536 | "function-arguments": { 1537 | "begin": "(\\()", 1538 | "end": "(?=\\))(?!\\)\\s*\\()", 1539 | "beginCaptures": { 1540 | "1": { 1541 | "name": "punctuation.definition.arguments.begin.python" 1542 | } 1543 | }, 1544 | "contentName": "meta.function-call.arguments.python", 1545 | "patterns": [ 1546 | { 1547 | "name": "punctuation.separator.arguments.python", 1548 | "match": "(,)" 1549 | }, 1550 | { 1551 | "match": "(?x)\n (?:(?<=[,(])|^) \\s* (\\*{1,2})\n", 1552 | "captures": { 1553 | "1": { 1554 | "name": "keyword.operator.unpacking.arguments.python" 1555 | } 1556 | } 1557 | }, 1558 | { 1559 | "include": "#lambda-incomplete" 1560 | }, 1561 | { 1562 | "include": "#illegal-names" 1563 | }, 1564 | { 1565 | "match": "\\b([[:alpha:]_]\\w*)\\s*(=)(?!=)", 1566 | "captures": { 1567 | "1": { 1568 | "name": "variable.parameter.function-call.python" 1569 | }, 1570 | "2": { 1571 | "name": "keyword.operator.assignment.python" 1572 | } 1573 | } 1574 | }, 1575 | { 1576 | "name": "keyword.operator.assignment.python", 1577 | "match": "=(?!=)" 1578 | }, 1579 | { 1580 | "include": "#expression" 1581 | }, 1582 | { 1583 | "match": "\\s*(\\))\\s*(\\()", 1584 | "captures": { 1585 | "1": { 1586 | "name": "punctuation.definition.arguments.end.python" 1587 | }, 1588 | "2": { 1589 | "name": "punctuation.definition.arguments.begin.python" 1590 | } 1591 | } 1592 | } 1593 | ] 1594 | }, 1595 | "builtin-callables": { 1596 | "patterns": [ 1597 | { 1598 | "include": "#illegal-names" 1599 | }, 1600 | { 1601 | "include": "#illegal-object-name" 1602 | }, 1603 | { 1604 | "include": "#builtin-exceptions" 1605 | }, 1606 | { 1607 | "include": "#builtin-functions" 1608 | }, 1609 | { 1610 | "include": "#builtin-types" 1611 | } 1612 | ] 1613 | }, 1614 | "builtin-possible-callables": { 1615 | "patterns": [ 1616 | { 1617 | "include": "#builtin-callables" 1618 | }, 1619 | { 1620 | "include": "#magic-names" 1621 | } 1622 | ] 1623 | }, 1624 | "builtin-exceptions": { 1625 | "name": "support.type.exception.python", 1626 | "match": "(?x) (?)\n", 2038 | "end": "(\\)|(?=\\'))|((?=(?)\n", 2342 | "end": "(\\)|(?=\\'\\'\\'))", 2343 | "beginCaptures": { 2344 | "1": { 2345 | "name": "support.other.parenthesis.regexp punctuation.parenthesis.named.begin.regexp" 2346 | }, 2347 | "2": { 2348 | "name": "entity.name.tag.named.group.regexp" 2349 | } 2350 | }, 2351 | "endCaptures": { 2352 | "1": { 2353 | "name": "support.other.parenthesis.regexp punctuation.parenthesis.named.end.regexp" 2354 | }, 2355 | "2": { 2356 | "name": "invalid.illegal.newline.python" 2357 | } 2358 | }, 2359 | "patterns": [ 2360 | { 2361 | "include": "#single-three-regexp-expression" 2362 | }, 2363 | { 2364 | "include": "#comments-string-single-three" 2365 | } 2366 | ] 2367 | }, 2368 | "single-three-regexp-comments": { 2369 | "name": "comment.regexp", 2370 | "begin": "\\(\\?#", 2371 | "end": "(\\)|(?=\\'\\'\\'))", 2372 | "beginCaptures": { 2373 | "0": { 2374 | "name": "punctuation.comment.begin.regexp" 2375 | } 2376 | }, 2377 | "endCaptures": { 2378 | "1": { 2379 | "name": "punctuation.comment.end.regexp" 2380 | }, 2381 | "2": { 2382 | "name": "invalid.illegal.newline.python" 2383 | } 2384 | }, 2385 | "patterns": [ 2386 | { 2387 | "include": "#codetags" 2388 | } 2389 | ] 2390 | }, 2391 | "single-three-regexp-lookahead": { 2392 | "begin": "(\\()\\?=", 2393 | "end": "(\\)|(?=\\'\\'\\'))", 2394 | "beginCaptures": { 2395 | "0": { 2396 | "name": "keyword.operator.lookahead.regexp" 2397 | }, 2398 | "1": { 2399 | "name": "punctuation.parenthesis.lookahead.begin.regexp" 2400 | } 2401 | }, 2402 | "endCaptures": { 2403 | "1": { 2404 | "name": "keyword.operator.lookahead.regexp punctuation.parenthesis.lookahead.end.regexp" 2405 | }, 2406 | "2": { 2407 | "name": "invalid.illegal.newline.python" 2408 | } 2409 | }, 2410 | "patterns": [ 2411 | { 2412 | "include": "#single-three-regexp-expression" 2413 | }, 2414 | { 2415 | "include": "#comments-string-single-three" 2416 | } 2417 | ] 2418 | }, 2419 | "single-three-regexp-lookahead-negative": { 2420 | "begin": "(\\()\\?!", 2421 | "end": "(\\)|(?=\\'\\'\\'))", 2422 | "beginCaptures": { 2423 | "0": { 2424 | "name": "keyword.operator.lookahead.negative.regexp" 2425 | }, 2426 | "1": { 2427 | "name": "punctuation.parenthesis.lookahead.begin.regexp" 2428 | } 2429 | }, 2430 | "endCaptures": { 2431 | "1": { 2432 | "name": "keyword.operator.lookahead.negative.regexp punctuation.parenthesis.lookahead.end.regexp" 2433 | }, 2434 | "2": { 2435 | "name": "invalid.illegal.newline.python" 2436 | } 2437 | }, 2438 | "patterns": [ 2439 | { 2440 | "include": "#single-three-regexp-expression" 2441 | }, 2442 | { 2443 | "include": "#comments-string-single-three" 2444 | } 2445 | ] 2446 | }, 2447 | "single-three-regexp-lookbehind": { 2448 | "begin": "(\\()\\?<=", 2449 | "end": "(\\)|(?=\\'\\'\\'))", 2450 | "beginCaptures": { 2451 | "0": { 2452 | "name": "keyword.operator.lookbehind.regexp" 2453 | }, 2454 | "1": { 2455 | "name": "punctuation.parenthesis.lookbehind.begin.regexp" 2456 | } 2457 | }, 2458 | "endCaptures": { 2459 | "1": { 2460 | "name": "keyword.operator.lookbehind.regexp punctuation.parenthesis.lookbehind.end.regexp" 2461 | }, 2462 | "2": { 2463 | "name": "invalid.illegal.newline.python" 2464 | } 2465 | }, 2466 | "patterns": [ 2467 | { 2468 | "include": "#single-three-regexp-expression" 2469 | }, 2470 | { 2471 | "include": "#comments-string-single-three" 2472 | } 2473 | ] 2474 | }, 2475 | "single-three-regexp-lookbehind-negative": { 2476 | "begin": "(\\()\\?)\n", 2667 | "end": "(\\)|(?=\"))|((?=(?)\n", 2971 | "end": "(\\)|(?=\"\"\"))", 2972 | "beginCaptures": { 2973 | "1": { 2974 | "name": "support.other.parenthesis.regexp punctuation.parenthesis.named.begin.regexp" 2975 | }, 2976 | "2": { 2977 | "name": "entity.name.tag.named.group.regexp" 2978 | } 2979 | }, 2980 | "endCaptures": { 2981 | "1": { 2982 | "name": "support.other.parenthesis.regexp punctuation.parenthesis.named.end.regexp" 2983 | }, 2984 | "2": { 2985 | "name": "invalid.illegal.newline.python" 2986 | } 2987 | }, 2988 | "patterns": [ 2989 | { 2990 | "include": "#double-three-regexp-expression" 2991 | }, 2992 | { 2993 | "include": "#comments-string-double-three" 2994 | } 2995 | ] 2996 | }, 2997 | "double-three-regexp-comments": { 2998 | "name": "comment.regexp", 2999 | "begin": "\\(\\?#", 3000 | "end": "(\\)|(?=\"\"\"))", 3001 | "beginCaptures": { 3002 | "0": { 3003 | "name": "punctuation.comment.begin.regexp" 3004 | } 3005 | }, 3006 | "endCaptures": { 3007 | "1": { 3008 | "name": "punctuation.comment.end.regexp" 3009 | }, 3010 | "2": { 3011 | "name": "invalid.illegal.newline.python" 3012 | } 3013 | }, 3014 | "patterns": [ 3015 | { 3016 | "include": "#codetags" 3017 | } 3018 | ] 3019 | }, 3020 | "double-three-regexp-lookahead": { 3021 | "begin": "(\\()\\?=", 3022 | "end": "(\\)|(?=\"\"\"))", 3023 | "beginCaptures": { 3024 | "0": { 3025 | "name": "keyword.operator.lookahead.regexp" 3026 | }, 3027 | "1": { 3028 | "name": "punctuation.parenthesis.lookahead.begin.regexp" 3029 | } 3030 | }, 3031 | "endCaptures": { 3032 | "1": { 3033 | "name": "keyword.operator.lookahead.regexp punctuation.parenthesis.lookahead.end.regexp" 3034 | }, 3035 | "2": { 3036 | "name": "invalid.illegal.newline.python" 3037 | } 3038 | }, 3039 | "patterns": [ 3040 | { 3041 | "include": "#double-three-regexp-expression" 3042 | }, 3043 | { 3044 | "include": "#comments-string-double-three" 3045 | } 3046 | ] 3047 | }, 3048 | "double-three-regexp-lookahead-negative": { 3049 | "begin": "(\\()\\?!", 3050 | "end": "(\\)|(?=\"\"\"))", 3051 | "beginCaptures": { 3052 | "0": { 3053 | "name": "keyword.operator.lookahead.negative.regexp" 3054 | }, 3055 | "1": { 3056 | "name": "punctuation.parenthesis.lookahead.begin.regexp" 3057 | } 3058 | }, 3059 | "endCaptures": { 3060 | "1": { 3061 | "name": "keyword.operator.lookahead.negative.regexp punctuation.parenthesis.lookahead.end.regexp" 3062 | }, 3063 | "2": { 3064 | "name": "invalid.illegal.newline.python" 3065 | } 3066 | }, 3067 | "patterns": [ 3068 | { 3069 | "include": "#double-three-regexp-expression" 3070 | }, 3071 | { 3072 | "include": "#comments-string-double-three" 3073 | } 3074 | ] 3075 | }, 3076 | "double-three-regexp-lookbehind": { 3077 | "begin": "(\\()\\?<=", 3078 | "end": "(\\)|(?=\"\"\"))", 3079 | "beginCaptures": { 3080 | "0": { 3081 | "name": "keyword.operator.lookbehind.regexp" 3082 | }, 3083 | "1": { 3084 | "name": "punctuation.parenthesis.lookbehind.begin.regexp" 3085 | } 3086 | }, 3087 | "endCaptures": { 3088 | "1": { 3089 | "name": "keyword.operator.lookbehind.regexp punctuation.parenthesis.lookbehind.end.regexp" 3090 | }, 3091 | "2": { 3092 | "name": "invalid.illegal.newline.python" 3093 | } 3094 | }, 3095 | "patterns": [ 3096 | { 3097 | "include": "#double-three-regexp-expression" 3098 | }, 3099 | { 3100 | "include": "#comments-string-double-three" 3101 | } 3102 | ] 3103 | }, 3104 | "double-three-regexp-lookbehind-negative": { 3105 | "begin": "(\\()\\?=^]? [-+ ]? \\#?\n \\d* ,? (\\.\\d+)? [bcdeEfFgGnosxX%]? )(?=})\n", 3864 | "captures": { 3865 | "1": { 3866 | "name": "storage.type.format.python" 3867 | }, 3868 | "2": { 3869 | "name": "storage.type.format.python" 3870 | } 3871 | } 3872 | }, 3873 | { 3874 | "include": "#fstring-terminator-single-tail" 3875 | } 3876 | ] 3877 | }, 3878 | "fstring-terminator-single-tail": { 3879 | "begin": "((?:=?)(?:![rsa])?)(:)(?=.*?{)", 3880 | "end": "(?=})|(?=\\n)", 3881 | "beginCaptures": { 3882 | "1": { 3883 | "name": "storage.type.format.python" 3884 | }, 3885 | "2": { 3886 | "name": "storage.type.format.python" 3887 | } 3888 | }, 3889 | "patterns": [ 3890 | { 3891 | "include": "#fstring-illegal-single-brace" 3892 | }, 3893 | { 3894 | "include": "#fstring-single-brace" 3895 | }, 3896 | { 3897 | "name": "storage.type.format.python", 3898 | "match": "([bcdeEfFgGnosxX%])(?=})" 3899 | }, 3900 | { 3901 | "name": "storage.type.format.python", 3902 | "match": "(\\.\\d+)" 3903 | }, 3904 | { 3905 | "name": "storage.type.format.python", 3906 | "match": "(,)" 3907 | }, 3908 | { 3909 | "name": "storage.type.format.python", 3910 | "match": "(\\d+)" 3911 | }, 3912 | { 3913 | "name": "storage.type.format.python", 3914 | "match": "(\\#)" 3915 | }, 3916 | { 3917 | "name": "storage.type.format.python", 3918 | "match": "([-+ ])" 3919 | }, 3920 | { 3921 | "name": "storage.type.format.python", 3922 | "match": "([<>=^])" 3923 | }, 3924 | { 3925 | "name": "storage.type.format.python", 3926 | "match": "(\\w)" 3927 | } 3928 | ] 3929 | }, 3930 | "fstring-fnorm-quoted-multi-line": { 3931 | "name": "meta.fstring.python", 3932 | "begin": "(\\b[fF])([bBuU])?('''|\"\"\")", 3933 | "end": "(\\3)", 3934 | "beginCaptures": { 3935 | "1": { 3936 | "name": "string.interpolated.python string.quoted.multi.python storage.type.string.python" 3937 | }, 3938 | "2": { 3939 | "name": "invalid.illegal.prefix.python" 3940 | }, 3941 | "3": { 3942 | "name": "punctuation.definition.string.begin.python string.interpolated.python string.quoted.multi.python" 3943 | } 3944 | }, 3945 | "endCaptures": { 3946 | "1": { 3947 | "name": "punctuation.definition.string.end.python string.interpolated.python string.quoted.multi.python" 3948 | }, 3949 | "2": { 3950 | "name": "invalid.illegal.newline.python" 3951 | } 3952 | }, 3953 | "patterns": [ 3954 | { 3955 | "include": "#fstring-guts" 3956 | }, 3957 | { 3958 | "include": "#fstring-illegal-multi-brace" 3959 | }, 3960 | { 3961 | "include": "#fstring-multi-brace" 3962 | }, 3963 | { 3964 | "include": "#fstring-multi-core" 3965 | } 3966 | ] 3967 | }, 3968 | "fstring-normf-quoted-multi-line": { 3969 | "name": "meta.fstring.python", 3970 | "begin": "(\\b[bBuU])([fF])('''|\"\"\")", 3971 | "end": "(\\3)", 3972 | "beginCaptures": { 3973 | "1": { 3974 | "name": "invalid.illegal.prefix.python" 3975 | }, 3976 | "2": { 3977 | "name": "string.interpolated.python string.quoted.multi.python storage.type.string.python" 3978 | }, 3979 | "3": { 3980 | "name": "punctuation.definition.string.begin.python string.quoted.multi.python" 3981 | } 3982 | }, 3983 | "endCaptures": { 3984 | "1": { 3985 | "name": "punctuation.definition.string.end.python string.interpolated.python string.quoted.multi.python" 3986 | }, 3987 | "2": { 3988 | "name": "invalid.illegal.newline.python" 3989 | } 3990 | }, 3991 | "patterns": [ 3992 | { 3993 | "include": "#fstring-guts" 3994 | }, 3995 | { 3996 | "include": "#fstring-illegal-multi-brace" 3997 | }, 3998 | { 3999 | "include": "#fstring-multi-brace" 4000 | }, 4001 | { 4002 | "include": "#fstring-multi-core" 4003 | } 4004 | ] 4005 | }, 4006 | "fstring-raw-quoted-multi-line": { 4007 | "name": "meta.fstring.python", 4008 | "begin": "(\\b(?:[rR][fF]|[fF][rR]))('''|\"\"\")", 4009 | "end": "(\\2)", 4010 | "beginCaptures": { 4011 | "1": { 4012 | "name": "string.interpolated.python string.quoted.raw.multi.python storage.type.string.python" 4013 | }, 4014 | "2": { 4015 | "name": "punctuation.definition.string.begin.python string.quoted.raw.multi.python" 4016 | } 4017 | }, 4018 | "endCaptures": { 4019 | "1": { 4020 | "name": "punctuation.definition.string.end.python string.interpolated.python string.quoted.raw.multi.python" 4021 | }, 4022 | "2": { 4023 | "name": "invalid.illegal.newline.python" 4024 | } 4025 | }, 4026 | "patterns": [ 4027 | { 4028 | "include": "#fstring-raw-guts" 4029 | }, 4030 | { 4031 | "include": "#fstring-illegal-multi-brace" 4032 | }, 4033 | { 4034 | "include": "#fstring-multi-brace" 4035 | }, 4036 | { 4037 | "include": "#fstring-raw-multi-core" 4038 | } 4039 | ] 4040 | }, 4041 | "fstring-multi-core": { 4042 | "name": "string.interpolated.python string.quoted.multi.python", 4043 | "match": "(?x)\n (.+?)\n (\n (?# .* and .*? in multi-line match need special handling of\n newlines otherwise SublimeText and Atom will match slightly\n differently.\n\n The guard for newlines has to be separate from the\n lookahead because of special $ matching rule.)\n ($\\n?)\n |\n (?=[\\\\\\}\\{]|'''|\"\"\")\n )\n (?# due to how multiline regexps are matched we need a special case\n for matching a newline character)\n | \\n\n" 4044 | }, 4045 | "fstring-raw-multi-core": { 4046 | "name": "string.interpolated.python string.quoted.raw.multi.python", 4047 | "match": "(?x)\n (.+?)\n (\n (?# .* and .*? in multi-line match need special handling of\n newlines otherwise SublimeText and Atom will match slightly\n differently.\n\n The guard for newlines has to be separate from the\n lookahead because of special $ matching rule.)\n ($\\n?)\n |\n (?=[\\\\\\}\\{]|'''|\"\"\")\n )\n (?# due to how multiline regexps are matched we need a special case\n for matching a newline character)\n | \\n\n" 4048 | }, 4049 | "fstring-multi-brace": { 4050 | "comment": "value interpolation using { ... }", 4051 | "begin": "(\\{)", 4052 | "end": "(?x)\n (\\})\n", 4053 | "beginCaptures": { 4054 | "1": { 4055 | "name": "constant.character.format.placeholder.other.python" 4056 | } 4057 | }, 4058 | "endCaptures": { 4059 | "1": { 4060 | "name": "constant.character.format.placeholder.other.python" 4061 | } 4062 | }, 4063 | "patterns": [ 4064 | { 4065 | "include": "#fstring-terminator-multi" 4066 | }, 4067 | { 4068 | "include": "#f-expression" 4069 | } 4070 | ] 4071 | }, 4072 | "fstring-terminator-multi": { 4073 | "patterns": [ 4074 | { 4075 | "name": "storage.type.format.python", 4076 | "match": "(=(![rsa])?)(?=})" 4077 | }, 4078 | { 4079 | "name": "storage.type.format.python", 4080 | "match": "(=?![rsa])(?=})" 4081 | }, 4082 | { 4083 | "match": "(?x)\n ( (?: =?) (?: ![rsa])? )\n ( : \\w? [<>=^]? [-+ ]? \\#?\n \\d* ,? (\\.\\d+)? [bcdeEfFgGnosxX%]? )(?=})\n", 4084 | "captures": { 4085 | "1": { 4086 | "name": "storage.type.format.python" 4087 | }, 4088 | "2": { 4089 | "name": "storage.type.format.python" 4090 | } 4091 | } 4092 | }, 4093 | { 4094 | "include": "#fstring-terminator-multi-tail" 4095 | } 4096 | ] 4097 | }, 4098 | "fstring-terminator-multi-tail": { 4099 | "begin": "((?:=?)(?:![rsa])?)(:)(?=.*?{)", 4100 | "end": "(?=})", 4101 | "beginCaptures": { 4102 | "1": { 4103 | "name": "storage.type.format.python" 4104 | }, 4105 | "2": { 4106 | "name": "storage.type.format.python" 4107 | } 4108 | }, 4109 | "patterns": [ 4110 | { 4111 | "include": "#fstring-illegal-multi-brace" 4112 | }, 4113 | { 4114 | "include": "#fstring-multi-brace" 4115 | }, 4116 | { 4117 | "name": "storage.type.format.python", 4118 | "match": "([bcdeEfFgGnosxX%])(?=})" 4119 | }, 4120 | { 4121 | "name": "storage.type.format.python", 4122 | "match": "(\\.\\d+)" 4123 | }, 4124 | { 4125 | "name": "storage.type.format.python", 4126 | "match": "(,)" 4127 | }, 4128 | { 4129 | "name": "storage.type.format.python", 4130 | "match": "(\\d+)" 4131 | }, 4132 | { 4133 | "name": "storage.type.format.python", 4134 | "match": "(\\#)" 4135 | }, 4136 | { 4137 | "name": "storage.type.format.python", 4138 | "match": "([-+ ])" 4139 | }, 4140 | { 4141 | "name": "storage.type.format.python", 4142 | "match": "([<>=^])" 4143 | }, 4144 | { 4145 | "name": "storage.type.format.python", 4146 | "match": "(\\w)" 4147 | } 4148 | ] 4149 | } 4150 | } 4151 | } 4152 | --------------------------------------------------------------------------------