Skip to content

Commit 50093bb

Browse files
committed
Inline JSON parser
1 parent d4e8226 commit 50093bb

File tree

1 file changed

+188
-1
lines changed

1 file changed

+188
-1
lines changed

src/typescript/Scala.tmLanguage.ts

Lines changed: 188 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ export const scalaTmLanguage: TmLanguage = {
416416
},
417417
patterns: [
418418
{
419-
"include": "source.json"
419+
"include": "#json-value"
420420
},
421421
],
422422
endCaptures: {
@@ -1417,6 +1417,193 @@ export const scalaTmLanguage: TmLanguage = {
14171417
include: '#xml-entity'
14181418
}
14191419
]
1420+
},
1421+
// inspired by https://github.com/microsoft/vscode-JSON.tmLanguage/blob/main/JSON.tmLanguage
1422+
'json-array': {
1423+
begin: '\\[',
1424+
end: '\\]',
1425+
beginCaptures: {
1426+
0: {
1427+
name: 'punctuation.definition.array.begin.json'
1428+
}
1429+
},
1430+
endCaptures: {
1431+
0: {
1432+
name: 'punctuation.definition.array.end.json'
1433+
}
1434+
},
1435+
name: "meta.structure.array.json",
1436+
patterns: [
1437+
{
1438+
include: '#json-value'
1439+
},
1440+
{
1441+
match: ',',
1442+
name: 'punctuation.separator.array.json'
1443+
},
1444+
{
1445+
match: '[^\\s\\]]',
1446+
name: 'invalid.illegal.expected-array-separator.json'
1447+
}
1448+
]
1449+
},
1450+
'json-comment': {
1451+
patterns: [
1452+
{
1453+
begin: '/\\\*\\\*(?!/)',
1454+
end: '\\\*/',
1455+
captures: {
1456+
0: {
1457+
name: 'punctuation.definition.comment.json'
1458+
}
1459+
},
1460+
name: 'comment.block.documentation.json'
1461+
},
1462+
{
1463+
begin: '/\\\*',
1464+
end: '\\\*/',
1465+
captures: {
1466+
0: {
1467+
name: 'punctuation.definition.comment.json'
1468+
}
1469+
},
1470+
name: 'comment.block.json'
1471+
},
1472+
]
1473+
},
1474+
'json-constant': {
1475+
match: '\\b(?:true|false|null)\\b',
1476+
name: 'constant.language.json'
1477+
},
1478+
'json-number': {
1479+
//match: '(?:\\d*)',
1480+
match: '-?(?:0|[1-9]\\d*)(?:(?:\\.\\d+)?(?:[eE][+-]?\\d+)?)?', // see the original for explanation
1481+
name: 'constant.numeric.json'
1482+
},
1483+
'json-object': {
1484+
begin: '\\{',
1485+
beginCaptures: {
1486+
0: {
1487+
name: 'punctuation.definition.dictionary.begin.json'
1488+
}
1489+
},
1490+
end: '\\}',
1491+
endCaptures: {
1492+
0: {
1493+
name: 'punctuation.definition.dictionary.end.json'
1494+
}
1495+
},
1496+
name: 'meta.structure.dictionary.json',
1497+
patterns: [
1498+
{
1499+
include: '#json-objectkey'
1500+
},
1501+
{
1502+
include: '#json-comment'
1503+
},
1504+
{
1505+
begin: ':',
1506+
beginCaptures: {
1507+
0: {
1508+
name: 'punctuation.separator.dictionary.key-value.json'
1509+
}
1510+
},
1511+
end: '(,)|(?=\\})',
1512+
endCaptures: {
1513+
1: {
1514+
name: 'punctuation.separator.dictionary.pair.json'
1515+
}
1516+
},
1517+
name: 'meta.structure.dictionary.value.json',
1518+
patterns: [
1519+
{
1520+
include: '#json-value'
1521+
},
1522+
{
1523+
match: '[^\\s,]',
1524+
name: 'invalid.illegal.expected-dictionary-separator.json'
1525+
}
1526+
]
1527+
},
1528+
{
1529+
match: '[^\\s\\}]',
1530+
name: 'invalid.illegal.expected-dictionary-separator.json'
1531+
}
1532+
]
1533+
},
1534+
'json-string': {
1535+
begin: '"',
1536+
beginCaptures: {
1537+
0: {
1538+
name: 'punctuation.definition.string.begin.json'
1539+
}
1540+
},
1541+
end: '"',
1542+
endCaptures: {
1543+
0: {
1544+
name: 'punctuation.definition.string.end.json'
1545+
}
1546+
},
1547+
name: 'string.quoted.double.json',
1548+
patterns: [
1549+
{
1550+
include: '#json-stringcontent'
1551+
}
1552+
]
1553+
},
1554+
'json-objectkey': {
1555+
begin: '"',
1556+
beginCaptures: {
1557+
0: {
1558+
name: 'punctuation.support.type.property-name.begin.json'
1559+
}
1560+
},
1561+
end: '"',
1562+
endCaptures: {
1563+
0: {
1564+
name: 'punctuation.support.type.property-name.end.json'
1565+
}
1566+
},
1567+
name: 'string.json support.type.property-name.json',
1568+
patterns: [
1569+
{
1570+
include: '#json-stringcontent'
1571+
}
1572+
]
1573+
},
1574+
'json-stringcontent': {
1575+
patterns: [
1576+
{
1577+
match: '(?x)\\\\(?:["\\\\/bfnrt]|u[0-9a-fA-F]{4})',
1578+
name: 'constant.character.escape.json'
1579+
},
1580+
{
1581+
match: '\\\\.',
1582+
name: 'invalid.illegal.unrecognized-string-escape.json'
1583+
}
1584+
]
1585+
},
1586+
'json-value': {
1587+
patterns: [
1588+
{
1589+
include: '#json-constant'
1590+
},
1591+
{
1592+
include: '#json-number'
1593+
},
1594+
{
1595+
include: '#json-string'
1596+
},
1597+
{
1598+
include: '#json-array'
1599+
},
1600+
{
1601+
include: '#json-object'
1602+
},
1603+
{
1604+
include: '#json-comment'
1605+
},
1606+
]
14201607
}
14211608
},
14221609
uuid: '158C0929-299A-40C8-8D89-316BE0C446E8',

0 commit comments

Comments
 (0)